FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

destructure record rest elements by tsnobip · Pull Request #8317 · rescript-lang/rescript · GitHub

destructure record rest elements - #8317

Merged
tsnobip merged 47 commits into
masterfrom
fix-8311
Jul 3, 2026
Merged

destructure record rest elements#8317
tsnobip merged 47 commits into
masterfrom
fix-8311

Conversation

tsnobip commented Mar 28, 2026

Copy link
Copy Markdown
Member

fixes #8311

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

pkg-pr-new Bot commented Mar 28, 2026
edited
Loading

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: 5e37735

tsnobip force-pushed the fix-8311 branch 2 times, most recently from 536855c to 2245765 Compare March 31, 2026 10:50
tsnobip marked this pull request as ready for review March 31, 2026 10:51
Comment thread compiler/ml/ast_mapper_to0.ml Outdated

cknitt commented Mar 31, 2026

Copy link
Copy Markdown
Member

@codex review

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 thread compiler/ml/depend.ml Outdated
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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 thread compiler/ml/matching.ml Outdated
Comment thread compiler/core/lam_compile_primitive.ml Outdated

tsnobip commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

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 commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

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 commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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 commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 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".

tsnobip commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

tsnobip commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a87f7f9406

ℹ️ 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/rec_check.ml Outdated
Comment thread analysis/reanalyze/src/dead_value.ml Outdated
tsnobip added 3 commits June 18, 2026 17:38
Signed-off-by: tsnobip <dontshootthink@gmail.com>
Signed-off-by: tsnobip <dontshootthink@gmail.com>
Signed-off-by: tsnobip <dontshootthink@gmail.com>

tsnobip commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 686c0d40a4

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

tsnobip commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed0fd1736e

ℹ️ 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/common/pattern_printer.ml Outdated

cknitt commented Jun 30, 2026

Copy link
Copy Markdown
Member

I asked Codex (locally) if it noticed anything else, here is the output (I think the one about ast0 can be ignored):

Yes. The biggest one I’d flag is in compiler/core/js_pass_record_rest.ml.

materialize_fields rewrites later reads of source.field to the destructured local binding introduced for object rest:

let {name, ...restConfig as rest} = source
// later source.name can become name

That is only valid if source cannot be reassigned or observed through mutation between the destructure and the read. The pass rewrites the whole remaining tail block, including nested function bodies, so cases like this look risky:

let mutable source = {name: "a", version: "1", debug: false}
let {name: _, ...restConfig as rest} = source
source = {name: "b", version: "2", debug: true}
source.name

If the JS pass replaces the final source.name with the destructured name, it returns the old value. Even worse with a closure created after destructuring and called after reassignment. I’d expect either no rewrite, or a much narrower rewrite that stops at writes/reassignments and probably does not descend into nested functions.

Other questionable points:

  • compiler/common/pattern_printer.ml drops _rest, as discussed. Mostly diagnostic-only, but rest-only patterns can become odd empty-record diagnostics.
  • compiler/ml/parmatch.ml also drops _rest in Conv.conv, so exhaustiveness counterexamples cannot show record-rest shape. Probably acceptable, but it reinforces that diagnostics are lossy.
  • compiler/core/j.ml adds Object_rest_param, but the PR mostly seems to avoid emitting it and instead moves destructuring into the body for directive-sensitive cases. That may be dead or premature AST surface unless another pass produces it.
  • compiler/ml/ast_mapper_to0.ml / ast_mapper_from0.ml encode record rest through a synthetic res.record_rest attribute when converting to/from the old parsetree. That is a brittle bridge: malformed or user/PPX-created attributes could be silently ignored or collide with real metadata unless this attribute namespace is clearly reserved.
  • Tooling support is uneven: completion/signature-help mostly ignore _rest, while hints/semantic tokens handle it. That’s not a compiler correctness issue, but the feature may feel half-supported in editor workflows.

If I were reviewing the PR, I’d lead with the js_pass_record_rest rewrite across mutation/closures. That one looks like the highest chance of a real behavioral regression.

tsnobip commented Jul 1, 2026
edited
Loading

Copy link
Copy Markdown
Member Author

Yes. The biggest one I’d flag is in compiler/core/js_pass_record_rest.ml.

materialize_fields rewrites later reads of source.field to the destructured local binding introduced for object rest:

let {name, ...restConfig as rest} = source
// later source.name can become name

That is only valid if source cannot be reassigned or observed through mutation between the destructure and the read. The pass rewrites the whole remaining tail block, including nested function bodies, so cases like this look risky:

let mutable source = {name: "a", version: "1", debug: false}
let {name: _, ...restConfig as rest} = source
source = {name: "b", version: "2", debug: true}
source.name

@cknitt codex has been warning me multiple times about this issue but always with invented rescript syntax and semantics, typically let mutable is not a thing in rescript and if you use a ref instead I can't reproduce any issue in this case. Could you try to come up with any reproducible issue in the dev playground.

I'll take a look at the other issues you've raised.

UPDATE: I've addressed the other issues.

cknitt commented Jul 2, 2026

Copy link
Copy Markdown
Member

Could you try to come up with any reproducible issue in the dev playground

Didn't manage to come up with anything either.

UPDATE: I've addressed the other issues.

Thanks! 👍

tsnobip merged commit 6a38bea into master Jul 3, 2026
30 checks passed
tsnobip deleted the fix-8311 branch July 3, 2026 07:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support destructuring/pattern matching of record rest elements

4 participants


Back | FazBrowse Home | New Git URL