Repository navigation
Fix inlined char switches losing their result - #9492
Conversation
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page ✏️ Fix inlined char switches losing their result3e46383 · cknitt + Claude · Dec 01, 2026, 19:42 UTC · edited
JavaScript generation now follows the fall-through when it folds a switch: it takes the first body that isn't empty. Lambda also folds a switch on a char constant, as it does for an int. JS modified (inlined switch on a char constant) @inline
let classify = x =>
switch x {
| 'a' => "a"
| 98 => "b"
| 'c' .. 'e' => "c-e"
| 102 | 'g' => "f-g"
| _ => "other"
}
@inline
let check = (actual, expected) => Console.log((actual, expected))
check(classify('d'), "c-e")
-let actual;
-console.log([actual, "c-e"]);
+console.log(["c-e", "c-e"]);Fixes #9489 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9492 +/- ##
==========================================
+ Coverage 82.49% 82.52% +0.02%
==========================================
Files 467 468 +1
Lines 66125 66161 +36
==========================================
+ Hits 54553 54602 +49
+ Misses 11572 11559 -13
🚀 New features to boost your workflow:
|
✅ Compiler benchmarksAllocated wordsIn total: 655,172,566 → 655,168,748 (±0.00%). Generated projects: 627,299,514 → 627,299,374 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,128,430,307 → 9,127,893,614 (-0.01%).
Output sizeIn total: 27,368,788 → 27,368,754 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 3e46383 compared with base 69e11bf in this run. |
f27e32b to
90cff12
Compare
rescript
@rescript/belt
@rescript/darwin-arm64
@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-9492 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
90cff12 to
35b5f9a
Compare
35b5f9a to
0ac84c7
Compare
Why:
When a function with a switch is inlined into a call such as
`classify('d')`, the switch's argument is a constant, so constant
folding can replace the switch with the matching case. Lambda did
this for int constants but not for char constants, so JavaScript
generation folded the switch instead. It took only the body of the
matching case. But cases with the same action share one body: case
100 has an empty body and falls through to case 101. So nothing
assigned the result.
JavaScript generation now follows the fall-through when it folds a
switch: it takes the first body that isn't empty. Lambda also folds a
switch on a char constant, as it does for an int.
JS modified (inlined switch on a char constant):
Example:
@inline
let classify = x =>
switch x {
| 'a' => "a"
| 98 => "b"
| 'c' .. 'e' => "c-e"
| 102 | 'g' => "f-g"
| _ => "other"
}
@inline
let check = (actual, expected) => Console.log((actual, expected))
check(classify('d'), "c-e")
Before (js):
let actual;
console.log([actual, "c-e"]);
After (js):
console.log(["c-e", "c-e"]);
Fixes #9489
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du
Signed-off-by: Christoph Knittel <ck@cca.io>
0ac84c7 to
3e46383
Compare
Fixes #9489.
An inlined switch on a char constant could lose its result:
When
classify('d')is inlined, the switch's argument is the constant'd', so constant folding can replace the whole switch with the matching case. Lambda did this for int constants but not for char constants, so here JavaScript generation folded the switch instead. It took only the body of the matching case, 100. But case 100 shares its action with cases 99 and 101, so its own body is empty, and nothing assigned the result.The fix. JavaScript generation now falls through empty cases to the shared body when it folds a switch on a constant. Lambda also folds a switch on a char constant, as it does for an int. This shortens
char_int_alias_test's output too.Tests.
inline_constant_switch_testruns the example. Once Lambda folds char constants, no program I found still reaches the fold in JavaScript generation, so the new unit tests inounit_constant_switch_testscall it directly.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du