Skip to content

Move the v0 AST and its bridge into their own library - #9365

Draft
cknitt wants to merge 1 commit into
masterfrom
ast0-library
Draft

cknitt wants to merge 1 commit into
masterfrom
ast0-library

Conversation

@cknitt

@cknitt cknitt commented Nov 21, 2026

Copy link
Copy Markdown
Member

External PPXes read and write a frozen AST, Parsetree0. It and the code that translates between it and the current parsetree were spread over compiler/ml and ext. This PR moves them into one compiler library, ast0 in compiler/ast0, so the frozen format and its bridge have one home, and the rule "never change Parsetree0" covers one directory.

  • Parsetree0, Ast_helper0, Ast_mapper_to0, Ast_mapper_from0 and Ast_dict0 move from compiler/ml. Module names stay the same.
  • extension_of_error moves back from Builtin_attributes into Ast_mapper_from0, its only user.
  • The v0 wire magic numbers move from Config (ext) to a new Ast0_magic. ext has nothing v0-specific left.
  • ast0 sits above ml and needs ml and flow_parser. Nothing in ml uses the v0 modules. Its users list it in their dune files: common (Ml_binary), core (Cmd_ppx_apply), the res_parser CLI, tools/bin and the unit tests.
  • compiler/AGENTS.md, compiler/syntax/README.md and the dead-code script, which exempts parsetree0.ml by path, name the new paths.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

The frozen Parsetree0 that external PPXes read and write, and the code that
translates between it and the current parsetree, were spread over ml and ext.
They now form one compiler library, ast0 in compiler/ast0: Parsetree0,
Ast_helper0, Ast_mapper_to0, Ast_mapper_from0 and Ast_dict0 move from ml,
extension_of_error moves back from Builtin_attributes into Ast_mapper_from0,
its only user, and the v0 magic numbers move from Config to a new Ast0_magic.
Module names stay the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Move the frozen v0 AST for PPXes and its bridge to the current parsetree into their own compiler library, ast0.

Semantic Diff

1 commit · Full page

Move the v0 AST and its bridge into their own library

d64227f · cknitt + Claude · Nov 21, 2026, 10:21 UTC

The frozen Parsetree0 that external PPXes read and write, and the code that translates between it and the current parsetree, were spread over ml and ext. They now form one compiler library, ast0 in compiler/ast0: Parsetree0, Ast_helper0, Ast_mapper_to0, Ast_mapper_from0 and Ast_dict0 move from ml, extension_of_error moves back from Builtin_attributes into Ast_mapper_from0, its only user, and the v0 magic numbers move from Config to a new Ast0_magic. Module names stay the same.

@github-actions

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 636,549,959 → 636,549,921 (±0.00%).

Generated projects: 629,016,819 → 629,017,360 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 9,223,229,365 → 9,224,323,260 (+0.01%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,457,139 21,494,482 +0.17%
packages/@rescript/runtime/Stdlib_List.resi 24,669,625 24,707,982 +0.16%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,680,137 25,715,862 +0.14%
parse/RedBlackTree.res 14,988,776 15,009,157 +0.14%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,351,234 31,393,536 +0.13%
packages/@rescript/runtime/Stdlib_String.resi 29,604,131 29,642,469 +0.13%
packages/@rescript/belt/src/Belt_Array.resi 33,852,138 33,894,733 +0.13%
parse/RedBlackTreeNoComments.res 14,562,467 14,580,658 +0.12%
packages/@rescript/runtime/JsxDOM.res 117,246,011 117,375,222 +0.11%

Output size

In total: 25,969,532 → 25,969,532 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request d64227f compared with base caa6dd2 in this run.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.20%. Comparing base (caa6dd2) to head (d64227f).

Files with missing lines Patch % Lines
compiler/ast0/ast_mapper_from0.ml 87.50% 1 Missing ⚠️
compiler/common/ml_binary.ml 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9365      +/-   ##
==========================================
- Coverage   82.20%   82.20%   -0.01%     
==========================================
  Files         462      462              
  Lines       65763    65762       -1     
==========================================
- Hits        54058    54057       -1     
  Misses      11705    11705              
Files with missing lines Coverage Δ
compiler/ast0/ast_dict0.ml 100.00% <ø> (ø)
compiler/ast0/ast_helper0.ml 62.91% <ø> (ø)
compiler/ast0/ast_mapper_to0.ml 80.36% <ø> (ø)
compiler/ast0/parsetree0.ml 100.00% <ø> (ø)
compiler/ext/config.ml 100.00% <ø> (ø)
compiler/ml/builtin_attributes.ml 83.67% <ø> (-0.14%) ⬇️
tests/ounit_tests/ounit_ast_mapper0_tests.ml 90.58% <100.00%> (ø)
tools/bin/main.ml 41.50% <100.00%> (-0.55%) ⬇️
compiler/ast0/ast_mapper_from0.ml 79.51% <87.50%> (ø)
compiler/common/ml_binary.ml 42.85% <50.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9365

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9365

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9365

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9365

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9365

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9365

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9365

commit: d64227f

@github-actions

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants