Respect the solve polarity for conditions that don't mention the var - #9345
Merged
Conversation
…able
solve_for_{inner,outer}_interval track whether they're solving for the region
where the condition is true or where it's false, in SolveForInterval::target,
which visit(const Not *) flips. The early-out for conditions that don't mention
the variable being solved for didn't consult it, so under a negation it
returned the two answers the wrong way round.
That inverts the safe direction. Solving
!(((y % 2) != 1) && ((y % 2) != 0))
for x gives an empty outer interval, claiming the condition is nowhere true,
when it's a tautology. Written the other way round as
((y % 2) == 0) || ((y % 2) == 1)
there's no Not to flip the polarity, and it correctly gives everything.
An empty outer interval is not merely imprecise. TrimNoOps asks for the outer
interval of the condition under which a loop body does something, and deletes
the loop when that comes back empty.
The rest of the class already handles this: fail() widens to everything for an
outer bound and narrows to nothing for an inner one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
5 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9345 +/- ##
==========================================
+ Coverage 70.01% 70.05% +0.04%
==========================================
Files 258 258
Lines 78699 78699
Branches 19160 19164 +4
==========================================
+ Hits 55100 55132 +32
+ Misses 17881 17872 -9
+ Partials 5718 5695 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alexreinking
approved these changes
Aug 15, 2026
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.
solve_for_{inner,outer}_interval track whether they're solving for the region where the condition is true or where it's false, in SolveForInterval::target, which visit(const Not *) flips. The early-out for conditions that don't mention the variable being solved for didn't consult it, so under a negation it returned the two answers the wrong way round.
That inverts the safe direction. Solving
!(((y % 2) != 1) && ((y % 2) != 0))
for x gives an empty outer interval, claiming the condition is nowhere true, when it's a tautology. Written the other way round as
((y % 2) == 0) || ((y % 2) == 1)
there's no Not to flip the polarity, and it correctly gives everything.