From d3deaae99d900ff830952f8e75ef2eb61affe568 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 21 Oct 2021 12:09:18 -0700 Subject: [PATCH] collapse some common code --- crates/wasmtime/src/instance.rs | 58 +++++++++++++-------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/crates/wasmtime/src/instance.rs b/crates/wasmtime/src/instance.rs index b2cf6affa5..bced7cfe4c 100644 --- a/crates/wasmtime/src/instance.rs +++ b/crates/wasmtime/src/instance.rs @@ -126,6 +126,11 @@ impl Instance { typecheck_externs(store.0, module, imports)?; Instantiator::new(store.0, module, ImportSource::Externs(imports))? }; + assert!( + !store.0.async_support(), + "cannot use `new` when async support is enabled on the config" + ); + i.run(&mut store) } @@ -162,7 +167,14 @@ impl Instance { typecheck_externs(store.0, module, imports)?; Instantiator::new(store.0, module, ImportSource::Externs(imports))? }; - i.run_async(&mut store).await + let mut store = store.as_context_mut(); + assert!( + store.0.async_support(), + "cannot use `new_async` without enabling async support on the config" + ); + store + .on_fiber(|store| i.run(&mut store.as_context_mut())) + .await? } pub(crate) fn from_wasmtime(handle: InstanceData, store: &mut StoreOpaque) -> Instance { @@ -472,13 +484,6 @@ impl<'a> Instantiator<'a> { } fn run(&mut self, store: &mut StoreContextMut<'_, T>) -> Result { - assert!( - !store.0.async_support(), - "cannot use `new` when async support is enabled on the config" - ); - - // NB: this is the same code as `run_async`. It's intentionally - // small but should be kept in sync (modulo the async bits). loop { if let Some((instance, start, toplevel)) = self.step(store.0)? { if let Some(start) = start { @@ -491,33 +496,6 @@ impl<'a> Instantiator<'a> { } } - #[cfg(feature = "async")] - async fn run_async(&mut self, store: &mut StoreContextMut<'_, T>) -> Result - where - T: Send, - { - assert!( - store.0.async_support(), - "cannot use `new_async` without enabling async support on the config" - ); - - // NB: this is the same code as `run`. It's intentionally - // small but should be kept in sync (modulo the async bits). - store - .on_fiber(|store| loop { - let step = self.step(store.0)?; - if let Some((instance, start, toplevel)) = step { - if let Some(start) = start { - Instantiator::start_raw(store, instance, start)? - } - if toplevel { - break Ok(instance); - } - } - }) - .await? - } - /// Processes the next initializer for the next instance being created /// without running any wasm code. /// @@ -1002,7 +980,15 @@ impl InstancePre { ImportSource::Definitions(&self.items), )? }; - i.run_async(&mut store.as_context_mut()).await + + let mut store = store.as_context_mut(); + assert!( + store.0.async_support(), + "cannot use `new_async` without enabling async support on the config" + ); + store + .on_fiber(|store| i.run(&mut store.as_context_mut())) + .await? } fn ensure_comes_from_same_store(&self, store: &StoreOpaque) -> Result<()> {