Skip to content

Conversation

@cristianoc
Copy link
Collaborator

for #8039

cristianoc added a commit that referenced this pull request Dec 9, 2025
…mplification

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
cristianoc added a commit that referenced this pull request Dec 9, 2025
…mplification

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
cknitt pushed a commit to cknitt/rescript that referenced this pull request Dec 9, 2025
…mplification

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 rescript-lang#8039 and rescript-lang#8042 (large unboxed variants).
   Note: PR rescript-lang#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 rescript-lang#8074
Closes rescript-lang#8039
Closes rescript-lang#8042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants