Commit 79d2f70
committed
fix(codegen): uniform heap representation for variants — fixes mixed-rep match
Zero-argument variants (None, plain enum cases) were emitted as raw i32 tags
while argument-carrying variants (Some(x), Ok/Err) were heap pointers to
[tag][fields]. A `match` over a value that can be either form (Option/Result)
mis-read one as the other: `match None { Some(v) => v, None => d }`
dereferenced the raw tag as a pointer in the Some(v) arm and returned garbage
instead of d (#607).
Box zero-arg variants as a heap [tag] too, so EVERY variant value is uniformly
a pointer; the zero-arg match arm now dereferences [ptr+0] for the tag,
symmetric with construction and with the args path. Touches the construction
sites (bare-ident ExprVar, ExprVariant) and the zero-arg PatCon match.
Verified under node: unwrap_or(None,99)=99 and unwrap_or(Some 7,99)=7 (the
None case was 0 before); Result Ok/Err and plain multi-constructor enums
unchanged. dune test 461 green; adds tests/codegen/mixed_variant_match — a
runtime regression (main()==9907) executed by run_codegen_wasm_tests.sh.
Closes the mixed-representation match item in #607.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M81 parent 0f8e6c5 commit 79d2f70
3 files changed
Lines changed: 78 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
521 | 541 | | |
522 | 542 | | |
523 | 543 | | |
| |||
536 | 556 | | |
537 | 557 | | |
538 | 558 | | |
539 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
540 | 563 | | |
541 | 564 | | |
542 | 565 | | |
| |||
2067 | 2090 | | |
2068 | 2091 | | |
2069 | 2092 | | |
2070 | | - | |
2071 | | - | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
2072 | 2096 | | |
2073 | 2097 | | |
2074 | 2098 | | |
2075 | 2099 | | |
2076 | 2100 | | |
2077 | | - | |
| 2101 | + | |
| 2102 | + | |
2078 | 2103 | | |
2079 | 2104 | | |
2080 | 2105 | | |
| |||
2204 | 2229 | | |
2205 | 2230 | | |
2206 | 2231 | | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
2207 | 2235 | | |
2208 | | - | |
| 2236 | + | |
| 2237 | + | |
2209 | 2238 | | |
2210 | 2239 | | |
2211 | 2240 | | |
| |||
2216 | 2245 | | |
2217 | 2246 | | |
2218 | 2247 | | |
| 2248 | + | |
2219 | 2249 | | |
2220 | 2250 | | |
2221 | 2251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments