Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the ref.test Wasm GC instruction #9401

Merged
merged 6 commits into from
Oct 8, 2024

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Oct 8, 2024

This commit implements the ref.test instruction, which tests whether a reference is of a given type.

We implement inline fast paths for abstract types, but currently rely on an out-of-line libcall for concrete types in the general case. This is known to be suboptimal. (FWIW, we also emit a fast path in front of the libcall where we first check the actual type and expected type for equality and skip the libcall if they are equal.)

This implementation is expected to be improved in the future by exposing a module's types' supertypes arrays to Wasm, so that the Wasm can do the O(1) subtype checks inline. This will make the vast majority of all ref.tests inlinable. After that, the only remaining case that would require out-of-line libcalls would be when a module is given an instance of a type that it did not itself define (but which could be a subtype of a type it defined, for example, and which itself might not even have been defined until after this module's instance was created!)

This commit implements the `ref.test` instruction, which tests whether a
reference is of a given type.

We implement inline fast paths for abstract types, but currently rely on an
out-of-line libcall for concrete types in the general case. This is known to be
suboptimal. (FWIW, we also emit a fast path in front of the libcall where we
first check the actual type and expected type for equality and skip the libcall
if they are equal.)

This implementation is expected to be improved in the future by exposing a
module's types' supertypes arrays to Wasm, so that the Wasm can do the O(1)
subtype checks inline. This will make the vast majority of all `ref.test`s
inlinable. After that, the only remaining case that would require out-of-line
libcalls would be when a module is given an instance of a type that it did not
itself define (but which could be a subtype of a type it defined, for example,
and which itself might not even have been defined until after this module's
instance was created!)
@fitzgen fitzgen requested a review from a team as a code owner October 8, 2024 21:20
@fitzgen fitzgen requested review from alexcrichton and removed request for a team October 8, 2024 21:20
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks for all the helpful comments!

crates/cranelift/src/gc/enabled.rs Outdated Show resolved Hide resolved
@fitzgen fitzgen enabled auto-merge October 8, 2024 21:45
@fitzgen fitzgen added this pull request to the merge queue Oct 8, 2024
Merged via the queue into bytecodealliance:main with commit bc6b0fe Oct 8, 2024
39 checks passed
@fitzgen fitzgen deleted the ref-test branch October 8, 2024 22:23
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