← Back to Pull requests

[ConstraintAnalysis] Fix asymmetry in provesPair overlap check #9258

Merged
tlively merged 2 files (203 lines) on Oct 13, 2026 23:45 UTC
View on GitHub
tlively tlively commented on Oct 13, 2026 20:47 UTC
Author

Fixes provesPair to symmetrically check disjointness using proven spans rather than exact spans, since a disjoint superset implies disjoint subsets. This addresses an assertion failure in approximateOr where asymmetric comparison of constraints incorrectly produced an OR-induced contradiction.

Removes unreachable empty() span checks in provesPair since empty spans are only produced by immediate contradictions, which are evaluated to contradictions prior to reaching provesPair.

Diff: 203 lines (+187 / -16) across 2 files Reviewer: kripken Review duration: 178m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.36) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 203 lines diff across 2 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.77 · 2 substantive comment(s)
0.77
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
80%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.318
Real PR Conversation Timeline
5 items
kripken kripken commented on code on Oct 13, 2026 22:13 UTC
Code Review
src/ir/constraint.cpp:1
@@ -342,26 +342,46 @@ Result provesPair(const Constraint& a, const Constraint& b) {
   // must be a constant in this case, so that we know the type.
   if (aConstant || bConstant) {
     auto type = aConstant ? aConstant->type : bConstant->type;
-    // Use proven spans for a, and exact for b. This allows us to do
-    // a => proven spans for a => exact spans for b => b.
+    // A constraint's "proven spans" are an over-approximation (superset) of the
+    // values for which the constraint holds (c => proven(c)), whereas its
+    // "exact spans" are the exact set of values (c <=> exact(c)), which may not
+    // exist when comparing against another local.
+    //
+    // To prove that a => b (return True), we check that b's exact spans contain
+    // a's proven spans:
+    //
+    //   a => proven(a) => exact(b) => b
+    //
+    // Using proven(b) here would be unsound because exact(b) => proven(b) goes
+    // the wrong way.
+    //
+    // To prove that a => !b (return False), however, it suffices to check that
+    // a's proven spans and b's proven spans do not overlap:
+    //
+    //   a => proven(a) => !proven(b) => !b
+    //
+    // Using proven(b) instead of exact(b) here is both more powerful (it works
+    // when b compares against a local, such as x <_u $y having proven span
+    // [0, MAX_UINT - 1]) and ensures that disjointness is symmetric between
+    // provesPair(a, b) and provesPair(b, a).
+    //
+    // Note that empty spans (from immediate contradictions such as
+    // x >_s MAX_INT) do not need special-casing: an empty proven(a) is
+    // vacuously contained in any exact(b) (returning True), and an empty
+    // proven(b) has no overlap with any proven(a) (returning False).
     if (auto aSpans = a.getProvenSpans(type)) {
-      if (auto bSpans = b.getSpans(type)) {
-        if (aSpans->empty()) {
-          // An empty span implies a contradiction (e.g. x > MAX_INT), as it
-          // means no possible number can apply. And contradictions prove
-          // anything.
-          return True;
-        }
-        if (bSpans->empty()) {
-          // Anything that is not a contradiction can prove a contradiction.
-          return False;
-        }
+      auto bSpans = b.getSpans(type);
+      auto bProvenSpans = b.getProvenSpans(type);

Seems confusing to now have aSpans meaning "a's proven spans" while bSpans means "b's exact spans". Perhaps rename one?

kripken kripken commented on Oct 13, 2026 22:16 UTC
Reviewer

Another option might be to change how we assert on when a contradiction arrives, but making it symmetrical seems nicer actually. lgtm % comment on variable names.

tlively tlively commented on code on Oct 13, 2026 23:09 UTC
Code Review
src/ir/constraint.cpp:1
@@ -342,26 +342,46 @@ Result provesPair(const Constraint& a, const Constraint& b) {
   // must be a constant in this case, so that we know the type.
   if (aConstant || bConstant) {
     auto type = aConstant ? aConstant->type : bConstant->type;
-    // Use proven spans for a, and exact for b. This allows us to do
-    // a => proven spans for a => exact spans for b => b.
+    // A constraint's "proven spans" are an over-approximation (superset) of the
+    // values for which the constraint holds (c => proven(c)), whereas its
+    // "exact spans" are the exact set of values (c <=> exact(c)), which may not
+    // exist when comparing against another local.
+    //
+    // To prove that a => b (return True), we check that b's exact spans contain
+    // a's proven spans:
+    //
+    //   a => proven(a) => exact(b) => b
+    //
+    // Using proven(b) here would be unsound because exact(b) => proven(b) goes
+    // the wrong way.
+    //
+    // To prove that a => !b (return False), however, it suffices to check that
+    // a's proven spans and b's proven spans do not overlap:
+    //
+    //   a => proven(a) => !proven(b) => !b
+    //
+    // Using proven(b) instead of exact(b) here is both more powerful (it works
+    // when b compares against a local, such as x <_u $y having proven span
+    // [0, MAX_UINT - 1]) and ensures that disjointness is symmetric between
+    // provesPair(a, b) and provesPair(b, a).
+    //
+    // Note that empty spans (from immediate contradictions such as
+    // x >_s MAX_INT) do not need special-casing: an empty proven(a) is
+    // vacuously contained in any exact(b) (returning True), and an empty
+    // proven(b) has no overlap with any proven(a) (returning False).
     if (auto aSpans = a.getProvenSpans(type)) {
-      if (auto bSpans = b.getSpans(type)) {
-        if (aSpans->empty()) {
-          // An empty span implies a contradiction (e.g. x > MAX_INT), as it
-          // means no possible number can apply. And contradictions prove
-          // anything.
-          return True;
-        }
-        if (bSpans->empty()) {
-          // Anything that is not a contradiction can prove a contradiction.
-          return False;
-        }
+      auto bSpans = b.getSpans(type);
+      auto bProvenSpans = b.getProvenSpans(type);

Done, renamed aSpans to aProvenSpans.

kripken kripken approved these changes on Oct 13, 2026 23:31 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
tlively tlively
Labels
risk: low confidence: 80.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.3% (MEDIUM) · Higher = larger blast radius
36.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 80.9% · Lower = rushed or shallow review
80.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 6.9% · Safe to merge
6.9%