Skip to content

[CustomDescriptors] Ensure a non-nullable type for be_on_cast_desc_eq on null - #8975

Open
kripken wants to merge 4 commits into
WebAssembly:mainfrom
kripken:ref.br_on
Open

[CustomDescriptors] Ensure a non-nullable type for be_on_cast_desc_eq on null#8975
kripken wants to merge 4 commits into
WebAssembly:mainfrom
kripken:ref.br_on

Conversation

@kripken

@kripken kripken commented Aug 6, 2026

Copy link
Copy Markdown
Member

If the desc is null, the cast is not even executed, making it unreachable.
We typed it as nullable if the ref was (in the code path type = ref->type;),
but emiting an uninhabitable type is more precise, and also avoids a fuzz
bug (see new test) where refinalize actually un-refined a type: it turned it
from non-nullable to nullable.

@kripken
kripken requested a review from tlively August 6, 2026 18:01
@kripken
kripken requested a review from a team as a code owner August 6, 2026 18:01

@tlively tlively left a comment

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.

Should update the title to say br_on_cast_desc_eq rather than ref.cast_desc_eq.

Comment on lines +9 to +15
(type $0 (sub (descriptor $2) (struct)))
;; CHECK: (type $1 (sub $0 (descriptor $3) (struct)))
(type $1 (sub $0 (descriptor $3) (struct)))
;; CHECK: (type $2 (sub (describes $0) (struct)))
(type $2 (sub (describes $0) (struct)))
;; CHECK: (type $3 (sub $2 (describes $1) (struct (field i32))))
(type $3 (sub $2 (describes $1) (struct (field i32))))

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.

Can we use any in the test instead of defining any types?

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.

We need to br_on_cast_desc_eq on a defined descriptor type? Otherwise we get Fatal: test/lit/passes/local-subtyping-desc.wast:65:5: error: cast target must have descriptor

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.

Oh right, of course. Can we get away with just defining a single describee/descriptor pair, then?

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.

Good point, the subtyping was not needed. Simplified.

Comment on lines +64 to +69
(local.set $2
(br_on_cast_desc_eq $block (ref null $1) (ref null $1)
(ref.null $1)
(local.get $1)
)
)

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.

The test says we can refine local $2 and therefore the br_on_cast_desc_eq must be refinalized to the correct type. But isn't that backward and self-justifying? Without the change to finalization, we should not be trying to refine local $2 in the first place. If this refinement is a new optimization, that's one thing, but I don't see how the change can be a correct bug fix.

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.

This is a indeed confusing so I added a detailed comment now about exactly how the types get refined here during the 2 iterations of the pass. Hopefully that makes things clearer?

This is not an optimization, it fixes an assertion. Though I suppose it is also better and might optimize some things? Btw, this fixes a whole set of fuzzer bugs that were very annoying to track down - both I and AI gave up on most of them. This was the first testcase that was practical to investigate (and luckily it solves the others too).

@kripken kripken changed the title [CustomDescriptors] Ensure a non-nullable type for ref.cast_desc_eq on null [CustomDescriptors] Ensure a non-nullable type for be_on_cast_desc_eq on null Aug 7, 2026
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