Skip to content

Consolidate large record mutation output into a single spread object literal#8473

Open
cometkim wants to merge 3 commits into
rescript-lang:masterfrom
cometkim:object-dup-by-spread
Open

Consolidate large record mutation output into a single spread object literal#8473
cometkim wants to merge 3 commits into
rescript-lang:masterfrom
cometkim:object-dup-by-spread

Conversation

@cometkim

Copy link
Copy Markdown
Member

Follow-up to #7043

To avoid excessive variations in the Lambda types, I added a kind of pattern matching for record mutation (Pduprecord + Psetfield chain).

But it is not a very efficient implementation; it might be better to just change the IR.

…teral

So it emits `{...x, a: 1}` instead of `let newrecord = {...x}; newrecord.a = 1;`.

@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: 55281545d1

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

{primitive = Psetfield (_, fld_info); args = [Lvar id'; value]; _},
rest )
when Ident.same id' copy_id ->
collect_dup_overrides copy_id rest ((fld_info, value) :: acc)

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 field update evaluation order

When a record update overrides more than one field and the override expressions have side effects, this collector reverses the Lsequence order: each Psetfield is consed onto acc, and the fold below compiles that reversed list. The previous output executed the Psetfield chain in order, so cases like two logging/counter updates now run in the opposite order. Collect in order, or reverse before compiling values, before emitting the object literal.

Useful? React with 👍 / 👎.

Comment thread compiler/core/lam_compile.ml Outdated
Some
(Js_output.output_of_block_and_expression lambda_cxt.continuation
blocks
(E.obj ~dup:init_val (List.rev props))))

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 Keep spread initializers live in effect-only updates

When the optimized record update is used only for effects and the override values are pure, this emits a single Object(Some spread, props) value; Js_analyzer.no_side_effect_expression currently treats Object(_, kvs) as pure by checking only kvs, so append_output/output_as_block can drop {...getRecord(), x: 1} entirely and skip the side effects of getRecord(). The old temp-plus-assignment path kept the spread initializer live because the temp was used by the assignment.

Useful? React with 👍 / 👎.

title={"barry"}
{...baseProps}
className={"barry"}
title={"barry"}

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.

The order changed because it now follows the declaration order rather than the source order.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.42%. Comparing base (516e650) to head (8da6722).

Files with missing lines Patch % Lines
compiler/core/js_dump.ml 80.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8473   +/-   ##
=======================================
  Coverage   74.42%   74.42%           
=======================================
  Files         451      451           
  Lines       61459    61497   +38     
=======================================
+ Hits        45743    45772   +29     
- Misses      15716    15725    +9     
Files with missing lines Coverage Δ
compiler/core/js_analyzer.ml 83.33% <100.00%> (+0.35%) ⬆️
compiler/core/lam_compile.ml 86.43% <100.00%> (+0.46%) ⬆️
compiler/core/js_dump.ml 86.91% <80.00%> (-0.90%) ⬇️
🚀 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 Jun 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 8da6722

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