MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / build_imports

Method build_imports

crates/wasmtime/src/runtime/component/instance.rs:950–980  ·  view source on GitHub ↗
(
        &mut self,
        store: &mut StoreOpaque,
        module: &Module,
        args: impl Iterator<Item = &'b CoreDef>,
    )

Source from the content-addressed store, hash-verified

948 }
949
950 fn build_imports<'b>(
951 &mut self,
952 store: &mut StoreOpaque,
953 module: &Module,
954 args: impl Iterator<Item = &'b CoreDef>,
955 ) -> Result<&OwnedImports, OutOfMemory> {
956 self.core_imports.clear();
957 self.core_imports.reserve(module)?;
958 let mut imports = module.compiled_module().module().imports();
959
960 for arg in args {
961 // The general idea of Wasmtime is that at runtime type-checks for
962 // core wasm instantiations internally within a component are
963 // unnecessary and superfluous. Naturally though mistakes may be
964 // made, so double-check this property of wasmtime in debug mode.
965
966 if cfg!(debug_assertions) {
967 let (imp_module, imp_name, expected) = imports.next().unwrap();
968 self.assert_type_matches(store, module, arg, imp_module, imp_name, expected);
969 }
970
971 // The unsafety here should be ok since the `export` is loaded
972 // directly from an instance which should only give us valid export
973 // items.
974 let export = lookup_vmdef(store, self.id, arg);
975 self.core_imports.push_export(store, &export)?;
976 }
977 debug_assert!(imports.next().is_none());
978
979 Ok(&self.core_imports)
980 }
981
982 fn assert_type_matches(
983 &self,

Callers 1

runMethod · 0.80

Calls 11

lookup_vmdefFunction · 0.85
OkFunction · 0.85
compiled_moduleMethod · 0.80
assert_type_matchesMethod · 0.80
clearMethod · 0.45
reserveMethod · 0.45
importsMethod · 0.45
moduleMethod · 0.45
unwrapMethod · 0.45
nextMethod · 0.45
push_exportMethod · 0.45

Tested by

no test coverage detected