Propagate optional import names to the wasmtime/C API

With the module linking proposal the field name on imports is now
optional, and only the module is required to be specified. This commit
propagates this API change to the boundary of wasmtime's API, ensuring
consumers are aware of what's optional with module linking and what
isn't. Note that it's expected that all existing users will either
update accordingly or unwrap the result since module linking is
presumably disabled.
This commit is contained in:
Alex Crichton
2020-11-23 15:17:34 -08:00
parent 1dd20b4371
commit 62be6841e4
18 changed files with 132 additions and 93 deletions

View File

@@ -581,7 +581,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
&mut self,
index: TypeIndex,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
assert_eq!(
self.info.functions.len(),
@@ -591,7 +591,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
self.info.functions.push(Exportable::new(index));
self.info
.imported_funcs
.push((String::from(module), String::from(field)));
.push((String::from(module), String::from(field.unwrap())));
Ok(())
}
@@ -609,12 +609,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
&mut self,
global: Global,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
self.info.globals.push(Exportable::new(global));
self.info
.imported_globals
.push((String::from(module), String::from(field)));
.push((String::from(module), String::from(field.unwrap())));
Ok(())
}
@@ -627,12 +627,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
&mut self,
table: Table,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
self.info.tables.push(Exportable::new(table));
self.info
.imported_tables
.push((String::from(module), String::from(field)));
.push((String::from(module), String::from(field.unwrap())));
Ok(())
}
@@ -672,12 +672,12 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
&mut self,
memory: Memory,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
self.info.memories.push(Exportable::new(memory));
self.info
.imported_memories
.push((String::from(module), String::from(field)));
.push((String::from(module), String::from(field.unwrap())));
Ok(())
}

View File

@@ -674,7 +674,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
index: TypeIndex,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()>;
/// Declares a table import to the environment.
@@ -682,7 +682,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
table: Table,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()>;
/// Declares a memory import to the environment.
@@ -690,7 +690,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
memory: Memory,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()>;
/// Declares an event import to the environment.
@@ -698,7 +698,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
event: Event,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
drop((event, module, field));
Err(WasmError::Unsupported("wasm events".to_string()))
@@ -709,7 +709,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
global: Global,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()>;
/// Declares a module import to the environment.
@@ -717,7 +717,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
drop((ty_index, module, field));
Err(WasmError::Unsupported("module linking".to_string()))
@@ -728,7 +728,7 @@ pub trait ModuleEnvironment<'data>: TargetEnvironment {
&mut self,
ty_index: TypeIndex,
module: &'data str,
field: &'data str,
field: Option<&'data str>,
) -> WasmResult<()> {
drop((ty_index, module, field));
Err(WasmError::Unsupported("module linking".to_string()))

View File

@@ -156,27 +156,25 @@ pub fn parse_import_section<'data>(
for entry in imports {
let import = entry?;
let module_name = import.module;
let field_name = import.field.unwrap(); // TODO Handle error when module linking is implemented.
match entity_type(import.ty, environ)? {
EntityType::Function(idx) => {
environ.declare_func_import(idx, module_name, field_name)?;
environ.declare_func_import(idx, import.module, import.field)?;
}
EntityType::Module(idx) => {
environ.declare_module_import(idx, module_name, field_name)?;
environ.declare_module_import(idx, import.module, import.field)?;
}
EntityType::Instance(idx) => {
environ.declare_instance_import(idx, module_name, field_name)?;
environ.declare_instance_import(idx, import.module, import.field)?;
}
EntityType::Memory(ty) => {
environ.declare_memory_import(ty, module_name, field_name)?;
environ.declare_memory_import(ty, import.module, import.field)?;
}
EntityType::Event(e) => environ.declare_event_import(e, module_name, field_name)?,
EntityType::Event(e) => environ.declare_event_import(e, import.module, import.field)?,
EntityType::Global(ty) => {
environ.declare_global_import(ty, module_name, field_name)?;
environ.declare_global_import(ty, import.module, import.field)?;
}
EntityType::Table(ty) => {
environ.declare_table_import(ty, module_name, field_name)?;
environ.declare_table_import(ty, import.module, import.field)?;
}
}
}