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

Method _instantiate

crates/wasmtime/src/runtime/component/instance.rs:1163–1209  ·  view source on GitHub ↗
(
        &self,
        mut store: impl AsContextMut<Data = T>,
        asyncness: Asyncness,
    )

Source from the content-addressed store, hash-verified

1161 }
1162
1163 async fn _instantiate(
1164 &self,
1165 mut store: impl AsContextMut<Data = T>,
1166 asyncness: Asyncness,
1167 ) -> Result<Instance> {
1168 let store = store.as_context_mut();
1169 store.0.set_async_required(self.asyncness);
1170 store
1171 .engine()
1172 .allocator()
1173 .increment_component_instance_count()?;
1174
1175 // Helper structure to pair the above increment with a decrement should
1176 // anything fail below.
1177 let mut decrement = DecrementComponentInstanceCountOnDrop {
1178 store,
1179 enabled: true,
1180 };
1181
1182 let mut instantiator =
1183 Instantiator::new(&self.component, decrement.store.0, &self.imports)?;
1184 instantiator.run(&mut decrement.store, asyncness).await?;
1185
1186 let instance = Instance::from_wasmtime(decrement.store.0, instantiator.id);
1187 decrement.store.0.push_component_instance(instance);
1188
1189 // Everything has passed, don't decrement the instance count and let the
1190 // destructor for the `Store` handle that at this point.
1191 decrement.enabled = false;
1192 return Ok(instance);
1193
1194 struct DecrementComponentInstanceCountOnDrop<'a, T: 'static> {
1195 store: StoreContextMut<'a, T>,
1196 enabled: bool,
1197 }
1198
1199 impl<T> Drop for DecrementComponentInstanceCountOnDrop<'_, T> {
1200 fn drop(&mut self) {
1201 if self.enabled {
1202 self.store
1203 .engine()
1204 .allocator()
1205 .decrement_component_instance_count();
1206 }
1207 }
1208 }
1209 }
1210}

Callers 2

instantiateMethod · 0.80
instantiate_asyncMethod · 0.80

Calls 9

OkFunction · 0.85
newFunction · 0.50
as_context_mutMethod · 0.45
set_async_requiredMethod · 0.45
allocatorMethod · 0.45
engineMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected