diff --git a/crates/c-api/macros/src/lib.rs b/crates/c-api/macros/src/lib.rs index 91ec702531..304b95c4e9 100644 --- a/crates/c-api/macros/src/lib.rs +++ b/crates/c-api/macros/src/lib.rs @@ -72,17 +72,17 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream { #[no_mangle] pub extern fn #same(a: &#ty, b: &#ty) -> bool { - a.anyref().ptr_eq(&b.anyref()) + a.externref().ptr_eq(&b.externref()) } #[no_mangle] pub extern fn #get_host_info(a: &#ty) -> *mut std::os::raw::c_void { - crate::r#ref::get_host_info(&a.anyref()) + crate::r#ref::get_host_info(&a.externref()) } #[no_mangle] pub extern fn #set_host_info(a: &#ty, info: *mut std::os::raw::c_void) { - crate::r#ref::set_host_info(&a.anyref(), info, None) + crate::r#ref::set_host_info(&a.externref(), info, None) } #[no_mangle] @@ -91,12 +91,12 @@ 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.anyref(), info, finalizer) + crate::r#ref::set_host_info(&a.externref(), info, finalizer) } #[no_mangle] pub extern fn #as_ref(a: &#ty) -> Box { - let r = a.anyref(); + let r = a.externref(); Box::new(crate::wasm_ref_t { r }) } diff --git a/crates/c-api/src/extern.rs b/crates/c-api/src/extern.rs index b882082faf..025f233493 100644 --- a/crates/c-api/src/extern.rs +++ b/crates/c-api/src/extern.rs @@ -18,12 +18,12 @@ pub(crate) enum ExternHost { } impl wasm_extern_t { - fn anyref(&self) -> wasmtime::AnyRef { + fn externref(&self) -> wasmtime::ExternRef { match &self.which { - ExternHost::Func(f) => f.anyref(), - ExternHost::Global(f) => f.anyref(), - ExternHost::Memory(f) => f.anyref(), - ExternHost::Table(f) => f.anyref(), + ExternHost::Func(f) => f.externref(), + ExternHost::Global(f) => f.externref(), + ExternHost::Memory(f) => f.externref(), + ExternHost::Table(f) => f.externref(), } } } diff --git a/crates/c-api/src/func.rs b/crates/c-api/src/func.rs index 879248b23b..0d3e3d10c8 100644 --- a/crates/c-api/src/func.rs +++ b/crates/c-api/src/func.rs @@ -70,8 +70,8 @@ impl wasm_func_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.func().anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.func().externref() } } diff --git a/crates/c-api/src/global.rs b/crates/c-api/src/global.rs index fb3f163bab..b7ef6ebd7b 100644 --- a/crates/c-api/src/global.rs +++ b/crates/c-api/src/global.rs @@ -26,8 +26,8 @@ impl wasm_global_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.global().anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.global().externref() } } diff --git a/crates/c-api/src/instance.rs b/crates/c-api/src/instance.rs index 0ac864f5c3..6d528530d6 100644 --- a/crates/c-api/src/instance.rs +++ b/crates/c-api/src/instance.rs @@ -22,8 +22,8 @@ impl wasm_instance_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.instance.anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.instance.externref() } } diff --git a/crates/c-api/src/memory.rs b/crates/c-api/src/memory.rs index d77f01c4ea..48159b94ed 100644 --- a/crates/c-api/src/memory.rs +++ b/crates/c-api/src/memory.rs @@ -26,8 +26,8 @@ impl wasm_memory_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.memory().anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.memory().externref() } } diff --git a/crates/c-api/src/module.rs b/crates/c-api/src/module.rs index 0363632601..23c5eae364 100644 --- a/crates/c-api/src/module.rs +++ b/crates/c-api/src/module.rs @@ -15,8 +15,8 @@ pub struct wasm_module_t { wasmtime_c_api_macros::declare_ref!(wasm_module_t); impl wasm_module_t { - fn anyref(&self) -> wasmtime::AnyRef { - self.module.anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.module.externref() } } diff --git a/crates/c-api/src/ref.rs b/crates/c-api/src/ref.rs index 4606cc41ef..00f93865ce 100644 --- a/crates/c-api/src/ref.rs +++ b/crates/c-api/src/ref.rs @@ -1,11 +1,11 @@ use crate::HostInfoState; use std::os::raw::c_void; -use wasmtime::AnyRef; +use wasmtime::ExternRef; #[repr(C)] #[derive(Clone)] pub struct wasm_ref_t { - pub(crate) r: AnyRef, + pub(crate) r: ExternRef, } wasmtime_c_api_macros::declare_own!(wasm_ref_t); @@ -20,7 +20,7 @@ pub extern "C" fn wasm_ref_same(a: &wasm_ref_t, b: &wasm_ref_t) -> bool { a.r.ptr_eq(&b.r) } -pub(crate) fn get_host_info(r: &AnyRef) -> *mut c_void { +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(), @@ -37,7 +37,7 @@ pub extern "C" fn wasm_ref_get_host_info(a: &wasm_ref_t) -> *mut c_void { } pub(crate) fn set_host_info( - r: &AnyRef, + r: &ExternRef, info: *mut c_void, finalizer: Option, ) { diff --git a/crates/c-api/src/table.rs b/crates/c-api/src/table.rs index ab4ae3ff22..16626acf7b 100644 --- a/crates/c-api/src/table.rs +++ b/crates/c-api/src/table.rs @@ -1,7 +1,7 @@ use crate::{handle_result, wasm_func_t, wasm_ref_t, wasmtime_error_t}; use crate::{wasm_extern_t, wasm_store_t, wasm_tabletype_t, ExternHost}; use std::ptr; -use wasmtime::{AnyRef, HostRef, Table, Val}; +use wasmtime::{ExternRef, HostRef, Table, Val}; #[derive(Clone)] #[repr(transparent)] @@ -28,8 +28,8 @@ impl wasm_table_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.table().anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.table().externref() } } @@ -41,7 +41,7 @@ pub extern "C" fn wasm_table_new( ) -> Option> { let init: Val = match init { Some(init) => init.r.into(), - None => Val::AnyRef(AnyRef::Null), + None => Val::ExternRef(ExternRef::Null), }; let table = Table::new(&store.store.borrow(), tt.ty().ty.clone(), init).ok()?; Some(Box::new(wasm_table_t { @@ -60,7 +60,7 @@ pub extern "C" fn wasmtime_funcref_table_new( ) -> Option> { let init: Val = match init { Some(val) => Val::FuncRef(val.func().borrow().clone()), - None => Val::AnyRef(AnyRef::Null), + None => Val::ExternRef(ExternRef::Null), }; handle_result( Table::new(&store.store.borrow(), tt.ty().ty.clone(), init), @@ -84,7 +84,7 @@ pub extern "C" fn wasm_table_type(t: &wasm_table_t) -> Box { pub extern "C" fn wasm_table_get(t: &wasm_table_t, index: wasm_table_size_t) -> *mut wasm_ref_t { match t.table().borrow().get(index) { Some(val) => into_funcref(val), - None => into_funcref(Val::AnyRef(AnyRef::Null)), + None => into_funcref(Val::ExternRef(ExternRef::Null)), } } @@ -99,7 +99,7 @@ pub extern "C" fn wasmtime_funcref_table_get( *ptr = match val { // TODO: what do do about creating new `HostRef` handles here? Val::FuncRef(f) => Box::into_raw(Box::new(HostRef::new(f).into())), - Val::AnyRef(AnyRef::Null) => ptr::null_mut(), + Val::ExternRef(ExternRef::Null) => ptr::null_mut(), _ => return false, }; } @@ -127,20 +127,20 @@ pub extern "C" fn wasmtime_funcref_table_set( ) -> Option> { let val = match val { Some(val) => Val::FuncRef(val.func().borrow().clone()), - None => Val::AnyRef(AnyRef::Null), + None => Val::ExternRef(ExternRef::Null), }; handle_result(t.table().borrow().set(index, val), |()| {}) } fn into_funcref(val: Val) -> *mut wasm_ref_t { - if let Val::AnyRef(AnyRef::Null) = val { + if let Val::ExternRef(ExternRef::Null) = val { return ptr::null_mut(); } - let anyref = match val.anyref() { - Some(anyref) => anyref, + let externref = match val.externref() { + Some(externref) => externref, None => return ptr::null_mut(), }; - let r = Box::new(wasm_ref_t { r: anyref }); + let r = Box::new(wasm_ref_t { r: externref }); Box::into_raw(r) } @@ -148,7 +148,7 @@ unsafe fn from_funcref(r: *mut wasm_ref_t) -> Val { if !r.is_null() { Box::from_raw(r).r.into() } else { - Val::AnyRef(AnyRef::Null) + Val::ExternRef(ExternRef::Null) } } @@ -176,7 +176,7 @@ pub extern "C" fn wasmtime_funcref_table_grow( ) -> Option> { let val = match init { Some(val) => Val::FuncRef(val.func().borrow().clone()), - None => Val::AnyRef(AnyRef::Null), + None => Val::ExternRef(ExternRef::Null), }; handle_result(t.table().borrow().grow(delta, val), |prev| { if let Some(ptr) = prev_size { diff --git a/crates/c-api/src/trap.rs b/crates/c-api/src/trap.rs index 67ca334d7b..8a93cba14f 100644 --- a/crates/c-api/src/trap.rs +++ b/crates/c-api/src/trap.rs @@ -17,8 +17,8 @@ impl wasm_trap_t { } } - fn anyref(&self) -> wasmtime::AnyRef { - self.trap.anyref() + fn externref(&self) -> wasmtime::ExternRef { + self.trap.externref() } } diff --git a/crates/c-api/src/types/val.rs b/crates/c-api/src/types/val.rs index 5333ec6086..a421516b86 100644 --- a/crates/c-api/src/types/val.rs +++ b/crates/c-api/src/types/val.rs @@ -13,7 +13,7 @@ pub const WASM_I32: wasm_valkind_t = 0; pub const WASM_I64: wasm_valkind_t = 1; pub const WASM_F32: wasm_valkind_t = 2; pub const WASM_F64: wasm_valkind_t = 3; -pub const WASM_ANYREF: wasm_valkind_t = 128; +pub const WASM_EXTERNREF: wasm_valkind_t = 128; pub const WASM_FUNCREF: wasm_valkind_t = 129; #[no_mangle] @@ -34,7 +34,7 @@ pub(crate) fn into_valtype(kind: wasm_valkind_t) -> ValType { WASM_I64 => ValType::I64, WASM_F32 => ValType::F32, WASM_F64 => ValType::F64, - WASM_ANYREF => ValType::AnyRef, + WASM_EXTERNREF => ValType::ExternRef, WASM_FUNCREF => ValType::FuncRef, _ => panic!("unexpected kind: {}", kind), } @@ -46,7 +46,7 @@ pub(crate) fn from_valtype(ty: &ValType) -> wasm_valkind_t { ValType::I64 => WASM_I64, ValType::F32 => WASM_F32, ValType::F64 => WASM_F64, - ValType::AnyRef => WASM_ANYREF, + ValType::ExternRef => WASM_EXTERNREF, ValType::FuncRef => WASM_FUNCREF, _ => panic!("wasm_valkind_t has no known conversion for {:?}", ty), } diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index a6df5a56c4..a3d9608437 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -65,7 +65,7 @@ pub fn instantiate_with_config(wasm: &[u8], config: Config) { Ok(imps) => imps, Err(_) => { // There are some value types that we can't synthesize a - // dummy value for (e.g. anyrefs) and for modules that + // dummy value for (e.g. externrefs) and for modules that // import things of these types we skip instantiation. return; } @@ -147,7 +147,7 @@ pub fn differential_execution( Ok(imps) => imps, Err(e) => { // There are some value types that we can't synthesize a - // dummy value for (e.g. anyrefs) and for modules that + // dummy value for (e.g. externrefs) and for modules that // import things of these types we skip instantiation. eprintln!("Warning: failed to synthesize dummy imports: {}", e); continue; @@ -244,9 +244,8 @@ pub fn differential_execution( fail() } } - (Val::AnyRef(_), Val::AnyRef(_)) | (Val::FuncRef(_), Val::FuncRef(_)) => { - continue - } + (Val::ExternRef(_), Val::ExternRef(_)) + | (Val::FuncRef(_), Val::FuncRef(_)) => continue, _ => fail(), } } @@ -329,7 +328,7 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) { Ok(imps) => imps, Err(_) => { // There are some value types that we can't synthesize a - // dummy value for (e.g. anyrefs) and for modules that + // dummy value for (e.g. externrefs) and for modules that // import things of these types we skip instantiation. continue; } diff --git a/crates/fuzzing/src/oracles/dummy.rs b/crates/fuzzing/src/oracles/dummy.rs index 2e904ec1a3..1dc35ed3ad 100644 --- a/crates/fuzzing/src/oracles/dummy.rs +++ b/crates/fuzzing/src/oracles/dummy.rs @@ -44,9 +44,9 @@ pub fn dummy_value(val_ty: &ValType) -> Result { "dummy_value: unsupported function return type: v128".to_string(), )) } - ValType::AnyRef => { + ValType::ExternRef => { return Err(Trap::new( - "dummy_value: unsupported function return type: anyref".to_string(), + "dummy_value: unsupported function return type: externref".to_string(), )) } ValType::FuncRef => { diff --git a/crates/wasmtime/src/func.rs b/crates/wasmtime/src/func.rs index dda4fcee73..70bf2843bc 100644 --- a/crates/wasmtime/src/func.rs +++ b/crates/wasmtime/src/func.rs @@ -298,7 +298,7 @@ impl Func { /// | `f32` | `f32` | /// | `f64` | `f64` | /// | (not supported) | `v128` | - /// | (not supported) | `anyref` | + /// | (not supported) | `externref` | /// /// Any of the Rust types can be returned from the closure as well, in /// addition to some extra types diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rs index 0342833269..e08fbb15f9 100644 --- a/crates/wasmtime/src/lib.rs +++ b/crates/wasmtime/src/lib.rs @@ -29,7 +29,7 @@ pub use crate::func::*; pub use crate::instance::Instance; pub use crate::linker::*; pub use crate::module::Module; -pub use crate::r#ref::{AnyRef, HostRef}; +pub use crate::r#ref::{ExternRef, HostRef}; pub use crate::runtime::*; pub use crate::trap::Trap; pub use crate::types::*; diff --git a/crates/wasmtime/src/ref.rs b/crates/wasmtime/src/ref.rs index 2083c183d0..f78aaf0e9c 100644 --- a/crates/wasmtime/src/ref.rs +++ b/crates/wasmtime/src/ref.rs @@ -38,7 +38,7 @@ pub struct OtherRef(Rc>); /// Represents an opaque reference to any data within WebAssembly. #[derive(Clone)] -pub enum AnyRef { +pub enum ExternRef { /// A reference to no data. Null, /// A reference to data stored internally in `wasmtime`. @@ -47,52 +47,54 @@ pub enum AnyRef { Other(OtherRef), } -impl AnyRef { - /// Creates a new instance of `AnyRef` from `Box`. +impl ExternRef { + /// Creates a new instance of `ExternRef` from `Box`. pub fn new(data: Box) -> Self { let info = AnyAndHostInfo { any: data, host_info: None, }; - AnyRef::Other(OtherRef(Rc::new(RefCell::new(info)))) + ExternRef::Other(OtherRef(Rc::new(RefCell::new(info)))) } /// Creates a `Null` reference. pub fn null() -> Self { - AnyRef::Null + ExternRef::Null } /// Returns the data stored in the reference if available. /// # Panics - /// Panics if the variant isn't `AnyRef::Other`. + /// Panics if the variant isn't `ExternRef::Other`. pub fn data(&self) -> cell::Ref> { match self { - AnyRef::Other(OtherRef(r)) => cell::Ref::map(r.borrow(), |r| &r.any), - _ => panic!("expected AnyRef::Other"), + ExternRef::Other(OtherRef(r)) => cell::Ref::map(r.borrow(), |r| &r.any), + _ => panic!("expected ExternRef::Other"), } } - /// Returns true if the two `AnyRef`'s point to the same value (not just + /// Returns true if the two `ExternRef`'s point to the same value (not just /// values that compare as equal). - pub fn ptr_eq(&self, other: &AnyRef) -> bool { + pub fn ptr_eq(&self, other: &ExternRef) -> bool { match (self, other) { - (AnyRef::Null, AnyRef::Null) => true, - (AnyRef::Ref(InternalRef(ref a)), AnyRef::Ref(InternalRef(ref b))) => { + (ExternRef::Null, ExternRef::Null) => true, + (ExternRef::Ref(InternalRef(ref a)), ExternRef::Ref(InternalRef(ref b))) => { a.ptr_eq(b.as_ref()) } - (AnyRef::Other(OtherRef(ref a)), AnyRef::Other(OtherRef(ref b))) => Rc::ptr_eq(a, b), + (ExternRef::Other(OtherRef(ref a)), ExternRef::Other(OtherRef(ref b))) => { + Rc::ptr_eq(a, b) + } _ => false, } } /// Returns a mutable reference to the host information if available. /// # Panics - /// Panics if `AnyRef` is already borrowed or `AnyRef` is `Null`. + /// Panics if `ExternRef` is already borrowed or `ExternRef` is `Null`. pub fn host_info(&self) -> Option>> { match self { - AnyRef::Null => panic!("null"), - AnyRef::Ref(r) => r.0.host_info(), - AnyRef::Other(r) => { + ExternRef::Null => panic!("null"), + ExternRef::Ref(r) => r.0.host_info(), + ExternRef::Other(r) => { let info = cell::RefMut::map(r.0.borrow_mut(), |b| &mut b.host_info); if info.is_none() { return None; @@ -102,26 +104,26 @@ impl AnyRef { } } - /// Sets the host information for an `AnyRef`. + /// Sets the host information for an `ExternRef`. /// # Panics - /// Panics if `AnyRef` is already borrowed or `AnyRef` is `Null`. + /// Panics if `ExternRef` is already borrowed or `ExternRef` is `Null`. pub fn set_host_info(&self, info: Option>) { match self { - AnyRef::Null => panic!("null"), - AnyRef::Ref(r) => r.0.set_host_info(info), - AnyRef::Other(r) => { + ExternRef::Null => panic!("null"), + ExternRef::Ref(r) => r.0.set_host_info(info), + ExternRef::Other(r) => { r.0.borrow_mut().host_info = info; } } } } -impl fmt::Debug for AnyRef { +impl fmt::Debug for ExternRef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - AnyRef::Null => write!(f, "null"), - AnyRef::Ref(_) => write!(f, "anyref"), - AnyRef::Other(_) => write!(f, "other ref"), + ExternRef::Null => write!(f, "null"), + ExternRef::Ref(_) => write!(f, "externref"), + ExternRef::Other(_) => write!(f, "other ref"), } } } @@ -129,7 +131,7 @@ impl fmt::Debug for AnyRef { struct ContentBox { content: T, host_info: Option>, - anyref_data: Weak, + externref_data: Weak, } /// Represents a piece of data located in the host environment. @@ -138,11 +140,11 @@ pub struct HostRef(Rc>>); impl HostRef { /// Creates a new `HostRef` from `T`. pub fn new(item: T) -> HostRef { - let anyref_data: Weak> = Weak::new(); + let externref_data: Weak> = Weak::new(); let content = ContentBox { content: item, host_info: None, - anyref_data, + externref_data, }; HostRef(Rc::new(RefCell::new(content))) } @@ -168,17 +170,17 @@ impl HostRef { } /// Returns an opaque reference to the wrapped data in the form of - /// an `AnyRef`. + /// an `ExternRef`. /// # Panics /// Panics if `HostRef` is already mutably borrowed. - pub fn anyref(&self) -> AnyRef { - let r = self.0.borrow_mut().anyref_data.upgrade(); + pub fn externref(&self) -> ExternRef { + let r = self.0.borrow_mut().externref_data.upgrade(); if let Some(r) = r { - return AnyRef::Ref(InternalRef(r)); + return ExternRef::Ref(InternalRef(r)); } - let anyref_data: Rc = Rc::new(self.clone()); - self.0.borrow_mut().anyref_data = Rc::downgrade(&anyref_data); - AnyRef::Ref(InternalRef(anyref_data)) + let externref_data: Rc = Rc::new(self.clone()); + self.0.borrow_mut().externref_data = Rc::downgrade(&externref_data); + ExternRef::Ref(InternalRef(externref_data)) } } diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs index f1a0b7892a..2ba9f2fc4b 100644 --- a/crates/wasmtime/src/runtime.rs +++ b/crates/wasmtime/src/runtime.rs @@ -172,7 +172,7 @@ impl Config { /// feature can be enabled through this method for appropriate wasm /// modules. /// - /// This feature gates items such as the `anyref` type and multiple tables + /// This feature gates items such as the `externref` type and multiple tables /// being in a module. Note that enabling the reference types feature will /// also enable the bulk memory feature. /// diff --git a/crates/wasmtime/src/types.rs b/crates/wasmtime/src/types.rs index 8bf966a048..5fe37eeea1 100644 --- a/crates/wasmtime/src/types.rs +++ b/crates/wasmtime/src/types.rs @@ -62,7 +62,7 @@ pub enum ValType { /// A 128 bit number. V128, /// A reference to opaque data in the Wasm instance. - AnyRef, /* = 128 */ + ExternRef, /* = 128 */ /// A reference to a Wasm function. FuncRef, } @@ -80,7 +80,7 @@ impl ValType { /// Returns true if `ValType` matches either of the reference types. pub fn is_ref(&self) -> bool { match self { - ValType::AnyRef | ValType::FuncRef => true, + ValType::ExternRef | ValType::FuncRef => true, _ => false, } } @@ -321,7 +321,7 @@ impl GlobalType { /// A descriptor for a table in a WebAssembly module. /// /// Tables are contiguous chunks of a specific element, typically a `funcref` or -/// an `anyref`. The most common use for tables is a function table through +/// an `externref`. The most common use for tables is a function table through /// which `call_indirect` can invoke other functions. #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct TableType { diff --git a/crates/wasmtime/src/values.rs b/crates/wasmtime/src/values.rs index 6eb8004d9f..c0b8dd8102 100644 --- a/crates/wasmtime/src/values.rs +++ b/crates/wasmtime/src/values.rs @@ -1,4 +1,4 @@ -use crate::r#ref::AnyRef; +use crate::r#ref::ExternRef; use crate::{Func, Store, ValType}; use anyhow::{bail, Result}; use std::ptr; @@ -25,10 +25,10 @@ pub enum Val { /// `f64::from_bits` to create an `f64` value. F64(u64), - /// An `anyref` value which can hold opaque data to the wasm instance itself. + /// An `externref` value which can hold opaque data to the wasm instance itself. /// /// Note that this is a nullable value as well. - AnyRef(AnyRef), + ExternRef(ExternRef), /// A first-class reference to a WebAssembly function. FuncRef(Func), @@ -62,9 +62,9 @@ macro_rules! accessors { } impl Val { - /// Returns a null `anyref` value. + /// Returns a null `externref` value. pub fn null() -> Val { - Val::AnyRef(AnyRef::null()) + Val::ExternRef(ExternRef::null()) } /// Returns the corresponding [`ValType`] for this `Val`. @@ -74,7 +74,7 @@ impl Val { Val::I64(_) => ValType::I64, Val::F32(_) => ValType::F32, Val::F64(_) => ValType::F64, - Val::AnyRef(_) => ValType::AnyRef, + Val::ExternRef(_) => ValType::ExternRef, Val::FuncRef(_) => ValType::FuncRef, Val::V128(_) => ValType::V128, } @@ -115,10 +115,10 @@ impl Val { /// Attempt to access the underlying value of this `Val`, returning /// `None` if it is not the correct type. /// - /// This will return `Some` for both the `AnyRef` and `FuncRef` types. - pub fn anyref(&self) -> Option { + /// This will return `Some` for both the `ExternRef` and `FuncRef` types. + pub fn externref(&self) -> Option { match self { - Val::AnyRef(e) => Some(e.clone()), + Val::ExternRef(e) => Some(e.clone()), _ => None, } } @@ -129,8 +129,8 @@ impl Val { /// # Panics /// /// Panics if `self` is not of the right type. - pub fn unwrap_anyref(&self) -> AnyRef { - self.anyref().expect("expected anyref") + pub fn unwrap_externref(&self) -> ExternRef { + self.externref().expect("expected externref") } pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool { @@ -138,10 +138,10 @@ impl Val { Val::FuncRef(f) => Store::same(store, f.store()), // TODO: need to implement this once we actually finalize what - // `anyref` will look like and it's actually implemented to pass it + // `externref` will look like and it's actually implemented to pass it // to compiled wasm as well. - Val::AnyRef(AnyRef::Ref(_)) | Val::AnyRef(AnyRef::Other(_)) => false, - Val::AnyRef(AnyRef::Null) => true, + Val::ExternRef(ExternRef::Ref(_)) | Val::ExternRef(ExternRef::Other(_)) => false, + Val::ExternRef(ExternRef::Null) => true, // Integers have no association with any particular store, so // they're always considered as "yes I came from that store", @@ -174,9 +174,9 @@ impl From for Val { } } -impl From for Val { - fn from(val: AnyRef) -> Val { - Val::AnyRef(val) +impl From for Val { + fn from(val: ExternRef) -> Val { + Val::ExternRef(val) } } @@ -194,7 +194,7 @@ pub(crate) fn into_checked_anyfunc( bail!("cross-`Store` values are not supported"); } Ok(match val { - Val::AnyRef(AnyRef::Null) => wasmtime_runtime::VMCallerCheckedAnyfunc { + Val::ExternRef(ExternRef::Null) => wasmtime_runtime::VMCallerCheckedAnyfunc { func_ptr: ptr::null(), type_index: wasmtime_runtime::VMSharedSignatureIndex::default(), vmctx: ptr::null_mut(), @@ -216,7 +216,7 @@ pub(crate) fn from_checked_anyfunc( store: &Store, ) -> Val { if item.type_index == wasmtime_runtime::VMSharedSignatureIndex::default() { - return Val::AnyRef(AnyRef::Null); + return Val::ExternRef(ExternRef::Null); } let instance_handle = unsafe { wasmtime_runtime::InstanceHandle::from_vmctx(item.vmctx) }; let export = wasmtime_runtime::ExportFunction { diff --git a/crates/wast/src/spectest.rs b/crates/wast/src/spectest.rs index 60f6a6d09f..ed10b77862 100644 --- a/crates/wast/src/spectest.rs +++ b/crates/wast/src/spectest.rs @@ -35,7 +35,7 @@ pub fn link_spectest(linker: &mut Linker) -> Result<()> { linker.define("spectest", "global_f64", g)?; let ty = TableType::new(ValType::FuncRef, Limits::new(10, Some(20))); - let table = Table::new(linker.store(), ty, Val::AnyRef(AnyRef::Null))?; + let table = Table::new(linker.store(), ty, Val::ExternRef(ExternRef::Null))?; linker.define("spectest", "table", table)?; let ty = MemoryType::new(Limits::new(1, Some(2))); diff --git a/src/commands/run.rs b/src/commands/run.rs index d253402097..e638606b82 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -337,8 +337,8 @@ impl RunCommand { Val::I64(i) => println!("{}", i), Val::F32(f) => println!("{}", f), Val::F64(f) => println!("{}", f), - Val::AnyRef(_) => println!(""), - Val::FuncRef(_) => println!(""), + Val::ExternRef(_) => println!(""), + Val::FuncRef(_) => println!(""), Val::V128(i) => println!("{}", i), } } diff --git a/tests/all/externals.rs b/tests/all/externals.rs index ba9978cbb9..0919f13685 100644 --- a/tests/all/externals.rs +++ b/tests/all/externals.rs @@ -28,27 +28,47 @@ fn bad_tables() { // get out of bounds let ty = TableType::new(ValType::FuncRef, Limits::new(0, Some(1))); - let t = Table::new(&Store::default(), ty.clone(), Val::AnyRef(AnyRef::Null)).unwrap(); + let t = Table::new( + &Store::default(), + ty.clone(), + Val::ExternRef(ExternRef::Null), + ) + .unwrap(); assert!(t.get(0).is_none()); assert!(t.get(u32::max_value()).is_none()); // set out of bounds or wrong type let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(1))); - let t = Table::new(&Store::default(), ty.clone(), Val::AnyRef(AnyRef::Null)).unwrap(); + let t = Table::new( + &Store::default(), + ty.clone(), + Val::ExternRef(ExternRef::Null), + ) + .unwrap(); assert!(t.set(0, Val::I32(0)).is_err()); - assert!(t.set(0, Val::AnyRef(AnyRef::Null)).is_ok()); - assert!(t.set(1, Val::AnyRef(AnyRef::Null)).is_err()); + assert!(t.set(0, Val::ExternRef(ExternRef::Null)).is_ok()); + assert!(t.set(1, Val::ExternRef(ExternRef::Null)).is_err()); // grow beyond max let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(1))); - let t = Table::new(&Store::default(), ty.clone(), Val::AnyRef(AnyRef::Null)).unwrap(); - assert!(t.grow(0, Val::AnyRef(AnyRef::Null)).is_ok()); - assert!(t.grow(1, Val::AnyRef(AnyRef::Null)).is_err()); + let t = Table::new( + &Store::default(), + ty.clone(), + Val::ExternRef(ExternRef::Null), + ) + .unwrap(); + assert!(t.grow(0, Val::ExternRef(ExternRef::Null)).is_ok()); + assert!(t.grow(1, Val::ExternRef(ExternRef::Null)).is_err()); assert_eq!(t.size(), 1); // grow wrong type let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(2))); - let t = Table::new(&Store::default(), ty.clone(), Val::AnyRef(AnyRef::Null)).unwrap(); + let t = Table::new( + &Store::default(), + ty.clone(), + Val::ExternRef(ExternRef::Null), + ) + .unwrap(); assert!(t.grow(1, Val::I32(0)).is_err()); assert_eq!(t.size(), 1); } @@ -68,7 +88,7 @@ fn cross_store() -> anyhow::Result<()> { let ty = MemoryType::new(Limits::new(1, None)); let memory = Memory::new(&store2, ty); let ty = TableType::new(ValType::FuncRef, Limits::new(1, None)); - let table = Table::new(&store2, ty, Val::AnyRef(AnyRef::Null))?; + let table = Table::new(&store2, ty, Val::ExternRef(ExternRef::Null))?; let need_func = Module::new(&store1, r#"(module (import "" "" (func)))"#)?; assert!(Instance::new(&need_func, &[func.into()]).is_err()); @@ -105,7 +125,7 @@ fn cross_store() -> anyhow::Result<()> { // ============ Cross-store funcs ============== - // TODO: need to actually fill this out once we support anyref params/locals + // TODO: need to actually fill this out once we support externref params/locals // let module = Module::new(&store1, r#"(module (func (export "a") (param funcref)))"#)?; Ok(()) diff --git a/tests/all/linker.rs b/tests/all/linker.rs index efca285267..b84d7e9c1d 100644 --- a/tests/all/linker.rs +++ b/tests/all/linker.rs @@ -56,11 +56,11 @@ fn link_twice_bad() -> Result<()> { // tables let ty = TableType::new(ValType::FuncRef, Limits::new(1, None)); - let table = Table::new(&store, ty, Val::AnyRef(AnyRef::Null))?; + let table = Table::new(&store, ty, Val::ExternRef(ExternRef::Null))?; linker.define("", "", table.clone())?; assert!(linker.define("", "", table.clone()).is_err()); let ty = TableType::new(ValType::FuncRef, Limits::new(2, None)); - let table = Table::new(&store, ty, Val::AnyRef(AnyRef::Null))?; + let table = Table::new(&store, ty, Val::ExternRef(ExternRef::Null))?; assert!(linker.define("", "", table.clone()).is_err()); Ok(()) } diff --git a/tests/all/table.rs b/tests/all/table.rs index 8408cd9051..f7599e87cc 100644 --- a/tests/all/table.rs +++ b/tests/all/table.rs @@ -4,9 +4,9 @@ use wasmtime::*; fn get_none() { let store = Store::default(); let ty = TableType::new(ValType::FuncRef, Limits::new(1, None)); - let table = Table::new(&store, ty, Val::AnyRef(AnyRef::Null)).unwrap(); + let table = Table::new(&store, ty, Val::ExternRef(ExternRef::Null)).unwrap(); match table.get(0) { - Some(Val::AnyRef(AnyRef::Null)) => {} + Some(Val::ExternRef(ExternRef::Null)) => {} _ => panic!(), } assert!(table.get(1).is_none()); diff --git a/tests/all/use_after_drop.rs b/tests/all/use_after_drop.rs index b1f45041ce..67edfc158a 100644 --- a/tests/all/use_after_drop.rs +++ b/tests/all/use_after_drop.rs @@ -11,7 +11,7 @@ fn use_func_after_drop() -> Result<()> { assert_eq!(closed_over_data, "abcd"); }); let ty = TableType::new(ValType::FuncRef, Limits::new(1, None)); - table = Table::new(&store, ty, Val::AnyRef(AnyRef::Null))?; + table = Table::new(&store, ty, Val::ExternRef(ExternRef::Null))?; table.set(0, func.into())?; } let func = table.get(0).unwrap().funcref().unwrap().clone();