Skip to content

Remove parser modes - #8610

Open
cknitt wants to merge 40 commits into
rescript-lang:masterfrom
cknitt:codex/remove-parser-mode
Open

Remove parser modes#8610
cknitt wants to merge 40 commits into
rescript-lang:masterfrom
cknitt:codex/remove-parser-mode

Conversation

@cknitt

@cknitt cknitt commented Sep 3, 2026

Copy link
Copy Markdown
Member

Motivation

The parser previously had two modes:

type mode = ParseForTypeChecker | Default

These produced different trees for printing and type checking. The printer needed to preserve constructor argument grouping and parentheses, while the type-checker representation collapsed those distinctions.

The modes also handled differences in string-literal representation. [#8606](#8606) unified that representation and was the first step toward removing the modes. Constructor argument grouping was the main remaining obstacle.

This PR replaces the two representations with one source-preserving parsetree, while retaining existing source and PPX compatibility.

Source syntax and semantic arity

Constructor expressions and patterns now carry located argument lists:

Pexp_construct of Longident.t loc * expression list loc
Ppat_construct of Longident.t loc * pattern list loc

The same approach applies to polymorphic variant expressions, patterns, and type payload groups.

These lists describe what was written, not the constructor’s declared arity. For example, omitting locations:

C(x, y)   → [x; y]
C((x, y)) → [Pexp_tuple [x; y]]

The printer can preserve either spelling. Once the type checker resolves an ordinary constructor’s declaration, it normalizes the arguments accordingly: unpacking a tuple for a multi-argument constructor or packing multiple syntactic arguments into a single tuple payload.

Existing spellings such as Some(x, y) and Some((x, y)) therefore remain supported. This does not introduce stricter arity rules or require source migration.

Normalization happens within the existing type-checking flow, without an additional AST pass. Ordinary constructors continue into the typedtree as semantic argument lists; polymorphic variants retain their optional single-payload representation. No typedtree or later-layer representation changes are needed.

Argument locations

Argument lists carry their own source span, including the surrounding parentheses. Consumers no longer need to reconstruct that span from individual arguments or encode it in attributes.

This simplifies printing and comment handling and fixes constructor signature help appearing in whitespace or comments between the constructor name and its arguments. Signature help now uses the argument-list boundaries.

Cleanup

The unified representation removes:

  • ParseForTypeChecker and Default
  • for_printer parameters and the developer-only -typechecker parser flag
  • mode-dependent tuple wrapping in the parser
  • redundant tuple unpacking and source-shape reconstruction in printers, traversals, and editor tooling

It also consolidates constructor argument parsing and printing, makes AST helpers accept located argument lists directly, and confines legacy explicit-arity attribute handling to the AST0 compatibility boundary.

PPX compatibility

The frozen parsetree0 representation remains unchanged.

The bridge encodes multiple syntactic arguments as a tuple with internal _res.constructor_args metadata. Conversion back consumes that metadata and restores the argument list. A single tuple argument needs no marker.

Unmarked tuples generated by existing PPXs remain supported: their semantic grouping is resolved during type checking. Legacy explicit_arity and ocaml.explicit_arity attributes are handled at the bridge boundary.

Multi-argument locations survive through the encoded tuple. Where AST0 cannot represent a separate outer argument-list span for a single payload, conversion falls back to the payload’s location.

Testing

Coverage includes constructor and polymorphic variant expressions, patterns, and type payloads; tuple grouping compatibility; arity diagnostics; AST0 round trips and legacy PPX output; argument locations and parser recovery; printing and comment preservation; signature-help boundaries; and end-to-end compilation and runtime behavior.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T20:21:16.942816Z 425e204 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

ℹ️ 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/ast_mapper_from0.ml
Comment thread compiler/ml/typecore.ml
Comment thread compiler/syntax/src/res_comments_table.ml Outdated
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.81838% with 110 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.55%. Comparing base (0aa58d8) to head (425e204).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
tests/ounit_tests/ounit_ast_mapper0_tests.ml 89.02% 26 Missing ⚠️
analysis/src/dump_ast.ml 0.00% 12 Missing ⚠️
analysis/src/type_utils.ml 77.77% 12 Missing ⚠️
compiler/ml/printast.ml 0.00% 11 Missing ⚠️
...s/ounit_tests/ounit_constructor_arguments_tests.ml 86.30% 10 Missing ⚠️
compiler/ml/ast_mapper.ml 81.81% 4 Missing ⚠️
compiler/ml/typecore.ml 89.74% 4 Missing ⚠️
compiler/syntax/src/res_core.ml 90.24% 4 Missing ⚠️
compiler/frontend/bs_builtin_ppx.ml 66.66% 3 Missing ⚠️
compiler/ml/ast_helper.ml 57.14% 3 Missing ⚠️
... and 14 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8610      +/-   ##
==========================================
+ Coverage   77.38%   77.55%   +0.17%     
==========================================
  Files         474      475       +1     
  Lines       63524    63851     +327     
==========================================
+ Hits        49156    49518     +362     
+ Misses      14368    14333      -35     
Files with missing lines Coverage Δ
analysis/src/codemod.ml 68.96% <ø> (ø)
analysis/src/commands.ml 63.82% <ø> (ø)
analysis/src/completion_expressions.ml 85.45% <100.00%> (+5.60%) ⬆️
analysis/src/completion_patterns.ml 86.59% <100.00%> (-1.13%) ⬇️
analysis/src/diagnostics.ml 75.00% <ø> (ø)
analysis/src/hint.ml 75.00% <100.00%> (ø)
analysis/src/process_attributes.ml 83.78% <100.00%> (ø)
analysis/src/shared_types.ml 70.42% <ø> (ø)
analysis/src/xform.ml 88.26% <100.00%> (+0.25%) ⬆️
compiler/bsc/rescript_compiler_main.ml 71.49% <ø> (ø)
... and 45 more

... and 4 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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 425e204

@cknitt

cknitt commented Sep 3, 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: b374049de4

ℹ️ 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/ext/config.ml Outdated
@cknitt
cknitt requested a review from cristianoc September 3, 2026 19:16
@cknitt

cknitt commented Sep 4, 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: cbf4a97d54

ℹ️ 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/ast_mapper_to0.ml Outdated
Comment thread analysis/src/signature_help.ml Outdated

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what happens in the bridge should stat in the bridge: ast should be restored and any encoding trick should be gone and not leaked in to the type checker

Comment thread compiler/ml/ast_mapper_to0.ml Outdated
cknitt added a commit to cknitt/rescript that referenced this pull request Sep 4, 2026
Apply the normalization approach proposed by @cristianoc in PR rescript-lang#8610. Keep source argument lists for printing and resolve semantic grouping after constructor disambiguation, without legacy PPX marker handling in the type checker or printer.

Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the codex/remove-parser-mode branch from cbf4a97 to a6d5edc Compare September 4, 2026 16:00
@cknitt

cknitt commented Sep 4, 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: a6d5edc346

ℹ️ 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 analysis/src/completion_expressions.ml
Comment thread analysis/src/signature_help.ml Outdated
@cknitt cknitt changed the title Remove parser modes by encoding constructor arity explicitly Remove parser modes Sep 4, 2026
@cknitt

cknitt commented Sep 4, 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: cc3063c7aa

ℹ️ 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/ast_mapper_to0.ml Outdated
@cknitt

cknitt commented Sep 5, 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: 3ed6059854

ℹ️ 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/ast_mapper_from0.ml
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
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 force-pushed the codex/remove-parser-mode branch from 6d16043 to 045c62d Compare September 5, 2026 16:59
@cknitt

cknitt commented Sep 5, 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: 045c62d6f4

ℹ️ 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 analysis/src/type_utils.ml
Comment thread analysis/src/type_utils.ml
Comment thread analysis/src/completion_expressions.ml Outdated
Comment thread analysis/src/signature_help.ml Outdated
Signed-off-by: Christoph Knittel <ck@cca.io>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Sep 5, 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: 531a5fd63b

ℹ️ 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/ast_mapper_from0.ml
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the codex/remove-parser-mode branch from a7a9475 to 425e204 Compare September 5, 2026 18:47
@cknitt

cknitt commented Sep 5, 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: 425e204de8

ℹ️ 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 +212 to +214
match tuple_args arg with
| Some args when split_tuple -> List.map map args
| _ -> [map arg])

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 Preserve attributes on marked constructor payload tuples

When a v0 PPX adds an attribute to the synthesized tuple for a marked multi-argument constructor or polymorphic-variant expression/pattern, this branch unwraps the tuple by mapping only its children, silently discarding the tuple's pexp_attributes or ppat_attributes. This breaks chained PPXs that communicate through payload attributes; as with the type-payload handling, keep an attributed tuple wrapper while consuming _res.constructor_args.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

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