Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/runtime/src/externref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ impl VMExternRefActivationsTable {
// The current `precise_stack_roots` becomes our new over-appoximated
// set for the next GC cycle.
let mut over_approximated = self.over_approximated_stack_roots.borrow_mut();
mem::swap(&mut *precise_stack_roots, &mut *over_approximated);
mem::swap(precise_stack_roots, &mut *over_approximated);

// And finally, the new `precise_stack_roots` should be cleared and
// remain empty until the next GC cycle.
Expand Down
63 changes: 43 additions & 20 deletions crates/wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::frame_info::GlobalFrameInfoRegistration;
use crate::trampoline::StoreInstanceHandle;
use crate::{Engine, Export, Extern, Func, Global, Memory, Module, Store, Table, Trap};
use anyhow::{anyhow, bail, Context, Error, Result};
use std::any::Any;
use std::mem;
use std::sync::Arc;
use wasmtime_environ::EntityIndex;
use wasmtime_jit::CompiledModule;
use wasmtime_runtime::{
Expand Down Expand Up @@ -102,7 +104,47 @@ pub struct Instance {
module: Module,
}

pub struct HostState {
#[allow(dead_code)]
frame_info_registration: Option<Arc<GlobalFrameInfoRegistration>>,
Copy link
Copy Markdown
Contributor

@bjorn3 bjorn3 Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frame_info_registration: Option<Arc<GlobalFrameInfoRegistration>>,
_frame_info_registration: Option<Arc<GlobalFrameInfoRegistration>>,

This suppresses the dead code warning for this field only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved #[allow(dead_code)] to above the frame_info_registration field

pub user_state: Option<Box<dyn Any>>,
}

impl Instance {
/// allows the caller to specify customimzed user_state, which can be accessed by
/// instance.host_state().downcast_ref::<HostState>.user_state
pub fn new_with_user_state(
store: &Store,
module: &Module,
imports: &[Extern],
user_state: Option<Box<dyn Any>>,
) -> Result<Instance, Error> {
if !Engine::same(store.engine(), module.engine()) {
bail!("cross-`Engine` instantiation is not currently supported");
}

let host_info = Box::new({
let frame_info_registration = module.register_frame_info();
store.register_jit_code(&module);
store.register_stack_maps(&module);

HostState {
frame_info_registration,
user_state,
}
});

let handle = with_imports(store, module.compiled_module(), imports, |imports| {
instantiate(store, module.compiled_module(), imports, host_info)
})?;

Ok(Instance {
handle,
store: store.clone(),
module: module.clone(),
})
}

/// Creates a new [`Instance`] from the previously compiled [`Module`] and
/// list of `imports` specified.
///
Expand Down Expand Up @@ -157,26 +199,7 @@ impl Instance {
/// [issue]: https://github.com/bytecodealliance/wasmtime/issues/727
/// [`ExternType`]: crate::ExternType
pub fn new(store: &Store, module: &Module, imports: &[Extern]) -> Result<Instance, Error> {
if !Engine::same(store.engine(), module.engine()) {
bail!("cross-`Engine` instantiation is not currently supported");
}

let host_info = Box::new({
let frame_info_registration = module.register_frame_info();
store.register_jit_code(&module);
store.register_stack_maps(&module);
frame_info_registration
});

let handle = with_imports(store, module.compiled_module(), imports, |imports| {
instantiate(store, module.compiled_module(), imports, host_info)
})?;

Ok(Instance {
handle,
store: store.clone(),
module: module.clone(),
})
Instance::new_with_user_state(store, module, imports, None)
}

/// Returns the associated [`Store`] that this `Instance` is compiled into.
Expand Down