Refactor away the Instantiator type in Wasmtime (#3972)
* Refactor away the `Instantiator` type in Wasmtime This internal type in Wasmtime was primarily used for the module linking proposal to handle instantiation of many instances and refactor out the sync and async parts to minimize duplication. With the removal of the module linking proposal, however, this type isn't really necessary any longer. In working to implement the component model proposal I was looking already to refactor this and I figured it'd be good to land that ahead of time on `main` separate of other refactorings. This commit removes the `Instantiator` type in the `instance` module. The type was already private to Wasmtime so this shouldn't have any impact on consumers. This allows simplifying various code paths to avoid another abstraction. The meat of instantiation is moved to `Instance::new_raw` which should be reusable for the component model as well. One bug is actually fixed in this commit as well where `Linker::instantiate` and `InstancePre::instantiate` failed to check that async support was disabled on a store. This means that they could have led to a panic if used with an async store and a start function called an async import (or an async resource limiter yielded). A few tests were updated with this. * Review comments
This commit is contained in:
@@ -69,9 +69,6 @@ fn run_and_count_yields_or_trap<F: Fn(Arc<Engine>)>(
|
||||
let linker = make_env(&engine);
|
||||
let module = Module::new(&engine, wasm).unwrap();
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = linker.instantiate(&mut store, &module).unwrap();
|
||||
let f = instance.get_func(&mut store, "run").unwrap();
|
||||
|
||||
store.set_epoch_deadline(initial);
|
||||
match delta {
|
||||
Some(delta) => {
|
||||
@@ -85,7 +82,11 @@ fn run_and_count_yields_or_trap<F: Fn(Arc<Engine>)>(
|
||||
let engine_clone = engine.clone();
|
||||
setup_func(engine_clone);
|
||||
|
||||
let mut future = Box::pin(f.call_async(&mut store, &[], &mut []));
|
||||
let mut future = Box::pin(async {
|
||||
let instance = linker.instantiate_async(&mut store, &module).await.unwrap();
|
||||
let f = instance.get_func(&mut store, "run").unwrap();
|
||||
f.call_async(&mut store, &[], &mut []).await
|
||||
});
|
||||
let mut yields = 0;
|
||||
loop {
|
||||
match future
|
||||
@@ -394,13 +395,15 @@ fn drop_future_on_epoch_yield() {
|
||||
|
||||
let module = Module::new(&engine, wasm).unwrap();
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = linker.instantiate(&mut store, &module).unwrap();
|
||||
let f = instance.get_func(&mut store, "run").unwrap();
|
||||
|
||||
store.set_epoch_deadline(1);
|
||||
store.epoch_deadline_async_yield_and_update(1);
|
||||
|
||||
let mut future = Box::pin(f.call_async(&mut store, &[], &mut []));
|
||||
let mut future = Box::pin(async {
|
||||
let instance = linker.instantiate_async(&mut store, &module).await.unwrap();
|
||||
let f = instance.get_func(&mut store, "run").unwrap();
|
||||
f.call_async(&mut store, &[], &mut []).await
|
||||
});
|
||||
match future
|
||||
.as_mut()
|
||||
.poll(&mut Context::from_waker(&dummy_waker()))
|
||||
|
||||
Reference in New Issue
Block a user