Type inline-record cases of untagged variants as objects in genType - #8693
Conversation
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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8693 |
Part of #8712.
Summary
@unboxed type t = Array(array<int>) | Record({x: int}) | Function(int => int)was emitted asnumber[] | number | ((_1:number) => number). At runtime theRecordcase is the object{x}: the compiled match dispatches ontypeof v === "object"and readsv.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).Test plan
dune builddune build @fmtdune build --profile browser @checkmakemake liblib/outputsmake testmake test-gentypemake test-analysismake checkformatnpm run check🤖 Generated with Claude Code