From e40c039e654ff817c56227b37b2e4b308a7efbf5 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 25 Jun 2020 10:24:40 -0700 Subject: [PATCH] wasmtime: Rip out incomplete/incorrect externref "host info" support Better to be loud that we don't support attaching arbitrary host info to `externref`s than to limp along and pretend we do support it. Supporting it properly won't reuse any of this code anyways. --- crates/c-api/macros/src/lib.rs | 8 +++-- crates/c-api/src/error.rs | 6 ++-- crates/c-api/src/func.rs | 18 +++++------ crates/c-api/src/global.rs | 2 +- crates/c-api/src/host_ref.rs | 6 ++-- crates/c-api/src/instance.rs | 19 +++++------- crates/c-api/src/linker.rs | 13 ++++---- crates/c-api/src/memory.rs | 2 +- crates/c-api/src/module.rs | 4 +-- crates/c-api/src/ref.rs | 45 ++++++--------------------- crates/c-api/src/table.rs | 12 ++------ crates/c-api/src/trap.rs | 10 +++--- crates/c-api/src/wasi.rs | 5 ++- crates/wasmtime/src/externals.rs | 7 ++--- crates/wasmtime/src/ref.rs | 53 ++------------------------------ crates/wasmtime/src/runtime.rs | 31 ------------------- crates/wasmtime/src/values.rs | 19 ++++++------ crates/wast/src/wast.rs | 6 ++-- tests/all/gc.rs | 11 +++---- 19 files changed, 79 insertions(+), 198 deletions(-) mode change 100644 => 100755 crates/wasmtime/src/ref.rs diff --git a/crates/c-api/macros/src/lib.rs b/crates/c-api/macros/src/lib.rs index 1ca2655660cd..9d24ceec01ff 100644 --- a/crates/c-api/macros/src/lib.rs +++ b/crates/c-api/macros/src/lib.rs @@ -77,12 +77,13 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream { #[no_mangle] pub extern fn #get_host_info(a: &#ty) -> *mut std::os::raw::c_void { - crate::r#ref::get_host_info(&a.externref()) + std::ptr::null_mut() } #[no_mangle] pub extern fn #set_host_info(a: &#ty, info: *mut std::os::raw::c_void) { - crate::r#ref::set_host_info(&a.externref(), info, None) + eprintln!("`{}` is not implemented", stringify!(#set_host_info)); + std::process::abort(); } #[no_mangle] @@ -91,7 +92,8 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream { info: *mut std::os::raw::c_void, finalizer: Option, ) { - crate::r#ref::set_host_info(&a.externref(), info, finalizer) + eprintln!("`{}` is not implemented", stringify!(#set_host_info_final)); + std::process::abort(); } #[no_mangle] diff --git a/crates/c-api/src/error.rs b/crates/c-api/src/error.rs index 3ea634b56047..cbb84873df6c 100644 --- a/crates/c-api/src/error.rs +++ b/crates/c-api/src/error.rs @@ -1,6 +1,6 @@ use crate::{wasm_name_t, wasm_trap_t}; use anyhow::{anyhow, Error, Result}; -use wasmtime::{Store, Trap}; +use wasmtime::Trap; #[repr(C)] pub struct wasmtime_error_t { @@ -10,8 +10,8 @@ pub struct wasmtime_error_t { wasmtime_c_api_macros::declare_own!(wasmtime_error_t); impl wasmtime_error_t { - pub(crate) fn to_trap(self, store: &Store) -> Box { - Box::new(wasm_trap_t::new(store, Trap::from(self.error))) + pub(crate) fn to_trap(self) -> Box { + Box::new(wasm_trap_t::new(Trap::from(self.error))) } } diff --git a/crates/c-api/src/func.rs b/crates/c-api/src/func.rs index 244daaeb4353..a863da99fac9 100644 --- a/crates/c-api/src/func.rs +++ b/crates/c-api/src/func.rs @@ -108,7 +108,7 @@ fn create_function( } Ok(()) }); - Box::new(HostRef::new(store, func).into()) + Box::new(HostRef::new(func).into()) } #[no_mangle] @@ -183,7 +183,7 @@ pub unsafe extern "C" fn wasm_func_call( &mut trap, ); match error { - Some(err) => Box::into_raw(err.to_trap(&wasm_func.ext.externref().store().unwrap())), + Some(err) => Box::into_raw(err.to_trap()), None => trap, } } @@ -211,7 +211,6 @@ fn _wasmtime_func_call( results: &mut [wasm_val_t], trap_ptr: &mut *mut wasm_trap_t, ) -> Option> { - let store = &func.ext.externref().store().unwrap(); let func = func.func().borrow(); if results.len() != func.result_arity() { return Some(Box::new(anyhow!("wrong number of results provided").into())); @@ -232,7 +231,7 @@ fn _wasmtime_func_call( } Ok(Err(trap)) => match trap.downcast::() { Ok(trap) => { - *trap_ptr = Box::into_raw(Box::new(wasm_trap_t::new(store, trap))); + *trap_ptr = Box::into_raw(Box::new(wasm_trap_t::new(trap))); None } Err(err) => Some(Box::new(err.into())), @@ -245,7 +244,7 @@ fn _wasmtime_func_call( } else { Trap::new("rust panic happened") }; - let trap = Box::new(wasm_trap_t::new(store, trap)); + let trap = Box::new(wasm_trap_t::new(trap)); *trap_ptr = Box::into_raw(trap); None } @@ -279,12 +278,11 @@ pub extern "C" fn wasmtime_caller_export_get( ) -> Option> { let name = str::from_utf8(name.as_slice()).ok()?; let export = caller.caller.get_export(name)?; - let store = caller.caller.store(); let which = match export { - Extern::Func(f) => ExternHost::Func(HostRef::new(&store, f)), - Extern::Global(g) => ExternHost::Global(HostRef::new(&store, g)), - Extern::Memory(m) => ExternHost::Memory(HostRef::new(&store, m)), - Extern::Table(t) => ExternHost::Table(HostRef::new(&store, t)), + Extern::Func(f) => ExternHost::Func(HostRef::new(f)), + Extern::Global(g) => ExternHost::Global(HostRef::new(g)), + Extern::Memory(m) => ExternHost::Memory(HostRef::new(m)), + Extern::Table(t) => ExternHost::Table(HostRef::new(t)), }; Some(Box::new(wasm_extern_t { which })) } diff --git a/crates/c-api/src/global.rs b/crates/c-api/src/global.rs index 3d4f768ba1a8..7864d463ec5d 100644 --- a/crates/c-api/src/global.rs +++ b/crates/c-api/src/global.rs @@ -59,7 +59,7 @@ pub extern "C" fn wasmtime_global_new( handle_result(global, |global| { *ret = Box::into_raw(Box::new(wasm_global_t { ext: wasm_extern_t { - which: ExternHost::Global(HostRef::new(&store.store, global)), + which: ExternHost::Global(HostRef::new(global)), }, })); }) diff --git a/crates/c-api/src/host_ref.rs b/crates/c-api/src/host_ref.rs index 41ac6a16f145..7945f762c838 100644 --- a/crates/c-api/src/host_ref.rs +++ b/crates/c-api/src/host_ref.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::cell::{self, RefCell}; use std::convert::TryFrom; use std::marker::PhantomData; -use wasmtime::{ExternRef, Store}; +use wasmtime::ExternRef; /// Represents a piece of data located in the host environment. #[derive(Debug)] @@ -19,9 +19,9 @@ where T: 'static + Any, { /// Creates a new `HostRef` from `T`. - pub fn new(store: &Store, item: T) -> HostRef { + pub fn new(item: T) -> HostRef { HostRef { - externref: ExternRef::new(store, RefCell::new(item)), + externref: ExternRef::new(RefCell::new(item)), _phantom: PhantomData, } } diff --git a/crates/c-api/src/instance.rs b/crates/c-api/src/instance.rs index aed706b686aa..2885e203806a 100644 --- a/crates/c-api/src/instance.rs +++ b/crates/c-api/src/instance.rs @@ -4,7 +4,7 @@ use crate::{wasm_store_t, wasmtime_error_t, ExternHost}; use anyhow::Result; use std::cell::RefCell; use std::ptr; -use wasmtime::{Extern, Instance, Store, Trap}; +use wasmtime::{Extern, Instance, Trap}; #[repr(C)] #[derive(Clone)] @@ -17,9 +17,8 @@ wasmtime_c_api_macros::declare_ref!(wasm_instance_t); impl wasm_instance_t { pub(crate) fn new(instance: Instance) -> wasm_instance_t { - let store = instance.store().clone(); wasm_instance_t { - instance: HostRef::new(&store, instance), + instance: HostRef::new(instance), exports_cache: RefCell::new(None), } } @@ -51,7 +50,7 @@ pub unsafe extern "C" fn wasm_instance_new( assert!(trap.is_null()); assert!(instance.is_null()); if let Some(result) = result { - *result = Box::into_raw(err.to_trap(&store.store)); + *result = Box::into_raw(err.to_trap()); } None } @@ -109,7 +108,6 @@ fn _wasmtime_instance_new( .collect::>(); let module = &module.module.borrow(); handle_instantiate( - store, Instance::new(store, module, &imports), instance_ptr, trap_ptr, @@ -117,7 +115,6 @@ fn _wasmtime_instance_new( } pub fn handle_instantiate( - store: &Store, instance: Result, instance_ptr: &mut *mut wasm_instance_t, trap_ptr: &mut *mut wasm_trap_t, @@ -133,7 +130,7 @@ pub fn handle_instantiate( } Err(e) => match e.downcast::() { Ok(trap) => { - write(trap_ptr, wasm_trap_t::new(store, trap)); + write(trap_ptr, wasm_trap_t::new(trap)); None } Err(e) => Some(Box::new(e.into())), @@ -149,10 +146,10 @@ pub extern "C" fn wasm_instance_exports(instance: &wasm_instance_t, out: &mut wa instance .exports() .map(|e| match e.into_extern() { - Extern::Func(f) => ExternHost::Func(HostRef::new(instance.store(), f)), - Extern::Global(f) => ExternHost::Global(HostRef::new(instance.store(), f)), - Extern::Memory(f) => ExternHost::Memory(HostRef::new(instance.store(), f)), - Extern::Table(f) => ExternHost::Table(HostRef::new(instance.store(), f)), + Extern::Func(f) => ExternHost::Func(HostRef::new(f)), + Extern::Global(f) => ExternHost::Global(HostRef::new(f)), + Extern::Memory(f) => ExternHost::Memory(HostRef::new(f)), + Extern::Table(f) => ExternHost::Table(HostRef::new(f)), }) .collect() }); diff --git a/crates/c-api/src/linker.rs b/crates/c-api/src/linker.rs index 613201370d86..4114403605bb 100644 --- a/crates/c-api/src/linker.rs +++ b/crates/c-api/src/linker.rs @@ -88,7 +88,7 @@ pub extern "C" fn wasmtime_linker_instantiate( trap_ptr: &mut *mut wasm_trap_t, ) -> Option> { let result = linker.linker.instantiate(&module.module.borrow()); - super::instance::handle_instantiate(linker.linker.store(), result, instance_ptr, trap_ptr) + super::instance::handle_instantiate(result, instance_ptr, trap_ptr) } #[no_mangle] @@ -117,7 +117,7 @@ pub extern "C" fn wasmtime_linker_get_default( Err(_) => return bad_utf8(), }; handle_result(linker.get_default(name), |f| { - *func = Box::into_raw(Box::new(HostRef::new(linker.store(), f).into())) + *func = Box::into_raw(Box::new(HostRef::new(f).into())) }) } @@ -138,12 +138,11 @@ pub extern "C" fn wasmtime_linker_get_one_by_name( Err(_) => return bad_utf8(), }; handle_result(linker.get_one_by_name(module, name), |item| { - let store = linker.store(); let which = match item { - Extern::Func(f) => ExternHost::Func(HostRef::new(&store, f)), - Extern::Global(g) => ExternHost::Global(HostRef::new(&store, g)), - Extern::Memory(m) => ExternHost::Memory(HostRef::new(&store, m)), - Extern::Table(t) => ExternHost::Table(HostRef::new(&store, t)), + Extern::Func(f) => ExternHost::Func(HostRef::new(f)), + Extern::Global(g) => ExternHost::Global(HostRef::new(g)), + Extern::Memory(m) => ExternHost::Memory(HostRef::new(m)), + Extern::Table(t) => ExternHost::Table(HostRef::new(t)), }; *item_ptr = Box::into_raw(Box::new(wasm_extern_t { which })) }) diff --git a/crates/c-api/src/memory.rs b/crates/c-api/src/memory.rs index ed25b24bea88..4e6474053a1c 100644 --- a/crates/c-api/src/memory.rs +++ b/crates/c-api/src/memory.rs @@ -37,7 +37,7 @@ pub extern "C" fn wasm_memory_new( store: &wasm_store_t, mt: &wasm_memorytype_t, ) -> Box { - let memory = HostRef::new(&store.store, Memory::new(&store.store, mt.ty().ty.clone())); + let memory = HostRef::new(Memory::new(&store.store, mt.ty().ty.clone())); Box::new(wasm_memory_t { ext: wasm_extern_t { which: ExternHost::Memory(memory), diff --git a/crates/c-api/src/module.rs b/crates/c-api/src/module.rs index 9e3d3434fb1b..69cc74731db4 100644 --- a/crates/c-api/src/module.rs +++ b/crates/c-api/src/module.rs @@ -63,7 +63,7 @@ pub extern "C" fn wasmtime_module_new( .map(|e| wasm_exporttype_t::new(e.name().to_owned(), e.ty())) .collect::>(); let module = Box::new(wasm_module_t { - module: HostRef::new(store, module), + module: HostRef::new(module), imports, exports, }); @@ -130,7 +130,7 @@ pub extern "C" fn wasm_module_obtain( .map(|e| wasm_exporttype_t::new(e.name().to_owned(), e.ty())) .collect::>(); Some(Box::new(wasm_module_t { - module: HostRef::new(&store.store, module), + module: HostRef::new(module), imports, exports, })) diff --git a/crates/c-api/src/ref.rs b/crates/c-api/src/ref.rs index 5e14c51c3847..5ddc4378364b 100644 --- a/crates/c-api/src/ref.rs +++ b/crates/c-api/src/ref.rs @@ -1,4 +1,3 @@ -use crate::HostInfoState; use std::os::raw::c_void; use wasmtime::ExternRef; @@ -24,47 +23,23 @@ pub extern "C" fn wasm_ref_same(a: &wasm_ref_t, b: &wasm_ref_t) -> bool { } } -pub(crate) fn get_host_info(r: &ExternRef) -> *mut c_void { - let host_info = match r.host_info() { - Some(info) => info, - None => return std::ptr::null_mut(), - }; - let host_info = host_info.borrow(); - match host_info.downcast_ref::() { - Some(state) => state.info, - None => std::ptr::null_mut(), - } -} - #[no_mangle] -pub extern "C" fn wasm_ref_get_host_info(a: &wasm_ref_t) -> *mut c_void { - a.r.as_ref() - .map_or(std::ptr::null_mut(), |r| get_host_info(r)) -} - -pub(crate) fn set_host_info( - r: &ExternRef, - info: *mut c_void, - finalizer: Option, -) { - let info = if info.is_null() && finalizer.is_none() { - None - } else { - Some(Box::new(crate::HostInfoState { info, finalizer }) as Box) - }; - r.set_host_info(info); +pub extern "C" fn wasm_ref_get_host_info(_ref: &wasm_ref_t) -> *mut c_void { + std::ptr::null_mut() } #[no_mangle] -pub extern "C" fn wasm_ref_set_host_info(a: &wasm_ref_t, info: *mut c_void) { - a.r.as_ref().map(|r| set_host_info(r, info, None)); +pub extern "C" fn wasm_ref_set_host_info(_ref: &wasm_ref_t, _info: *mut c_void) { + eprintln!("`wasm_ref_set_host_info` is not implemented"); + std::process::abort(); } #[no_mangle] pub extern "C" fn wasm_ref_set_host_info_with_finalizer( - a: &wasm_ref_t, - info: *mut c_void, - finalizer: Option, + _ref: &wasm_ref_t, + _info: *mut c_void, + _finalizer: Option, ) { - a.r.as_ref().map(|r| set_host_info(r, info, finalizer)); + eprintln!("`wasm_ref_set_host_info_with_finalizer` is not implemented"); + std::process::abort(); } diff --git a/crates/c-api/src/table.rs b/crates/c-api/src/table.rs index ad7d8f4cf151..5865b15b4ab5 100644 --- a/crates/c-api/src/table.rs +++ b/crates/c-api/src/table.rs @@ -47,7 +47,7 @@ pub extern "C" fn wasm_table_new( let table = Table::new(&store.store, tt.ty().ty.clone(), init).ok()?; Some(Box::new(wasm_table_t { ext: wasm_extern_t { - which: ExternHost::Table(HostRef::new(&store.store, table)), + which: ExternHost::Table(HostRef::new(table)), }, })) } @@ -68,7 +68,7 @@ pub extern "C" fn wasmtime_funcref_table_new( |table| { *out = Box::into_raw(Box::new(wasm_table_t { ext: wasm_extern_t { - which: ExternHost::Table(HostRef::new(&store.store, table)), + which: ExternHost::Table(HostRef::new(table)), }, })); }, @@ -100,13 +100,7 @@ pub extern "C" fn wasmtime_funcref_table_get( *ptr = match val { // TODO: what do do about creating new `HostRef` handles here? Val::FuncRef(None) => ptr::null_mut(), - Val::FuncRef(Some(f)) => { - let store = match t.table().as_ref().store() { - None => return false, - Some(store) => store, - }; - Box::into_raw(Box::new(HostRef::new(&store, f).into())) - } + Val::FuncRef(Some(f)) => Box::into_raw(Box::new(HostRef::new(f).into())), _ => return false, }; } diff --git a/crates/c-api/src/trap.rs b/crates/c-api/src/trap.rs index 9c43d53e9f25..97737a4d46bd 100644 --- a/crates/c-api/src/trap.rs +++ b/crates/c-api/src/trap.rs @@ -1,7 +1,7 @@ use crate::host_ref::HostRef; use crate::{wasm_frame_vec_t, wasm_instance_t, wasm_name_t, wasm_store_t}; use once_cell::unsync::OnceCell; -use wasmtime::{Store, Trap}; +use wasmtime::Trap; #[repr(C)] #[derive(Clone)] @@ -12,9 +12,9 @@ pub struct wasm_trap_t { wasmtime_c_api_macros::declare_ref!(wasm_trap_t); impl wasm_trap_t { - pub(crate) fn new(store: &Store, trap: Trap) -> wasm_trap_t { + pub(crate) fn new(trap: Trap) -> wasm_trap_t { wasm_trap_t { - trap: HostRef::new(store, trap), + trap: HostRef::new(trap), } } @@ -38,7 +38,7 @@ pub type wasm_message_t = wasm_name_t; #[no_mangle] pub extern "C" fn wasm_trap_new( - store: &wasm_store_t, + _store: &wasm_store_t, message: &wasm_message_t, ) -> Box { let message = message.as_slice(); @@ -47,7 +47,7 @@ pub extern "C" fn wasm_trap_new( } let message = String::from_utf8_lossy(&message[..message.len() - 1]); Box::new(wasm_trap_t { - trap: HostRef::new(&store.store, Trap::new(message)), + trap: HostRef::new(Trap::new(message)), }) } diff --git a/crates/c-api/src/wasi.rs b/crates/c-api/src/wasi.rs index 6daad6aaef1a..85c31f8980d2 100644 --- a/crates/c-api/src/wasi.rs +++ b/crates/c-api/src/wasi.rs @@ -314,7 +314,7 @@ pub unsafe extern "C" fn wasi_instance_new( })), Err(e) => { *trap = Box::into_raw(Box::new(wasm_trap_t { - trap: HostRef::new(store, Trap::new(e)), + trap: HostRef::new(Trap::new(e)), })); None @@ -352,14 +352,13 @@ pub extern "C" fn wasi_instance_bind_import<'a>( if &export.ty() != import.ty.func()? { return None; } - let store = export.store(); let entry = instance .export_cache .entry(name.to_string()) .or_insert_with(|| { Box::new(wasm_extern_t { - which: ExternHost::Func(HostRef::new(store, export.clone())), + which: ExternHost::Func(HostRef::new(export.clone())), }) }); Some(entry) diff --git a/crates/wasmtime/src/externals.rs b/crates/wasmtime/src/externals.rs index cbcaa542f1f0..93c2ddc66544 100644 --- a/crates/wasmtime/src/externals.rs +++ b/crates/wasmtime/src/externals.rs @@ -355,10 +355,9 @@ impl Table { Some(unsafe { from_checked_anyfunc(f, &self.instance.store) }) } runtime::TableElement::ExternRef(None) => Some(Val::ExternRef(None)), - runtime::TableElement::ExternRef(Some(x)) => Some(Val::ExternRef(Some(ExternRef { - inner: x, - store: self.instance.store.weak(), - }))), + runtime::TableElement::ExternRef(Some(x)) => { + Some(Val::ExternRef(Some(ExternRef { inner: x }))) + } } } diff --git a/crates/wasmtime/src/ref.rs b/crates/wasmtime/src/ref.rs old mode 100644 new mode 100755 index 988c1590093d..88c5e47f82e9 --- a/crates/wasmtime/src/ref.rs +++ b/crates/wasmtime/src/ref.rs @@ -1,34 +1,22 @@ #![allow(missing_docs)] use std::any::Any; -use std::cell::RefCell; -use std::fmt; -use std::rc::{Rc, Weak}; use wasmtime_runtime::VMExternRef; /// Represents an opaque reference to any data within WebAssembly. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ExternRef { pub(crate) inner: VMExternRef, - pub(crate) store: Weak, } impl ExternRef { /// Creates a new instance of `ExternRef` wrapping the given value. - pub fn new(store: &crate::Store, value: T) -> ExternRef + pub fn new(value: T) -> ExternRef where T: 'static + Any, { let inner = VMExternRef::new(value); - let store = store.weak(); - ExternRef { inner, store } - } - - /// Get this reference's store. - /// - /// Returns `None` if this reference outlived its store. - pub fn store(&self) -> Option { - crate::runtime::Store::upgrade(&self.store) + ExternRef { inner } } /// Get the underlying data for this `ExternRef`. @@ -48,39 +36,4 @@ impl ExternRef { pub fn ptr_eq(&self, other: &ExternRef) -> bool { VMExternRef::eq(&self.inner, &other.inner) } - - /// Returns the host information for this `externref`, if previously created - /// with `set_host_info`. - pub fn host_info(&self) -> Option>> { - let store = crate::Store::upgrade(&self.store)?; - store.host_info(self) - } - - /// Set the host information for this `externref`, returning the old host - /// information if it was previously set. - pub fn set_host_info(&self, info: T) -> Option>> - where - T: 'static + Any, - { - let store = crate::Store::upgrade(&self.store)?; - store.set_host_info(self, Some(Rc::new(RefCell::new(info)))) - } - - /// Remove the host information for this `externref`, returning the old host - /// information if it was previously set. - pub fn remove_host_info(&self) -> Option>> { - let store = crate::Store::upgrade(&self.store)?; - store.set_host_info(self, None) - } -} - -impl fmt::Debug for ExternRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let ExternRef { inner, store: _ } = self; - let store = self.store(); - f.debug_struct("ExternRef") - .field("inner", &inner) - .field("store", &store) - .finish() - } } diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs index d42860b9b923..a33254b1ddb5 100644 --- a/crates/wasmtime/src/runtime.rs +++ b/crates/wasmtime/src/runtime.rs @@ -1,12 +1,9 @@ use crate::externals::MemoryCreator; -use crate::r#ref::ExternRef; use crate::trampoline::{MemoryCreatorProxy, StoreInstanceHandle}; use crate::Module; use anyhow::{bail, Result}; -use std::any::Any; use std::cell::RefCell; use std::cmp; -use std::collections::HashMap; use std::convert::TryFrom; use std::fmt; use std::hash::{Hash, Hasher}; @@ -815,7 +812,6 @@ pub(crate) struct StoreInner { instances: RefCell>, signal_handler: RefCell>>>, jit_code_ranges: RefCell>, - host_info: RefCell>>>, externref_activations_table: Rc, stack_map_registry: Rc, } @@ -857,7 +853,6 @@ impl Store { instances: RefCell::new(Vec::new()), signal_handler: RefCell::new(None), jit_code_ranges: RefCell::new(Vec::new()), - host_info: RefCell::new(HashMap::new()), externref_activations_table: Rc::new(VMExternRefActivationsTable::new()), stack_map_registry: Rc::new(StackMapRegistry::default()), }), @@ -980,32 +975,6 @@ impl Store { Some(Self { inner }) } - pub(crate) fn host_info(&self, externref: &ExternRef) -> Option>> { - debug_assert!( - std::rc::Weak::ptr_eq(&self.weak(), &externref.store), - "externref must be from this store" - ); - let infos = self.inner.host_info.borrow(); - infos.get(&HostInfoKey(externref.inner.clone())).cloned() - } - - pub(crate) fn set_host_info( - &self, - externref: &ExternRef, - info: Option>>, - ) -> Option>> { - debug_assert!( - std::rc::Weak::ptr_eq(&self.weak(), &externref.store), - "externref must be from this store" - ); - let mut infos = self.inner.host_info.borrow_mut(); - if let Some(info) = info { - infos.insert(HostInfoKey(externref.inner.clone()), info) - } else { - infos.remove(&HostInfoKey(externref.inner.clone())) - } - } - pub(crate) fn signal_handler(&self) -> std::cell::Ref<'_, Option>>> { self.inner.signal_handler.borrow() } diff --git a/crates/wasmtime/src/values.rs b/crates/wasmtime/src/values.rs index 8ab44857325c..a123319a2651 100644 --- a/crates/wasmtime/src/values.rs +++ b/crates/wasmtime/src/values.rs @@ -126,7 +126,6 @@ impl Val { } else { Val::ExternRef(Some(ExternRef { inner: VMExternRef::clone_from_raw(raw), - store: store.weak(), })) } } @@ -180,15 +179,15 @@ impl Val { Val::FuncRef(Some(f)) => Store::same(store, f.store()), Val::FuncRef(None) => true, - // TODO: need to implement this once we actually finalize what - // `externref` will look like and it's actually implemented to pass it - // to compiled wasm as well. - Val::ExternRef(Some(e)) => e.store.ptr_eq(&store.weak()), - Val::ExternRef(None) => true, - - // Integers have no association with any particular store, so - // they're always considered as "yes I came from that store", - Val::I32(_) | Val::I64(_) | Val::F32(_) | Val::F64(_) | Val::V128(_) => true, + // Integers, floats, vectors, and `externref`s have no association + // with any particular store, so they're always considered as "yes I + // came from that store", + Val::I32(_) + | Val::I64(_) + | Val::F32(_) + | Val::F64(_) + | Val::V128(_) + | Val::ExternRef(_) => true, } } } diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rs index 50a6976f4d3c..92e68bb9ebea 100644 --- a/crates/wast/src/wast.rs +++ b/crates/wast/src/wast.rs @@ -10,7 +10,7 @@ use wast::{ }; /// Translate from a `script::Value` to a `RuntimeValue`. -fn runtime_value(store: &Store, v: &wast::Expression<'_>) -> Result { +fn runtime_value(v: &wast::Expression<'_>) -> Result { use wast::Instruction::*; if v.instrs.len() != 1 { @@ -24,7 +24,7 @@ fn runtime_value(store: &Store, v: &wast::Expression<'_>) -> Result { V128Const(x) => Val::V128(u128::from_le_bytes(x.to_le_bytes())), RefNull(RefType::Extern) => Val::ExternRef(None), RefNull(RefType::Func) => Val::FuncRef(None), - RefExtern(x) => Val::ExternRef(Some(ExternRef::new(store, *x))), + RefExtern(x) => Val::ExternRef(Some(ExternRef::new(*x))), other => bail!("couldn't convert {:?} to a runtime value", other), }) } @@ -120,7 +120,7 @@ impl WastContext { let values = exec .args .iter() - .map(|v| runtime_value(&self.store, v)) + .map(|v| runtime_value(v)) .collect::>>()?; self.invoke(exec.module.map(|i| i.name()), exec.name, &values) } diff --git a/tests/all/gc.rs b/tests/all/gc.rs index 78ff8dc8e3c5..4b4d8849dbf5 100644 --- a/tests/all/gc.rs +++ b/tests/all/gc.rs @@ -38,7 +38,7 @@ fn smoke_test_gc() -> anyhow::Result<()> { let func = instance.get_func("func").unwrap(); let inner_dropped = Rc::new(Cell::new(false)); - let r = ExternRef::new(&store, SetFlagOnDrop(inner_dropped.clone())); + let r = ExternRef::new(SetFlagOnDrop(inner_dropped.clone())); { let args = [Val::I32(5), Val::ExternRef(Some(r.clone()))]; func.call(&args)?; @@ -88,7 +88,7 @@ fn wasm_dropping_refs() -> anyhow::Result<()> { // NB: 4096 is greater than the initial `VMExternRefActivationsTable` // capacity, so this will trigger at least one GC. for _ in 0..4096 { - let r = ExternRef::new(&store, CountDrops(num_refs_dropped.clone())); + let r = ExternRef::new(CountDrops(num_refs_dropped.clone())); let args = [Val::ExternRef(Some(r))]; drop_ref.call(&args)?; } @@ -158,13 +158,10 @@ fn many_live_refs() -> anyhow::Result<()> { vec![ValType::ExternRef].into_boxed_slice(), ), { - let store = store.clone(); let live_refs = live_refs.clone(); move |_caller, _params, results| { - results[0] = Val::ExternRef(Some(ExternRef::new( - &store, - CountLiveRefs::new(live_refs.clone()), - ))); + results[0] = + Val::ExternRef(Some(ExternRef::new(CountLiveRefs::new(live_refs.clone())))); Ok(()) } },