Fix exponential compilation blowup in pattern matching and boolean si… #8078
+525
−342
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…mplification
This PR fixes two sources of exponential compilation time:
Boolean expression simplification (
js_exp_make.ml): Thesimplify_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 Fix infinite recursion in E.econd when optimizing nested conditionals #8039 and repro large variant timeout #8042 (large unboxed variants). Note: PR Fix infinite recursion in E.econd when optimizing nested conditionals #8039's diagnosis of "infinite recursion" was incorrect - the actual issue was exponential blowup, not infinite loops.
Exhaustiveness checking (
parmatch.ml): Theexhaust_gadtfunction 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:
Added test cases for both scenarios.
Closes #8074
Closes #8039
Closes #8042