Skip to content

[ConstraintAnalysis] Check unreachable after LocalSet before adding non-nullability - #9436

Open
tlively wants to merge 1 commit into
mainfrom
constraint-analysis-unreachable-non-null
Open

tlively wants to merge 1 commit into
mainfrom
constraint-analysis-unreachable-non-null

Conversation

@tlively

@tlively tlively commented Nov 29, 2026

Copy link
Copy Markdown
Member

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.

…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.
@github-actions
github-actions Bot requested a review from aheejin November 29, 2026 03:26
(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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

if (provesEverything()) {
// Nothing to add.
return;
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants