Skip to content

Delete Bs_ast_mapper, keeping Ast_mapper at upstream shape - #8578

Open
cristianoc wants to merge 1 commit into
masterfrom
cleanup/fold-bs-ast-mapper
Open

Delete Bs_ast_mapper, keeping Ast_mapper at upstream shape#8578
cristianoc wants to merge 1 commit into
masterfrom
cleanup/fold-bs-ast-mapper

Conversation

@cristianoc

Copy link
Copy Markdown
Collaborator

Follow-up cleanup from the n-ary functions series (#8557); the frontend-veneer sweep it deferred.

What

Bs_ast_mapper was a 600-line mechanical fork of the vendored Ast_mapper whose entire delta — still delimited by fossilized cppo (* #if *) comments — was three group-level hooks: type_declaration_list, value_bindings, value_bindings_rec. Only value_bindings ever had a client (tuple/module-record pattern flattening for non-recursive lets); the other two were never overridden by anything. Meanwhile the fork had drifted: it dropped ~loc/~attrs when rebuilding JSX fragments and did not remap JSX element-name locations. Every parsetree change paid the duplication tax twice (three times in August alone during the n-ary series).

Rather than folding hooks into Ast_mapper, this keeps it byte-identical to its upstream shape and moves the one real behavior into the client: bs_builtin_ppx's default_expr_mapper is now a thin wrapper that flattens non-recursive Pexp_let groups before delegating, so every fallback in expr_mapper inherits the flattening uniformly, and structure_item_mapper handles Pstr_value (Nonrecursive, _) the same way. Recursive groups map per binding — their patterns are restricted to variables (Illegal_letrec_pat), so group rewrites do not apply.

The fallback-uniformity point is load-bearing and corpus-guarded: hello_res.res's nested let {length: l, add} = module(List) reaches the flattener only through a specialized case's fallback — an intermediate version of this change that flattened in a match case instead failed exactly there.

Riders

  • Ast_typ_uncurry (one function, one consumer, curried-era name) inlined into ast_core_type_class_type and deleted.
  • ast_external_mk's four hand-rolled expression/structure/module-expr record towers replaced with Ast_helper constructors.
  • ast_tdcls's two dead-hook accessor calls replaced with plain List.map.

Verification

Generated output is byte-identical across the full test suite (make test, analysis suites, zero snapshot or expectation changes); formatting green. Not user-facing, so no CHANGELOG entry.

🤖 Generated with Claude Code

Bs_ast_mapper was a 600-line mechanical fork of the vendored Ast_mapper
whose entire delta - still delimited by fossilized cppo (* #if *)
comments - was three group-level hooks: type_declaration_list,
value_bindings, and value_bindings_rec. Only value_bindings ever had a
client (tuple/module-record pattern flattening for non-recursive lets);
the other two were never overridden by anything. Meanwhile the fork had
drifted: it dropped ~loc/~attrs when rebuilding JSX fragments and did
not remap JSX element-name locations. Every parsetree change paid the
duplication tax twice.

Rather than folding hooks into Ast_mapper, keep it byte-identical to
its upstream shape and move the one real behavior into the client:
bs_builtin_ppx's default_expr_mapper is now a thin wrapper that
flattens non-recursive Pexp_let groups before delegating, so every
fallback in expr_mapper inherits the flattening uniformly (hello_res's
nested [let {length: l, add} = module(List)] reaches it only through a
fallback and pins this), and structure_item_mapper handles
Pstr_value(Nonrecursive) the same way. Recursive groups map per
binding - their patterns are restricted to variables, so group
rewrites do not apply.

Also: inline Ast_typ_uncurry's one function into its one consumer and
delete the module; replace ast_external_mk's hand-rolled expression,
structure, and module-expr records with Ast_helper constructors;
replace ast_tdcls's two dead-hook accessor calls with plain List.map.

Generated output is byte-identical across the test suite.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a608f64ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Bs_ast_invariant.warn_discarded_unused_attributes attrs

type mapper = Bs_ast_mapper.mapper
type mapper = Ast_mapper.mapper

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required DCO sign-off

The reviewed commit message has no Signed-off-by: trailer, so it does not meet this repository's mandatory DCO commit standard. Add a sign-off using the commit author's name and email before merging.

AGENTS.md reference: AGENTS.md:L275-L277

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.93%. Comparing base (cf8dd8c) to head (0a608f6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8578      +/-   ##
==========================================
- Coverage   75.95%   75.93%   -0.02%     
==========================================
  Files         474      472       -2     
  Lines       62905    62608     -297     
==========================================
- Hits        47779    47541     -238     
+ Misses      15126    15067      -59     
Files with missing lines Coverage Δ
compiler/frontend/ast_core_type_class_type.ml 76.08% <100.00%> (+1.66%) ⬆️
compiler/frontend/ast_exp_apply.ml 79.66% <ø> (ø)
compiler/frontend/ast_exp_extension.ml 95.83% <ø> (ø)
compiler/frontend/ast_external.ml 76.19% <ø> (ø)
compiler/frontend/ast_external_mk.ml 100.00% <100.00%> (ø)
compiler/frontend/ast_tdcls.ml 100.00% <100.00%> (ø)
compiler/frontend/ast_tuple_pattern_flatten.ml 96.87% <ø> (ø)
compiler/frontend/ast_uncurry_gen.ml 95.23% <ø> (ø)
compiler/frontend/ast_util.ml 88.88% <ø> (ø)
compiler/frontend/bs_builtin_ppx.ml 90.90% <100.00%> (+0.28%) ⬆️
🚀 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 Aug 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8578

@rescript/belt

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/belt@8578

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8578

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8578

@rescript/win32-x64

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

commit: 0a608f6

@github-actions

Copy link
Copy Markdown

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.

1 participant