Skip to content

Fix the sign of @inline bigint constants - #8732

Merged
cknitt merged 2 commits into
masterfrom
fix-inline-bigint-sign
Oct 7, 2026
Merged

cknitt merged 2 commits into
masterfrom
fix-inline-bigint-sign

Conversation

@cknitt

@cknitt cknitt commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Bigint_utils.parse_bigint returns whether a literal is positive, but Ast_external_mk.inline_bigint bound that flag as negative, so every @inline bigint constant was stored with its sign inverted.

Translation passed the flag straight into Lambda's Const_bigint, whose flag means positive, which inverted it back. So generated JavaScript was correct, but signatures and error messages printed the wrong sign:

Values do not match:
  let x: bigint
is not included in
  @inline(-12n) let x: bigint   // declared as @inline(12n)

This renames the field to positive, matching Bigint_utils.parse_bigint, Asttypes.Const_bigint, Lambda.Const_bigint and Js_op.bigint_lit, which all record whether a bigint is positive. The flag now passes through the frontend and translation unchanged.

Found while looking into structural @inline constants (#8624).

Tests

  • tests/tests/src/inline_const.res: a functor whose parameter declares @inline(12n) and @inline(-5n). A functor parameter is currently the only way to reach codegen with a bigint inline constant, since @inline let x = 12n isn't supported in implementations yet. This pins that the JS output keeps 12n / -5n.
  • super_errors/inline_bigint_signature_mismatch.res: pins the printed sign of both constants in a signature mismatch.

🤖 Generated with Claude Code

Bigint_utils.parse_bigint returns whether the literal is positive, but
Ast_external_mk.inline_bigint bound that flag as `negative`, so the
stored inline constant had its sign inverted. Translation passed the
flag straight through as Lambda's positive `sign`, inverting it back, so
generated JavaScript was correct; signatures and error messages printed
`@inline(-12n)` for `@inline(12n)`.

Store the real `negative` flag and convert it to Lambda's sign in
translcore.

Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the fix-inline-bigint-sign branch from c02bbfe to eac1e3d Compare October 7, 2026 06:16
Bigint_utils.parse_bigint, Asttypes.Const_bigint, Lambda.Const_bigint and
Js_op.bigint_lit all record whether a bigint is positive. The inline
constant was the only one recording `negative`, which is how its sign got
inverted. Use `positive` there too, so the value passes through the
frontend and translation unchanged.

Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt marked this pull request as ready for review October 7, 2026 06:26
@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 3b2c6f1

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.81%. Comparing base (1cc1da7) to head (3b2c6f1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8732      +/-   ##
==========================================
+ Coverage   79.79%   79.81%   +0.02%     
==========================================
  Files         464      464              
  Lines       63134    63134              
==========================================
+ Hits        50377    50391      +14     
+ Misses      12757    12743      -14     
Files with missing lines Coverage Δ
compiler/frontend/ast_external_mk.ml 100.00% <100.00%> (+13.33%) ⬆️
compiler/ml/external_ffi_types.ml 95.00% <ø> (ø)
compiler/ml/translcore.ml 86.34% <100.00%> (+0.16%) ⬆️
compiler/syntax/src/res_outcome_printer.ml 63.36% <100.00%> (+1.04%) ⬆️

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

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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-10-07T06:40:12.707783Z 3b2c6f1 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 3b2c6f1492

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

@cknitt
cknitt requested a review from cristianoc October 7, 2026 06:40
@cknitt
cknitt merged commit d7ffff5 into master Oct 7, 2026
24 checks passed
@cknitt
cknitt deleted the fix-inline-bigint-sign branch October 7, 2026 09:08
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