Repository navigation
Conversation
…on-nullability When ConstraintAnalysis::applyToConstraints handles a LocalSet, calling constraints.set(set->index, value) can discover a contradiction (for example when copying constraints from a local known to be equal to another local and non-null, inside a branch where that other local is known to be null) and mark constraints as unreachable. Previously, the subsequent non-nullability check called constraints.approximateAnd without checking constraints.unreachable first, triggering an assertion failure. Return early when constraints.unreachable becomes true after constraints.set, and add regression tests in constraint-analysis-gc.wast.
aheejin
reviewed
Nov 29, 2026
| (func $contradiction-before-non-null (param $p (ref any)) | ||
| (local $a anyref) | ||
| (local $b anyref) | ||
| ;; $a gets Eq $p and Ne null, while $p only gets Eq $a. Inside the |
Member
There was a problem hiding this comment.
Unrelated to this PR, but doesn't $p get Ne null even if its type is ref any?
Comment on lines
+626
to
+630
| if (constraints.unreachable) { | ||
| // Applying the set may discover a contradiction, making this code | ||
| // unreachable before we can apply further constraints. | ||
| return; | ||
| } |
Member
There was a problem hiding this comment.
Don't other callsites of approximateAnd have this problem?
If some of them do, wouldn't it be more convenient to add this check to approximateAnd or approximateAndInternal instead so that it just returns when it is unreachable? In case of AndedConstraintSet::approximateAnd, it also returns without doing anything if provesEverything is true, which is I think similar to unreachable in BasicBlockConstraintMap:
binaryen/src/ir/constraint.cpp
Lines 552 to 555 in e100f01
This branch has not been deployed
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.
When ConstraintAnalysis::applyToConstraints handles a LocalSet, calling constraints.set(set->index, value) can discover a contradiction (for example when copying constraints from a local known to be equal to another local and non-null, inside a branch where that other local is known to be null) and mark constraints as unreachable. Previously, the subsequent non-nullability check called constraints.approximateAnd without checking constraints.unreachable first, triggering an assertion failure. Return early when constraints.unreachable becomes true after constraints.set, and add regression tests in constraint-analysis-gc.wast.