Skip to content

ConstraintAnalysis: Infer non-nullability from trapping operations - #9434

Open
kripken wants to merge 31 commits into
WebAssembly:mainfrom
kripken:ca.gc.2mine
Open

kripken wants to merge 31 commits into
WebAssembly:mainfrom
kripken:ca.gc.2mine

Conversation

@kripken

@kripken kripken commented Nov 26, 2026

Copy link
Copy Markdown
Member

Consider

(struct.get
  (local.get $x)
)
(ref.is_null
  (local.get $x)
)

The struct.get traps if x is null, so we can infer it is not null
afterwards, or we wouldn't get there.

@github-actions
github-actions Bot requested a review from tlively November 26, 2026 00:55
}

return;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@aheejin You suggested an early return for the LocalSet case here, but I think after this refactor it would break the symmetry of the new code after it... so I left it as is. But open to suggestions here.

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.

Yeah early return doesn't make sense if the function handles more things than local.set

@chharvey

Copy link
Copy Markdown
Contributor

Also a related issue:

(local $x (ref null any))
(local $y (ref any))
(if
  (result (ref any))
  (ref.is_null (local.get $x))
  (then (local.get $y))
  (else (local.get $x)) ;; <-- error: returning if-else's false must have right type
  ;; to fix, use (else (ref.as_non_null (local.get $x))
)

If the else branch got selected, then $x can’t have been null.

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.

3 participants