Repository navigation
Commit 33fbfc7
Fix compiler crash on unreachable guarded or-patterns (#8896)
* Skip handlers of unreachable or-patterns
A guarded or-pattern after a case that matches everything crashed the
compiler with "Fatal error: Matching.comp_exit". The or-pattern is compiled
to a handler that its rows jump to. Its rows were dropped as unreachable, but
the handler was still compiled; when its guard fails it falls through to the
following cases, and in a match without a default there is nothing to fall
through to. A handler that the compiled match never jumps to is now skipped.
Example (rescript):
let g = () => true
let f = x =>
switch x {
| _ => 2
| 1 | 2 if g() => 3
}
Before (text):
>> Fatal error: Matching.comp_exit
Fatal error: exception Misc.Fatal_error
After (js):
function f(x) {
return 2;
}
Source: compiled with the parent commit and with this one.
Review: Can skipping a handler drop reachable code? The handler is skipped
only when no `Lstaticraise` to its exit occurs in the compiled match, so no
path can reach it.
Area: lambda tests
Output: unchanged, all committed generated JS is byte-identical; programs
that crashed now compile
Tests: +tests/tests/src/unreachable_or_guard_test.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Test unreachable guarded or-patterns as a warning fixture
The regression test disabled warning 11 for its module. It is now a
super_errors fixture, which compiles with all warnings and records the four
unused-case warnings; without the fix its snapshot shows the fatal error.
Area: tests
Output: unchanged
Tests: +tests/build_tests/super_errors/fixtures/warning_11_unreachable_guarded_or_pattern.res
-tests/tests/src/unreachable_or_guard_test.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Collect raised exits once when compiling or-pattern handlers
Whether a handler is reachable was checked by scanning the whole compiled
match, including function bodies, once per handler. The exits are now
collected into a table once, extended with each compiled handler, and
function bodies are skipped, since static exits cannot leave a function.
Area: lambda
Output: unchanged
Tests: none, because the output is unchanged; the reachability check is
covered by warning_11_unreachable_guarded_or_pattern.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo
Signed-off-by: Christoph Knittel <ck@cca.io>
---------
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 1eb91bb commit 33fbfc7
4 files changed
Lines changed: 95 additions & 0 deletions
File tree
- changes
- compiler/ml
- tests/build_tests/super_errors
- expected
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2592 | 2592 | | |
2593 | 2593 | | |
2594 | 2594 | | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
2595 | 2605 | | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
2596 | 2609 | | |
2597 | 2610 | | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
2598 | 2615 | | |
2599 | 2616 | | |
2600 | 2617 | | |
2601 | 2618 | | |
| 2619 | + | |
2602 | 2620 | | |
2603 | 2621 | | |
2604 | 2622 | | |
| |||
| 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 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 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 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments