-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Wasmtime: Finish support for the typed function references proposal #7943
Merged
fitzgen
merged 19 commits into
bytecodealliance:main
from
fitzgen:canonicalize-typed-function-references
Feb 20, 2024
Merged
Wasmtime: Finish support for the typed function references proposal #7943
fitzgen
merged 19 commits into
bytecodealliance:main
from
fitzgen:canonicalize-typed-function-references
Feb 20, 2024
Commits on Feb 16, 2024
-
Wasmtime: Finish support for the typed function references proposal
While we supported the function references proposal inside Wasm, we didn't support it on the "outside" in the Wasmtime embedder APIs. So much of the work here is exposing typed function references, and their type system updates, in the embedder API. These changes include: * `ValType::FuncRef` and `ValType::ExternRef` are gone, replaced with the introduction of the `RefType` and `HeapType` types and a `ValType::Ref(RefType)` variant. * `ValType` and `FuncType` no longer implement `Eq` and `PartialEq`. Instead there are `ValType::matches` and `FuncType::matches` methods which check directional subtyping. I also added `ValType::eq` and `FuncType::eq` static methods for the rare case where someone needs to check precise equality, but that is almost never actually the case, 99.99% of the time you want to check subtyping. * There are also public `Val::matches_ty` predicates for checking if a value is an instance of a type, as well as internal helpers like `Val::ensure_matches_ty` that return a formatted error if the value does not match the given type. These helpers are used throughout Wasmtime internals now. * There is now a dedicated `wasmtime::Ref` type that represents reference values. Table operations have been updated to take and return `Ref`s rather than `Val`s. Furthermore, this commit also includes type registry changes to correctly manage lifetimes of types that reference other types. This wasn't previously an issue because the only thing that could reference types that reference other types was a Wasm module that added all the types that could reference each other at the same time and removed them all at the same time. But now that the previously discussed work to expose these things in the embedder API is done, type lifetime management in the registry becomes a little trickier because the embedder might grab a reference to a type that references another type, and then unload the Wasm module that originally defined that type, but then the user should still be able use that type and the other types it transtively references. Before, we were refcounting individual registry entries. Now, we still are refcounting individual entries, but now we are also accounting for type-to-type references and adding a new type to the registry will increment the refcounts of each of the types that it references, and removing a type from the registry will decrement the refcounts of each of the types it references, and then recursively (logically, not literally) remove any types whose refcount has now reached zero. Additionally, this PR adds support for subtyping to `Func::typed`- and `Func::wrap`-style APIs. For result types, you can always use a supertype of the WebAssembly function's actual declared return type in `Func::typed`. And for param types, you can always use a subtype of the Wasm function's actual declared param type. Doing these things essentially erases information but is always correct. But additionally, for functions which take a reference to a concrete type as a parameter, you can also use the concrete type's supertype. Consider a WebAssembly function that takes a reference to a function with a concrete type: `(ref null <func type index>)`. In this scenario, there is no static `wasmtime::Foo` Rust type that corresponds to that particular Wasm-defined concrete reference type because Wasm modules are loaded dynamically at runtime. You *could* do `f.typed::<Option<NoFunc>, ()>()`, and while that is correctly typed and valid, it is often overly restrictive. The only value you could call the resulting typed function with is the null function reference, but we'd like to call it with non-null function references that happen to be of the correct type. Therefore, `f.typed<Option<Func>, ()>()` is also allowed in this case, even though `Option<Func>` represents `(ref null func)` which is the supertype, not subtype, of `(ref null <func type index>)`. This does imply some minimal dynamic type checks in this case, but it is supported for better ergonomics, to enable passing non-null references into the function. We can investigate whether it is possible to use generic type parameters and combinators to define Rust types that precisely match concrete reference types in future, follow-up pull requests. But for now, we've made things usable, at least. Finally, this also takes the first baby step towards adding support for the Wasm GC proposal. Right now the only thing that is supported is `nofunc` references, and this was mainly to make testing function reference subtyping easier. But that does mean that supporting `nofunc` references entailed also adding a `wasmtime::NoFunc` type as well as the `Config::wasm_gc(enabled)` knob. So we officially have an in-progress implementation of Wasm GC in Wasmtime after this PR lands! Fixes bytecodealliance#6455
Configuration menu - View commit details
-
Copy full SHA for ad731d3 - Browse repository at this point
Copy the full SHA ad731d3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6b6d124 - Browse repository at this point
Copy the full SHA 6b6d124View commit details -
Configuration menu - View commit details
-
Copy full SHA for 289bdd4 - Browse repository at this point
Copy the full SHA 289bdd4View commit details -
Remove unnecessary engine parameters from a few methods
Ever since `FuncType`'s internal `RegisteredType` holds onto its own `Engine`, we don't need these anymore. Still useful to keep the `Engine` parameter around for the `ensure_matches` methods because that can be used to check correct store/engine usage for embedders.
Configuration menu - View commit details
-
Copy full SHA for 680ac2e - Browse repository at this point
Copy the full SHA 680ac2eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 424787b - Browse repository at this point
Copy the full SHA 424787bView commit details -
Configuration menu - View commit details
-
Copy full SHA for d7533d6 - Browse repository at this point
Copy the full SHA d7533d6View commit details -
Configuration menu - View commit details
-
Copy full SHA for c50d546 - Browse repository at this point
Copy the full SHA c50d546View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1ef1db8 - Browse repository at this point
Copy the full SHA 1ef1db8View commit details -
Configuration menu - View commit details
-
Copy full SHA for d9245af - Browse repository at this point
Copy the full SHA d9245afView commit details -
Configuration menu - View commit details
-
Copy full SHA for b03beb1 - Browse repository at this point
Copy the full SHA b03beb1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2380b23 - Browse repository at this point
Copy the full SHA 2380b23View commit details -
Configuration menu - View commit details
-
Copy full SHA for 539d7b6 - Browse repository at this point
Copy the full SHA 539d7b6View commit details -
Configuration menu - View commit details
-
Copy full SHA for fdf1889 - Browse repository at this point
Copy the full SHA fdf1889View commit details -
Configuration menu - View commit details
-
Copy full SHA for ce29e58 - Browse repository at this point
Copy the full SHA ce29e58View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3942b81 - Browse repository at this point
Copy the full SHA 3942b81View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3aa04da - Browse repository at this point
Copy the full SHA 3aa04daView commit details -
Configuration menu - View commit details
-
Copy full SHA for 027151b - Browse repository at this point
Copy the full SHA 027151bView commit details
Commits on Feb 20, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 62a8944 - Browse repository at this point
Copy the full SHA 62a8944View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8aced9e - Browse repository at this point
Copy the full SHA 8aced9eView commit details
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.