Skip to content

Commit e7e20d7

Browse files
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 #8042
1 parent e8380f1 commit e7e20d7

File tree

6 files changed

+524
-342
lines changed

6 files changed

+524
-342
lines changed

0 commit comments

Comments
 (0)