Skip to content

Represent explicit expression braces in parsetree v1 - #8678

Open
cknitt wants to merge 5 commits into
codex/switch-case-bracesfrom
codex/pexp-braces
Open

cknitt wants to merge 5 commits into
codex/switch-case-bracesfrom
codex/pexp-braces

Conversation

@cknitt

@cknitt cknitt commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Refs #8624

Summary

  • Add Pexp_braces with a separate delimiter location and use it throughout the parser, printer, type checker, editor analysis, and AST visitors.
  • Keep res.braces/ns.braces compatibility decoding and encoding in the frozen v0 AST bridge.
  • Make else formatting follow the same brace handling as if, and preserve multiline pipe formatting when comments precede a braced JSX value.
  • Add AST bridge tests and refresh syntax snapshots, including explicit braces in the diagnostic ML printer.

Tests

  • make test
  • make test-syntax
  • make test-syntax-roundtrip
  • make test-analysis

Stacked on #8677.

@cknitt
cknitt added this pull request to stack #8679 September 26, 2026 06:13
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt marked this pull request as ready for review September 26, 2026 06:37

@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: 6710020aa7

ℹ️ 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".

Comment thread compiler/syntax/src/res_printer.ml Outdated
Comment thread compiler/ml/typecore.ml Outdated
@pkg-pr-new

pkg-pr-new Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 792a549

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.98077% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.58%. Comparing base (73a7957) to head (792a549).

Files with missing lines Patch % Lines
compiler/syntax/src/res_parsetree_viewer.ml 63.15% 7 Missing ⚠️
compiler/syntax/src/res_core.ml 78.94% 4 Missing ⚠️
compiler/ml/printast.ml 0.00% 3 Missing ⚠️
analysis/src/completion_front_end.ml 88.88% 2 Missing ⚠️
compiler/ml/ast_mapper_from0.ml 88.23% 2 Missing ⚠️
compiler/syntax/src/res_parens.ml 92.00% 2 Missing ⚠️
compiler/syntax/src/res_printer.ml 93.93% 2 Missing ⚠️
analysis/src/utils.ml 0.00% 1 Missing ⚠️
compiler/ml/typecore.ml 83.33% 1 Missing ⚠️
tests/ounit_tests/ounit_ast_mapper0_tests.ml 96.00% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           codex/switch-case-braces    #8678   +/-   ##
=========================================================
  Coverage                     78.57%   78.58%           
=========================================================
  Files                           476      476           
  Lines                         64157    64245   +88     
=========================================================
+ Hits                          50414    50484   +70     
- Misses                        13743    13761   +18     
Files with missing lines Coverage Δ
analysis/src/completion_expressions.ml 85.32% <100.00%> (ø)
analysis/src/xform.ml 88.35% <100.00%> (+0.08%) ⬆️
compiler/frontend/ast_open_cxt.ml 100.00% <100.00%> (ø)
compiler/frontend/bs_builtin_ppx.ml 91.34% <100.00%> (+0.03%) ⬆️
compiler/ml/ast_helper.ml 80.86% <100.00%> (+0.13%) ⬆️
compiler/ml/ast_iterator.ml 93.87% <100.00%> (+0.03%) ⬆️
compiler/ml/ast_mapper.ml 77.63% <100.00%> (+0.14%) ⬆️
compiler/ml/ast_mapper_to0.ml 71.37% <100.00%> (+0.17%) ⬆️
compiler/ml/depend.ml 83.28% <100.00%> (+0.05%) ⬆️
compiler/ml/pprintast.ml 91.30% <100.00%> (+0.01%) ⬆️
... and 13 more

... and 2 files with indirect coverage changes

🚀 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.

Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: eaa2818c1e

ℹ️ 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".

Comment thread compiler/ml/parsetree.ml
Comment thread analysis/src/completion_front_end.ml
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

@codex review

@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: 792a5491dc

ℹ️ 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".

Comment on lines +432 to +433
| {pexp_desc = Pexp_braces {expr = inner}} ->
spelunk_for_fun_expression inner

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 Preserve async status when unwrapping component braces

When an async component uses explicit outer braces, such as @react.component let make = {async (~x) => ...}, this branch unwraps it for function discovery, but is_async at jsx_v4.ml:605 still probes the original binding.pvb_expr. Ast_async.dig_async_payload_from_function returns false for Pexp_braces, so the rewritten implementation becomes non-async and its component wrapper omits Jsx.promise. Fresh evidence beyond the earlier JSX finding is this unchanged async probe; unwrap the expression for async detection as well.

AGENTS.md reference: AGENTS.md:L53-L53

Useful? React with 👍 / 👎.

Comment thread compiler/ml/typecore.ml
Comment on lines +2463 to +2467
| Pexp_braces {expr = inner} ->
let exp =
type_expect ~context ?deprecated_context ~recarg env inner ty_expected
in
{exp with exp_attributes = sexp.pexp_attributes @ exp.exp_attributes}

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 Forward frontend decorators through brace wrappers

When a transform-sensitive decorator precedes a braced function, for example let f = @this {(self, x) => ...}, the decorator now resides on the Pexp_braces wrapper. bs_builtin_ppx.expr_mapper only recognizes @this while matching a Pexp_fun, and its default traversal reaches the inner function without forwarding the wrapper attributes; copying them onto the typed expression here happens after frontend transformation, so the method callback is emitted as an ordinary function with incorrect this behavior. Handle brace wrappers in the frontend mapper or forward applicable attributes before visiting the inner expression.

AGENTS.md reference: compiler/AGENTS.md:L24-L31

Useful? React with 👍 / 👎.

Comment thread compiler/ml/parsetree.ml
}

and expression_desc =
| Pexp_braces of {expr: expression; braces_loc: Location.t}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update editor binding classifiers for braced expressions

Introducing this wrapper changes every explicitly braced binding's top-level descriptor, but the editor classifiers still inspect that descriptor directly. For example, analysis/src/document_symbol.ml:18-21 now reports let f = {x => x} as a variable rather than a function, while analysis/src/hint.ml:120-129 omits its function code lens (and the analogous inlay-hint match also skips braced values). Unwrap Pexp_braces in these binding classifiers and add analysis coverage beyond completion.

AGENTS.md reference: AGENTS.md:L104-L109

Useful? React with 👍 / 👎.

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.

1 participant