Optimize: constant-fold interval conversions for literal intervals#1707
Optimize: constant-fold interval conversions for literal intervals#1707
Conversation
When convertIntervalExpression receives an Interval literal (not a
computed expression), directly convert the bounds and preserve the
lowClosed/highClosed booleans instead of using runtime Property
extraction.
Before: Interval(low=As(T, Property("low", source=Interval(...))), ...)
After: Interval(low=As(T, originalLow), lowClosed=originalLowClosed, ...)
The Property extraction is still used for non-literal intervals
(expression refs, function call results) where bounds aren't known
at compile time.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Related IssuesThe following open issues may be related to this PR:
|
|
Formatting check succeeded! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1707 +/- ##
============================================
+ Coverage 61.96% 61.97% +0.01%
- Complexity 3940 3941 +1
============================================
Files 210 210
Lines 20367 20378 +11
Branches 3879 3882 +3
============================================
+ Hits 12621 12630 +9
Misses 6139 6139
- Partials 1607 1609 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
c-schuler
left a comment
There was a problem hiding this comment.
Looks good! The only thing I'd point out is that the existing test for this path only validates that no errors occurred. There's no test that verifies the optimized output differs from the old output or that the simpler ELM evaluates correctly. Not a blocker for approval though
#1707 constant-folds interval conversions for bare Interval literals, but some operator paths (e.g., `ends`) route through a cast+interval conversion chain where convertExpression wraps the Interval in an As cast before the interval conversion. The `expression is Interval` check then fails, falling back to runtime Property extraction. Unwrap As casts to find the inner Interval literal, enabling constant folding for all operator paths that produce Interval(null, null) or similar literal interval conversions. Extracted constantFoldIntervalConversion and unwrapIntervalLiteral helpers to keep convertIntervalExpression within the detekt line limit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…1709) #1707 constant-folds interval conversions for bare Interval literals, but some operator paths (e.g., `ends`) route through a cast+interval conversion chain where convertExpression wraps the Interval in an As cast before the interval conversion. The `expression is Interval` check then fails, falling back to runtime Property extraction. Unwrap As casts to find the inner Interval literal, enabling constant folding for all operator paths that produce Interval(null, null) or similar literal interval conversions. Extracted constantFoldIntervalConversion and unwrapIntervalLiteral helpers to keep convertIntervalExpression within the detekt line limit. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


Summary
When
convertIntervalExpressionreceives anIntervalliteral (e.g.,Interval(null, null)), it now directly converts the bounds and preserveslowClosed/highClosedbooleans instead of using runtimePropertyextraction.Before:
After:
The
Propertyextraction path is still used for non-literal intervals (expression refs, function call results) where bounds aren't statically known.Test plan
cql-to-elmJVM tests passIntervalliterals, preserving existing behavior for computed intervals🤖 Generated with Claude Code