Implement imported/exported modules/instances (#2461)
* Implement imported/exported modules/instances This commit implements the final piece of the module linking proposal which is to flesh out the support for importing/exporting instances and modules. This ended up having a few changes: * Two more `PrimaryMap` instances are now stored in an `Instance`. The value for instances is `InstanceHandle` (pretty easy) and for modules it's `Box<dyn Any>` (less easy). * The custom host state for `InstanceHandle` for `wasmtime` is now `Arc<TypeTables` to be able to fully reconstruct an instance's types just from its instance. * Type matching for imports now has been updated to take instances/modules into account. One of the main downsides of this implementation is that type matching of imports is duplicated between wasmparser and wasmtime, leading to posssible bugs especially in the subtelties of module linking. I'm not sure how best to unify these two pieces of validation, however, and it may be more trouble than it's worth. cc #2094 * Update wat/wast/wasmparser * Review comments * Fix a bug in publish script to vendor the right witx Currently there's two witx binaries in our repository given the two wasi spec submodules, so this updates the publication script to vendor the right one.
This commit is contained in:
@@ -346,6 +346,31 @@ impl Module {
|
||||
pub fn is_imported_global(&self, index: GlobalIndex) -> bool {
|
||||
index.index() < self.num_imported_globals
|
||||
}
|
||||
|
||||
/// Returns an iterator of all the imports in this module, along with their
|
||||
/// module name, field name, and type that's being imported.
|
||||
pub fn imports(&self) -> impl Iterator<Item = (&str, Option<&str>, EntityType)> {
|
||||
self.initializers.iter().filter_map(move |i| match i {
|
||||
Initializer::Import {
|
||||
module,
|
||||
field,
|
||||
index,
|
||||
} => Some((module.as_str(), field.as_deref(), self.type_of(*index))),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the type of an item based on its index
|
||||
pub fn type_of(&self, index: EntityIndex) -> EntityType {
|
||||
match index {
|
||||
EntityIndex::Global(i) => EntityType::Global(self.globals[i]),
|
||||
EntityIndex::Table(i) => EntityType::Table(self.table_plans[i].table),
|
||||
EntityIndex::Memory(i) => EntityType::Memory(self.memory_plans[i].memory),
|
||||
EntityIndex::Function(i) => EntityType::Function(self.functions[i]),
|
||||
EntityIndex::Instance(i) => EntityType::Instance(self.instances[i]),
|
||||
EntityIndex::Module(i) => EntityType::Module(self.modules[i]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// All types which are recorded for the entirety of a translation.
|
||||
@@ -376,7 +401,7 @@ pub struct ModuleSignature {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct InstanceSignature {
|
||||
/// The name of what's being exported as well as its type signature.
|
||||
pub exports: Vec<(String, EntityType)>,
|
||||
pub exports: IndexMap<String, EntityType>,
|
||||
}
|
||||
|
||||
mod passive_data_serde {
|
||||
|
||||
Reference in New Issue
Block a user