Skip to content

Type inline-record cases of untagged variants as objects in genType - #8693

Merged
cknitt merged 4 commits into
masterfrom
cristianoc/fix-gentype-untagged-inline-record
Oct 3, 2026
Merged

cknitt merged 4 commits into
masterfrom
cristianoc/fix-gentype-untagged-inline-record

Conversation

@cristianoc

@cristianoc cristianoc commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #8712.

Summary

  • Type inline-record cases of untagged variants as objects in genType. genType collapsed every single-field inline record of an untagged variant case to its field type, so @unboxed type t = Array(array<int>) | Record({x: int}) | Function(int => int) was emitted as number[] | number | ((_1:number) => number). At runtime the Record case is the object {x}: the compiled match dispatches on typeof v === "object" and reads v.x. A single field collapses to its type only when the whole declaration is unboxed (type_representation = Unboxed, as in @unboxed type r2 = B({g: string}), whose runtime value is the string).
  • Remove Variant_runtime.constructor_is_untagged. genType's inline-record translation was its only caller, and that caller now decides field collapsing from the declaration's type_representation alone. Nothing else in compiler, analysis, tools or tests references it, and Variant_runtime is a compiler-internal module.

Test plan

  • dune build
  • dune build @fmt
  • dune build --profile browser @check
  • make
  • make lib
  • no change in the runtime and Belt lib/ outputs
  • make test
  • make test-gentype
  • make test-analysis
  • make checkformat
  • npm run check

🤖 Generated with Claude Code

cristianoc and others added 2 commits October 2, 2026 07:36
genType collapsed every single-field inline record of an untagged variant
case to its field type, so `@unboxed type t = Array(array<int>) |
Record({x: int}) | Function(int => int)` was emitted as
`number[] | number | ((_1:number) => number)`. At runtime the `Record`
case is the object `{x}`: the compiled match dispatches on
`typeof v === "object"` and reads `v.x`. A single field collapses to its
type only when the whole declaration is unboxed
(`type_representation = Unboxed`, as in `@unboxed type r2 = B({g: string})`,
whose runtime value is the string).

Unboxed.res gains `tLength`, called from index.tsx with `{x: 3}`; tsc
rejected that call before this change (TS2353) and accepts it now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
genType's inline-record translation was its only caller, and that caller
now decides field collapsing from the declaration's type_representation
alone. Nothing else in compiler, analysis, tools or tests references it,
and Variant_runtime is a compiler-internal module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
@cristianoc
cristianoc requested a review from cknitt October 2, 2026 06:29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
@cristianoc cristianoc mentioned this pull request Oct 2, 2026
21 of 22 tasks

@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: c1e58c9075

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

(type_representation = Unboxed
|| Variant_runtime.constructor_is_untagged layout
position);
~unboxed:(type_representation = Unboxed);

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 Add the required changelog entry

This changes a user-visible generated TypeScript type and fixes incorrect genType output, but the commit does not update CHANGELOG.md; document the fix under the current Unreleased bug-fix section and include the required PR link.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added in 1abeeb3, under the Unreleased section with the PR link.

@genType @unboxed
type t = Array(array<int>) | Record({x: int}) | Function(int => int)

@genType

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 Sign off the commit under DCO

The reviewed commit message has no Signed-Off-By: trailer, so it does not satisfy this repository's DCO commit requirement; add a valid sign-off before submitting the change.

AGENTS.md reference: AGENTS.md:L68-L72

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Every commit on this branch carries a Signed-off-by trailer (git log --format='%(trailers:key=Signed-off-by)' origin/master..HEAD lists one per commit), so there is nothing to add.

@chatgpt-codex-connector

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-02T06:32:37.644793Z c1e58c9 PR opened
ℹ️ 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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 20c702e

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

@cknitt
cknitt enabled auto-merge (squash) October 3, 2026 07:17
@cknitt
cknitt merged commit 55c2e54 into master Oct 3, 2026
24 checks passed
@cknitt
cknitt deleted the cristianoc/fix-gentype-untagged-inline-record branch October 3, 2026 07:33
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