-
Notifications
You must be signed in to change notification settings - Fork 246
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
wasmparser: Use type-specific identifiers pervasively #1257
wasmparser: Use type-specific identifiers pervasively #1257
Conversation
FWIW: 3.5 million fuzz iterations and no problems discovered thus far. |
ed6fd19
to
370d151
Compare
This commit changes `wasmparser` from the uni-typed `TypeId` identifier to a myriad of type-specific identifiers, such as `ComponentInstanceTypeId` and `ComponentDefinedTypeId`. There are also identifiers for any kind of type within some group, such as `ComponentAnyTypeId` for any kind of component type and `AnyTypeId` for any kind of type, component or core. The `wasmparser::Types` arena can be indexed by any of these leaf type identifiers, which all implement the `TypeIdentifier` trait. The resulting indexed data is the particular type, e.g. a `ComponentFuncType`, rather than the uni-typed `wasmparser::Type`. There was a lot of ocean boiling involved here. Apologies in advance for the pain of this upgrade! That said, it should provide type safety benefits moving forward and sets the stage for further identifier refactors for core types that are necessary for Wasm GC. If you are upgrading and were using `TypeId` before, and don't want to spend time gaining type safety on your type lookups, then just use `AnyTypeId` instead of the old `TypeId`. They are morally identical. Alternatively, if you know a particular `TypeId` was always a component function, for example, and you always did `types[id].unwrap_component_func()`, then you can switch to using `ComponentFuncTypeId`. Co-Authored-By: Alex Crichton <alex@alexcrichton.com>
370d151
to
60e1398
Compare
/// Unwrap a `FuncType` or panic. | ||
pub fn unwrap_func(&self) -> &FuncType { | ||
self.structural_type.unwrap_func() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this perhaps also check that is_final
is true or false? (I forget which it should check for)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is final == true
but there is nothing stopping one from defining a non-final function type, and I'd imagine this would still want to return the underlying function type.
This commit updates the wasm-tools family of crate for a number of notable updates: * bytecodealliance/wasm-tools#1257 - wasmparser's ID-based infrastructure has been refactored to have more precise types for each ID rather than one all-purpose `TypeId`. * bytecodealliance/wasm-tools#1262 - the implementation of "implementation imports" for the component model which both updates the binary format in addition to adding more syntactic forms of imports. * bytecodealliance/wasm-tools#1260 - a new encoding scheme for component information for `wit-component` in objects (not used by Wasmtime but used by bindings generators). Translation for components needed to be updated to account for the first change, but otherwise this was a straightforward update.
* Update wasm-tools crates This commit updates the wasm-tools family of crate for a number of notable updates: * bytecodealliance/wasm-tools#1257 - wasmparser's ID-based infrastructure has been refactored to have more precise types for each ID rather than one all-purpose `TypeId`. * bytecodealliance/wasm-tools#1262 - the implementation of "implementation imports" for the component model which both updates the binary format in addition to adding more syntactic forms of imports. * bytecodealliance/wasm-tools#1260 - a new encoding scheme for component information for `wit-component` in objects (not used by Wasmtime but used by bindings generators). Translation for components needed to be updated to account for the first change, but otherwise this was a straightforward update. * Remove a TODO
This commit changes
wasmparser
from the uni-typedTypeId
identifier to a myriad of type-specific identifiers, such asComponentInstanceTypeId
andComponentDefinedTypeId
. There are also identifiers for any kind of type within some group, such asComponentAnyTypeId
for any kind of component type andAnyTypeId
for any kind of type, component or core.The
wasmparser::Types
arena can be indexed by any of these leaf type identifiers, which all implement theTypeIdentifier
trait. The resulting indexed data is the particular type, e.g. aComponentFuncType
, rather than the uni-typedwasmparser::Type
.There was a lot of ocean boiling involved here. Apologies in advance for the pain of this upgrade! That said, it should provide type safety benefits moving forward and sets the stage for further identifier refactors for core types that are necessary for Wasm GC.
If you are upgrading and were using
TypeId
before, and don't want to spend time gaining type safety on your type lookups, then just useAnyTypeId
instead of the oldTypeId
. They are morally identical. Alternatively, if you know a particularTypeId
was always a component function, for example, and you always didtypes[id].unwrap_component_func()
, then you can switch to usingComponentFuncTypeId
.