Skip to content

Start a recursive array record as an empty array - #9232

Merged
cknitt merged 1 commit into
masterfrom
record-array-let-rec
Nov 5, 2026
Merged

cknitt merged 1 commit into
masterfrom
record-array-let-rec

Conversation

@cknitt

@cknitt cknitt commented Nov 5, 2026

Copy link
Copy Markdown
Member

Follow-up to #9224 from a review that finished after it merged.

A recursive value starts as an empty placeholder, which is filled in afterwards: by index for constant fields, otherwise by Object.assign. dummy_obj made that placeholder {} for every record, so a let rec of an array record (fields with the runtime names "0", "1", …) stayed an object. This was already the case before #9224, but it is the last place that broke the invariant that a value of a Record_array type is a JavaScript array. The placeholder is now [] for an array record, and Object.assign keeps an array target an array.

type rec cell = {@as("0") value: int, @as("1") next: cell}
let rec cell = {value: 1, next: cell}
-let cell = {};
+let cell = [];
 cell[0] = 1;
 cell[1] = cell;

Also: an array record in an arrow body no longer gets the parentheses an object literal needs (a => ([a, b]) becomes a => [a, b]).

New tests in array_record_test.res check Array.isArray for a recursive array record built at top level (constant fields) and inside a function (a variable field, the other placeholder path).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gLWSz9kGHhX9sue9WB

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Build a recursive let rec value of a record whose fields have the runtime names "0", "1", … as a JavaScript array instead of an object.

Semantic Diff

1 commit · Full page

Start a recursive array record as an empty array

628013a · cknitt + Claude · Nov 05, 2026, 05:55 UTC

Fable review: a recursive value starts as an empty placeholder that is filled in afterwards, and the placeholder of every record was {}, so a let rec of an array record stayed an object. It is now [] for an array record. An array record in an arrow body also no longer gets the parentheses an object literal needs.

JS modified (recursive array record)

type rec cell = {@as("0") value: int, @as("1") next: cell}
let rec cell = {value: 1, next: cell}

js

-let cell = {};
+let cell = [];
 cell[0] = 1;
 cell[1] = cell;

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.74%. Comparing base (8585311) to head (628013a).

Files with missing lines Patch % Lines
compiler/core/js_exp_make.ml 25.00% 3 Missing ⚠️
compiler/core/js_dump.ml 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9232   +/-   ##
=======================================
  Coverage   81.74%   81.74%           
=======================================
  Files         457      457           
  Lines       65564    65566    +2     
=======================================
+ Hits        53595    53597    +2     
  Misses      11969    11969           
Files with missing lines Coverage Δ
compiler/core/js_dump.ml 93.82% <33.33%> (+<0.01%) ⬆️
compiler/core/js_exp_make.ml 66.28% <25.00%> (+0.04%) ⬆️
🚀 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 Nov 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 628013a

@cknitt

cknitt commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-11-05T08:09:37.158760Z e3841b9 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.

@cknitt
cknitt requested a review from cristianoc November 5, 2026 08:08
@cknitt
cknitt marked this pull request as ready for review November 5, 2026 08:08
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: e3841b9dba

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

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

Just make sure this is sound.
There are ways of treating empty array unsoundly.

Though this looks like back-end code so you just need to check that the generated code is OK.

Fable review: a recursive value starts as an empty placeholder that is
filled in afterwards, and the placeholder of every record was `{}`, so a
`let rec` of an array record stayed an object. It is now `[]` for an
array record. An array record in an arrow body also no longer gets the
parentheses an object literal needs.

JS modified (recursive array record):
Example:
    type rec cell = {@as("0") value: int, @as("1") next: cell}
    let rec cell = {value: 1, next: cell}
Before (js):
    let cell = {};
    cell[0] = 1;
    cell[1] = cell;
After (js):
    let cell = [];
    cell[0] = 1;
    cell[1] = cell;

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLWSz9kGHhX9sue9WB
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the record-array-let-rec branch from e3841b9 to 628013a Compare November 5, 2026 13:39
@cknitt

cknitt commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

@cristianoc I checked the generated code and ran it in Node.

The empty [] is only the placeholder of a let rec. It is filled in place before anything else can read the value, and it always ends up with the record's full length:

Case JS Result
constant fields x = []; x[0] = x; x[1] = 2; array, length 2
trailing optional field left out x[1] = undefined is still written length 2, same as the literal [n, undefined], so equality agrees
runtime field Primitive_object.updateDummy(x, [compute(), x]), which is Object.assign array, length 2
closure field updateDummy(x, [() => 3, x, 3]) array, length 3
mutual recursion with an object record ra = [], rb = {} array and object, as typed

Untagged dispatch on a recursive value (Cell(u) | Obj({..}) | S(string)) picks Cell through Array.isArray.

The placeholder is the same Array [] that dummy_obj already used for tuples and module exports. Before this PR, an array record started as {}, an object, which was the unsound case. Rebased onto master with the lsp fix (628013a).

@cknitt
cknitt enabled auto-merge (squash) November 5, 2026 14:11
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

@cknitt
cknitt merged commit 306ccfc into master Nov 5, 2026
26 checks passed
@cknitt
cknitt deleted the record-array-let-rec branch November 5, 2026 14:18
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