Repository navigation
Fix constant folding of comparison chains - #699
Merged
Merged
Conversation
ggleyzer
requested changes
Oct 13, 2026
ggleyzer
left a comment
Collaborator
There was a problem hiding this comment.
I cannot reproduce any of the claimed issues. I tried:
Boolean f1 = 1 < 2 < 3;
assert f1;
f1 = 1 < 2 < 0;
assert !f1;
and everything compiles and runs. What is the problem you're fixing?
lagergren
added a commit
that referenced
this pull request
Oct 13, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 13, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
ggleyzer
requested changes
Oct 13, 2026
ggleyzer
reviewed
Oct 13, 2026
ggleyzer
approved these changes
Oct 14, 2026
lagergren
added a commit
that referenced
this pull request
Oct 14, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 14, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 15, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 19, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 20, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 21, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 21, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 26, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 26, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 26, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 26, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 27, 2026
Replace raw collections and duplicated validation, branch joining, operand emission, and declaration rendering with typed shared helpers. Remove dead paths and clarify null and type invariants. Fix constant comparison folding, equality-chain branch emission, and tuple foreach targets. Cover these paths with Ecstasy compiler and runtime regressions. The constant-folding fix is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 27, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 28, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 28, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 29, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 29, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Oct 29, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 2, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 4, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 5, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 9, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 11, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 22, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 26, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 26, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 27, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
lagergren
added a commit
that referenced
this pull request
Nov 28, 2026
Mirror the LSP branch cleanup while retaining this branch’s compiler diagnostics and tests. Replace duplicated validation and emission paths with typed helpers, remove dead code, and make null and type invariants explicit. Include Ecstasy regressions for comparison chains, tuple foreach targets, loop control flow, branch narrowing, and switch ranges. Constant-chain folding is also isolated in PR #699.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Why?
1 < 2 < 3never fold:constPrevis initialized to null and never assigned, so every attempted comparison throws aNullPointerExceptionthat the fallback silently catches.constPrevwould leave two hazards in the old loop: retaining a true constant prefix when a later operand is nonconstant, and stopping validation after a false prefix.How?
Implications
This is an independent compiler bug fix based directly on master. It does not depend on the LSP implementation or its embedding API changes. Runtime chain generation is unchanged.
Changes
CmpChainExpression.java: separate operand checking from constant evaluation, correctly carry the preceding constant through the chain, and explain the folding and equality rules beside their implementations.xdk/src/test/resources/compiler-errors/comparisonChains.x: one concise Ecstasy regression case run by the existingCompilerErrorsTest. The chain1 < 2 < 3must fold toTrueand collide with the precedingTrueswitch case, producingCOMPILER-77(duplicate value).Manual verification
The retained
1 < 2 < 3case was verified against unchanged master in the original regression run: it reportsCOMPILER-78(constant required), rather than the expectedCOMPILER-77(duplicate value). With the fix, the simplified fixture reports the expected duplicate-case diagnostic.After simplifying the fixture,
:xdk:test --tests org.xvm.xdk.CompilerErrorsTest --rerun-tasks --no-build-cacheandspotlessCheckpassed. JUnit XML confirms three tests, zero failures, zero errors and zero skips. The XDK libraries were rebuilt with the corrected compiler.