Skip to content

destructure record rest elements#8317

Open
tsnobip wants to merge 30 commits into
masterfrom
fix-8311
Open

destructure record rest elements#8317
tsnobip wants to merge 30 commits into
masterfrom
fix-8311

Conversation

@tsnobip

@tsnobip tsnobip commented Mar 28, 2026

Copy link
Copy Markdown
Member

fixes #8311

@tsnobip tsnobip changed the title destructure record rest elements - fixes #8311 destructure record rest elements Mar 28, 2026
@pkg-pr-new

pkg-pr-new Bot commented Mar 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 95022a9

@tsnobip tsnobip force-pushed the fix-8311 branch 2 times, most recently from 536855c to 2245765 Compare March 31, 2026 10:50
@tsnobip tsnobip marked this pull request as ready for review March 31, 2026 10:51
Comment thread compiler/ml/ast_mapper_to0.ml Outdated
construct ~loc ~attrs (map_loc sub l) (map_opt (sub.pat sub) p)
| Ppat_variant (l, p) -> variant ~loc ~attrs l (map_opt (sub.pat sub) p)
| Ppat_record (lpl, cf) ->
| Ppat_record (lpl, cf, _rest) ->

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure about what should be done here

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.

good question: it goes to ast0 and then back during ppx, so any use of a ppx would discard this at the moment, and change the code

normally, one tries to encode additional ast information in special annotations, so they can be recovered on the way back (from_0)

@cknitt

cknitt commented Mar 31, 2026

Copy link
Copy Markdown
Member

@codex review

@cknitt cknitt requested a review from cristianoc March 31, 2026 11:29

@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: 224576540e

ℹ️ 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/matching.ml Outdated
Comment on lines +2747 to +2748
match pat.pat_desc with
| Tpat_record (_, _, Some rest) ->

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 Bind rest variables in nested record patterns

inject_record_rest_binding only handles cases where the top-level pattern is Tpat_record (_, _, Some rest). When a record-rest appears inside another pattern shape (for example a tuple, constructor, or-or pattern), no Precord_spread_new binding is emitted even though typing has already introduced rest as a bound identifier. This causes incorrect code generation for valid nested destructuring forms because the rest variable is referenced without being initialized from the matched record.

Useful? React with 👍 / 👎.

Comment thread compiler/ml/depend.ml Outdated
Comment on lines 186 to 189
| Ppat_record (pl, _, _rest) ->
List.iter
(fun {lid = lbl; x = p} ->
add bv lbl;

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 Track dependencies from record-rest annotations

The dependency walker now matches Ppat_record (pl, _, _rest) but never visits _rest. As a result, module/type paths used only in record-rest annotations (e.g. ...M.t as rest) are omitted from dependency collection, so changing those modules may not trigger recompilation or proper dependency invalidation.

Useful? React with 👍 / 👎.

Comment thread compiler/syntax/src/res_core.ml Outdated
Comment on lines +1552 to +1553
| PatRest rest_pat -> (fields, flag, Some rest_pat)
| PatUnderscore -> (fields, flag, rest))

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 Reject duplicate record-rest clauses during parsing

parse_record_pattern stores rest as Some rest_pat every time it sees PatRest and does not check whether a previous rest was already parsed. This lets patterns with multiple rest clauses be accepted while silently discarding one clause, which is ambiguous and can mask user mistakes instead of producing a syntax error.

Useful? React with 👍 / 👎.

@tsnobip

tsnobip commented Apr 1, 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: f835e3f28e

ℹ️ 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/typecore.ml Outdated
Comment on lines +1622 to +1625
let rest_field_names =
List.map
(fun (l : Types.label_declaration) -> Ident.name l.ld_id)
rest_labels

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 Check rest record field types, not just field names

The new rest-pattern validation only compares field names (rest_field_names) and never unifies the rest type’s field types with the source record’s field types. That lets incompatible rest annotations type-check (for example, source b: string with rest type b: int), so rest.b is typed incorrectly and can break soundness at runtime.

Useful? React with 👍 / 👎.

Comment thread compiler/ml/matching.ml Outdated
simplify ((p :: patl, bind Alias id arg action) :: rem)
| Tpat_record ([], _) -> (omega :: patl, action) :: simplify rem
| Tpat_record (lbls, closed) ->
| Tpat_record ([], _, _rest) -> (omega :: patl, action) :: simplify rem

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 rest binding for empty-field record patterns

The Tpat_record ([], _, _rest) fast path drops the rest binder entirely, so a pattern like {...Sub.t as rest} is simplified to _ without generating the rest binding. If such a pattern is accepted by parsing/type-checking, code that uses rest in the branch can compile to incorrect/unbound behavior.

Useful? React with 👍 / 👎.

Comment thread compiler/core/lam_compile_primitive.ml Outdated
@tsnobip

tsnobip commented Apr 1, 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: da71513258

ℹ️ 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/typecore.ml Outdated
Comment thread analysis/src/ProcessCmt.ml Outdated
@tsnobip

tsnobip commented Apr 1, 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: 73a9b5dd3d

ℹ️ 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/typecore.ml Outdated
Comment thread compiler/ml/parsetree0.ml Outdated
@tsnobip

tsnobip commented Apr 1, 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: 73a9b5dd3d

ℹ️ 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/typecore.ml Outdated
@tsnobip

tsnobip commented Apr 1, 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: 792d7084c5

ℹ️ 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/parsetree0.ml Outdated
Comment thread compiler/ml/typecore.ml Outdated
@tsnobip

tsnobip commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tsnobip

tsnobip commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@tsnobip

tsnobip commented Apr 7, 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: ef14238e21

ℹ️ 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/typecore.ml Outdated
@tsnobip

tsnobip commented Apr 7, 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: a54691411c

ℹ️ 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/frontend/ast_tuple_pattern_flatten.ml Outdated
@tsnobip

tsnobip commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

Signed-off-by: tsnobip <dontshootthink@gmail.com>
Comment on lines +8 to +21
function describeConfig(c) {
let {name, ...rest} = c;
return [
name,
rest
];
}

function getNameAndSubConfig({name, ...subConfig}) {
return [
name,
subConfig
];
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@cknitt this is a much better output, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks almost NSFW!

@tsnobip tsnobip force-pushed the fix-8311 branch 2 times, most recently from dbe99a2 to 84b5246 Compare June 16, 2026 16:30
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.49145% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.69%. Comparing base (516e650) to head (95022a9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
compiler/ml/typecore_record_rest.ml 88.59% 13 Missing ⚠️
compiler/ml/printast.ml 0.00% 6 Missing ⚠️
compiler/core/js_pass_flatten_and_mark_dead.ml 68.75% 5 Missing ⚠️
compiler/ml/matching.ml 79.16% 5 Missing ⚠️
compiler/core/js_dump.ml 92.98% 4 Missing ⚠️
compiler/core/js_pass_record_rest.ml 93.44% 4 Missing ⚠️
compiler/ml/ast_mapper_from0.ml 60.00% 4 Missing ⚠️
compiler/ml/parmatch.ml 83.33% 4 Missing ⚠️
compiler/ml/typedtree.ml 72.72% 3 Missing ⚠️
compiler/syntax/src/res_core.ml 89.28% 3 Missing ⚠️
... and 13 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8317      +/-   ##
==========================================
+ Coverage   74.42%   74.69%   +0.27%     
==========================================
  Files         451      454       +3     
  Lines       61459    61971     +512     
==========================================
+ Hits        45743    46292     +549     
+ Misses      15716    15679      -37     
Files with missing lines Coverage Δ
analysis/reanalyze/src/dead_value.ml 86.11% <100.00%> (ø)
analysis/src/completion_front_end.ml 81.53% <100.00%> (ø)
analysis/src/completion_patterns.ml 90.38% <100.00%> (ø)
analysis/src/hint.ml 73.07% <100.00%> (+1.07%) ⬆️
analysis/src/process_cmt.ml 81.81% <100.00%> (+0.32%) ⬆️
analysis/src/process_extra.ml 86.74% <100.00%> (+0.21%) ⬆️
analysis/src/signature_help.ml 78.66% <100.00%> (ø)
analysis/src/xform.ml 88.68% <100.00%> (ø)
compiler/common/pattern_printer.ml 87.50% <100.00%> (ø)
compiler/core/j.ml 100.00% <100.00%> (ø)
... and 45 more

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

@tsnobip tsnobip force-pushed the fix-8311 branch 3 times, most recently from 5b5fae2 to 9d0c34d Compare June 17, 2026 09:04
@github-actions

Copy link
Copy Markdown

Comment thread compiler/ml/depend.ml Outdated
@tsnobip

tsnobip commented Jun 17, 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: 0029c8382c

ℹ️ 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/typecore_record_rest.ml
@tsnobip

tsnobip commented Jun 17, 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: 95022a9352

ℹ️ 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/core/js_pass_record_rest.ml
@tsnobip

tsnobip commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Support destructuring/pattern matching of record rest elements

4 participants