Commit 0c49e79
committed
Fix exponential compilation blowup in pattern matching and boolean simplification
This PR fixes two sources of exponential compilation time:
1. **Boolean expression simplification** (`js_exp_make.ml`):
The `simplify_and_` function had O(3^n) recursive behavior when
simplifying nested AND expressions. Added a depth limit (10) to
prevent exponential blowup while preserving optimizations for
normal cases.
Fixes the issue reported in #8039 and #8042 (large unboxed variants).
Note: PR #8039's diagnosis of "infinite recursion" was incorrect -
the actual issue was exponential blowup, not infinite loops.
2. **Exhaustiveness checking** (`parmatch.ml`):
The `exhaust_gadt` function had exponential complexity (~4^n) when
checking exhaustiveness for dict pattern matching. Added a call
count limit (1000) that conservatively reports non-exhaustive when
exceeded, preventing hangs while maintaining correctness.
Performance improvements:
- Large unboxed variants (28 cases): 3.79s -> 0.03s (126x faster)
- Dict pattern matching (6 cases): 0.94s -> 0.04s (24x faster)
Added test cases for both scenarios.
Closes #8074
Closes #8039
Closes #80421 parent e8380f1 commit 0c49e79
File tree
7 files changed
+525
-342
lines changed- compiler
- core
- ml
- tests/tests/src
7 files changed
+525
-342
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
0 commit comments