Merge pull request #1733 from fitzgen/rename-anyref-to-externref
Rename `anyref` to `externref` across the board
This commit is contained in:
@@ -72,17 +72,17 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn #same(a: &#ty, b: &#ty) -> bool {
|
pub extern fn #same(a: &#ty, b: &#ty) -> bool {
|
||||||
a.anyref().ptr_eq(&b.anyref())
|
a.externref().ptr_eq(&b.externref())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn #get_host_info(a: &#ty) -> *mut std::os::raw::c_void {
|
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]
|
#[no_mangle]
|
||||||
pub extern fn #set_host_info(a: &#ty, info: *mut std::os::raw::c_void) {
|
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]
|
#[no_mangle]
|
||||||
@@ -91,12 +91,12 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||||||
info: *mut std::os::raw::c_void,
|
info: *mut std::os::raw::c_void,
|
||||||
finalizer: Option<extern "C" fn(*mut std::os::raw::c_void)>,
|
finalizer: Option<extern "C" fn(*mut std::os::raw::c_void)>,
|
||||||
) {
|
) {
|
||||||
crate::r#ref::set_host_info(&a.anyref(), info, finalizer)
|
crate::r#ref::set_host_info(&a.externref(), info, finalizer)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn #as_ref(a: &#ty) -> Box<crate::wasm_ref_t> {
|
pub extern fn #as_ref(a: &#ty) -> Box<crate::wasm_ref_t> {
|
||||||
let r = a.anyref();
|
let r = a.externref();
|
||||||
Box::new(crate::wasm_ref_t { r })
|
Box::new(crate::wasm_ref_t { r })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ pub(crate) enum ExternHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl wasm_extern_t {
|
impl wasm_extern_t {
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
match &self.which {
|
match &self.which {
|
||||||
ExternHost::Func(f) => f.anyref(),
|
ExternHost::Func(f) => f.externref(),
|
||||||
ExternHost::Global(f) => f.anyref(),
|
ExternHost::Global(f) => f.externref(),
|
||||||
ExternHost::Memory(f) => f.anyref(),
|
ExternHost::Memory(f) => f.externref(),
|
||||||
ExternHost::Table(f) => f.anyref(),
|
ExternHost::Table(f) => f.externref(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ impl wasm_func_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.func().anyref()
|
self.func().externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ impl wasm_global_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.global().anyref()
|
self.global().externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ impl wasm_instance_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.instance.anyref()
|
self.instance.externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ impl wasm_memory_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.memory().anyref()
|
self.memory().externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub struct wasm_module_t {
|
|||||||
wasmtime_c_api_macros::declare_ref!(wasm_module_t);
|
wasmtime_c_api_macros::declare_ref!(wasm_module_t);
|
||||||
|
|
||||||
impl wasm_module_t {
|
impl wasm_module_t {
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.module.anyref()
|
self.module.externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::HostInfoState;
|
use crate::HostInfoState;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use wasmtime::AnyRef;
|
use wasmtime::ExternRef;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasm_ref_t {
|
pub struct wasm_ref_t {
|
||||||
pub(crate) r: AnyRef,
|
pub(crate) r: ExternRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
wasmtime_c_api_macros::declare_own!(wasm_ref_t);
|
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)
|
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() {
|
let host_info = match r.host_info() {
|
||||||
Some(info) => info,
|
Some(info) => info,
|
||||||
None => return std::ptr::null_mut(),
|
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(
|
pub(crate) fn set_host_info(
|
||||||
r: &AnyRef,
|
r: &ExternRef,
|
||||||
info: *mut c_void,
|
info: *mut c_void,
|
||||||
finalizer: Option<extern "C" fn(*mut c_void)>,
|
finalizer: Option<extern "C" fn(*mut c_void)>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::{handle_result, wasm_func_t, wasm_ref_t, wasmtime_error_t};
|
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 crate::{wasm_extern_t, wasm_store_t, wasm_tabletype_t, ExternHost};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use wasmtime::{AnyRef, HostRef, Table, Val};
|
use wasmtime::{ExternRef, HostRef, Table, Val};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
@@ -28,8 +28,8 @@ impl wasm_table_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.table().anyref()
|
self.table().externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ pub extern "C" fn wasm_table_new(
|
|||||||
) -> Option<Box<wasm_table_t>> {
|
) -> Option<Box<wasm_table_t>> {
|
||||||
let init: Val = match init {
|
let init: Val = match init {
|
||||||
Some(init) => init.r.into(),
|
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()?;
|
let table = Table::new(&store.store.borrow(), tt.ty().ty.clone(), init).ok()?;
|
||||||
Some(Box::new(wasm_table_t {
|
Some(Box::new(wasm_table_t {
|
||||||
@@ -60,7 +60,7 @@ pub extern "C" fn wasmtime_funcref_table_new(
|
|||||||
) -> Option<Box<wasmtime_error_t>> {
|
) -> Option<Box<wasmtime_error_t>> {
|
||||||
let init: Val = match init {
|
let init: Val = match init {
|
||||||
Some(val) => Val::FuncRef(val.func().borrow().clone()),
|
Some(val) => Val::FuncRef(val.func().borrow().clone()),
|
||||||
None => Val::AnyRef(AnyRef::Null),
|
None => Val::ExternRef(ExternRef::Null),
|
||||||
};
|
};
|
||||||
handle_result(
|
handle_result(
|
||||||
Table::new(&store.store.borrow(), tt.ty().ty.clone(), init),
|
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<wasm_tabletype_t> {
|
|||||||
pub extern "C" fn wasm_table_get(t: &wasm_table_t, index: wasm_table_size_t) -> *mut wasm_ref_t {
|
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) {
|
match t.table().borrow().get(index) {
|
||||||
Some(val) => into_funcref(val),
|
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 {
|
*ptr = match val {
|
||||||
// TODO: what do do about creating new `HostRef` handles here?
|
// TODO: what do do about creating new `HostRef` handles here?
|
||||||
Val::FuncRef(f) => Box::into_raw(Box::new(HostRef::new(f).into())),
|
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,
|
_ => return false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -127,20 +127,20 @@ pub extern "C" fn wasmtime_funcref_table_set(
|
|||||||
) -> Option<Box<wasmtime_error_t>> {
|
) -> Option<Box<wasmtime_error_t>> {
|
||||||
let val = match val {
|
let val = match val {
|
||||||
Some(val) => Val::FuncRef(val.func().borrow().clone()),
|
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), |()| {})
|
handle_result(t.table().borrow().set(index, val), |()| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_funcref(val: Val) -> *mut wasm_ref_t {
|
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();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
let anyref = match val.anyref() {
|
let externref = match val.externref() {
|
||||||
Some(anyref) => anyref,
|
Some(externref) => externref,
|
||||||
None => return ptr::null_mut(),
|
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)
|
Box::into_raw(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ unsafe fn from_funcref(r: *mut wasm_ref_t) -> Val {
|
|||||||
if !r.is_null() {
|
if !r.is_null() {
|
||||||
Box::from_raw(r).r.into()
|
Box::from_raw(r).r.into()
|
||||||
} else {
|
} else {
|
||||||
Val::AnyRef(AnyRef::Null)
|
Val::ExternRef(ExternRef::Null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ pub extern "C" fn wasmtime_funcref_table_grow(
|
|||||||
) -> Option<Box<wasmtime_error_t>> {
|
) -> Option<Box<wasmtime_error_t>> {
|
||||||
let val = match init {
|
let val = match init {
|
||||||
Some(val) => Val::FuncRef(val.func().borrow().clone()),
|
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| {
|
handle_result(t.table().borrow().grow(delta, val), |prev| {
|
||||||
if let Some(ptr) = prev_size {
|
if let Some(ptr) = prev_size {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ impl wasm_trap_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn anyref(&self) -> wasmtime::AnyRef {
|
fn externref(&self) -> wasmtime::ExternRef {
|
||||||
self.trap.anyref()
|
self.trap.externref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub const WASM_I32: wasm_valkind_t = 0;
|
|||||||
pub const WASM_I64: wasm_valkind_t = 1;
|
pub const WASM_I64: wasm_valkind_t = 1;
|
||||||
pub const WASM_F32: wasm_valkind_t = 2;
|
pub const WASM_F32: wasm_valkind_t = 2;
|
||||||
pub const WASM_F64: wasm_valkind_t = 3;
|
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;
|
pub const WASM_FUNCREF: wasm_valkind_t = 129;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -34,7 +34,7 @@ pub(crate) fn into_valtype(kind: wasm_valkind_t) -> ValType {
|
|||||||
WASM_I64 => ValType::I64,
|
WASM_I64 => ValType::I64,
|
||||||
WASM_F32 => ValType::F32,
|
WASM_F32 => ValType::F32,
|
||||||
WASM_F64 => ValType::F64,
|
WASM_F64 => ValType::F64,
|
||||||
WASM_ANYREF => ValType::AnyRef,
|
WASM_EXTERNREF => ValType::ExternRef,
|
||||||
WASM_FUNCREF => ValType::FuncRef,
|
WASM_FUNCREF => ValType::FuncRef,
|
||||||
_ => panic!("unexpected kind: {}", kind),
|
_ => panic!("unexpected kind: {}", kind),
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ pub(crate) fn from_valtype(ty: &ValType) -> wasm_valkind_t {
|
|||||||
ValType::I64 => WASM_I64,
|
ValType::I64 => WASM_I64,
|
||||||
ValType::F32 => WASM_F32,
|
ValType::F32 => WASM_F32,
|
||||||
ValType::F64 => WASM_F64,
|
ValType::F64 => WASM_F64,
|
||||||
ValType::AnyRef => WASM_ANYREF,
|
ValType::ExternRef => WASM_EXTERNREF,
|
||||||
ValType::FuncRef => WASM_FUNCREF,
|
ValType::FuncRef => WASM_FUNCREF,
|
||||||
_ => panic!("wasm_valkind_t has no known conversion for {:?}", ty),
|
_ => panic!("wasm_valkind_t has no known conversion for {:?}", ty),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ pub fn instantiate_with_config(wasm: &[u8], config: Config) {
|
|||||||
Ok(imps) => imps,
|
Ok(imps) => imps,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// There are some value types that we can't synthesize a
|
// 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.
|
// import things of these types we skip instantiation.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ pub fn differential_execution(
|
|||||||
Ok(imps) => imps,
|
Ok(imps) => imps,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// There are some value types that we can't synthesize a
|
// 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.
|
// import things of these types we skip instantiation.
|
||||||
eprintln!("Warning: failed to synthesize dummy imports: {}", e);
|
eprintln!("Warning: failed to synthesize dummy imports: {}", e);
|
||||||
continue;
|
continue;
|
||||||
@@ -244,9 +244,8 @@ pub fn differential_execution(
|
|||||||
fail()
|
fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Val::AnyRef(_), Val::AnyRef(_)) | (Val::FuncRef(_), Val::FuncRef(_)) => {
|
(Val::ExternRef(_), Val::ExternRef(_))
|
||||||
continue
|
| (Val::FuncRef(_), Val::FuncRef(_)) => continue,
|
||||||
}
|
|
||||||
_ => fail(),
|
_ => fail(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +328,7 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
|
|||||||
Ok(imps) => imps,
|
Ok(imps) => imps,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// There are some value types that we can't synthesize a
|
// 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.
|
// import things of these types we skip instantiation.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ pub fn dummy_value(val_ty: &ValType) -> Result<Val, Trap> {
|
|||||||
"dummy_value: unsupported function return type: v128".to_string(),
|
"dummy_value: unsupported function return type: v128".to_string(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
ValType::AnyRef => {
|
ValType::ExternRef => {
|
||||||
return Err(Trap::new(
|
return Err(Trap::new(
|
||||||
"dummy_value: unsupported function return type: anyref".to_string(),
|
"dummy_value: unsupported function return type: externref".to_string(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
ValType::FuncRef => {
|
ValType::FuncRef => {
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ impl Func {
|
|||||||
/// | `f32` | `f32` |
|
/// | `f32` | `f32` |
|
||||||
/// | `f64` | `f64` |
|
/// | `f64` | `f64` |
|
||||||
/// | (not supported) | `v128` |
|
/// | (not supported) | `v128` |
|
||||||
/// | (not supported) | `anyref` |
|
/// | (not supported) | `externref` |
|
||||||
///
|
///
|
||||||
/// Any of the Rust types can be returned from the closure as well, in
|
/// Any of the Rust types can be returned from the closure as well, in
|
||||||
/// addition to some extra types
|
/// addition to some extra types
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub use crate::func::*;
|
|||||||
pub use crate::instance::Instance;
|
pub use crate::instance::Instance;
|
||||||
pub use crate::linker::*;
|
pub use crate::linker::*;
|
||||||
pub use crate::module::Module;
|
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::runtime::*;
|
||||||
pub use crate::trap::Trap;
|
pub use crate::trap::Trap;
|
||||||
pub use crate::types::*;
|
pub use crate::types::*;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub struct OtherRef(Rc<RefCell<AnyAndHostInfo>>);
|
|||||||
|
|
||||||
/// Represents an opaque reference to any data within WebAssembly.
|
/// Represents an opaque reference to any data within WebAssembly.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum AnyRef {
|
pub enum ExternRef {
|
||||||
/// A reference to no data.
|
/// A reference to no data.
|
||||||
Null,
|
Null,
|
||||||
/// A reference to data stored internally in `wasmtime`.
|
/// A reference to data stored internally in `wasmtime`.
|
||||||
@@ -47,52 +47,54 @@ pub enum AnyRef {
|
|||||||
Other(OtherRef),
|
Other(OtherRef),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnyRef {
|
impl ExternRef {
|
||||||
/// Creates a new instance of `AnyRef` from `Box<dyn Any>`.
|
/// Creates a new instance of `ExternRef` from `Box<dyn Any>`.
|
||||||
pub fn new(data: Box<dyn Any>) -> Self {
|
pub fn new(data: Box<dyn Any>) -> Self {
|
||||||
let info = AnyAndHostInfo {
|
let info = AnyAndHostInfo {
|
||||||
any: data,
|
any: data,
|
||||||
host_info: None,
|
host_info: None,
|
||||||
};
|
};
|
||||||
AnyRef::Other(OtherRef(Rc::new(RefCell::new(info))))
|
ExternRef::Other(OtherRef(Rc::new(RefCell::new(info))))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `Null` reference.
|
/// Creates a `Null` reference.
|
||||||
pub fn null() -> Self {
|
pub fn null() -> Self {
|
||||||
AnyRef::Null
|
ExternRef::Null
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the data stored in the reference if available.
|
/// Returns the data stored in the reference if available.
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if the variant isn't `AnyRef::Other`.
|
/// Panics if the variant isn't `ExternRef::Other`.
|
||||||
pub fn data(&self) -> cell::Ref<Box<dyn Any>> {
|
pub fn data(&self) -> cell::Ref<Box<dyn Any>> {
|
||||||
match self {
|
match self {
|
||||||
AnyRef::Other(OtherRef(r)) => cell::Ref::map(r.borrow(), |r| &r.any),
|
ExternRef::Other(OtherRef(r)) => cell::Ref::map(r.borrow(), |r| &r.any),
|
||||||
_ => panic!("expected AnyRef::Other"),
|
_ => panic!("expected ExternRef::Other"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the two `AnyRef<T>`'s point to the same value (not just
|
/// Returns true if the two `ExternRef<T>`'s point to the same value (not just
|
||||||
/// values that compare as equal).
|
/// values that compare as equal).
|
||||||
pub fn ptr_eq(&self, other: &AnyRef) -> bool {
|
pub fn ptr_eq(&self, other: &ExternRef) -> bool {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(AnyRef::Null, AnyRef::Null) => true,
|
(ExternRef::Null, ExternRef::Null) => true,
|
||||||
(AnyRef::Ref(InternalRef(ref a)), AnyRef::Ref(InternalRef(ref b))) => {
|
(ExternRef::Ref(InternalRef(ref a)), ExternRef::Ref(InternalRef(ref b))) => {
|
||||||
a.ptr_eq(b.as_ref())
|
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,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a mutable reference to the host information if available.
|
/// Returns a mutable reference to the host information if available.
|
||||||
/// # Panics
|
/// # 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<cell::RefMut<Box<dyn Any>>> {
|
pub fn host_info(&self) -> Option<cell::RefMut<Box<dyn Any>>> {
|
||||||
match self {
|
match self {
|
||||||
AnyRef::Null => panic!("null"),
|
ExternRef::Null => panic!("null"),
|
||||||
AnyRef::Ref(r) => r.0.host_info(),
|
ExternRef::Ref(r) => r.0.host_info(),
|
||||||
AnyRef::Other(r) => {
|
ExternRef::Other(r) => {
|
||||||
let info = cell::RefMut::map(r.0.borrow_mut(), |b| &mut b.host_info);
|
let info = cell::RefMut::map(r.0.borrow_mut(), |b| &mut b.host_info);
|
||||||
if info.is_none() {
|
if info.is_none() {
|
||||||
return 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
|
||||||
/// 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<Box<dyn Any>>) {
|
pub fn set_host_info(&self, info: Option<Box<dyn Any>>) {
|
||||||
match self {
|
match self {
|
||||||
AnyRef::Null => panic!("null"),
|
ExternRef::Null => panic!("null"),
|
||||||
AnyRef::Ref(r) => r.0.set_host_info(info),
|
ExternRef::Ref(r) => r.0.set_host_info(info),
|
||||||
AnyRef::Other(r) => {
|
ExternRef::Other(r) => {
|
||||||
r.0.borrow_mut().host_info = info;
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
AnyRef::Null => write!(f, "null"),
|
ExternRef::Null => write!(f, "null"),
|
||||||
AnyRef::Ref(_) => write!(f, "anyref"),
|
ExternRef::Ref(_) => write!(f, "externref"),
|
||||||
AnyRef::Other(_) => write!(f, "other ref"),
|
ExternRef::Other(_) => write!(f, "other ref"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +131,7 @@ impl fmt::Debug for AnyRef {
|
|||||||
struct ContentBox<T> {
|
struct ContentBox<T> {
|
||||||
content: T,
|
content: T,
|
||||||
host_info: Option<Box<dyn Any>>,
|
host_info: Option<Box<dyn Any>>,
|
||||||
anyref_data: Weak<dyn InternalRefBase>,
|
externref_data: Weak<dyn InternalRefBase>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a piece of data located in the host environment.
|
/// Represents a piece of data located in the host environment.
|
||||||
@@ -138,11 +140,11 @@ pub struct HostRef<T>(Rc<RefCell<ContentBox<T>>>);
|
|||||||
impl<T: 'static> HostRef<T> {
|
impl<T: 'static> HostRef<T> {
|
||||||
/// Creates a new `HostRef<T>` from `T`.
|
/// Creates a new `HostRef<T>` from `T`.
|
||||||
pub fn new(item: T) -> HostRef<T> {
|
pub fn new(item: T) -> HostRef<T> {
|
||||||
let anyref_data: Weak<HostRef<T>> = Weak::new();
|
let externref_data: Weak<HostRef<T>> = Weak::new();
|
||||||
let content = ContentBox {
|
let content = ContentBox {
|
||||||
content: item,
|
content: item,
|
||||||
host_info: None,
|
host_info: None,
|
||||||
anyref_data,
|
externref_data,
|
||||||
};
|
};
|
||||||
HostRef(Rc::new(RefCell::new(content)))
|
HostRef(Rc::new(RefCell::new(content)))
|
||||||
}
|
}
|
||||||
@@ -168,17 +170,17 @@ impl<T: 'static> HostRef<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an opaque reference to the wrapped data in the form of
|
/// Returns an opaque reference to the wrapped data in the form of
|
||||||
/// an `AnyRef`.
|
/// an `ExternRef`.
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if `HostRef<T>` is already mutably borrowed.
|
/// Panics if `HostRef<T>` is already mutably borrowed.
|
||||||
pub fn anyref(&self) -> AnyRef {
|
pub fn externref(&self) -> ExternRef {
|
||||||
let r = self.0.borrow_mut().anyref_data.upgrade();
|
let r = self.0.borrow_mut().externref_data.upgrade();
|
||||||
if let Some(r) = r {
|
if let Some(r) = r {
|
||||||
return AnyRef::Ref(InternalRef(r));
|
return ExternRef::Ref(InternalRef(r));
|
||||||
}
|
}
|
||||||
let anyref_data: Rc<dyn InternalRefBase> = Rc::new(self.clone());
|
let externref_data: Rc<dyn InternalRefBase> = Rc::new(self.clone());
|
||||||
self.0.borrow_mut().anyref_data = Rc::downgrade(&anyref_data);
|
self.0.borrow_mut().externref_data = Rc::downgrade(&externref_data);
|
||||||
AnyRef::Ref(InternalRef(anyref_data))
|
ExternRef::Ref(InternalRef(externref_data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ impl Config {
|
|||||||
/// feature can be enabled through this method for appropriate wasm
|
/// feature can be enabled through this method for appropriate wasm
|
||||||
/// modules.
|
/// 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
|
/// being in a module. Note that enabling the reference types feature will
|
||||||
/// also enable the bulk memory feature.
|
/// also enable the bulk memory feature.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ pub enum ValType {
|
|||||||
/// A 128 bit number.
|
/// A 128 bit number.
|
||||||
V128,
|
V128,
|
||||||
/// A reference to opaque data in the Wasm instance.
|
/// A reference to opaque data in the Wasm instance.
|
||||||
AnyRef, /* = 128 */
|
ExternRef, /* = 128 */
|
||||||
/// A reference to a Wasm function.
|
/// A reference to a Wasm function.
|
||||||
FuncRef,
|
FuncRef,
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ impl ValType {
|
|||||||
/// Returns true if `ValType` matches either of the reference types.
|
/// Returns true if `ValType` matches either of the reference types.
|
||||||
pub fn is_ref(&self) -> bool {
|
pub fn is_ref(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ValType::AnyRef | ValType::FuncRef => true,
|
ValType::ExternRef | ValType::FuncRef => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ impl GlobalType {
|
|||||||
/// A descriptor for a table in a WebAssembly module.
|
/// A descriptor for a table in a WebAssembly module.
|
||||||
///
|
///
|
||||||
/// Tables are contiguous chunks of a specific element, typically a `funcref` or
|
/// 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.
|
/// which `call_indirect` can invoke other functions.
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
||||||
pub struct TableType {
|
pub struct TableType {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::r#ref::AnyRef;
|
use crate::r#ref::ExternRef;
|
||||||
use crate::{Func, Store, ValType};
|
use crate::{Func, Store, ValType};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
@@ -25,10 +25,10 @@ pub enum Val {
|
|||||||
/// `f64::from_bits` to create an `f64` value.
|
/// `f64::from_bits` to create an `f64` value.
|
||||||
F64(u64),
|
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.
|
/// Note that this is a nullable value as well.
|
||||||
AnyRef(AnyRef),
|
ExternRef(ExternRef),
|
||||||
|
|
||||||
/// A first-class reference to a WebAssembly function.
|
/// A first-class reference to a WebAssembly function.
|
||||||
FuncRef(Func),
|
FuncRef(Func),
|
||||||
@@ -62,9 +62,9 @@ macro_rules! accessors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Val {
|
impl Val {
|
||||||
/// Returns a null `anyref` value.
|
/// Returns a null `externref` value.
|
||||||
pub fn null() -> Val {
|
pub fn null() -> Val {
|
||||||
Val::AnyRef(AnyRef::null())
|
Val::ExternRef(ExternRef::null())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the corresponding [`ValType`] for this `Val`.
|
/// Returns the corresponding [`ValType`] for this `Val`.
|
||||||
@@ -74,7 +74,7 @@ impl Val {
|
|||||||
Val::I64(_) => ValType::I64,
|
Val::I64(_) => ValType::I64,
|
||||||
Val::F32(_) => ValType::F32,
|
Val::F32(_) => ValType::F32,
|
||||||
Val::F64(_) => ValType::F64,
|
Val::F64(_) => ValType::F64,
|
||||||
Val::AnyRef(_) => ValType::AnyRef,
|
Val::ExternRef(_) => ValType::ExternRef,
|
||||||
Val::FuncRef(_) => ValType::FuncRef,
|
Val::FuncRef(_) => ValType::FuncRef,
|
||||||
Val::V128(_) => ValType::V128,
|
Val::V128(_) => ValType::V128,
|
||||||
}
|
}
|
||||||
@@ -115,10 +115,10 @@ impl Val {
|
|||||||
/// Attempt to access the underlying value of this `Val`, returning
|
/// Attempt to access the underlying value of this `Val`, returning
|
||||||
/// `None` if it is not the correct type.
|
/// `None` if it is not the correct type.
|
||||||
///
|
///
|
||||||
/// This will return `Some` for both the `AnyRef` and `FuncRef` types.
|
/// This will return `Some` for both the `ExternRef` and `FuncRef` types.
|
||||||
pub fn anyref(&self) -> Option<AnyRef> {
|
pub fn externref(&self) -> Option<ExternRef> {
|
||||||
match self {
|
match self {
|
||||||
Val::AnyRef(e) => Some(e.clone()),
|
Val::ExternRef(e) => Some(e.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,8 +129,8 @@ impl Val {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `self` is not of the right type.
|
/// Panics if `self` is not of the right type.
|
||||||
pub fn unwrap_anyref(&self) -> AnyRef {
|
pub fn unwrap_externref(&self) -> ExternRef {
|
||||||
self.anyref().expect("expected anyref")
|
self.externref().expect("expected externref")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool {
|
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()),
|
Val::FuncRef(f) => Store::same(store, f.store()),
|
||||||
|
|
||||||
// TODO: need to implement this once we actually finalize what
|
// 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.
|
// to compiled wasm as well.
|
||||||
Val::AnyRef(AnyRef::Ref(_)) | Val::AnyRef(AnyRef::Other(_)) => false,
|
Val::ExternRef(ExternRef::Ref(_)) | Val::ExternRef(ExternRef::Other(_)) => false,
|
||||||
Val::AnyRef(AnyRef::Null) => true,
|
Val::ExternRef(ExternRef::Null) => true,
|
||||||
|
|
||||||
// Integers have no association with any particular store, so
|
// Integers have no association with any particular store, so
|
||||||
// they're always considered as "yes I came from that store",
|
// they're always considered as "yes I came from that store",
|
||||||
@@ -174,9 +174,9 @@ impl From<f64> for Val {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AnyRef> for Val {
|
impl From<ExternRef> for Val {
|
||||||
fn from(val: AnyRef) -> Val {
|
fn from(val: ExternRef) -> Val {
|
||||||
Val::AnyRef(val)
|
Val::ExternRef(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ pub(crate) fn into_checked_anyfunc(
|
|||||||
bail!("cross-`Store` values are not supported");
|
bail!("cross-`Store` values are not supported");
|
||||||
}
|
}
|
||||||
Ok(match val {
|
Ok(match val {
|
||||||
Val::AnyRef(AnyRef::Null) => wasmtime_runtime::VMCallerCheckedAnyfunc {
|
Val::ExternRef(ExternRef::Null) => wasmtime_runtime::VMCallerCheckedAnyfunc {
|
||||||
func_ptr: ptr::null(),
|
func_ptr: ptr::null(),
|
||||||
type_index: wasmtime_runtime::VMSharedSignatureIndex::default(),
|
type_index: wasmtime_runtime::VMSharedSignatureIndex::default(),
|
||||||
vmctx: ptr::null_mut(),
|
vmctx: ptr::null_mut(),
|
||||||
@@ -216,7 +216,7 @@ pub(crate) fn from_checked_anyfunc(
|
|||||||
store: &Store,
|
store: &Store,
|
||||||
) -> Val {
|
) -> Val {
|
||||||
if item.type_index == wasmtime_runtime::VMSharedSignatureIndex::default() {
|
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 instance_handle = unsafe { wasmtime_runtime::InstanceHandle::from_vmctx(item.vmctx) };
|
||||||
let export = wasmtime_runtime::ExportFunction {
|
let export = wasmtime_runtime::ExportFunction {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn link_spectest(linker: &mut Linker) -> Result<()> {
|
|||||||
linker.define("spectest", "global_f64", g)?;
|
linker.define("spectest", "global_f64", g)?;
|
||||||
|
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(10, Some(20)));
|
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)?;
|
linker.define("spectest", "table", table)?;
|
||||||
|
|
||||||
let ty = MemoryType::new(Limits::new(1, Some(2)));
|
let ty = MemoryType::new(Limits::new(1, Some(2)));
|
||||||
|
|||||||
@@ -337,8 +337,8 @@ impl RunCommand {
|
|||||||
Val::I64(i) => println!("{}", i),
|
Val::I64(i) => println!("{}", i),
|
||||||
Val::F32(f) => println!("{}", f),
|
Val::F32(f) => println!("{}", f),
|
||||||
Val::F64(f) => println!("{}", f),
|
Val::F64(f) => println!("{}", f),
|
||||||
Val::AnyRef(_) => println!("<anyref>"),
|
Val::ExternRef(_) => println!("<externref>"),
|
||||||
Val::FuncRef(_) => println!("<anyref>"),
|
Val::FuncRef(_) => println!("<externref>"),
|
||||||
Val::V128(i) => println!("{}", i),
|
Val::V128(i) => println!("{}", i),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,27 +28,47 @@ fn bad_tables() {
|
|||||||
|
|
||||||
// get out of bounds
|
// get out of bounds
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(0, Some(1)));
|
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(0).is_none());
|
||||||
assert!(t.get(u32::max_value()).is_none());
|
assert!(t.get(u32::max_value()).is_none());
|
||||||
|
|
||||||
// set out of bounds or wrong type
|
// set out of bounds or wrong type
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(1)));
|
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::I32(0)).is_err());
|
||||||
assert!(t.set(0, Val::AnyRef(AnyRef::Null)).is_ok());
|
assert!(t.set(0, Val::ExternRef(ExternRef::Null)).is_ok());
|
||||||
assert!(t.set(1, Val::AnyRef(AnyRef::Null)).is_err());
|
assert!(t.set(1, Val::ExternRef(ExternRef::Null)).is_err());
|
||||||
|
|
||||||
// grow beyond max
|
// grow beyond max
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(1)));
|
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(
|
||||||
assert!(t.grow(0, Val::AnyRef(AnyRef::Null)).is_ok());
|
&Store::default(),
|
||||||
assert!(t.grow(1, Val::AnyRef(AnyRef::Null)).is_err());
|
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);
|
assert_eq!(t.size(), 1);
|
||||||
|
|
||||||
// grow wrong type
|
// grow wrong type
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, Some(2)));
|
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!(t.grow(1, Val::I32(0)).is_err());
|
||||||
assert_eq!(t.size(), 1);
|
assert_eq!(t.size(), 1);
|
||||||
}
|
}
|
||||||
@@ -68,7 +88,7 @@ fn cross_store() -> anyhow::Result<()> {
|
|||||||
let ty = MemoryType::new(Limits::new(1, None));
|
let ty = MemoryType::new(Limits::new(1, None));
|
||||||
let memory = Memory::new(&store2, ty);
|
let memory = Memory::new(&store2, ty);
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, None));
|
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)))"#)?;
|
let need_func = Module::new(&store1, r#"(module (import "" "" (func)))"#)?;
|
||||||
assert!(Instance::new(&need_func, &[func.into()]).is_err());
|
assert!(Instance::new(&need_func, &[func.into()]).is_err());
|
||||||
@@ -105,7 +125,7 @@ fn cross_store() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// ============ Cross-store funcs ==============
|
// ============ 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)))"#)?;
|
// let module = Module::new(&store1, r#"(module (func (export "a") (param funcref)))"#)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ fn link_twice_bad() -> Result<()> {
|
|||||||
|
|
||||||
// tables
|
// tables
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, None));
|
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())?;
|
linker.define("", "", table.clone())?;
|
||||||
assert!(linker.define("", "", table.clone()).is_err());
|
assert!(linker.define("", "", table.clone()).is_err());
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(2, None));
|
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());
|
assert!(linker.define("", "", table.clone()).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use wasmtime::*;
|
|||||||
fn get_none() {
|
fn get_none() {
|
||||||
let store = Store::default();
|
let store = Store::default();
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, None));
|
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) {
|
match table.get(0) {
|
||||||
Some(Val::AnyRef(AnyRef::Null)) => {}
|
Some(Val::ExternRef(ExternRef::Null)) => {}
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
}
|
||||||
assert!(table.get(1).is_none());
|
assert!(table.get(1).is_none());
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ fn use_func_after_drop() -> Result<()> {
|
|||||||
assert_eq!(closed_over_data, "abcd");
|
assert_eq!(closed_over_data, "abcd");
|
||||||
});
|
});
|
||||||
let ty = TableType::new(ValType::FuncRef, Limits::new(1, None));
|
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())?;
|
table.set(0, func.into())?;
|
||||||
}
|
}
|
||||||
let func = table.get(0).unwrap().funcref().unwrap().clone();
|
let func = table.get(0).unwrap().funcref().unwrap().clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user