diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e9d8ceea..f0525b9172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,8 @@ Dates in this file are formattes as `YYYY-MM-DD`. - They now show `nan:0x{bytes}` where `{bytes}` is their respective raw bytes. - Implement `Sync` for `ResumableInvocation` and `TypedResumableInvocation`. (https://github.com/wasmi-labs/wasmi/pull/870) - Properly mirror Wasmtime's fuel API. (https://github.com/wasmi-labs/wasmi/pull/1002) +- Renamed some Wasmi items to improve its Wasmtime mirroring. (https://github.com/wasmi-labs/wasmi/pull/1011) +- Improve Wasmtime API mirror for Store fuel. (https://github.com/wasmi-labs/wasmi/pull/1002) ### Removed diff --git a/crates/cli/src/display.rs b/crates/cli/src/display.rs index af1e9872ab..311ad28ed6 100644 --- a/crates/cli/src/display.rs +++ b/crates/cli/src/display.rs @@ -1,12 +1,12 @@ use crate::context::Context; use std::fmt::{self, Display}; -use wasmi::{core::ValueType, FuncType, Value}; +use wasmi::{core::ValType, FuncType, Val}; -/// [`Display`]-wrapper type for [`ValueType`]. -pub struct DisplayValueType<'a>(&'a ValueType); +/// [`Display`]-wrapper type for [`ValType`]. +pub struct DisplayValueType<'a>(&'a ValType); -impl<'a> From<&'a ValueType> for DisplayValueType<'a> { - fn from(value_type: &'a ValueType) -> Self { +impl<'a> From<&'a ValType> for DisplayValueType<'a> { + fn from(value_type: &'a ValType) -> Self { Self(value_type) } } @@ -14,21 +14,21 @@ impl<'a> From<&'a ValueType> for DisplayValueType<'a> { impl Display for DisplayValueType<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { - ValueType::I32 => write!(f, "i32"), - ValueType::I64 => write!(f, "i64"), - ValueType::F32 => write!(f, "f32"), - ValueType::F64 => write!(f, "f64"), - ValueType::FuncRef => write!(f, "funcref"), - ValueType::ExternRef => write!(f, "externref"), + ValType::I32 => write!(f, "i32"), + ValType::I64 => write!(f, "i64"), + ValType::F32 => write!(f, "f32"), + ValType::F64 => write!(f, "f64"), + ValType::FuncRef => write!(f, "funcref"), + ValType::ExternRef => write!(f, "externref"), } } } -/// [`Display`]-wrapper type for [`Value`]. -pub struct DisplayValue<'a>(&'a Value); +/// [`Display`]-wrapper type for [`Val`]. +pub struct DisplayValue<'a>(&'a Val); -impl<'a> From<&'a Value> for DisplayValue<'a> { - fn from(value: &'a Value) -> Self { +impl<'a> From<&'a Val> for DisplayValue<'a> { + fn from(value: &'a Val) -> Self { Self(value) } } @@ -36,12 +36,12 @@ impl<'a> From<&'a Value> for DisplayValue<'a> { impl<'a> fmt::Display for DisplayValue<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.0 { - Value::I32(value) => write!(f, "{value}"), - Value::I64(value) => write!(f, "{value}"), - Value::F32(value) => write!(f, "{value}"), - Value::F64(value) => write!(f, "{value}"), - Value::FuncRef(value) => panic!("cannot display funcref values but found {value:?}"), - Value::ExternRef(value) => { + Val::I32(value) => write!(f, "{value}"), + Val::I64(value) => write!(f, "{value}"), + Val::F32(value) => write!(f, "{value}"), + Val::F64(value) => write!(f, "{value}"), + Val::FuncRef(value) => panic!("cannot display funcref values but found {value:?}"), + Val::ExternRef(value) => { panic!("cannot display externref values but found {value:?}") } } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index d67c25e41e..5d12ea8852 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, bail, Error, Result}; use clap::Parser; use context::Context; use std::{path::Path, process}; -use wasmi::{Func, FuncType, Value}; +use wasmi::{Func, FuncType, Val}; mod args; mod context; @@ -80,7 +80,7 @@ fn print_remaining_fuel(args: &Args, ctx: &Context) { /// # Errors /// /// If too many or too few function arguments were given to the invoked function. -fn typecheck_args(func_name: &str, func_ty: &FuncType, args: &[Value]) -> Result<(), Error> { +fn typecheck_args(func_name: &str, func_ty: &FuncType, args: &[Val]) -> Result<(), Error> { if func_ty.params().len() != args.len() { bail!( "invalid amount of arguments given to function {}. expected {} but received {}", @@ -125,7 +125,7 @@ fn get_invoked_func(args: &Args, ctx: &Context) -> Result<(String, Func), Error> } /// Prints a signalling text that Wasm execution has started. -fn print_execution_start(wasm_file: &Path, func_name: &str, func_args: &[Value]) { +fn print_execution_start(wasm_file: &Path, func_name: &str, func_args: &[Val]) { println!( "executing File({wasm_file:?})::{func_name}({}) ...", DisplaySequence::new(", ", func_args.iter().map(DisplayValue::from)) @@ -133,7 +133,7 @@ fn print_execution_start(wasm_file: &Path, func_name: &str, func_args: &[Value]) } /// Prints the results of the Wasm computation in a human readable form. -fn print_pretty_results(results: &[Value]) { +fn print_pretty_results(results: &[Val]) { match results.len() { 0 => {} 1 => { diff --git a/crates/cli/src/tests.rs b/crates/cli/src/tests.rs index 1a5aa59350..a1a53c61ea 100644 --- a/crates/cli/src/tests.rs +++ b/crates/cli/src/tests.rs @@ -1,6 +1,6 @@ use super::*; use core::borrow::Borrow; -use wasmi::core::ValueType; +use wasmi::core::ValType; fn assert_display(func_type: impl Borrow, expected: &str) { assert_eq!( @@ -16,18 +16,18 @@ fn display_0in_0out() { #[test] fn display_1in_0out() { - assert_display(FuncType::new([ValueType::I32], []), "fn(i32)"); + assert_display(FuncType::new([ValType::I32], []), "fn(i32)"); } #[test] fn display_0in_1out() { - assert_display(FuncType::new([], [ValueType::I32]), "fn() -> i32"); + assert_display(FuncType::new([], [ValType::I32]), "fn() -> i32"); } #[test] fn display_1in_1out() { assert_display( - FuncType::new([ValueType::I32], [ValueType::I32]), + FuncType::new([ValType::I32], [ValType::I32]), "fn(i32) -> i32", ); } @@ -35,15 +35,7 @@ fn display_1in_1out() { #[test] fn display_4in_0out() { assert_display( - FuncType::new( - [ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, - ], - [], - ), + FuncType::new([ValType::I32, ValType::I64, ValType::F32, ValType::F64], []), "fn(i32, i64, f32, f64)", ); } @@ -51,15 +43,7 @@ fn display_4in_0out() { #[test] fn display_0in_4out() { assert_display( - FuncType::new( - [], - [ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, - ], - ), + FuncType::new([], [ValType::I32, ValType::I64, ValType::F32, ValType::F64]), "fn() -> (i32, i64, f32, f64)", ); } @@ -68,18 +52,8 @@ fn display_0in_4out() { fn display_4in_4out() { assert_display( FuncType::new( - [ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, - ], - [ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, - ], + [ValType::I32, ValType::I64, ValType::F32, ValType::F64], + [ValType::I32, ValType::I64, ValType::F32, ValType::F64], ), "fn(i32, i64, f32, f64) -> (i32, i64, f32, f64)", ); diff --git a/crates/cli/src/utils.rs b/crates/cli/src/utils.rs index 98987f5d3a..55f59e6227 100644 --- a/crates/cli/src/utils.rs +++ b/crates/cli/src/utils.rs @@ -2,9 +2,9 @@ use crate::display::DisplayValueType; use anyhow::{anyhow, bail, Error}; use std::{ffi::OsStr, fs, path::Path}; use wasmi::{ - core::{ValueType, F32, F64}, + core::{ValType, F32, F64}, FuncType, - Value, + Val, }; /// Converts the given `.wat` into `.wasm`. @@ -30,27 +30,27 @@ pub fn read_wasm_or_wat(wasm_file: &Path) -> Result, Error> { Ok(wasm_bytes) } -/// Returns a [`Value`] buffer capable of holding the return values. +/// Returns a [`Val`] buffer capable of holding the return values. /// /// The returned buffer can be used as function results for [`Func::call`](`wasmi::Func::call`). -pub fn prepare_func_results(ty: &FuncType) -> Box<[Value]> { - ty.results().iter().copied().map(Value::default).collect() +pub fn prepare_func_results(ty: &FuncType) -> Box<[Val]> { + ty.results().iter().copied().map(Val::default).collect() } /// Decode the given `args` for the [`FuncType`] `ty`. /// -/// Returns the decoded `args` as a slice of [`Value`] which can be used +/// Returns the decoded `args` as a slice of [`Val`] which can be used /// as function arguments for [`Func::call`][`wasmi::Func::call`]. /// /// # Errors /// -/// - If there is a type mismatch between `args` and the expected [`ValueType`] by `ty`. +/// - If there is a type mismatch between `args` and the expected [`ValType`] by `ty`. /// - If too many or too few `args` are given for [`FuncType`] `ty`. /// - If unsupported [`ExternRef`] or [`FuncRef`] types are encountered. /// /// [`FuncRef`]: wasmi::FuncRef /// [`ExternRef`]: wasmi::ExternRef -pub fn decode_func_args(ty: &FuncType, args: &[String]) -> Result, Error> { +pub fn decode_func_args(ty: &FuncType, args: &[String]) -> Result, Error> { ty.params() .iter() .zip(args) @@ -68,22 +68,22 @@ pub fn decode_func_args(ty: &FuncType, args: &[String]) -> Result, }; } match param_type { - ValueType::I32 => arg.parse::().map(Value::from).map_err(make_err!()), - ValueType::I64 => arg.parse::().map(Value::from).map_err(make_err!()), - ValueType::F32 => arg + ValType::I32 => arg.parse::().map(Val::from).map_err(make_err!()), + ValType::I64 => arg.parse::().map(Val::from).map_err(make_err!()), + ValType::F32 => arg .parse::() .map(F32::from) - .map(Value::from) + .map(Val::from) .map_err(make_err!()), - ValueType::F64 => arg + ValType::F64 => arg .parse::() .map(F64::from) - .map(Value::from) + .map(Val::from) .map_err(make_err!()), - ValueType::FuncRef => { + ValType::FuncRef => { bail!("the wasmi CLI cannot take arguments of type funcref") } - ValueType::ExternRef => { + ValType::ExternRef => { bail!("the wasmi CLI cannot take arguments of type externref") } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 3d147199f2..3da69698d3 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -41,6 +41,6 @@ pub use self::{ nan_preserving_float::{F32, F64}, trap::{Trap, TrapCode}, units::Pages, - untyped::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedError, UntypedValue}, - value::ValueType, + untyped::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedError, UntypedVal}, + value::ValType, }; diff --git a/crates/core/src/untyped.rs b/crates/core/src/untyped.rs index 7b2bf3e0ef..ebf96c6f1b 100644 --- a/crates/core/src/untyped.rs +++ b/crates/core/src/untyped.rs @@ -24,14 +24,14 @@ use paste::paste; /// Provides a dense and simple interface to all functional Wasm operations. #[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord)] #[repr(transparent)] -pub struct UntypedValue { +pub struct UntypedVal { /// This inner value is required to have enough bits to represent /// all fundamental WebAssembly types `i32`, `i64`, `f32` and `f64`. bits: u64, } -impl UntypedValue { - /// Returns the underlying bits of the [`UntypedValue`]. +impl UntypedVal { + /// Returns the underlying bits of the [`UntypedVal`]. pub fn to_bits(self) -> u64 { self.bits } @@ -40,8 +40,8 @@ impl UntypedValue { macro_rules! impl_from_untyped_for_int { ( $( $int:ty ),* $(,)? ) => { $( - impl From for $int { - fn from(untyped: UntypedValue) -> Self { + impl From for $int { + fn from(untyped: UntypedVal) -> Self { untyped.to_bits() as _ } } @@ -53,8 +53,8 @@ impl_from_untyped_for_int!(i8, i16, i32, i64, u8, u16, u32, u64); macro_rules! impl_from_untyped_for_float { ( $( $float:ty ),* $(,)? ) => { $( - impl From for $float { - fn from(untyped: UntypedValue) -> Self { + impl From for $float { + fn from(untyped: UntypedVal) -> Self { Self::from_bits(untyped.to_bits() as _) } } @@ -63,8 +63,8 @@ macro_rules! impl_from_untyped_for_float { } impl_from_untyped_for_float!(f32, f64, F32, F64); -impl From for bool { - fn from(untyped: UntypedValue) -> Self { +impl From for bool { + fn from(untyped: UntypedVal) -> Self { untyped.to_bits() != 0 } } @@ -72,7 +72,7 @@ impl From for bool { macro_rules! impl_from_unsigned_prim { ( $( $prim:ty ),* $(,)? ) => { $( - impl From<$prim> for UntypedValue { + impl From<$prim> for UntypedVal { #[allow(clippy::cast_lossless)] fn from(value: $prim) -> Self { Self { bits: value as _ } @@ -89,7 +89,7 @@ impl_from_unsigned_prim!( macro_rules! impl_from_signed_prim { ( $( $prim:ty as $base:ty ),* $(,)? ) => { $( - impl From<$prim> for UntypedValue { + impl From<$prim> for UntypedVal { #[allow(clippy::cast_lossless)] fn from(value: $prim) -> Self { Self { bits: u64::from(value as $base) } @@ -109,7 +109,7 @@ impl_from_signed_prim!( macro_rules! impl_from_float { ( $( $float:ty ),* $(,)? ) => { $( - impl From<$float> for UntypedValue { + impl From<$float> for UntypedVal { fn from(value: $float) -> Self { Self { bits: u64::from(value.to_bits()), @@ -139,7 +139,7 @@ fn effective_address(address: u32, offset: u32) -> Result { .ok_or(TrapCode::MemoryOutOfBounds) } -impl UntypedValue { +impl UntypedVal { /// Executes a generic `T.loadN_[s|u]` Wasm operation. /// /// # Errors @@ -1338,10 +1338,10 @@ macro_rules! for_each_tuple { } } -/// An error that may occur upon encoding or decoding slices of [`UntypedValue`]. +/// An error that may occur upon encoding or decoding slices of [`UntypedVal`]. #[derive(Debug, Copy, Clone)] pub enum UntypedError { - /// The [`UntypedValue`] slice length did not match `Self`. + /// The [`UntypedVal`] slice length did not match `Self`. InvalidLen, } @@ -1363,8 +1363,8 @@ impl Display for UntypedError { } } -impl UntypedValue { - /// Decodes the slice of [`UntypedValue`] as a value of type `T`. +impl UntypedVal { + /// Decodes the slice of [`UntypedVal`] as a value of type `T`. /// /// # Note /// @@ -1381,7 +1381,7 @@ impl UntypedValue { ::decode_untyped_slice(slice) } - /// Encodes the slice of [`UntypedValue`] from the given value of type `T`. + /// Encodes the slice of [`UntypedVal`] from the given value of type `T`. /// /// # Note /// @@ -1399,9 +1399,9 @@ impl UntypedValue { } } -/// Tuple types that allow to decode a slice of [`UntypedValue`]. +/// Tuple types that allow to decode a slice of [`UntypedVal`]. pub trait DecodeUntypedSlice: Sized { - /// Decodes the slice of [`UntypedValue`] as a value of type `Self`. + /// Decodes the slice of [`UntypedVal`] as a value of type `Self`. /// /// # Note /// @@ -1411,15 +1411,15 @@ pub trait DecodeUntypedSlice: Sized { /// # Errors /// /// If the tuple length of `Self` and the length of `slice` does not match. - fn decode_untyped_slice(params: &[UntypedValue]) -> Result; + fn decode_untyped_slice(params: &[UntypedVal]) -> Result; } impl DecodeUntypedSlice for T1 where - T1: From, + T1: From, { #[inline] - fn decode_untyped_slice(results: &[UntypedValue]) -> Result { + fn decode_untyped_slice(results: &[UntypedVal]) -> Result { <(T1,) as DecodeUntypedSlice>::decode_untyped_slice(results).map(|t| t.0) } } @@ -1429,16 +1429,16 @@ macro_rules! impl_decode_untyped_slice { impl<$($tuple),*> DecodeUntypedSlice for ($($tuple,)*) where $( - $tuple: From + $tuple: From ),* { #[allow(non_snake_case)] #[inline] - fn decode_untyped_slice(results: &[UntypedValue]) -> Result { + fn decode_untyped_slice(results: &[UntypedVal]) -> Result { match results { &[ $($tuple),* ] => Ok(( $( - <$tuple as From>::from($tuple), + <$tuple as From>::from($tuple), )* )), _ => Err(UntypedError::invalid_len()), @@ -1449,9 +1449,9 @@ macro_rules! impl_decode_untyped_slice { } for_each_tuple!(impl_decode_untyped_slice); -/// Tuple types that allow to encode a slice of [`UntypedValue`]. +/// Tuple types that allow to encode a slice of [`UntypedVal`]. pub trait EncodeUntypedSlice { - /// Encodes the slice of [`UntypedValue`] from the given value of type `Self`. + /// Encodes the slice of [`UntypedVal`] from the given value of type `Self`. /// /// # Note /// @@ -1461,15 +1461,15 @@ pub trait EncodeUntypedSlice { /// # Errors /// /// If the tuple length of `Self` and the length of `slice` does not match. - fn encode_untyped_slice(self, results: &mut [UntypedValue]) -> Result<(), UntypedError>; + fn encode_untyped_slice(self, results: &mut [UntypedVal]) -> Result<(), UntypedError>; } impl EncodeUntypedSlice for T1 where - T1: Into, + T1: Into, { #[inline] - fn encode_untyped_slice(self, results: &mut [UntypedValue]) -> Result<(), UntypedError> { + fn encode_untyped_slice(self, results: &mut [UntypedVal]) -> Result<(), UntypedError> { <(T1,) as EncodeUntypedSlice>::encode_untyped_slice((self,), results) } } @@ -1480,17 +1480,17 @@ macro_rules! impl_encode_untyped_slice { impl<$($tuple),*> EncodeUntypedSlice for ($($tuple,)*) where $( - $tuple: Into + $tuple: Into ),* { #[allow(non_snake_case)] #[inline] - fn encode_untyped_slice(self, results: &mut [UntypedValue]) -> Result<(), UntypedError> { + fn encode_untyped_slice(self, results: &mut [UntypedVal]) -> Result<(), UntypedError> { match results { [ $( [< _results_ $tuple >] ,)* ] => { let ( $( [< _self_ $tuple >] ,)* ) = self; $( - *[< _results_ $tuple >] = <$tuple as Into>::into([< _self_ $tuple >]); + *[< _results_ $tuple >] = <$tuple as Into>::into([< _self_ $tuple >]); )* Ok(()) } diff --git a/crates/core/src/value.rs b/crates/core/src/value.rs index 7a1d9e7cd2..da233825c9 100644 --- a/crates/core/src/value.rs +++ b/crates/core/src/value.rs @@ -6,11 +6,11 @@ use crate::{ /// Type of a value. /// -/// See [`Value`] for details. +/// See [`Val`] for details. /// -/// [`Value`]: enum.Value.html +/// [`Val`]: enum.Value.html #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum ValueType { +pub enum ValType { /// 32-bit signed or unsigned integer. I32, /// 64-bit signed or unsigned integer. @@ -25,18 +25,18 @@ pub enum ValueType { ExternRef, } -impl ValueType { - /// Returns `true` if [`ValueType`] is a Wasm numeric type. +impl ValType { + /// Returns `true` if [`ValType`] is a Wasm numeric type. /// - /// This is `true` for [`ValueType::I32`], [`ValueType::I64`], - /// [`ValueType::F32`] and [`ValueType::F64`]. + /// This is `true` for [`ValType::I32`], [`ValType::I64`], + /// [`ValType::F32`] and [`ValType::F64`]. pub fn is_num(&self) -> bool { matches!(self, Self::I32 | Self::I64 | Self::F32 | Self::F64) } - /// Returns `true` if [`ValueType`] is a Wasm reference type. + /// Returns `true` if [`ValType`] is a Wasm reference type. /// - /// This is `true` for [`ValueType::FuncRef`] and [`ValueType::ExternRef`]. + /// This is `true` for [`ValType::FuncRef`] and [`ValType::ExternRef`]. pub fn is_ref(&self) -> bool { matches!(self, Self::ExternRef | Self::FuncRef) } diff --git a/crates/wasmi/benches/benches.rs b/crates/wasmi/benches/benches.rs index 5cdb00c8f7..220bf54d40 100644 --- a/crates/wasmi/benches/benches.rs +++ b/crates/wasmi/benches/benches.rs @@ -15,7 +15,7 @@ use std::{ sync::OnceLock, }; use wasmi::{ - core::{Pages, TrapCode, ValueType, F32, F64}, + core::{Pages, TrapCode, ValType, F32, F64}, CompilationMode, Engine, Extern, @@ -25,7 +25,7 @@ use wasmi::{ Memory, Module, Store, - Value, + Val, }; criterion_group!( @@ -468,12 +468,12 @@ fn bench_linker_setup_same(c: &mut Criterion) { /// Generates `count` host functions with different signatures. fn generate_unique_host_functions(count: usize) -> Vec<(String, FuncType)> { let types = [ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, - ValueType::FuncRef, - ValueType::ExternRef, + ValType::I32, + ValType::I64, + ValType::F32, + ValType::F64, + ValType::FuncRef, + ValType::ExternRef, ]; (0..count) .map(|i| { @@ -706,7 +706,7 @@ fn bench_execute_tiny_keccak(c: &mut Criterion) { .get_export(&store, "bench_tiny_keccak") .and_then(Extern::into_func) .unwrap(); - let mut test_data_ptr = Value::I32(0); + let mut test_data_ptr = Val::I32(0); prepare .call(&mut store, &[], slice::from_mut(&mut test_data_ptr)) .unwrap(); @@ -723,8 +723,8 @@ fn bench_execute_rev_comp(c: &mut Criterion) { let (mut store, instance) = load_instance_from_file(WASM_KERNEL); // Allocate buffers for the input and output. - let mut result = Value::I32(0); - let input_size = Value::I32(REVCOMP_INPUT.len() as i32); + let mut result = Val::I32(0); + let input_size = Val::I32(REVCOMP_INPUT.len() as i32); let prepare_rev_complement = instance .get_export(&store, "prepare_rev_complement") .and_then(Extern::into_func) @@ -733,7 +733,7 @@ fn bench_execute_rev_comp(c: &mut Criterion) { .call(&mut store, &[input_size], slice::from_mut(&mut result)) .unwrap(); let test_data_ptr = match &result { - Value::I32(value) => Value::I32(*value), + Val::I32(value) => Val::I32(*value), _ => panic!("unexpected non-I32 result found for prepare_rev_complement"), }; @@ -750,7 +750,7 @@ fn bench_execute_rev_comp(c: &mut Criterion) { ) .unwrap(); let input_data_mem_offset = match &result { - Value::I32(value) => *value, + Val::I32(value) => *value, _ => panic!("unexpected non-I32 result found for prepare_rev_complement"), }; @@ -787,7 +787,7 @@ fn bench_execute_rev_comp(c: &mut Criterion) { ) .unwrap(); let output_data_mem_offset = match &result { - Value::I32(value) => *value, + Val::I32(value) => *value, _ => panic!("unexpected non-I32 result found for prepare_rev_complement"), }; @@ -805,8 +805,8 @@ fn bench_execute_regex_redux(c: &mut Criterion) { let (mut store, instance) = load_instance_from_file(WASM_KERNEL); // Allocate buffers for the input and output. - let mut result = Value::I32(0); - let input_size = Value::I32(REVCOMP_INPUT.len() as i32); + let mut result = Val::I32(0); + let input_size = Val::I32(REVCOMP_INPUT.len() as i32); let prepare_regex_redux = instance .get_export(&store, "prepare_regex_redux") .and_then(Extern::into_func) @@ -815,7 +815,7 @@ fn bench_execute_regex_redux(c: &mut Criterion) { .call(&mut store, &[input_size], slice::from_mut(&mut result)) .unwrap(); let test_data_ptr = match &result { - Value::I32(value) => Value::I32(*value), + Val::I32(value) => Val::I32(*value), _ => panic!("unexpected non-I32 result found for prepare_regex_redux"), }; @@ -832,7 +832,7 @@ fn bench_execute_regex_redux(c: &mut Criterion) { ) .unwrap(); let input_data_mem_offset = match &result { - Value::I32(value) => *value, + Val::I32(value) => *value, _ => panic!("unexpected non-I32 result found for regex_redux_input_ptr"), }; @@ -1019,24 +1019,24 @@ fn bench_overhead_call_untyped_16(c: &mut Criterion) { .and_then(Extern::into_func) .unwrap(); let params = &[ - Value::default(ValueType::I32), - Value::default(ValueType::I64), - Value::default(ValueType::F32), - Value::default(ValueType::F64), - Value::default(ValueType::I32), - Value::default(ValueType::I64), - Value::default(ValueType::F32), - Value::default(ValueType::F64), - Value::default(ValueType::I32), - Value::default(ValueType::I64), - Value::default(ValueType::F32), - Value::default(ValueType::F64), - Value::default(ValueType::I32), - Value::default(ValueType::I64), - Value::default(ValueType::F32), - Value::default(ValueType::F64), + Val::default(ValType::I32), + Val::default(ValType::I64), + Val::default(ValType::F32), + Val::default(ValType::F64), + Val::default(ValType::I32), + Val::default(ValType::I64), + Val::default(ValType::F32), + Val::default(ValType::F64), + Val::default(ValType::I32), + Val::default(ValType::I64), + Val::default(ValType::F32), + Val::default(ValType::F64), + Val::default(ValType::I32), + Val::default(ValType::I64), + Val::default(ValType::F32), + Val::default(ValType::F64), ]; - let results = &mut [0; 16].map(Value::I32); + let results = &mut [0; 16].map(Val::I32); b.iter(|| { for _ in 0..REPETITIONS { bare_call.call(&mut store, params, results).unwrap(); @@ -1053,13 +1053,13 @@ fn bench_execute_global_bump(c: &mut Criterion) { .get_export(&store, "bump") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I32(0); + let mut result = Val::I32(0); b.iter(|| { count_until .call( &mut store, - &[Value::I32(BUMP_AMOUNT)], + &[Val::I32(BUMP_AMOUNT)], slice::from_mut(&mut result), ) .unwrap(); @@ -1076,15 +1076,11 @@ fn bench_execute_global_const(c: &mut Criterion) { .get_export(&store, "call") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I32(0); + let mut result = Val::I32(0); b.iter(|| { count_until - .call( - &mut store, - &[Value::I32(LIMIT)], - slice::from_mut(&mut result), - ) + .call(&mut store, &[Val::I32(LIMIT)], slice::from_mut(&mut result)) .unwrap(); assert_eq!(result.i32(), Some(LIMIT)); }) @@ -1123,13 +1119,13 @@ fn bench_execute_recursive_ok(c: &mut Criterion) { .get_export(&store, "call") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I32(0); + let mut result = Val::I32(0); b.iter(|| { bench_call .call( &mut store, - &[Value::I32(RECURSIVE_DEPTH)], + &[Val::I32(RECURSIVE_DEPTH)], slice::from_mut(&mut result), ) .unwrap(); @@ -1149,13 +1145,13 @@ fn bench_execute_recursive_scan(c: &mut Criterion) { .get_export(&store, "func") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I32(0); + let mut result = Val::I32(0); b.iter(|| { bench_call .call( &mut store, - &[Value::I32(RECURSIVE_SCAN_DEPTH)], + &[Val::I32(RECURSIVE_SCAN_DEPTH)], slice::from_mut(&mut result), ) .unwrap(); @@ -1172,10 +1168,10 @@ fn bench_execute_recursive_trap(c: &mut Criterion) { .get_export(&store, "call") .and_then(Extern::into_func) .unwrap(); - let mut result = [Value::I32(0)]; + let mut result = [Val::I32(0)]; b.iter(|| { let error = bench_call - .call(&mut store, &[Value::I32(1000)], &mut result) + .call(&mut store, &[Val::I32(1000)], &mut result) .unwrap_err(); match error.kind() { wasmi::errors::ErrorKind::TrapCode(trap_code) => assert_matches::assert_matches!( @@ -1196,13 +1192,13 @@ fn bench_execute_recursive_is_even(c: &mut Criterion) { .get_export(&store, "is_even") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I32(0); + let mut result = Val::I32(0); b.iter(|| { bench_call .call( &mut store, - &[Value::I32(50_000)], + &[Val::I32(50_000)], slice::from_mut(&mut result), ) .unwrap(); @@ -1233,12 +1229,12 @@ fn bench_execute_host_calls(c: &mut Criterion) { .get_export(&store, "call") .and_then(Extern::into_func) .unwrap(); - let mut result = Value::I64(0); + let mut result = Val::I64(0); b.iter(|| { call.call( &mut store, - &[Value::I64(HOST_CALLS_REPETITIONS)], + &[Val::I64(HOST_CALLS_REPETITIONS)], slice::from_mut(&mut result), ) .unwrap(); @@ -1342,11 +1338,11 @@ fn bench_execute_memory_sum(c: &mut Criterion) { *byte = new_byte; expected_sum += new_byte as u64 as i64; } - let mut result = Value::I64(0); + let mut result = Val::I64(0); b.iter(|| { sum.call( &mut store, - &[Value::I32(len as i32)], + &[Val::I32(len as i32)], slice::from_mut(&mut result), ) .unwrap(); @@ -1372,9 +1368,9 @@ fn bench_execute_memory_fill(c: &mut Criterion) { let value = 0x42_u8; mem.data_mut(&mut store)[ptr..(ptr + len)].fill(0x00); let params = [ - Value::I32(ptr as i32), - Value::I32(len as i32), - Value::I32(value as i32), + Val::I32(ptr as i32), + Val::I32(len as i32), + Val::I32(value as i32), ]; b.iter(|| { fill.call(&mut store, ¶ms, &mut []).unwrap(); @@ -1421,10 +1417,10 @@ fn bench_execute_vec_add(c: &mut Criterion) { // Prepare parameters and all Wasm `vec_add`: let params = [ - Value::I32(ptr_result as i32), - Value::I32(ptr_a as i32), - Value::I32(ptr_b as i32), - Value::I32(len as i32), + Val::I32(ptr_result as i32), + Val::I32(ptr_a as i32), + Val::I32(ptr_b as i32), + Val::I32(len as i32), ]; b.iter(|| { vec_add.call(&mut store, ¶ms, &mut []).unwrap(); diff --git a/crates/wasmi/src/engine/block_type.rs b/crates/wasmi/src/engine/block_type.rs index 073eb9eb12..cf5bf7b453 100644 --- a/crates/wasmi/src/engine/block_type.rs +++ b/crates/wasmi/src/engine/block_type.rs @@ -1,5 +1,5 @@ use crate::{ - core::ValueType, + core::ValType, engine::DedupFuncType, module::{utils::WasmiValueType, FuncTypeIdx, ModuleHeader}, Engine, @@ -53,7 +53,7 @@ impl BlockType { } /// Creates a [`BlockType`] with no parameters and a single result type. - fn returns(_return_type: ValueType) -> Self { + fn returns(_return_type: ValType) -> Self { Self::from_inner(BlockTypeInner::Returns) } diff --git a/crates/wasmi/src/engine/bytecode/provider.rs b/crates/wasmi/src/engine/bytecode/provider.rs index cf48ee1f5c..a9dfc2da71 100644 --- a/crates/wasmi/src/engine/bytecode/provider.rs +++ b/crates/wasmi/src/engine/bytecode/provider.rs @@ -1,5 +1,5 @@ use super::{AnyConst32, Register}; -use crate::{core::UntypedValue, engine::translator::TranslationError, Error}; +use crate::{core::UntypedVal, engine::translator::TranslationError, Error}; use std::vec::{Drain, Vec}; #[cfg(doc)] @@ -52,7 +52,7 @@ impl Provider { /// /// The [`UntypedProvider`] is primarily used for execution of /// Wasmi bytecode where typing usually no longer plays a role. -pub type UntypedProvider = Provider; +pub type UntypedProvider = Provider; impl From for UntypedProvider { fn from(register: Register) -> Self { @@ -60,15 +60,15 @@ impl From for UntypedProvider { } } -impl From for UntypedProvider { - fn from(register: UntypedValue) -> Self { +impl From for UntypedProvider { + fn from(register: UntypedVal) -> Self { Self::Const(register) } } impl UntypedProvider { /// Creates a new immediate value [`UntypedProvider`]. - pub fn immediate(value: impl Into) -> Self { + pub fn immediate(value: impl Into) -> Self { Self::from(value.into()) } } diff --git a/crates/wasmi/src/engine/bytecode/utils.rs b/crates/wasmi/src/engine/bytecode/utils.rs index 93324d531e..bb79131b2d 100644 --- a/crates/wasmi/src/engine/bytecode/utils.rs +++ b/crates/wasmi/src/engine/bytecode/utils.rs @@ -1,6 +1,6 @@ use super::{Const16, Const32}; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{Instr, TranslationError}, Error, }; @@ -904,10 +904,10 @@ impl ComparatorOffsetParam { Some(Self { cmp, offset }) } - /// Creates a new [`ComparatorOffsetParam`] from the given [`UntypedValue`]. + /// Creates a new [`ComparatorOffsetParam`] from the given [`UntypedVal`]. /// - /// Returns `None` if the [`UntypedValue`] has an invalid encoding. - pub fn from_untyped(value: UntypedValue) -> Option { + /// Returns `None` if the [`UntypedVal`] has an invalid encoding. + pub fn from_untyped(value: UntypedVal) -> Option { Self::from_u64(u64::from(value)) } @@ -919,7 +919,7 @@ impl ComparatorOffsetParam { } } -impl From for UntypedValue { +impl From for UntypedVal { fn from(params: ComparatorOffsetParam) -> Self { Self::from(params.as_u64()) } diff --git a/crates/wasmi/src/engine/cache.rs b/crates/wasmi/src/engine/cache.rs index 0b193f21df..14d71b28f6 100644 --- a/crates/wasmi/src/engine/cache.rs +++ b/crates/wasmi/src/engine/cache.rs @@ -1,5 +1,5 @@ use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{DataSegmentIdx, ElementSegmentIdx, FuncIdx, GlobalIdx, TableIdx}, instance::InstanceEntity, memory::DataSegment, @@ -23,7 +23,7 @@ pub struct InstanceCache { /// The bytes of a default linear memory of the currently used [`Instance`]. default_memory_bytes: Option>, /// The last accessed global variable value of the currently used [`Instance`]. - last_global: Option<(GlobalIdx, NonNull)>, + last_global: Option<(GlobalIdx, NonNull)>, /// The current instance in use. instance: Instance, /// The default linear memory of the currently used [`Instance`]. @@ -313,7 +313,7 @@ impl InstanceCache { /// If the currently used [`Instance`] does not have a default table. #[cold] #[inline] - fn load_global_at(&mut self, ctx: &mut StoreInner, index: GlobalIdx) -> NonNull { + fn load_global_at(&mut self, ctx: &mut StoreInner, index: GlobalIdx) -> NonNull { let global = ctx .resolve_instance(self.instance()) .get_global(index.to_u32()) @@ -340,7 +340,7 @@ impl InstanceCache { &mut self, ctx: &'ctx mut StoreInner, global_index: GlobalIdx, - ) -> &'ctx mut UntypedValue { + ) -> &'ctx mut UntypedVal { let mut ptr = match self.last_global { Some((index, global)) if index == global_index => global, _ => self.load_global_at(ctx, global_index), @@ -358,7 +358,7 @@ impl InstanceCache { /// /// If the currently used [`Instance`] does not have a [`Func`] at the index. #[inline(always)] - pub fn get_global(&mut self, ctx: &mut StoreInner, global_index: GlobalIdx) -> UntypedValue { + pub fn get_global(&mut self, ctx: &mut StoreInner, global_index: GlobalIdx) -> UntypedVal { *self.get_global_mut(ctx, global_index) } @@ -373,7 +373,7 @@ impl InstanceCache { &mut self, ctx: &mut StoreInner, global_index: GlobalIdx, - new_value: UntypedValue, + new_value: UntypedVal, ) { *self.get_global_mut(ctx, global_index) = new_value; } diff --git a/crates/wasmi/src/engine/code_map.rs b/crates/wasmi/src/engine/code_map.rs index 4662068adf..fe1cef689a 100644 --- a/crates/wasmi/src/engine/code_map.rs +++ b/crates/wasmi/src/engine/code_map.rs @@ -14,7 +14,7 @@ use super::{ }; use crate::{ collections::arena::{Arena, ArenaIndex}, - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::bytecode::Instruction, module::{FuncIdx, ModuleHeader}, store::{Fuel, FuelError}, @@ -303,7 +303,7 @@ pub struct CompiledFuncEntity { /// function parameters, function locals and dynamically used registers. len_registers: u16, /// The constant values local to the [`CompiledFunc`]. - consts: Box<[UntypedValue]>, + consts: Box<[UntypedVal]>, } impl CompiledFuncEntity { @@ -316,10 +316,10 @@ impl CompiledFuncEntity { pub fn new(len_registers: u16, instrs: I, consts: C) -> Self where I: IntoIterator, - C: IntoIterator, + C: IntoIterator, { let instrs: Box<[Instruction]> = instrs.into_iter().collect(); - let consts: Box<[UntypedValue]> = consts.into_iter().collect(); + let consts: Box<[UntypedVal]> = consts.into_iter().collect(); assert!( !instrs.is_empty(), "compiled functions must have at least one instruction" @@ -368,7 +368,7 @@ impl CompiledFuncEntity { } /// Returns the function local constant values of the [`CompiledFunc`]. - pub fn consts(&self) -> &[UntypedValue] { + pub fn consts(&self) -> &[UntypedVal] { &self.consts } } diff --git a/crates/wasmi/src/engine/config.rs b/crates/wasmi/src/engine/config.rs index f01f5515ba..4deeed2632 100644 --- a/crates/wasmi/src/engine/config.rs +++ b/crates/wasmi/src/engine/config.rs @@ -1,5 +1,5 @@ use super::{EnforcedLimits, StackLimits}; -use crate::core::UntypedValue; +use crate::core::UntypedVal; use core::{mem::size_of, num::NonZeroU64}; use wasmparser::WasmFeatures; @@ -136,7 +136,7 @@ impl FuelCosts { impl Default for FuelCosts { fn default() -> Self { let bytes_per_fuel = 64; - let bytes_per_register = size_of::() as u64; + let bytes_per_register = size_of::() as u64; let registers_per_fuel = bytes_per_fuel / bytes_per_register; Self { base: 1, @@ -375,7 +375,7 @@ impl Config { /// By default no limits are enforced. /// /// [`Engine`]: crate::Engine - pub fn engine_limits(&mut self, limits: EnforcedLimits) -> &mut Self { + pub fn enforced_limits(&mut self, limits: EnforcedLimits) -> &mut Self { self.limits = limits; self } diff --git a/crates/wasmi/src/engine/executor/instrs.rs b/crates/wasmi/src/engine/executor/instrs.rs index 5e537df953..ba5a814c4a 100644 --- a/crates/wasmi/src/engine/executor/instrs.rs +++ b/crates/wasmi/src/engine/executor/instrs.rs @@ -1,7 +1,7 @@ pub use self::call::CallKind; use self::{call::CallOutcome, return_::ReturnOutcome}; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::{ bytecode::{ AnyConst32, @@ -863,7 +863,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { } /// Returns the [`Register`] value. - fn get_register(&self, register: Register) -> UntypedValue { + fn get_register(&self, register: Register) -> UntypedVal { // Safety: TODO unsafe { self.sp.get(register) } } @@ -871,13 +871,13 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { /// Returns the [`Register`] value. fn get_register_as(&self, register: Register) -> T where - T: From, + T: From, { T::from(self.get_register(register)) } /// Sets the [`Register`] value to `value`. - fn set_register(&mut self, register: Register, value: impl Into) { + fn set_register(&mut self, register: Register, value: impl Into) { // Safety: TODO unsafe { self.sp.set(register, value.into()) }; } @@ -988,7 +988,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { } /// Executes a generic unary [`Instruction`]. - fn execute_unary(&mut self, instr: UnaryInstr, op: fn(UntypedValue) -> UntypedValue) { + fn execute_unary(&mut self, instr: UnaryInstr, op: fn(UntypedVal) -> UntypedVal) { let value = self.get_register(instr.input); self.set_register(instr.result, op(value)); self.next_instr(); @@ -998,7 +998,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn try_execute_unary( &mut self, instr: UnaryInstr, - op: fn(UntypedValue) -> Result, + op: fn(UntypedVal) -> Result, ) -> Result<(), Error> { let value = self.get_register(instr.input); self.set_register(instr.result, op(value)?); @@ -1006,11 +1006,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { } /// Executes a generic binary [`Instruction`]. - fn execute_binary( - &mut self, - instr: BinInstr, - op: fn(UntypedValue, UntypedValue) -> UntypedValue, - ) { + fn execute_binary(&mut self, instr: BinInstr, op: fn(UntypedVal, UntypedVal) -> UntypedVal) { let lhs = self.get_register(instr.lhs); let rhs = self.get_register(instr.rhs); self.set_register(instr.result, op(lhs, rhs)); @@ -1021,13 +1017,13 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn execute_binary_imm16( &mut self, instr: BinInstrImm16, - op: fn(UntypedValue, UntypedValue) -> UntypedValue, + op: fn(UntypedVal, UntypedVal) -> UntypedVal, ) where T: From>, - UntypedValue: From, + UntypedVal: From, { let lhs = self.get_register(instr.reg_in); - let rhs = UntypedValue::from(::from(instr.imm_in)); + let rhs = UntypedVal::from(::from(instr.imm_in)); self.set_register(instr.result, op(lhs, rhs)); self.next_instr(); } @@ -1036,12 +1032,12 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn execute_binary_imm16_rev( &mut self, instr: BinInstrImm16, - op: fn(UntypedValue, UntypedValue) -> UntypedValue, + op: fn(UntypedVal, UntypedVal) -> UntypedVal, ) where T: From>, - UntypedValue: From, + UntypedVal: From, { - let lhs = UntypedValue::from(::from(instr.imm_in)); + let lhs = UntypedVal::from(::from(instr.imm_in)); let rhs = self.get_register(instr.reg_in); self.set_register(instr.result, op(lhs, rhs)); self.next_instr(); @@ -1051,7 +1047,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn try_execute_binary( &mut self, instr: BinInstr, - op: fn(UntypedValue, UntypedValue) -> Result, + op: fn(UntypedVal, UntypedVal) -> Result, ) -> Result<(), Error> { let lhs = self.get_register(instr.lhs); let rhs = self.get_register(instr.rhs); @@ -1063,7 +1059,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn try_execute_divrem_imm16( &mut self, instr: BinInstrImm16, - op: fn(UntypedValue, NonZeroT) -> Result, + op: fn(UntypedVal, NonZeroT) -> Result, ) -> Result<(), Error> where NonZeroT: From>, @@ -1078,7 +1074,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn execute_divrem_imm16( &mut self, instr: BinInstrImm16, - op: fn(UntypedValue, NonZeroT) -> UntypedValue, + op: fn(UntypedVal, NonZeroT) -> UntypedVal, ) where NonZeroT: From>, { @@ -1092,13 +1088,13 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn try_execute_binary_imm16_rev( &mut self, instr: BinInstrImm16, - op: fn(UntypedValue, UntypedValue) -> Result, + op: fn(UntypedVal, UntypedVal) -> Result, ) -> Result<(), Error> where T: From>, - UntypedValue: From, + UntypedVal: From, { - let lhs = UntypedValue::from(::from(instr.imm_in)); + let lhs = UntypedVal::from(::from(instr.imm_in)); let rhs = self.get_register(instr.reg_in); self.set_register(instr.result, op(lhs, rhs)?); self.try_next_instr() @@ -1145,28 +1141,28 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { } } -/// Extension method for [`UntypedValue`] required by the [`Executor`]. +/// Extension method for [`UntypedVal`] required by the [`Executor`]. trait UntypedValueExt { /// Executes a fused `i32.and` + `i32.eqz` instruction. - fn i32_and_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue; + fn i32_and_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal; /// Executes a fused `i32.or` + `i32.eqz` instruction. - fn i32_or_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue; + fn i32_or_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal; /// Executes a fused `i32.xor` + `i32.eqz` instruction. - fn i32_xor_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue; + fn i32_xor_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal; } -impl UntypedValueExt for UntypedValue { - fn i32_and_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue { - (i32::from(UntypedValue::i32_and(x, y)) == 0).into() +impl UntypedValueExt for UntypedVal { + fn i32_and_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal { + (i32::from(UntypedVal::i32_and(x, y)) == 0).into() } - fn i32_or_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue { - (i32::from(UntypedValue::i32_or(x, y)) == 0).into() + fn i32_or_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal { + (i32::from(UntypedVal::i32_or(x, y)) == 0).into() } - fn i32_xor_eqz(x: UntypedValue, y: UntypedValue) -> UntypedValue { - (i32::from(UntypedValue::i32_xor(x, y)) == 0).into() + fn i32_xor_eqz(x: UntypedVal, y: UntypedVal) -> UntypedVal { + (i32::from(UntypedVal::i32_xor(x, y)) == 0).into() } } diff --git a/crates/wasmi/src/engine/executor/instrs/binary.rs b/crates/wasmi/src/engine/executor/instrs/binary.rs index 09156cbf31..d26fd5cdd7 100644 --- a/crates/wasmi/src/engine/executor/instrs/binary.rs +++ b/crates/wasmi/src/engine/executor/instrs/binary.rs @@ -1,6 +1,6 @@ use super::{Executor, UntypedValueExt}; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::bytecode::{BinInstr, BinInstrImm, BinInstrImm16, Sign}, Error, }; @@ -22,50 +22,50 @@ macro_rules! impl_binary { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_binary! { - (Instruction::I32Add, execute_i32_add, UntypedValue::i32_add), - (Instruction::I32Sub, execute_i32_sub, UntypedValue::i32_sub), - (Instruction::I32Mul, execute_i32_mul, UntypedValue::i32_mul), - (Instruction::I32And, execute_i32_and, UntypedValue::i32_and), - (Instruction::I32AndEqz, execute_i32_and_eqz, UntypedValue::i32_and_eqz), - (Instruction::I32Or, execute_i32_or, UntypedValue::i32_or), - (Instruction::I32OrEqz, execute_i32_or_eqz, UntypedValue::i32_or_eqz), - (Instruction::I32Xor, execute_i32_xor, UntypedValue::i32_xor), - (Instruction::I32XorEqz, execute_i32_xor_eqz, UntypedValue::i32_xor_eqz), - - (Instruction::I64Add, execute_i64_add, UntypedValue::i64_add), - (Instruction::I64Sub, execute_i64_sub, UntypedValue::i64_sub), - (Instruction::I64Mul, execute_i64_mul, UntypedValue::i64_mul), - (Instruction::I64And, execute_i64_and, UntypedValue::i64_and), - (Instruction::I64Or, execute_i64_or, UntypedValue::i64_or), - (Instruction::I64Xor, execute_i64_xor, UntypedValue::i64_xor), - - (Instruction::I32Shl, execute_i32_shl, UntypedValue::i32_shl), - (Instruction::I32ShrU, execute_i32_shr_u, UntypedValue::i32_shr_u), - (Instruction::I32ShrS, execute_i32_shr_s, UntypedValue::i32_shr_s), - (Instruction::I32Rotl, execute_i32_rotl, UntypedValue::i32_rotl), - (Instruction::I32Rotr, execute_i32_rotr, UntypedValue::i32_rotr), - - (Instruction::I64Shl, execute_i64_shl, UntypedValue::i64_shl), - (Instruction::I64ShrU, execute_i64_shr_u, UntypedValue::i64_shr_u), - (Instruction::I64ShrS, execute_i64_shr_s, UntypedValue::i64_shr_s), - (Instruction::I64Rotl, execute_i64_rotl, UntypedValue::i64_rotl), - (Instruction::I64Rotr, execute_i64_rotr, UntypedValue::i64_rotr), - - (Instruction::F32Add, execute_f32_add, UntypedValue::f32_add), - (Instruction::F32Sub, execute_f32_sub, UntypedValue::f32_sub), - (Instruction::F32Mul, execute_f32_mul, UntypedValue::f32_mul), - (Instruction::F32Div, execute_f32_div, UntypedValue::f32_div), - (Instruction::F32Min, execute_f32_min, UntypedValue::f32_min), - (Instruction::F32Max, execute_f32_max, UntypedValue::f32_max), - (Instruction::F32Copysign, execute_f32_copysign, UntypedValue::f32_copysign), - - (Instruction::F64Add, execute_f64_add, UntypedValue::f64_add), - (Instruction::F64Sub, execute_f64_sub, UntypedValue::f64_sub), - (Instruction::F64Mul, execute_f64_mul, UntypedValue::f64_mul), - (Instruction::F64Div, execute_f64_div, UntypedValue::f64_div), - (Instruction::F64Min, execute_f64_min, UntypedValue::f64_min), - (Instruction::F64Max, execute_f64_max, UntypedValue::f64_max), - (Instruction::F64Copysign, execute_f64_copysign, UntypedValue::f64_copysign), + (Instruction::I32Add, execute_i32_add, UntypedVal::i32_add), + (Instruction::I32Sub, execute_i32_sub, UntypedVal::i32_sub), + (Instruction::I32Mul, execute_i32_mul, UntypedVal::i32_mul), + (Instruction::I32And, execute_i32_and, UntypedVal::i32_and), + (Instruction::I32AndEqz, execute_i32_and_eqz, UntypedVal::i32_and_eqz), + (Instruction::I32Or, execute_i32_or, UntypedVal::i32_or), + (Instruction::I32OrEqz, execute_i32_or_eqz, UntypedVal::i32_or_eqz), + (Instruction::I32Xor, execute_i32_xor, UntypedVal::i32_xor), + (Instruction::I32XorEqz, execute_i32_xor_eqz, UntypedVal::i32_xor_eqz), + + (Instruction::I64Add, execute_i64_add, UntypedVal::i64_add), + (Instruction::I64Sub, execute_i64_sub, UntypedVal::i64_sub), + (Instruction::I64Mul, execute_i64_mul, UntypedVal::i64_mul), + (Instruction::I64And, execute_i64_and, UntypedVal::i64_and), + (Instruction::I64Or, execute_i64_or, UntypedVal::i64_or), + (Instruction::I64Xor, execute_i64_xor, UntypedVal::i64_xor), + + (Instruction::I32Shl, execute_i32_shl, UntypedVal::i32_shl), + (Instruction::I32ShrU, execute_i32_shr_u, UntypedVal::i32_shr_u), + (Instruction::I32ShrS, execute_i32_shr_s, UntypedVal::i32_shr_s), + (Instruction::I32Rotl, execute_i32_rotl, UntypedVal::i32_rotl), + (Instruction::I32Rotr, execute_i32_rotr, UntypedVal::i32_rotr), + + (Instruction::I64Shl, execute_i64_shl, UntypedVal::i64_shl), + (Instruction::I64ShrU, execute_i64_shr_u, UntypedVal::i64_shr_u), + (Instruction::I64ShrS, execute_i64_shr_s, UntypedVal::i64_shr_s), + (Instruction::I64Rotl, execute_i64_rotl, UntypedVal::i64_rotl), + (Instruction::I64Rotr, execute_i64_rotr, UntypedVal::i64_rotr), + + (Instruction::F32Add, execute_f32_add, UntypedVal::f32_add), + (Instruction::F32Sub, execute_f32_sub, UntypedVal::f32_sub), + (Instruction::F32Mul, execute_f32_mul, UntypedVal::f32_mul), + (Instruction::F32Div, execute_f32_div, UntypedVal::f32_div), + (Instruction::F32Min, execute_f32_min, UntypedVal::f32_min), + (Instruction::F32Max, execute_f32_max, UntypedVal::f32_max), + (Instruction::F32Copysign, execute_f32_copysign, UntypedVal::f32_copysign), + + (Instruction::F64Add, execute_f64_add, UntypedVal::f64_add), + (Instruction::F64Sub, execute_f64_sub, UntypedVal::f64_sub), + (Instruction::F64Mul, execute_f64_mul, UntypedVal::f64_mul), + (Instruction::F64Div, execute_f64_div, UntypedVal::f64_div), + (Instruction::F64Min, execute_f64_min, UntypedVal::f64_min), + (Instruction::F64Max, execute_f64_max, UntypedVal::f64_max), + (Instruction::F64Copysign, execute_f64_copysign, UntypedVal::f64_copysign), } } @@ -82,32 +82,32 @@ macro_rules! impl_binary_imm16 { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_binary_imm16! { - (i32, Instruction::I32AddImm16, execute_i32_add_imm16, UntypedValue::i32_add), - (i32, Instruction::I32MulImm16, execute_i32_mul_imm16, UntypedValue::i32_mul), - (i32, Instruction::I32AndImm16, execute_i32_and_imm16, UntypedValue::i32_and), - (i32, Instruction::I32AndEqzImm16, execute_i32_and_eqz_imm16, UntypedValue::i32_and_eqz), - (i32, Instruction::I32OrImm16, execute_i32_or_imm16, UntypedValue::i32_or), - (i32, Instruction::I32OrEqzImm16, execute_i32_or_eqz_imm16, UntypedValue::i32_or_eqz), - (i32, Instruction::I32XorImm16, execute_i32_xor_imm16, UntypedValue::i32_xor), - (i32, Instruction::I32XorEqzImm16, execute_i32_xor_eqz_imm16, UntypedValue::i32_xor_eqz), - - (i64, Instruction::I64AddImm16, execute_i64_add_imm16, UntypedValue::i64_add), - (i64, Instruction::I64MulImm16, execute_i64_mul_imm16, UntypedValue::i64_mul), - (i64, Instruction::I64AndImm16, execute_i64_and_imm16, UntypedValue::i64_and), - (i64, Instruction::I64OrImm16, execute_i64_or_imm16, UntypedValue::i64_or), - (i64, Instruction::I64XorImm16, execute_i64_xor_imm16, UntypedValue::i64_xor), - - (i32, Instruction::I32ShlImm, execute_i32_shl_imm, UntypedValue::i32_shl), - (i32, Instruction::I32ShrUImm, execute_i32_shr_u_imm, UntypedValue::i32_shr_u), - (i32, Instruction::I32ShrSImm, execute_i32_shr_s_imm, UntypedValue::i32_shr_s), - (i32, Instruction::I32RotlImm, execute_i32_rotl_imm, UntypedValue::i32_rotl), - (i32, Instruction::I32RotrImm, execute_i32_rotr_imm, UntypedValue::i32_rotr), - - (i64, Instruction::I64ShlImm, execute_i64_shl_imm, UntypedValue::i64_shl), - (i64, Instruction::I64ShrUImm, execute_i64_shr_u_imm, UntypedValue::i64_shr_u), - (i64, Instruction::I64ShrSImm, execute_i64_shr_s_imm, UntypedValue::i64_shr_s), - (i64, Instruction::I64RotlImm, execute_i64_rotl_imm, UntypedValue::i64_rotl), - (i64, Instruction::I64RotrImm, execute_i64_rotr_imm, UntypedValue::i64_rotr), + (i32, Instruction::I32AddImm16, execute_i32_add_imm16, UntypedVal::i32_add), + (i32, Instruction::I32MulImm16, execute_i32_mul_imm16, UntypedVal::i32_mul), + (i32, Instruction::I32AndImm16, execute_i32_and_imm16, UntypedVal::i32_and), + (i32, Instruction::I32AndEqzImm16, execute_i32_and_eqz_imm16, UntypedVal::i32_and_eqz), + (i32, Instruction::I32OrImm16, execute_i32_or_imm16, UntypedVal::i32_or), + (i32, Instruction::I32OrEqzImm16, execute_i32_or_eqz_imm16, UntypedVal::i32_or_eqz), + (i32, Instruction::I32XorImm16, execute_i32_xor_imm16, UntypedVal::i32_xor), + (i32, Instruction::I32XorEqzImm16, execute_i32_xor_eqz_imm16, UntypedVal::i32_xor_eqz), + + (i64, Instruction::I64AddImm16, execute_i64_add_imm16, UntypedVal::i64_add), + (i64, Instruction::I64MulImm16, execute_i64_mul_imm16, UntypedVal::i64_mul), + (i64, Instruction::I64AndImm16, execute_i64_and_imm16, UntypedVal::i64_and), + (i64, Instruction::I64OrImm16, execute_i64_or_imm16, UntypedVal::i64_or), + (i64, Instruction::I64XorImm16, execute_i64_xor_imm16, UntypedVal::i64_xor), + + (i32, Instruction::I32ShlImm, execute_i32_shl_imm, UntypedVal::i32_shl), + (i32, Instruction::I32ShrUImm, execute_i32_shr_u_imm, UntypedVal::i32_shr_u), + (i32, Instruction::I32ShrSImm, execute_i32_shr_s_imm, UntypedVal::i32_shr_s), + (i32, Instruction::I32RotlImm, execute_i32_rotl_imm, UntypedVal::i32_rotl), + (i32, Instruction::I32RotrImm, execute_i32_rotr_imm, UntypedVal::i32_rotr), + + (i64, Instruction::I64ShlImm, execute_i64_shl_imm, UntypedVal::i64_shl), + (i64, Instruction::I64ShrUImm, execute_i64_shr_u_imm, UntypedVal::i64_shr_u), + (i64, Instruction::I64ShrSImm, execute_i64_shr_s_imm, UntypedVal::i64_shr_s), + (i64, Instruction::I64RotlImm, execute_i64_rotl_imm, UntypedVal::i64_rotl), + (i64, Instruction::I64RotrImm, execute_i64_rotr_imm, UntypedVal::i64_rotr), } } @@ -125,20 +125,20 @@ macro_rules! impl_binary_imm16_rev { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_binary_imm16_rev! { - (i32, Instruction::I32SubImm16Rev, execute_i32_sub_imm16_rev, UntypedValue::i32_sub), - (i64, Instruction::I64SubImm16Rev, execute_i64_sub_imm16_rev, UntypedValue::i64_sub), - - (i32, Instruction::I32ShlImm16Rev, execute_i32_shl_imm16_rev, UntypedValue::i32_shl), - (i32, Instruction::I32ShrUImm16Rev, execute_i32_shr_u_imm16_rev, UntypedValue::i32_shr_u), - (i32, Instruction::I32ShrSImm16Rev, execute_i32_shr_s_imm16_rev, UntypedValue::i32_shr_s), - (i32, Instruction::I32RotlImm16Rev, execute_i32_rotl_imm16_rev, UntypedValue::i32_rotl), - (i32, Instruction::I32RotrImm16Rev, execute_i32_rotr_imm16_rev, UntypedValue::i32_rotr), - - (i64, Instruction::I64ShlImm16Rev, execute_i64_shl_imm16_rev, UntypedValue::i64_shl), - (i64, Instruction::I64ShrUImm16Rev, execute_i64_shr_u_imm16_rev, UntypedValue::i64_shr_u), - (i64, Instruction::I64ShrSImm16Rev, execute_i64_shr_s_imm16_rev, UntypedValue::i64_shr_s), - (i64, Instruction::I64RotlImm16Rev, execute_i64_rotl_imm16_rev, UntypedValue::i64_rotl), - (i64, Instruction::I64RotrImm16Rev, execute_i64_rotr_imm16_rev, UntypedValue::i64_rotr), + (i32, Instruction::I32SubImm16Rev, execute_i32_sub_imm16_rev, UntypedVal::i32_sub), + (i64, Instruction::I64SubImm16Rev, execute_i64_sub_imm16_rev, UntypedVal::i64_sub), + + (i32, Instruction::I32ShlImm16Rev, execute_i32_shl_imm16_rev, UntypedVal::i32_shl), + (i32, Instruction::I32ShrUImm16Rev, execute_i32_shr_u_imm16_rev, UntypedVal::i32_shr_u), + (i32, Instruction::I32ShrSImm16Rev, execute_i32_shr_s_imm16_rev, UntypedVal::i32_shr_s), + (i32, Instruction::I32RotlImm16Rev, execute_i32_rotl_imm16_rev, UntypedVal::i32_rotl), + (i32, Instruction::I32RotrImm16Rev, execute_i32_rotr_imm16_rev, UntypedVal::i32_rotr), + + (i64, Instruction::I64ShlImm16Rev, execute_i64_shl_imm16_rev, UntypedVal::i64_shl), + (i64, Instruction::I64ShrUImm16Rev, execute_i64_shr_u_imm16_rev, UntypedVal::i64_shr_u), + (i64, Instruction::I64ShrSImm16Rev, execute_i64_shr_s_imm16_rev, UntypedVal::i64_shr_s), + (i64, Instruction::I64RotlImm16Rev, execute_i64_rotl_imm16_rev, UntypedVal::i64_rotl), + (i64, Instruction::I64RotrImm16Rev, execute_i64_rotr_imm16_rev, UntypedVal::i64_rotr), } } @@ -155,15 +155,15 @@ macro_rules! impl_fallible_binary { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_fallible_binary! { - (Instruction::I32DivS, execute_i32_div_s, UntypedValue::i32_div_s), - (Instruction::I32DivU, execute_i32_div_u, UntypedValue::i32_div_u), - (Instruction::I32RemS, execute_i32_rem_s, UntypedValue::i32_rem_s), - (Instruction::I32RemU, execute_i32_rem_u, UntypedValue::i32_rem_u), - - (Instruction::I64DivS, execute_i64_div_s, UntypedValue::i64_div_s), - (Instruction::I64DivU, execute_i64_div_u, UntypedValue::i64_div_u), - (Instruction::I64RemS, execute_i64_rem_s, UntypedValue::i64_rem_s), - (Instruction::I64RemU, execute_i64_rem_u, UntypedValue::i64_rem_u), + (Instruction::I32DivS, execute_i32_div_s, UntypedVal::i32_div_s), + (Instruction::I32DivU, execute_i32_div_u, UntypedVal::i32_div_u), + (Instruction::I32RemS, execute_i32_rem_s, UntypedVal::i32_rem_s), + (Instruction::I32RemU, execute_i32_rem_u, UntypedVal::i32_rem_u), + + (Instruction::I64DivS, execute_i64_div_s, UntypedVal::i64_div_s), + (Instruction::I64DivU, execute_i64_div_u, UntypedVal::i64_div_u), + (Instruction::I64RemS, execute_i64_rem_s, UntypedVal::i64_rem_s), + (Instruction::I64RemU, execute_i64_rem_u, UntypedVal::i64_rem_u), } } @@ -188,7 +188,7 @@ pub trait DivRemExt: Sized { fn i64_rem_u(self, rhs: NonZeroU64) -> Self; } -impl DivRemExt for UntypedValue { +impl DivRemExt for UntypedVal { fn i32_div_s(self, rhs: NonZeroI32) -> Result { i32::from(self) .checked_div(rhs.get()) @@ -247,11 +247,11 @@ macro_rules! impl_divrem_s_imm16 { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_divrem_s_imm16! { - (NonZeroI32, Instruction::I32DivSImm16, execute_i32_div_s_imm16, ::i32_div_s), - (NonZeroI32, Instruction::I32RemSImm16, execute_i32_rem_s_imm16, ::i32_rem_s), + (NonZeroI32, Instruction::I32DivSImm16, execute_i32_div_s_imm16, ::i32_div_s), + (NonZeroI32, Instruction::I32RemSImm16, execute_i32_rem_s_imm16, ::i32_rem_s), - (NonZeroI64, Instruction::I64DivSImm16, execute_i64_div_s_imm16, ::i64_div_s), - (NonZeroI64, Instruction::I64RemSImm16, execute_i64_rem_s_imm16, ::i64_rem_s), + (NonZeroI64, Instruction::I64DivSImm16, execute_i64_div_s_imm16, ::i64_div_s), + (NonZeroI64, Instruction::I64RemSImm16, execute_i64_rem_s_imm16, ::i64_rem_s), } } @@ -268,11 +268,11 @@ macro_rules! impl_divrem_u_imm16 { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_divrem_u_imm16! { - (NonZeroU32, Instruction::I32DivUImm16, execute_i32_div_u_imm16, ::i32_div_u), - (NonZeroU32, Instruction::I32RemUImm16, execute_i32_rem_u_imm16, ::i32_rem_u), + (NonZeroU32, Instruction::I32DivUImm16, execute_i32_div_u_imm16, ::i32_div_u), + (NonZeroU32, Instruction::I32RemUImm16, execute_i32_rem_u_imm16, ::i32_rem_u), - (NonZeroU64, Instruction::I64DivUImm16, execute_i64_div_u_imm16, ::i64_div_u), - (NonZeroU64, Instruction::I64RemUImm16, execute_i64_rem_u_imm16, ::i64_rem_u), + (NonZeroU64, Instruction::I64DivUImm16, execute_i64_div_u_imm16, ::i64_div_u), + (NonZeroU64, Instruction::I64RemUImm16, execute_i64_rem_u_imm16, ::i64_rem_u), } } @@ -289,15 +289,15 @@ macro_rules! impl_fallible_binary_imm16_rev { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_fallible_binary_imm16_rev! { - (i32, Instruction::I32DivSImm16Rev, execute_i32_div_s_imm16_rev, UntypedValue::i32_div_s), - (u32, Instruction::I32DivUImm16Rev, execute_i32_div_u_imm16_rev, UntypedValue::i32_div_u), - (i32, Instruction::I32RemSImm16Rev, execute_i32_rem_s_imm16_rev, UntypedValue::i32_rem_s), - (u32, Instruction::I32RemUImm16Rev, execute_i32_rem_u_imm16_rev, UntypedValue::i32_rem_u), - - (i64, Instruction::I64DivSImm16Rev, execute_i64_div_s_imm16_rev, UntypedValue::i64_div_s), - (u64, Instruction::I64DivUImm16Rev, execute_i64_div_u_imm16_rev, UntypedValue::i64_div_u), - (i64, Instruction::I64RemSImm16Rev, execute_i64_rem_s_imm16_rev, UntypedValue::i64_rem_s), - (u64, Instruction::I64RemUImm16Rev, execute_i64_rem_u_imm16_rev, UntypedValue::i64_rem_u), + (i32, Instruction::I32DivSImm16Rev, execute_i32_div_s_imm16_rev, UntypedVal::i32_div_s), + (u32, Instruction::I32DivUImm16Rev, execute_i32_div_u_imm16_rev, UntypedVal::i32_div_u), + (i32, Instruction::I32RemSImm16Rev, execute_i32_rem_s_imm16_rev, UntypedVal::i32_rem_s), + (u32, Instruction::I32RemUImm16Rev, execute_i32_rem_u_imm16_rev, UntypedVal::i32_rem_u), + + (i64, Instruction::I64DivSImm16Rev, execute_i64_div_s_imm16_rev, UntypedVal::i64_div_s), + (u64, Instruction::I64DivUImm16Rev, execute_i64_div_u_imm16_rev, UntypedVal::i64_div_u), + (i64, Instruction::I64RemSImm16Rev, execute_i64_rem_s_imm16_rev, UntypedVal::i64_rem_s), + (u64, Instruction::I64RemUImm16Rev, execute_i64_rem_u_imm16_rev, UntypedVal::i64_rem_u), } } @@ -307,7 +307,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { pub fn execute_f32_copysign_imm(&mut self, instr: BinInstrImm) { let lhs = self.get_register(instr.reg_in); let rhs = instr.imm_in.to_f32(); - self.set_register(instr.result, UntypedValue::f32_copysign(lhs, rhs.into())); + self.set_register(instr.result, UntypedVal::f32_copysign(lhs, rhs.into())); self.next_instr() } @@ -316,7 +316,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { pub fn execute_f64_copysign_imm(&mut self, instr: BinInstrImm) { let lhs = self.get_register(instr.reg_in); let rhs = instr.imm_in.to_f64(); - self.set_register(instr.result, UntypedValue::f64_copysign(lhs, rhs.into())); + self.set_register(instr.result, UntypedVal::f64_copysign(lhs, rhs.into())); self.next_instr() } } diff --git a/crates/wasmi/src/engine/executor/instrs/branch.rs b/crates/wasmi/src/engine/executor/instrs/branch.rs index 298feb3e15..2fc213d12e 100644 --- a/crates/wasmi/src/engine/executor/instrs/branch.rs +++ b/crates/wasmi/src/engine/executor/instrs/branch.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{ BranchBinOpInstr, BranchBinOpInstrImm16, @@ -94,7 +94,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { /// Executes a generic fused compare and branch instruction. fn execute_branch_binop(&mut self, instr: BranchBinOpInstr, f: fn(T, T) -> bool) where - T: From, + T: From, { self.execute_branch_binop_raw::(instr.lhs, instr.rhs, instr.offset, f) } @@ -107,7 +107,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { offset: impl Into, f: fn(T, T) -> bool, ) where - T: From, + T: From, { let lhs: T = self.get_register_as(lhs); let rhs: T = self.get_register_as(rhs); @@ -120,7 +120,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { /// Executes a generic fused compare and branch instruction with immediate `rhs` operand. fn execute_branch_binop_imm(&mut self, instr: BranchBinOpInstrImm16, f: fn(T, T) -> bool) where - T: From + From>, + T: From + From>, { let lhs: T = self.get_register_as(instr.lhs); let rhs = T::from(instr.rhs); diff --git a/crates/wasmi/src/engine/executor/instrs/comparison.rs b/crates/wasmi/src/engine/executor/instrs/comparison.rs index fbbfc307c3..c0189fa7a1 100644 --- a/crates/wasmi/src/engine/executor/instrs/comparison.rs +++ b/crates/wasmi/src/engine/executor/instrs/comparison.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{BinInstr, BinInstrImm16}, }; @@ -21,41 +21,41 @@ macro_rules! impl_comparison { impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_comparison! { - (Instruction::I32Eq, execute_i32_eq, UntypedValue::i32_eq), - (Instruction::I32Ne, execute_i32_ne, UntypedValue::i32_ne), - (Instruction::I32LtS, execute_i32_lt_s, UntypedValue::i32_lt_s), - (Instruction::I32LtU, execute_i32_lt_u, UntypedValue::i32_lt_u), - (Instruction::I32LeS, execute_i32_le_s, UntypedValue::i32_le_s), - (Instruction::I32LeU, execute_i32_le_u, UntypedValue::i32_le_u), - (Instruction::I32GtS, execute_i32_gt_s, UntypedValue::i32_gt_s), - (Instruction::I32GtU, execute_i32_gt_u, UntypedValue::i32_gt_u), - (Instruction::I32GeS, execute_i32_ge_s, UntypedValue::i32_ge_s), - (Instruction::I32GeU, execute_i32_ge_u, UntypedValue::i32_ge_u), + (Instruction::I32Eq, execute_i32_eq, UntypedVal::i32_eq), + (Instruction::I32Ne, execute_i32_ne, UntypedVal::i32_ne), + (Instruction::I32LtS, execute_i32_lt_s, UntypedVal::i32_lt_s), + (Instruction::I32LtU, execute_i32_lt_u, UntypedVal::i32_lt_u), + (Instruction::I32LeS, execute_i32_le_s, UntypedVal::i32_le_s), + (Instruction::I32LeU, execute_i32_le_u, UntypedVal::i32_le_u), + (Instruction::I32GtS, execute_i32_gt_s, UntypedVal::i32_gt_s), + (Instruction::I32GtU, execute_i32_gt_u, UntypedVal::i32_gt_u), + (Instruction::I32GeS, execute_i32_ge_s, UntypedVal::i32_ge_s), + (Instruction::I32GeU, execute_i32_ge_u, UntypedVal::i32_ge_u), - (Instruction::I64Eq, execute_i64_eq, UntypedValue::i64_eq), - (Instruction::I64Ne, execute_i64_ne, UntypedValue::i64_ne), - (Instruction::I64LtS, execute_i64_lt_s, UntypedValue::i64_lt_s), - (Instruction::I64LtU, execute_i64_lt_u, UntypedValue::i64_lt_u), - (Instruction::I64LeS, execute_i64_le_s, UntypedValue::i64_le_s), - (Instruction::I64LeU, execute_i64_le_u, UntypedValue::i64_le_u), - (Instruction::I64GtS, execute_i64_gt_s, UntypedValue::i64_gt_s), - (Instruction::I64GtU, execute_i64_gt_u, UntypedValue::i64_gt_u), - (Instruction::I64GeS, execute_i64_ge_s, UntypedValue::i64_ge_s), - (Instruction::I64GeU, execute_i64_ge_u, UntypedValue::i64_ge_u), + (Instruction::I64Eq, execute_i64_eq, UntypedVal::i64_eq), + (Instruction::I64Ne, execute_i64_ne, UntypedVal::i64_ne), + (Instruction::I64LtS, execute_i64_lt_s, UntypedVal::i64_lt_s), + (Instruction::I64LtU, execute_i64_lt_u, UntypedVal::i64_lt_u), + (Instruction::I64LeS, execute_i64_le_s, UntypedVal::i64_le_s), + (Instruction::I64LeU, execute_i64_le_u, UntypedVal::i64_le_u), + (Instruction::I64GtS, execute_i64_gt_s, UntypedVal::i64_gt_s), + (Instruction::I64GtU, execute_i64_gt_u, UntypedVal::i64_gt_u), + (Instruction::I64GeS, execute_i64_ge_s, UntypedVal::i64_ge_s), + (Instruction::I64GeU, execute_i64_ge_u, UntypedVal::i64_ge_u), - (Instruction::F32Eq, execute_f32_eq, UntypedValue::f32_eq), - (Instruction::F32Ne, execute_f32_ne, UntypedValue::f32_ne), - (Instruction::F32Lt, execute_f32_lt, UntypedValue::f32_lt), - (Instruction::F32Le, execute_f32_le, UntypedValue::f32_le), - (Instruction::F32Gt, execute_f32_gt, UntypedValue::f32_gt), - (Instruction::F32Ge, execute_f32_ge, UntypedValue::f32_ge), + (Instruction::F32Eq, execute_f32_eq, UntypedVal::f32_eq), + (Instruction::F32Ne, execute_f32_ne, UntypedVal::f32_ne), + (Instruction::F32Lt, execute_f32_lt, UntypedVal::f32_lt), + (Instruction::F32Le, execute_f32_le, UntypedVal::f32_le), + (Instruction::F32Gt, execute_f32_gt, UntypedVal::f32_gt), + (Instruction::F32Ge, execute_f32_ge, UntypedVal::f32_ge), - (Instruction::F64Eq, execute_f64_eq, UntypedValue::f64_eq), - (Instruction::F64Ne, execute_f64_ne, UntypedValue::f64_ne), - (Instruction::F64Lt, execute_f64_lt, UntypedValue::f64_lt), - (Instruction::F64Le, execute_f64_le, UntypedValue::f64_le), - (Instruction::F64Gt, execute_f64_gt, UntypedValue::f64_gt), - (Instruction::F64Ge, execute_f64_ge, UntypedValue::f64_ge), + (Instruction::F64Eq, execute_f64_eq, UntypedVal::f64_eq), + (Instruction::F64Ne, execute_f64_ne, UntypedVal::f64_ne), + (Instruction::F64Lt, execute_f64_lt, UntypedVal::f64_lt), + (Instruction::F64Le, execute_f64_le, UntypedVal::f64_le), + (Instruction::F64Gt, execute_f64_gt, UntypedVal::f64_gt), + (Instruction::F64Ge, execute_f64_ge, UntypedVal::f64_ge), } } @@ -73,26 +73,26 @@ macro_rules! impl_comparison_imm16 { impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_comparison_imm16! { - (i32, Instruction::I32EqImm16, execute_i32_eq_imm16, UntypedValue::i32_eq), - (i32, Instruction::I32NeImm16, execute_i32_ne_imm16, UntypedValue::i32_ne), - (i32, Instruction::I32LtSImm16, execute_i32_lt_s_imm16, UntypedValue::i32_lt_s), - (u32, Instruction::I32LtUImm16, execute_i32_lt_u_imm16, UntypedValue::i32_lt_u), - (i32, Instruction::I32LeSImm16, execute_i32_le_s_imm16, UntypedValue::i32_le_s), - (u32, Instruction::I32LeUImm16, execute_i32_le_u_imm16, UntypedValue::i32_le_u), - (i32, Instruction::I32GtSImm16, execute_i32_gt_s_imm16, UntypedValue::i32_gt_s), - (u32, Instruction::I32GtUImm16, execute_i32_gt_u_imm16, UntypedValue::i32_gt_u), - (i32, Instruction::I32GeSImm16, execute_i32_ge_s_imm16, UntypedValue::i32_ge_s), - (u32, Instruction::I32GeUImm16, execute_i32_ge_u_imm16, UntypedValue::i32_ge_u), + (i32, Instruction::I32EqImm16, execute_i32_eq_imm16, UntypedVal::i32_eq), + (i32, Instruction::I32NeImm16, execute_i32_ne_imm16, UntypedVal::i32_ne), + (i32, Instruction::I32LtSImm16, execute_i32_lt_s_imm16, UntypedVal::i32_lt_s), + (u32, Instruction::I32LtUImm16, execute_i32_lt_u_imm16, UntypedVal::i32_lt_u), + (i32, Instruction::I32LeSImm16, execute_i32_le_s_imm16, UntypedVal::i32_le_s), + (u32, Instruction::I32LeUImm16, execute_i32_le_u_imm16, UntypedVal::i32_le_u), + (i32, Instruction::I32GtSImm16, execute_i32_gt_s_imm16, UntypedVal::i32_gt_s), + (u32, Instruction::I32GtUImm16, execute_i32_gt_u_imm16, UntypedVal::i32_gt_u), + (i32, Instruction::I32GeSImm16, execute_i32_ge_s_imm16, UntypedVal::i32_ge_s), + (u32, Instruction::I32GeUImm16, execute_i32_ge_u_imm16, UntypedVal::i32_ge_u), - (i64, Instruction::I64EqImm16, execute_i64_eq_imm16, UntypedValue::i64_eq), - (i64, Instruction::I64NeImm16, execute_i64_ne_imm16, UntypedValue::i64_ne), - (i64, Instruction::I64LtSImm16, execute_i64_lt_s_imm16, UntypedValue::i64_lt_s), - (u64, Instruction::I64LtUImm16, execute_i64_lt_u_imm16, UntypedValue::i64_lt_u), - (i64, Instruction::I64LeSImm16, execute_i64_le_s_imm16, UntypedValue::i64_le_s), - (u64, Instruction::I64LeUImm16, execute_i64_le_u_imm16, UntypedValue::i64_le_u), - (i64, Instruction::I64GtSImm16, execute_i64_gt_s_imm16, UntypedValue::i64_gt_s), - (u64, Instruction::I64GtUImm16, execute_i64_gt_u_imm16, UntypedValue::i64_gt_u), - (i64, Instruction::I64GeSImm16, execute_i64_ge_s_imm16, UntypedValue::i64_ge_s), - (u64, Instruction::I64GeUImm16, execute_i64_ge_u_imm16, UntypedValue::i64_ge_u), + (i64, Instruction::I64EqImm16, execute_i64_eq_imm16, UntypedVal::i64_eq), + (i64, Instruction::I64NeImm16, execute_i64_ne_imm16, UntypedVal::i64_ne), + (i64, Instruction::I64LtSImm16, execute_i64_lt_s_imm16, UntypedVal::i64_lt_s), + (u64, Instruction::I64LtUImm16, execute_i64_lt_u_imm16, UntypedVal::i64_lt_u), + (i64, Instruction::I64LeSImm16, execute_i64_le_s_imm16, UntypedVal::i64_le_s), + (u64, Instruction::I64LeUImm16, execute_i64_le_u_imm16, UntypedVal::i64_le_u), + (i64, Instruction::I64GtSImm16, execute_i64_gt_s_imm16, UntypedVal::i64_gt_s), + (u64, Instruction::I64GtUImm16, execute_i64_gt_u_imm16, UntypedVal::i64_gt_u), + (i64, Instruction::I64GeSImm16, execute_i64_ge_s_imm16, UntypedVal::i64_ge_s), + (u64, Instruction::I64GeUImm16, execute_i64_ge_u_imm16, UntypedVal::i64_ge_u), } } diff --git a/crates/wasmi/src/engine/executor/instrs/conversion.rs b/crates/wasmi/src/engine/executor/instrs/conversion.rs index dd788d2618..3450b72b81 100644 --- a/crates/wasmi/src/engine/executor/instrs/conversion.rs +++ b/crates/wasmi/src/engine/executor/instrs/conversion.rs @@ -1,5 +1,5 @@ use super::Executor; -use crate::{core::UntypedValue, engine::bytecode::UnaryInstr, Error}; +use crate::{core::UntypedVal, engine::bytecode::UnaryInstr, Error}; #[cfg(doc)] use crate::engine::bytecode::Instruction; @@ -30,46 +30,46 @@ macro_rules! impl_fallible_conversion_impls { impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_conversion_impls! { - (Instruction::I32WrapI64, execute_i32_wrap_i64, UntypedValue::i32_wrap_i64), - (Instruction::I64ExtendI32S, execute_i64_extend_i32_s, UntypedValue::i64_extend_i32_s), - (Instruction::I64ExtendI32U, execute_i64_extend_i32_u, UntypedValue::i64_extend_i32_u), + (Instruction::I32WrapI64, execute_i32_wrap_i64, UntypedVal::i32_wrap_i64), + (Instruction::I64ExtendI32S, execute_i64_extend_i32_s, UntypedVal::i64_extend_i32_s), + (Instruction::I64ExtendI32U, execute_i64_extend_i32_u, UntypedVal::i64_extend_i32_u), - (Instruction::I32TruncSatF32S, execute_i32_trunc_sat_f32_s, UntypedValue::i32_trunc_sat_f32_s), - (Instruction::I32TruncSatF32U, execute_i32_trunc_sat_f32_u, UntypedValue::i32_trunc_sat_f32_u), - (Instruction::I32TruncSatF64S, execute_i32_trunc_sat_f64_s, UntypedValue::i32_trunc_sat_f64_s), - (Instruction::I32TruncSatF64U, execute_i32_trunc_sat_f64_u, UntypedValue::i32_trunc_sat_f64_u), - (Instruction::I64TruncSatF32S, execute_i64_trunc_sat_f32_s, UntypedValue::i64_trunc_sat_f32_s), - (Instruction::I64TruncSatF32U, execute_i64_trunc_sat_f32_u, UntypedValue::i64_trunc_sat_f32_u), - (Instruction::I64TruncSatF64S, execute_i64_trunc_sat_f64_s, UntypedValue::i64_trunc_sat_f64_s), - (Instruction::I64TruncSatF64U, execute_i64_trunc_sat_f64_u, UntypedValue::i64_trunc_sat_f64_u), + (Instruction::I32TruncSatF32S, execute_i32_trunc_sat_f32_s, UntypedVal::i32_trunc_sat_f32_s), + (Instruction::I32TruncSatF32U, execute_i32_trunc_sat_f32_u, UntypedVal::i32_trunc_sat_f32_u), + (Instruction::I32TruncSatF64S, execute_i32_trunc_sat_f64_s, UntypedVal::i32_trunc_sat_f64_s), + (Instruction::I32TruncSatF64U, execute_i32_trunc_sat_f64_u, UntypedVal::i32_trunc_sat_f64_u), + (Instruction::I64TruncSatF32S, execute_i64_trunc_sat_f32_s, UntypedVal::i64_trunc_sat_f32_s), + (Instruction::I64TruncSatF32U, execute_i64_trunc_sat_f32_u, UntypedVal::i64_trunc_sat_f32_u), + (Instruction::I64TruncSatF64S, execute_i64_trunc_sat_f64_s, UntypedVal::i64_trunc_sat_f64_s), + (Instruction::I64TruncSatF64U, execute_i64_trunc_sat_f64_u, UntypedVal::i64_trunc_sat_f64_u), - (Instruction::I32Extend8S, execute_i32_extend8_s, UntypedValue::i32_extend8_s), - (Instruction::I32Extend16S, execute_i32_extend16_s, UntypedValue::i32_extend16_s), - (Instruction::I64Extend8S, execute_i64_extend8_s, UntypedValue::i64_extend8_s), - (Instruction::I64Extend16S, execute_i64_extend16_s, UntypedValue::i64_extend16_s), - (Instruction::I64Extend32S, execute_i64_extend32_s, UntypedValue::i64_extend32_s), + (Instruction::I32Extend8S, execute_i32_extend8_s, UntypedVal::i32_extend8_s), + (Instruction::I32Extend16S, execute_i32_extend16_s, UntypedVal::i32_extend16_s), + (Instruction::I64Extend8S, execute_i64_extend8_s, UntypedVal::i64_extend8_s), + (Instruction::I64Extend16S, execute_i64_extend16_s, UntypedVal::i64_extend16_s), + (Instruction::I64Extend32S, execute_i64_extend32_s, UntypedVal::i64_extend32_s), - (Instruction::F32DemoteF64, execute_f32_demote_f64, UntypedValue::f32_demote_f64), - (Instruction::F64PromoteF32, execute_f64_promote_f32, UntypedValue::f64_promote_f32), + (Instruction::F32DemoteF64, execute_f32_demote_f64, UntypedVal::f32_demote_f64), + (Instruction::F64PromoteF32, execute_f64_promote_f32, UntypedVal::f64_promote_f32), - (Instruction::F32ConvertI32S, execute_f32_convert_i32_s, UntypedValue::f32_convert_i32_s), - (Instruction::F32ConvertI32U, execute_f32_convert_i32_u, UntypedValue::f32_convert_i32_u), - (Instruction::F32ConvertI64S, execute_f32_convert_i64_s, UntypedValue::f32_convert_i64_s), - (Instruction::F32ConvertI64U, execute_f32_convert_i64_u, UntypedValue::f32_convert_i64_u), - (Instruction::F64ConvertI32S, execute_f64_convert_i32_s, UntypedValue::f64_convert_i32_s), - (Instruction::F64ConvertI32U, execute_f64_convert_i32_u, UntypedValue::f64_convert_i32_u), - (Instruction::F64ConvertI64S, execute_f64_convert_i64_s, UntypedValue::f64_convert_i64_s), - (Instruction::F64ConvertI64U, execute_f64_convert_i64_u, UntypedValue::f64_convert_i64_u), + (Instruction::F32ConvertI32S, execute_f32_convert_i32_s, UntypedVal::f32_convert_i32_s), + (Instruction::F32ConvertI32U, execute_f32_convert_i32_u, UntypedVal::f32_convert_i32_u), + (Instruction::F32ConvertI64S, execute_f32_convert_i64_s, UntypedVal::f32_convert_i64_s), + (Instruction::F32ConvertI64U, execute_f32_convert_i64_u, UntypedVal::f32_convert_i64_u), + (Instruction::F64ConvertI32S, execute_f64_convert_i32_s, UntypedVal::f64_convert_i32_s), + (Instruction::F64ConvertI32U, execute_f64_convert_i32_u, UntypedVal::f64_convert_i32_u), + (Instruction::F64ConvertI64S, execute_f64_convert_i64_s, UntypedVal::f64_convert_i64_s), + (Instruction::F64ConvertI64U, execute_f64_convert_i64_u, UntypedVal::f64_convert_i64_u), } impl_fallible_conversion_impls! { - (Instruction::I32TruncF32S, execute_i32_trunc_f32_s, UntypedValue::i32_trunc_f32_s), - (Instruction::I32TruncF32U, execute_i32_trunc_f32_u, UntypedValue::i32_trunc_f32_u), - (Instruction::I32TruncF64S, execute_i32_trunc_f64_s, UntypedValue::i32_trunc_f64_s), - (Instruction::I32TruncF64U, execute_i32_trunc_f64_u, UntypedValue::i32_trunc_f64_u), - (Instruction::I64TruncF32S, execute_i64_trunc_f32_s, UntypedValue::i64_trunc_f32_s), - (Instruction::I64TruncF32U, execute_i64_trunc_f32_u, UntypedValue::i64_trunc_f32_u), - (Instruction::I64TruncF64S, execute_i64_trunc_f64_s, UntypedValue::i64_trunc_f64_s), - (Instruction::I64TruncF64U, execute_i64_trunc_f64_u, UntypedValue::i64_trunc_f64_u), + (Instruction::I32TruncF32S, execute_i32_trunc_f32_s, UntypedVal::i32_trunc_f32_s), + (Instruction::I32TruncF32U, execute_i32_trunc_f32_u, UntypedVal::i32_trunc_f32_u), + (Instruction::I32TruncF64S, execute_i32_trunc_f64_s, UntypedVal::i32_trunc_f64_s), + (Instruction::I32TruncF64U, execute_i32_trunc_f64_u, UntypedVal::i32_trunc_f64_u), + (Instruction::I64TruncF32S, execute_i64_trunc_f32_s, UntypedVal::i64_trunc_f32_s), + (Instruction::I64TruncF32U, execute_i64_trunc_f32_u, UntypedVal::i64_trunc_f32_u), + (Instruction::I64TruncF64S, execute_i64_trunc_f64_s, UntypedVal::i64_trunc_f64_s), + (Instruction::I64TruncF64U, execute_i64_trunc_f64_u, UntypedVal::i64_trunc_f64_u), } } diff --git a/crates/wasmi/src/engine/executor/instrs/copy.rs b/crates/wasmi/src/engine/executor/instrs/copy.rs index 8cb150dc04..53f9d17e43 100644 --- a/crates/wasmi/src/engine/executor/instrs/copy.rs +++ b/crates/wasmi/src/engine/executor/instrs/copy.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{AnyConst32, Const32, Instruction, Register, RegisterSpan}, }; use core::slice; @@ -12,7 +12,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { &mut self, result: Register, value: T, - f: fn(&mut Self, T) -> UntypedValue, + f: fn(&mut Self, T) -> UntypedVal, ) { let value = f(self, value); self.set_register(result, value); @@ -40,25 +40,19 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { /// Executes an [`Instruction::CopyImm32`]. #[inline(always)] pub fn execute_copy_imm32(&mut self, result: Register, value: AnyConst32) { - self.execute_copy_impl(result, value, |_, value| { - UntypedValue::from(u32::from(value)) - }) + self.execute_copy_impl(result, value, |_, value| UntypedVal::from(u32::from(value))) } /// Executes an [`Instruction::CopyI64Imm32`]. #[inline(always)] pub fn execute_copy_i64imm32(&mut self, result: Register, value: Const32) { - self.execute_copy_impl(result, value, |_, value| { - UntypedValue::from(i64::from(value)) - }) + self.execute_copy_impl(result, value, |_, value| UntypedVal::from(i64::from(value))) } /// Executes an [`Instruction::CopyF64Imm32`]. #[inline(always)] pub fn execute_copy_f64imm32(&mut self, result: Register, value: Const32) { - self.execute_copy_impl(result, value, |_, value| { - UntypedValue::from(f64::from(value)) - }) + self.execute_copy_impl(result, value, |_, value| UntypedVal::from(f64::from(value))) } /// Executes an [`Instruction::CopySpan`]. @@ -73,7 +67,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { pub fn execute_copy_span(&mut self, results: RegisterSpan, values: RegisterSpan, len: u16) { let results = results.iter_u16(len); let values = values.iter_u16(len); - let mut tmp = >::default(); + let mut tmp = >::default(); tmp.extend(values.into_iter().map(|value| self.get_register(value))); for (result, value) in results.into_iter().zip(tmp) { self.set_register(result, value); @@ -108,7 +102,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { #[inline(always)] pub fn execute_copy_many(&mut self, results: RegisterSpan, values: [Register; 2]) { // We need `tmp` since `values[n]` might be overwritten by previous copies. - let mut tmp = >::default(); + let mut tmp = >::default(); let mut ip = self.ip; tmp.extend(values.into_iter().map(|value| self.get_register(value))); ip.add(1); diff --git a/crates/wasmi/src/engine/executor/instrs/global.rs b/crates/wasmi/src/engine/executor/instrs/global.rs index c13f0967d6..2e7bdeaaee 100644 --- a/crates/wasmi/src/engine/executor/instrs/global.rs +++ b/crates/wasmi/src/engine/executor/instrs/global.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{Const16, GlobalIdx, Register}, }; @@ -38,7 +38,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { } /// Executes a generic `global.set` instruction. - fn execute_global_set_impl(&mut self, global: GlobalIdx, new_value: UntypedValue) { + fn execute_global_set_impl(&mut self, global: GlobalIdx, new_value: UntypedVal) { self.cache.set_global(self.ctx, global, new_value); self.next_instr() } diff --git a/crates/wasmi/src/engine/executor/instrs/load.rs b/crates/wasmi/src/engine/executor/instrs/load.rs index 296c774fea..a4cce6fb07 100644 --- a/crates/wasmi/src/engine/executor/instrs/load.rs +++ b/crates/wasmi/src/engine/executor/instrs/load.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::bytecode::{LoadAtInstr, LoadInstr, LoadOffset16Instr, Register}, Error, }; @@ -10,7 +10,7 @@ use crate::engine::bytecode::Instruction; /// The function signature of Wasm load operations. type WasmLoadOp = - fn(memory: &[u8], address: UntypedValue, offset: u32) -> Result; + fn(memory: &[u8], address: UntypedVal, offset: u32) -> Result; impl<'ctx, 'engine> Executor<'ctx, 'engine> { /// Executes a generic Wasm `store[N_{s|u}]` operation. @@ -30,7 +30,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn execute_load_extend( &mut self, result: Register, - address: UntypedValue, + address: UntypedVal, offset: u32, load_extend: WasmLoadOp, ) -> Result<(), Error> { @@ -59,7 +59,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { load_extend: WasmLoadOp, ) -> Result<(), Error> { let offset = u32::from(instr.address); - self.execute_load_extend(instr.result, UntypedValue::from(0u32), offset, load_extend)?; + self.execute_load_extend(instr.result, UntypedVal::from(0u32), offset, load_extend)?; self.try_next_instr() } @@ -113,87 +113,87 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I32Load, execute_i32_load), (Instruction::I32LoadAt, execute_i32_load_at), (Instruction::I32LoadOffset16, execute_i32_load_offset16), - UntypedValue::i32_load, + UntypedVal::i32_load, ), ( (Instruction::I64Load, execute_i64_load), (Instruction::I64LoadAt, execute_i64_load_at), (Instruction::I64LoadOffset16, execute_i64_load_offset16), - UntypedValue::i64_load, + UntypedVal::i64_load, ), ( (Instruction::F32Load, execute_f32_load), (Instruction::F32LoadAt, execute_f32_load_at), (Instruction::F32LoadOffset16, execute_f32_load_offset16), - UntypedValue::f32_load, + UntypedVal::f32_load, ), ( (Instruction::F64Load, execute_f64_load), (Instruction::F64LoadAt, execute_f64_load_at), (Instruction::F64LoadOffset16, execute_f64_load_offset16), - UntypedValue::f64_load, + UntypedVal::f64_load, ), ( (Instruction::I32Load8s, execute_i32_load8_s), (Instruction::I32Load8sAt, execute_i32_load8_s_at), (Instruction::I32Load8sOffset16, execute_i32_load8_s_offset16), - UntypedValue::i32_load8_s, + UntypedVal::i32_load8_s, ), ( (Instruction::I32Load8u, execute_i32_load8_u), (Instruction::I32Load8uAt, execute_i32_load8_u_at), (Instruction::I32Load8uOffset16, execute_i32_load8_u_offset16), - UntypedValue::i32_load8_u, + UntypedVal::i32_load8_u, ), ( (Instruction::I32Load16s, execute_i32_load16_s), (Instruction::I32Load16sAt, execute_i32_load16_s_at), (Instruction::I32Load16sOffset16, execute_i32_load16_s_offset16), - UntypedValue::i32_load16_s, + UntypedVal::i32_load16_s, ), ( (Instruction::I32Load16u, execute_i32_load16_u), (Instruction::I32Load16uAt, execute_i32_load16_u_at), (Instruction::I32Load16uOffset16, execute_i32_load16_u_offset16), - UntypedValue::i32_load16_u, + UntypedVal::i32_load16_u, ), ( (Instruction::I64Load8s, execute_i64_load8_s), (Instruction::I64Load8sAt, execute_i64_load8_s_at), (Instruction::I64Load8sOffset16, execute_i64_load8_s_offset16), - UntypedValue::i64_load8_s, + UntypedVal::i64_load8_s, ), ( (Instruction::I64Load8u, execute_i64_load8_u), (Instruction::I64Load8uAt, execute_i64_load8_u_at), (Instruction::I64Load8uOffset16, execute_i64_load8_u_offset16), - UntypedValue::i64_load8_u, + UntypedVal::i64_load8_u, ), ( (Instruction::I64Load16s, execute_i64_load16_s), (Instruction::I64Load16sAt, execute_i64_load16_s_at), (Instruction::I64Load16sOffset16, execute_i64_load16_s_offset16), - UntypedValue::i64_load16_s, + UntypedVal::i64_load16_s, ), ( (Instruction::I64Load16u, execute_i64_load16_u), (Instruction::I64Load16uAt, execute_i64_load16_u_at), (Instruction::I64Load16uOffset16, execute_i64_load16_u_offset16), - UntypedValue::i64_load16_u, + UntypedVal::i64_load16_u, ), ( (Instruction::I64Load32s, execute_i64_load32_s), (Instruction::I64Load32sAt, execute_i64_load32_s_at), (Instruction::I64Load32sOffset16, execute_i64_load32_s_offset16), - UntypedValue::i64_load32_s, + UntypedVal::i64_load32_s, ), ( (Instruction::I64Load32u, execute_i64_load32_u), (Instruction::I64Load32uAt, execute_i64_load32_u_at), (Instruction::I64Load32uOffset16, execute_i64_load32_u_offset16), - UntypedValue::i64_load32_u, + UntypedVal::i64_load32_u, ), } } diff --git a/crates/wasmi/src/engine/executor/instrs/return_.rs b/crates/wasmi/src/engine/executor/instrs/return_.rs index 8993c018a3..5b92e33421 100644 --- a/crates/wasmi/src/engine/executor/instrs/return_.rs +++ b/crates/wasmi/src/engine/executor/instrs/return_.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{ bytecode::{AnyConst32, Const32, Instruction, Register, RegisterSpan, RegisterSpanIter}, executor::stack::FrameRegisters, @@ -87,7 +87,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { fn execute_return_value( &mut self, value: T, - f: fn(&Self, T) -> UntypedValue, + f: fn(&Self, T) -> UntypedVal, ) -> ReturnOutcome { let (mut caller_sp, results) = self.return_caller_results(); let value = f(self, value); diff --git a/crates/wasmi/src/engine/executor/instrs/select.rs b/crates/wasmi/src/engine/executor/instrs/select.rs index c50acc1756..b5b48b70ae 100644 --- a/crates/wasmi/src/engine/executor/instrs/select.rs +++ b/crates/wasmi/src/engine/executor/instrs/select.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{ bytecode::{AnyConst32, Const32, Instruction, Register}, code_map::InstructionPtr, @@ -26,15 +26,15 @@ macro_rules! fetch_select_imm_param { } impl<'ctx, 'engine> Executor<'ctx, 'engine> { - /// Returns the parameter of [`Instruction::Select`] or [`Instruction::SelectRev`] as [`UntypedValue`]. - fn fetch_select_param(&self) -> UntypedValue { + /// Returns the parameter of [`Instruction::Select`] or [`Instruction::SelectRev`] as [`UntypedVal`]. + fn fetch_select_param(&self) -> UntypedVal { let mut addr: InstructionPtr = self.ip; addr.add(1); match *addr.get() { Instruction::Register(register) => self.get_register(register), - Instruction::Const32(value) => UntypedValue::from(u32::from(value)), - Instruction::I64Const32(value) => UntypedValue::from(i64::from(value)), - Instruction::F64Const32(value) => UntypedValue::from(f64::from(value)), + Instruction::Const32(value) => UntypedVal::from(u32::from(value)), + Instruction::I64Const32(value) => UntypedVal::from(i64::from(value)), + Instruction::F64Const32(value) => UntypedVal::from(f64::from(value)), unexpected => unreachable!( "expected a select parameter instruction word but found {unexpected:?}" ), @@ -49,8 +49,8 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { lhs: impl FnOnce(&Self) -> L, rhs: impl FnOnce(&Self) -> R, ) where - L: Into, - R: Into, + L: Into, + R: Into, { let condition: bool = self.get_register_as(condition); let selected = match condition { diff --git a/crates/wasmi/src/engine/executor/instrs/store.rs b/crates/wasmi/src/engine/executor/instrs/store.rs index 20526aa11b..0efc49b36b 100644 --- a/crates/wasmi/src/engine/executor/instrs/store.rs +++ b/crates/wasmi/src/engine/executor/instrs/store.rs @@ -1,6 +1,6 @@ use super::Executor; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::{ bytecode::{Const16, Instruction, Register, StoreAtInstr, StoreInstr, StoreOffset16Instr}, code_map::InstructionPtr, @@ -11,9 +11,9 @@ use crate::{ /// The function signature of Wasm store operations. type WasmStoreOp = fn( memory: &mut [u8], - address: UntypedValue, + address: UntypedVal, offset: u32, - value: UntypedValue, + value: UntypedVal, ) -> Result<(), TrapCode>; impl<'ctx, 'engine> Executor<'ctx, 'engine> { @@ -40,9 +40,9 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { #[inline(always)] fn execute_store_wrap( &mut self, - address: UntypedValue, + address: UntypedVal, offset: u32, - value: UntypedValue, + value: UntypedVal, store_wrap: WasmStoreOp, ) -> Result<(), Error> { let memory = self.cache.default_memory_bytes(self.ctx); @@ -81,7 +81,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { store_op: WasmStoreOp, ) -> Result<(), Error> where - T: From + Into, + T: From + Into, { self.execute_store_wrap( self.get_register(instr.ptr), @@ -98,7 +98,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { store_op: WasmStoreOp, ) -> Result<(), Error> { self.execute_store_wrap( - UntypedValue::from(0u32), + UntypedVal::from(0u32), u32::from(instr.address), self.get_register(instr.value), store_op, @@ -112,10 +112,10 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { store_op: WasmStoreOp, ) -> Result<(), Error> where - T: From + Into, + T: From + Into, { self.execute_store_wrap( - UntypedValue::from(0u32), + UntypedVal::from(0u32), u32::from(instr.address), T::from(instr.value).into(), store_op, @@ -187,7 +187,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I32StoreOffset16Imm16, execute_i32_store_offset16_imm16), (Instruction::I32StoreAt, execute_i32_store_at), (Instruction::I32StoreAtImm16, execute_i32_store_at_imm16), - UntypedValue::i32_store, + UntypedVal::i32_store, ), ( (Const16 => i64), @@ -196,7 +196,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I64StoreOffset16Imm16, execute_i64_store_offset16_imm16), (Instruction::I64StoreAt, execute_i64_store_at), (Instruction::I64StoreAtImm16, execute_i64_store_at_imm16), - UntypedValue::i64_store, + UntypedVal::i64_store, ), ( (i8 => i8), @@ -205,7 +205,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I32Store8Offset16Imm, execute_i32_store8_offset16_imm), (Instruction::I32Store8At, execute_i32_store8_at), (Instruction::I32Store8AtImm, execute_i32_store8_at_imm), - UntypedValue::i32_store8, + UntypedVal::i32_store8, ), ( (i16 => i16), @@ -214,7 +214,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I32Store16Offset16Imm, execute_i32_store16_offset16_imm), (Instruction::I32Store16At, execute_i32_store16_at), (Instruction::I32Store16AtImm, execute_i32_store16_at_imm), - UntypedValue::i32_store16, + UntypedVal::i32_store16, ), ( (i8 => i8), @@ -223,7 +223,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I64Store8Offset16Imm, execute_i64_store8_offset16_imm), (Instruction::I64Store8At, execute_i64_store8_at), (Instruction::I64Store8AtImm, execute_i64_store8_at_imm), - UntypedValue::i64_store8, + UntypedVal::i64_store8, ), ( (i16 => i16), @@ -232,7 +232,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I64Store16Offset16Imm, execute_i64_store16_offset16_imm), (Instruction::I64Store16At, execute_i64_store16_at), (Instruction::I64Store16AtImm, execute_i64_store16_at_imm), - UntypedValue::i64_store16, + UntypedVal::i64_store16, ), ( (Const16 => i32), @@ -241,7 +241,7 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::I64Store32Offset16Imm16, execute_i64_store32_offset16_imm16), (Instruction::I64Store32At, execute_i64_store32_at), (Instruction::I64Store32AtImm16, execute_i64_store32_at_imm16), - UntypedValue::i64_store32, + UntypedVal::i64_store32, ), } } @@ -286,13 +286,13 @@ impl<'ctx, 'engine> Executor<'ctx, 'engine> { (Instruction::F32Store, execute_f32_store), (Instruction::F32StoreOffset16, execute_f32_store_offset16), (Instruction::F32StoreAt, execute_f32_store_at), - UntypedValue::f32_store, + UntypedVal::f32_store, ), ( (Instruction::F64Store, execute_f64_store), (Instruction::F64StoreOffset16, execute_f64_store_offset16), (Instruction::F64StoreAt, execute_f64_store_at), - UntypedValue::f64_store, + UntypedVal::f64_store, ), } } diff --git a/crates/wasmi/src/engine/executor/instrs/unary.rs b/crates/wasmi/src/engine/executor/instrs/unary.rs index 0397e715a7..c279c4c389 100644 --- a/crates/wasmi/src/engine/executor/instrs/unary.rs +++ b/crates/wasmi/src/engine/executor/instrs/unary.rs @@ -1,5 +1,5 @@ use super::Executor; -use crate::{core::UntypedValue, engine::bytecode::UnaryInstr}; +use crate::{core::UntypedVal, engine::bytecode::UnaryInstr}; #[cfg(doc)] use crate::engine::bytecode::Instruction; @@ -18,28 +18,28 @@ macro_rules! impl_unary_impls { impl<'ctx, 'engine> Executor<'ctx, 'engine> { impl_unary_impls! { - (Instruction::I32Clz, execute_i32_clz, UntypedValue::i32_clz), - (Instruction::I32Ctz, execute_i32_ctz, UntypedValue::i32_ctz), - (Instruction::I32Popcnt, execute_i32_popcnt, UntypedValue::i32_popcnt), + (Instruction::I32Clz, execute_i32_clz, UntypedVal::i32_clz), + (Instruction::I32Ctz, execute_i32_ctz, UntypedVal::i32_ctz), + (Instruction::I32Popcnt, execute_i32_popcnt, UntypedVal::i32_popcnt), - (Instruction::I64Clz, execute_i64_clz, UntypedValue::i64_clz), - (Instruction::I64Ctz, execute_i64_ctz, UntypedValue::i64_ctz), - (Instruction::I64Popcnt, execute_i64_popcnt, UntypedValue::i64_popcnt), + (Instruction::I64Clz, execute_i64_clz, UntypedVal::i64_clz), + (Instruction::I64Ctz, execute_i64_ctz, UntypedVal::i64_ctz), + (Instruction::I64Popcnt, execute_i64_popcnt, UntypedVal::i64_popcnt), - (Instruction::F32Abs, execute_f32_abs, UntypedValue::f32_abs), - (Instruction::F32Neg, execute_f32_neg, UntypedValue::f32_neg), - (Instruction::F32Ceil, execute_f32_ceil, UntypedValue::f32_ceil), - (Instruction::F32Floor, execute_f32_floor, UntypedValue::f32_floor), - (Instruction::F32Trunc, execute_f32_trunc, UntypedValue::f32_trunc), - (Instruction::F32Nearest, execute_f32_nearest, UntypedValue::f32_nearest), - (Instruction::F32Sqrt, execute_f32_sqrt, UntypedValue::f32_sqrt), + (Instruction::F32Abs, execute_f32_abs, UntypedVal::f32_abs), + (Instruction::F32Neg, execute_f32_neg, UntypedVal::f32_neg), + (Instruction::F32Ceil, execute_f32_ceil, UntypedVal::f32_ceil), + (Instruction::F32Floor, execute_f32_floor, UntypedVal::f32_floor), + (Instruction::F32Trunc, execute_f32_trunc, UntypedVal::f32_trunc), + (Instruction::F32Nearest, execute_f32_nearest, UntypedVal::f32_nearest), + (Instruction::F32Sqrt, execute_f32_sqrt, UntypedVal::f32_sqrt), - (Instruction::F64Abs, execute_f64_abs, UntypedValue::f64_abs), - (Instruction::F64Neg, execute_f64_neg, UntypedValue::f64_neg), - (Instruction::F64Ceil, execute_f64_ceil, UntypedValue::f64_ceil), - (Instruction::F64Floor, execute_f64_floor, UntypedValue::f64_floor), - (Instruction::F64Trunc, execute_f64_trunc, UntypedValue::f64_trunc), - (Instruction::F64Nearest, execute_f64_nearest, UntypedValue::f64_nearest), - (Instruction::F64Sqrt, execute_f64_sqrt, UntypedValue::f64_sqrt), + (Instruction::F64Abs, execute_f64_abs, UntypedVal::f64_abs), + (Instruction::F64Neg, execute_f64_neg, UntypedVal::f64_neg), + (Instruction::F64Ceil, execute_f64_ceil, UntypedVal::f64_ceil), + (Instruction::F64Floor, execute_f64_floor, UntypedVal::f64_floor), + (Instruction::F64Trunc, execute_f64_trunc, UntypedVal::f64_trunc), + (Instruction::F64Nearest, execute_f64_nearest, UntypedVal::f64_nearest), + (Instruction::F64Sqrt, execute_f64_sqrt, UntypedVal::f64_sqrt), } } diff --git a/crates/wasmi/src/engine/executor/stack/values.rs b/crates/wasmi/src/engine/executor/stack/values.rs index 1a04fc8857..7acaa3778b 100644 --- a/crates/wasmi/src/engine/executor/stack/values.rs +++ b/crates/wasmi/src/engine/executor/stack/values.rs @@ -1,6 +1,6 @@ use super::err_stack_overflow; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::{bytecode::Register, CompiledFuncEntity}, }; use core::{fmt, fmt::Debug, iter, mem, ptr}; @@ -13,7 +13,7 @@ use crate::engine::CompiledFunc; pub struct ValueStack { /// The values on the [`ValueStack`]. - values: Vec, + values: Vec, /// Index of the first free value in the `values` buffer. sp: usize, /// Maximal possible `sp` value. @@ -50,7 +50,7 @@ impl Eq for ValueStack {} impl Default for ValueStack { fn default() -> Self { - const REGISTER_SIZE: usize = mem::size_of::(); + const REGISTER_SIZE: usize = mem::size_of::(); Self::new( Self::DEFAULT_MIN_HEIGHT / REGISTER_SIZE, Self::DEFAULT_MAX_HEIGHT / REGISTER_SIZE, @@ -75,7 +75,7 @@ impl ValueStack { "initial value stack length is greater than maximum value stack length", ); Self { - values: vec![UntypedValue::default(); initial_len], + values: vec![UntypedVal::default(); initial_len], sp: 0, max_sp: maximum_len, } @@ -163,7 +163,7 @@ impl ValueStack { // the current value stack length and add the additional flat amount // on top. This avoids too many frequent reallocations. self.values - .extend(iter::repeat(UntypedValue::default()).take(new_len)); + .extend(iter::repeat(UntypedVal::default()).take(new_len)); } Ok(()) } @@ -186,7 +186,7 @@ impl ValueStack { .get_mut(self.sp..) .and_then(|slice| slice.get_mut(..amount)) .unwrap_or_else(|| panic!("did not reserve enough value stack space")); - cells.fill(UntypedValue::default()); + cells.fill(UntypedVal::default()); self.sp += amount; ValueStackOffset(old_sp) } @@ -199,7 +199,7 @@ impl ValueStack { /// # Panics /// /// If the value stack cannot fit `additional` stack values. - pub fn extend_slice(&mut self, values: &[UntypedValue]) -> ValueStackOffset { + pub fn extend_slice(&mut self, values: &[UntypedVal]) -> ValueStackOffset { if values.is_empty() { return ValueStackOffset(self.sp); } @@ -270,7 +270,7 @@ impl ValueStack { /// `values` required to be stored on the [`ValueStack`]. pub unsafe fn fill_at(&mut self, offset: impl Into, values: I) where - I: IntoIterator, + I: IntoIterator, { let offset = offset.into().0; let mut values = values.into_iter(); @@ -287,17 +287,17 @@ impl ValueStack { /// Returns a shared slice over the values of the [`ValueStack`]. #[inline] - pub fn as_slice(&self) -> &[UntypedValue] { + pub fn as_slice(&self) -> &[UntypedVal] { &self.values[0..self.sp] } /// Returns an exclusive slice over the values of the [`ValueStack`]. #[inline] - pub fn as_slice_mut(&mut self) -> &mut [UntypedValue] { + pub fn as_slice_mut(&mut self) -> &mut [UntypedVal] { &mut self.values[0..self.sp] } - /// Removes the slice `from..to` of [`UntypedValue`] cells from the [`ValueStack`]. + /// Removes the slice `from..to` of [`UntypedVal`] cells from the [`ValueStack`]. /// /// Returns the number of drained [`ValueStack`] cells. /// @@ -393,7 +393,7 @@ impl From for usize { /// [`CallStack`]: [`super::CallStack`] pub struct FrameRegisters { /// The underlying raw pointer to a [`CallFrame`] on the [`ValueStack`]. - ptr: *mut UntypedValue, + ptr: *mut UntypedVal, } impl Debug for FrameRegisters { @@ -404,17 +404,17 @@ impl Debug for FrameRegisters { impl FrameRegisters { /// Creates a new [`FrameRegisters`]. - fn new(ptr: *mut UntypedValue) -> Self { + fn new(ptr: *mut UntypedVal) -> Self { Self { ptr } } - /// Returns the [`UntypedValue`] at the given [`Register`]. + /// Returns the [`UntypedVal`] at the given [`Register`]. /// /// # Safety /// /// It is the callers responsibility to provide a [`Register`] that /// does not access the underlying [`ValueStack`] out of bounds. - pub unsafe fn get(&self, register: Register) -> UntypedValue { + pub unsafe fn get(&self, register: Register) -> UntypedVal { ptr::read(self.register_offset(register)) } @@ -424,12 +424,12 @@ impl FrameRegisters { /// /// It is the callers responsibility to provide a [`Register`] that /// does not access the underlying [`ValueStack`] out of bounds. - pub unsafe fn set(&mut self, register: Register, value: UntypedValue) { + pub unsafe fn set(&mut self, register: Register, value: UntypedVal) { ptr::write(self.register_offset(register), value) } /// Returns the underlying pointer offset by the [`Register`] index. - unsafe fn register_offset(&self, register: Register) -> *mut UntypedValue { + unsafe fn register_offset(&self, register: Register) -> *mut UntypedVal { unsafe { self.ptr.offset(register.to_i16() as isize) } } } diff --git a/crates/wasmi/src/engine/func_args.rs b/crates/wasmi/src/engine/func_args.rs index 2c0a16f674..42eea47fb6 100644 --- a/crates/wasmi/src/engine/func_args.rs +++ b/crates/wasmi/src/engine/func_args.rs @@ -1,9 +1,9 @@ //! API using the Rust type system to guide host function trampoline execution. use crate::{ - core::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedError, UntypedValue}, + core::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedError, UntypedVal}, value::WithType, - Value, + Val, }; use core::cmp; @@ -17,7 +17,7 @@ pub struct FuncParams<'a> { /// Therefore the length of the slice must be large enough /// to hold all parameters and all results but not both at /// the same time. - params_results: &'a mut [UntypedValue], + params_results: &'a mut [UntypedVal], /// The length of the expected parameters of the function invocation. len_params: usize, /// The length of the expected results of the function invocation. @@ -27,12 +27,12 @@ pub struct FuncParams<'a> { /// Used to encode host function results. #[derive(Debug)] pub struct FuncResults<'a> { - results: &'a mut [UntypedValue], + results: &'a mut [UntypedVal], } impl<'a> FuncResults<'a> { /// Create new [`FuncResults`] from the given `results` slice. - fn new(results: &'a mut [UntypedValue]) -> Self { + fn new(results: &'a mut [UntypedVal]) -> Self { Self { results } } @@ -45,7 +45,7 @@ impl<'a> FuncResults<'a> { where T: EncodeUntypedSlice, { - UntypedValue::encode_slice::(self.results, values) + UntypedVal::encode_slice::(self.results, values) .unwrap_or_else(|error| panic!("encountered unexpected invalid tuple length: {error}")); FuncFinished {} } @@ -55,7 +55,7 @@ impl<'a> FuncResults<'a> { /// # Panics /// /// If the number of expected results does not match the length of `values`. - pub fn encode_results_from_slice(self, values: &[Value]) -> Result { + pub fn encode_results_from_slice(self, values: &[Val]) -> Result { assert_eq!(self.results.len(), values.len()); self.results.iter_mut().zip(values).for_each(|(dst, src)| { *dst = src.clone().into(); @@ -82,7 +82,7 @@ impl<'a> FuncParams<'a> { /// If the length of hte `params_results` slice does not match the maximum /// of the `len_params` and `Len_results`. pub(super) fn new( - params_results: &'a mut [UntypedValue], + params_results: &'a mut [UntypedVal], len_params: usize, len_results: usize, ) -> Self { @@ -95,7 +95,7 @@ impl<'a> FuncParams<'a> { } /// Returns a slice over the untyped function parameters. - fn params(&self) -> &[UntypedValue] { + fn params(&self) -> &[UntypedVal] { &self.params_results[..self.len_params] } @@ -108,7 +108,7 @@ impl<'a> FuncParams<'a> { where T: DecodeUntypedSlice, { - let decoded = UntypedValue::decode_slice::(self.params()) + let decoded = UntypedVal::decode_slice::(self.params()) .unwrap_or_else(|error| panic!("encountered unexpected invalid tuple length: {error}")); let results = self.into_func_results(); (decoded, results) @@ -121,7 +121,7 @@ impl<'a> FuncParams<'a> { /// If the number of host function parameters and items in `values` does not match. pub fn decode_params_into_slice( self, - values: &mut [Value], + values: &mut [Val], ) -> Result, UntypedError> { assert_eq!(self.params().len(), values.len()); self.params().iter().zip(values).for_each(|(src, dst)| { diff --git a/crates/wasmi/src/engine/limits/stack.rs b/crates/wasmi/src/engine/limits/stack.rs index e1356ee74e..c2efde08fe 100644 --- a/crates/wasmi/src/engine/limits/stack.rs +++ b/crates/wasmi/src/engine/limits/stack.rs @@ -1,4 +1,4 @@ -use crate::core::UntypedValue; +use crate::core::UntypedVal; use core::{ fmt::{self, Display}, mem::size_of, @@ -65,7 +65,7 @@ impl StackLimits { impl Default for StackLimits { fn default() -> Self { - let register_len = size_of::(); + let register_len = size_of::(); let initial_value_stack_height = DEFAULT_MIN_VALUE_STACK_HEIGHT / register_len; let maximum_value_stack_height = DEFAULT_MAX_VALUE_STACK_HEIGHT / register_len; Self { diff --git a/crates/wasmi/src/engine/limits/tests.rs b/crates/wasmi/src/engine/limits/tests.rs index 27fbcbc13d..7be44adb42 100644 --- a/crates/wasmi/src/engine/limits/tests.rs +++ b/crates/wasmi/src/engine/limits/tests.rs @@ -12,7 +12,7 @@ fn wat2wasm(wat: &str) -> Vec { fn parse_with(wasm: &str, limits: EnforcedLimits) -> Result { let wasm = wat2wasm(wasm); let mut config = Config::default(); - config.engine_limits(limits); + config.enforced_limits(limits); let engine = Engine::new(&config); Module::new(&engine, &wasm[..]) } diff --git a/crates/wasmi/src/engine/mod.rs b/crates/wasmi/src/engine/mod.rs index eaee055d0c..9ba7571e35 100644 --- a/crates/wasmi/src/engine/mod.rs +++ b/crates/wasmi/src/engine/mod.rs @@ -67,7 +67,7 @@ use wasmparser::{FuncToValidate, FuncValidatorAllocations, ValidatorResources}; use self::bytecode::Instruction; #[cfg(test)] -use crate::core::UntypedValue; +use crate::core::UntypedVal; #[cfg(doc)] use crate::Store; @@ -353,7 +353,7 @@ impl Engine { &self, func: CompiledFunc, index: usize, - ) -> Result, Error> { + ) -> Result, Error> { self.inner.get_func_const(func, index) } @@ -771,7 +771,7 @@ impl EngineInner { &self, func: CompiledFunc, index: usize, - ) -> Result, Error> { + ) -> Result, Error> { // Function local constants are stored in reverse order of their indices since // they are allocated in reverse order to their absolute indices during function // translation. That is why we need to access them in reverse order. diff --git a/crates/wasmi/src/engine/resumable.rs b/crates/wasmi/src/engine/resumable.rs index 688c918cf5..46abc3177e 100644 --- a/crates/wasmi/src/engine/resumable.rs +++ b/crates/wasmi/src/engine/resumable.rs @@ -1,13 +1,5 @@ use super::{bytecode::RegisterSpan, Func}; -use crate::{ - engine::Stack, - func::CallResultsTuple, - AsContextMut, - Engine, - Error, - Value, - WasmResults, -}; +use crate::{engine::Stack, func::CallResultsTuple, AsContextMut, Engine, Error, Val, WasmResults}; use core::{fmt, marker::PhantomData, mem::replace, ops::Deref}; /// Returned by [`Engine`] methods for calling a function in a resumable way. @@ -213,9 +205,9 @@ impl ResumableInvocation { /// outputs required by the called function. pub fn resume( self, - mut ctx: impl AsContextMut, - inputs: &[Value], - outputs: &mut [Value], + mut ctx: impl AsContextMut, + inputs: &[Val], + outputs: &mut [Val], ) -> Result { self.engine .resolve_func_type(self.host_func().ty_dedup(ctx.as_context()), |func_type| { @@ -291,8 +283,8 @@ impl TypedResumableInvocation { /// [`TypedFunc`]: [`crate::TypedFunc`] pub fn resume( self, - mut ctx: impl AsContextMut, - inputs: &[Value], + mut ctx: impl AsContextMut, + inputs: &[Val], ) -> Result, Error> where Results: WasmResults, diff --git a/crates/wasmi/src/engine/tests/many_inout.rs b/crates/wasmi/src/engine/tests/many_inout.rs index e872c9bf10..0b44e3660f 100644 --- a/crates/wasmi/src/engine/tests/many_inout.rs +++ b/crates/wasmi/src/engine/tests/many_inout.rs @@ -1,4 +1,4 @@ -use crate::{Engine, Func, Linker, Module, Store, Value}; +use crate::{Engine, Func, Linker, Module, Store, Val}; use std::vec::Vec; /// Converts the given `.wat` into `.wasm`. @@ -26,7 +26,7 @@ fn setup_test(wat: &str) -> (Store<()>, Func) { fn many_params() { let wat = include_str!("wat/many_params.wat"); let (mut store, func) = setup_test(wat); - func.call(&mut store, &[0; 150].map(Value::I32), &mut []) + func.call(&mut store, &[0; 150].map(Val::I32), &mut []) .unwrap(); } @@ -34,10 +34,10 @@ fn many_params() { fn many_results() { let wat = include_str!("wat/many_results.wat"); let (mut store, func) = setup_test(wat); - let mut results = [0; 150].map(Value::I32); + let mut results = [0; 150].map(Val::I32); func.call(&mut store, &[], &mut results).unwrap(); for (i, result) in results.iter().enumerate() { - let &Value::I32(result) = result else { + let &Val::I32(result) = result else { panic!("unexpected result type at index {i}: {result:?}"); }; assert!(result as usize == i % 10); diff --git a/crates/wasmi/src/engine/traits.rs b/crates/wasmi/src/engine/traits.rs index 4fac171cf7..70c6afd2d9 100644 --- a/crates/wasmi/src/engine/traits.rs +++ b/crates/wasmi/src/engine/traits.rs @@ -1,4 +1,4 @@ -use crate::{core::UntypedValue, value::WithType, Value}; +use crate::{core::UntypedVal, value::WithType, Val}; use core::{iter, slice}; /// Types implementing this trait may be used as parameters for function execution. @@ -12,13 +12,13 @@ use core::{iter, slice}; /// [`Engine`]: [`crate::Engine`] pub trait CallParams { /// The iterator over the parameter values. - type Params: ExactSizeIterator; + type Params: ExactSizeIterator; /// Feeds the parameter values from the caller. fn call_params(self) -> Self::Params; } -impl<'a> CallParams for &'a [Value] { +impl<'a> CallParams for &'a [Val] { type Params = CallParamsValueIter<'a>; #[inline] @@ -29,18 +29,18 @@ impl<'a> CallParams for &'a [Value] { } } -/// An iterator over the [`UntypedValue`] call parameters. +/// An iterator over the [`UntypedVal`] call parameters. #[derive(Debug)] pub struct CallParamsValueIter<'a> { - iter: iter::Cloned>, + iter: iter::Cloned>, } impl<'a> Iterator for CallParamsValueIter<'a> { - type Item = UntypedValue; + type Item = UntypedVal; #[inline] fn next(&mut self) -> Option { - self.iter.next().map(UntypedValue::from) + self.iter.next().map(UntypedVal::from) } #[inline] @@ -73,17 +73,17 @@ pub trait CallResults { /// # Panics /// /// If the given `results` do not match the expected amount. - fn call_results(self, results: &[UntypedValue]) -> Self::Results; + fn call_results(self, results: &[UntypedVal]) -> Self::Results; } -impl<'a> CallResults for &'a mut [Value] { +impl<'a> CallResults for &'a mut [Val] { type Results = (); fn len_results(&self) -> usize { self.len() } - fn call_results(self, results: &[UntypedValue]) -> Self::Results { + fn call_results(self, results: &[UntypedVal]) -> Self::Results { assert_eq!(self.len(), results.len()); self.iter_mut().zip(results).for_each(|(dst, src)| { *dst = src.with_type(dst.ty()); diff --git a/crates/wasmi/src/engine/translator/control_stack.rs b/crates/wasmi/src/engine/translator/control_stack.rs index 6e4d305750..a3526eefa1 100644 --- a/crates/wasmi/src/engine/translator/control_stack.rs +++ b/crates/wasmi/src/engine/translator/control_stack.rs @@ -1,4 +1,4 @@ -use super::{typed_value::TypedValue, ControlFrame}; +use super::{typed_value::TypedVal, ControlFrame}; use crate::{ engine::bytecode::{Provider, ProviderSliceStack}, Error, @@ -38,7 +38,7 @@ pub struct ControlStack { /// during translation of the `then` branch these inputs have /// already been consumed. Therefore we need to duplicate them /// here to push them back on the stack once we see the `else` branch. - else_providers: ProviderSliceStack, + else_providers: ProviderSliceStack, } impl ControlStack { @@ -87,7 +87,7 @@ impl ControlStack { /// [`IfControlFrame`]: super::control_frame::IfControlFrame pub fn push_else_providers(&mut self, providers: I) -> Result<(), Error> where - I: IntoIterator>, + I: IntoIterator>, { self.else_providers.push(providers)?; Ok(()) @@ -96,7 +96,7 @@ impl ControlStack { /// Pops the top-most [`Provider`] slice of an `else` branch of an [`IfControlFrame`] to the [`ControlStack`]. /// /// [`IfControlFrame`]: super::control_frame::IfControlFrame - pub fn pop_else_providers(&mut self) -> Drain> { + pub fn pop_else_providers(&mut self) -> Drain> { self.else_providers .pop() .expect("missing else providers for `else` branch") diff --git a/crates/wasmi/src/engine/translator/instr_encoder.rs b/crates/wasmi/src/engine/translator/instr_encoder.rs index 9a0361d789..3770b444e5 100644 --- a/crates/wasmi/src/engine/translator/instr_encoder.rs +++ b/crates/wasmi/src/engine/translator/instr_encoder.rs @@ -6,7 +6,7 @@ use super::{ TypedProvider, }; use crate::{ - core::{UntypedValue, ValueType, F32}, + core::{UntypedVal, ValType, F32}, engine::{ bytecode::{ BinInstr, @@ -378,7 +378,7 @@ impl InstrEncoder { fn copy_imm( stack: &mut ValueStack, result: Register, - value: impl Into, + value: impl Into, ) -> Result { let cref = stack.alloc_const(value.into())?; Ok(Instruction::copy(result, cref)) @@ -395,18 +395,18 @@ impl InstrEncoder { Instruction::copy(result, value) } TypedProvider::Const(value) => match value.ty() { - ValueType::I32 => Instruction::copy_imm32(result, i32::from(value)), - ValueType::F32 => Instruction::copy_imm32(result, f32::from(value)), - ValueType::I64 => match >::try_from(i64::from(value)).ok() { + ValType::I32 => Instruction::copy_imm32(result, i32::from(value)), + ValType::F32 => Instruction::copy_imm32(result, f32::from(value)), + ValType::I64 => match >::try_from(i64::from(value)).ok() { Some(value) => Instruction::copy_i64imm32(result, value), None => copy_imm(stack, result, value)?, }, - ValueType::F64 => match >::try_from(f64::from(value)).ok() { + ValType::F64 => match >::try_from(f64::from(value)).ok() { Some(value) => Instruction::copy_f64imm32(result, value), None => copy_imm(stack, result, value)?, }, - ValueType::FuncRef => copy_imm(stack, result, value)?, - ValueType::ExternRef => copy_imm(stack, result, value)?, + ValType::FuncRef => copy_imm(stack, result, value)?, + ValType::ExternRef => copy_imm(stack, result, value)?, }, }; self.bump_fuel_consumption(fuel_info, FuelCosts::base)?; @@ -567,17 +567,17 @@ impl InstrEncoder { [] => Instruction::Return, [TypedProvider::Register(reg)] => Instruction::return_reg(*reg), [TypedProvider::Const(value)] => match value.ty() { - ValueType::I32 => Instruction::return_imm32(i32::from(*value)), - ValueType::I64 => match >::try_from(i64::from(*value)).ok() { + ValType::I32 => Instruction::return_imm32(i32::from(*value)), + ValType::I64 => match >::try_from(i64::from(*value)).ok() { Some(value) => Instruction::return_i64imm32(value), None => Instruction::return_reg(stack.alloc_const(*value)?), }, - ValueType::F32 => Instruction::return_imm32(F32::from(*value)), - ValueType::F64 => match >::try_from(f64::from(*value)).ok() { + ValType::F32 => Instruction::return_imm32(F32::from(*value)), + ValType::F64 => match >::try_from(f64::from(*value)).ok() { Some(value) => Instruction::return_f64imm32(value), None => Instruction::return_reg(stack.alloc_const(*value)?), }, - ValueType::FuncRef | ValueType::ExternRef => { + ValType::FuncRef | ValType::ExternRef => { Instruction::return_reg(stack.alloc_const(*value)?) } }, @@ -635,17 +635,17 @@ impl InstrEncoder { [] => Instruction::return_nez(condition), [TypedProvider::Register(reg)] => Instruction::return_nez_reg(condition, *reg), [TypedProvider::Const(value)] => match value.ty() { - ValueType::I32 => Instruction::return_nez_imm32(condition, i32::from(*value)), - ValueType::I64 => match >::try_from(i64::from(*value)).ok() { + ValType::I32 => Instruction::return_nez_imm32(condition, i32::from(*value)), + ValType::I64 => match >::try_from(i64::from(*value)).ok() { Some(value) => Instruction::return_nez_i64imm32(condition, value), None => Instruction::return_nez_reg(condition, stack.alloc_const(*value)?), }, - ValueType::F32 => Instruction::return_nez_imm32(condition, F32::from(*value)), - ValueType::F64 => match >::try_from(f64::from(*value)).ok() { + ValType::F32 => Instruction::return_nez_imm32(condition, F32::from(*value)), + ValType::F64 => match >::try_from(f64::from(*value)).ok() { Some(value) => Instruction::return_nez_f64imm32(condition, value), None => Instruction::return_nez_reg(condition, stack.alloc_const(*value)?), }, - ValueType::FuncRef | ValueType::ExternRef => { + ValType::FuncRef | ValType::ExternRef => { Instruction::return_nez_reg(condition, stack.alloc_const(*value)?) } }, @@ -1056,7 +1056,7 @@ impl InstrEncoder { make_instr: BranchCmpImmConstructor, ) -> Result, Error> where - T: From> + Into, + T: From> + Into, { if matches!(stack.get_register_space(instr.result), RegisterSpace::Local) { // We need to filter out instructions that store their result @@ -1249,7 +1249,7 @@ impl InstrEncoder { make_instr: BranchCmpImmConstructor, ) -> Result, Error> where - T: From> + Into, + T: From> + Into, { if matches!(stack.get_register_space(instr.result), RegisterSpace::Local) { // We need to filter out instructions that store their result @@ -1466,7 +1466,7 @@ impl Instruction { #[cfg(test)] mod tests { use super::*; - use crate::engine::translator::typed_value::TypedValue; + use crate::engine::translator::typed_value::TypedVal; #[test] fn has_overlapping_copies_works() { @@ -1481,14 +1481,14 @@ mod tests { assert!(!InstrEncoder::has_overlapping_copies( RegisterSpan::new(Register::from_i16(0)).iter(2), &[ - TypedProvider::Const(TypedValue::from(10_i32)), - TypedProvider::Const(TypedValue::from(20_i32)), + TypedProvider::Const(TypedVal::from(10_i32)), + TypedProvider::Const(TypedVal::from(20_i32)), ], )); assert!(InstrEncoder::has_overlapping_copies( RegisterSpan::new(Register::from_i16(0)).iter(2), &[ - TypedProvider::Const(TypedValue::from(10_i32)), + TypedProvider::Const(TypedVal::from(10_i32)), TypedProvider::register(0), ], )); diff --git a/crates/wasmi/src/engine/translator/mod.rs b/crates/wasmi/src/engine/translator/mod.rs index 23d8b55077..67e9a38a48 100644 --- a/crates/wasmi/src/engine/translator/mod.rs +++ b/crates/wasmi/src/engine/translator/mod.rs @@ -27,7 +27,7 @@ use self::{ control_stack::AcquiredTarget, labels::{LabelRef, LabelRegistry}, stack::ValueStack, - typed_value::TypedValue, + typed_value::TypedVal, utils::{WasmFloat, WasmInteger}, }; pub use self::{ @@ -40,7 +40,7 @@ pub use self::{ }; use super::code_map::CompiledFuncEntity; use crate::{ - core::{TrapCode, UntypedValue, ValueType}, + core::{TrapCode, UntypedVal, ValType}, engine::{ bytecode::{ AnyConst32, @@ -1258,9 +1258,9 @@ impl FuncTranslator { /// Evaluates the constants and pushes the proper result to the value stack. fn push_binary_consteval( &mut self, - lhs: TypedValue, - rhs: TypedValue, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + lhs: TypedVal, + rhs: TypedVal, + consteval: fn(TypedVal, TypedVal) -> TypedVal, ) -> Result<(), Error> { self.alloc.stack.push_const(consteval(lhs, rhs)); Ok(()) @@ -1279,7 +1279,7 @@ impl FuncTranslator { make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, ) -> Result<(), Error> where - T: Into, + T: Into, { let result = self.alloc.stack.push_dynamic()?; let rhs = self.alloc.stack.alloc_const(rhs)?; @@ -1300,7 +1300,7 @@ impl FuncTranslator { make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, ) -> Result<(), Error> where - T: Into, + T: Into, { let result = self.alloc.stack.push_dynamic()?; let lhs = self.alloc.stack.alloc_const(lhs)?; @@ -1343,13 +1343,13 @@ impl FuncTranslator { make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, make_instr_imm16: fn(result: Register, lhs: Register, rhs: Const16) -> Instruction, make_instr_imm16_rev: fn(result: Register, lhs: Const16, rhs: Register) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, make_instr_opt: fn(&mut Self, lhs: Register, rhs: Register) -> Result, make_instr_reg_imm_opt: fn(&mut Self, lhs: Register, rhs: T) -> Result, make_instr_imm_reg_opt: fn(&mut Self, lhs: T, rhs: Register) -> Result, ) -> Result<(), Error> where - T: Copy + From + Into + TryInto>, + T: Copy + From + Into + TryInto>, { bail_unreachable!(self); match self.alloc.stack.pop2() { @@ -1413,7 +1413,7 @@ impl FuncTranslator { fn translate_fbinary( &mut self, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, make_instr_opt: fn(&mut Self, lhs: Register, rhs: Register) -> Result, make_instr_reg_imm_opt: fn(&mut Self, lhs: Register, rhs: T) -> Result, make_instr_imm_reg_opt: fn(&mut Self, lhs: T, rhs: Register) -> Result, @@ -1470,7 +1470,7 @@ impl FuncTranslator { &mut self, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, make_instr_imm: fn(result: Register, lhs: Register, rhs: Sign) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, ) -> Result<(), Error> where T: WasmFloat, @@ -1526,12 +1526,12 @@ impl FuncTranslator { &mut self, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, make_instr_imm16: fn(result: Register, lhs: Register, rhs: Const16) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, make_instr_opt: fn(&mut Self, lhs: Register, rhs: Register) -> Result, make_instr_imm_opt: fn(&mut Self, lhs: Register, rhs: T) -> Result, ) -> Result<(), Error> where - T: Copy + From + TryInto>, + T: Copy + From + TryInto>, { bail_unreachable!(self); match self.alloc.stack.pop2() { @@ -1583,7 +1583,7 @@ impl FuncTranslator { fn translate_fbinary_commutative( &mut self, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, make_instr_opt: fn(&mut Self, lhs: Register, rhs: Register) -> Result, make_instr_imm_opt: fn(&mut Self, lhs: Register, rhs: T) -> Result, ) -> Result<(), Error> @@ -1640,7 +1640,7 @@ impl FuncTranslator { make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, make_instr_imm: fn(result: Register, lhs: Register, rhs: Const16) -> Instruction, make_instr_imm16_rev: fn(result: Register, lhs: Const16, rhs: Register) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> TypedValue, + consteval: fn(TypedVal, TypedVal) -> TypedVal, make_instr_imm_reg_opt: fn(&mut Self, lhs: T, rhs: Register) -> Result, ) -> Result<(), Error> where @@ -1714,7 +1714,7 @@ impl FuncTranslator { rhs: Const16, ) -> Instruction, make_instr_imm16_rev: fn(result: Register, lhs: Const16, rhs: Register) -> Instruction, - consteval: fn(TypedValue, TypedValue) -> Result, + consteval: fn(TypedVal, TypedVal) -> Result, make_instr_opt: fn(&mut Self, lhs: Register, rhs: Register) -> Result, make_instr_reg_imm_opt: fn(&mut Self, lhs: Register, rhs: T) -> Result, ) -> Result<(), Error> @@ -1773,7 +1773,7 @@ impl FuncTranslator { fn translate_unary( &mut self, make_instr: fn(result: Register, input: Register) -> Instruction, - consteval: fn(input: TypedValue) -> TypedValue, + consteval: fn(input: TypedVal) -> TypedVal, ) -> Result<(), Error> { bail_unreachable!(self); match self.alloc.stack.pop() { @@ -1793,7 +1793,7 @@ impl FuncTranslator { fn translate_unary_fallible( &mut self, make_instr: fn(result: Register, input: Register) -> Instruction, - consteval: fn(input: TypedValue) -> Result, + consteval: fn(input: TypedVal) -> Result, ) -> Result<(), Error> { bail_unreachable!(self); match self.alloc.stack.pop() { @@ -1831,7 +1831,7 @@ impl FuncTranslator { /// Encodes a [`TrapCode::MemoryOutOfBounds`] trap instruction if the effective address is invalid. fn effective_address_and( &mut self, - ptr: TypedValue, + ptr: TypedVal, offset: u32, f: impl FnOnce(&mut Self, u32) -> Result<(), Error>, ) -> Result<(), Error> { @@ -1920,7 +1920,7 @@ impl FuncTranslator { make_instr_at_imm: fn(address: Const32, value: U) -> Instruction, ) -> Result<(), Error> where - T: Copy + From, + T: Copy + From, U: TryFrom, { bail_unreachable!(self); @@ -2100,7 +2100,7 @@ impl FuncTranslator { /// - If both `lhs` and `rhs` are equal registers or constant values `lhs` is forwarded. /// - Properly chooses the correct `select` instruction encoding and optimizes for /// cases with 32-bit constant values. - fn translate_select(&mut self, type_hint: Option) -> Result<(), Error> { + fn translate_select(&mut self, type_hint: Option) -> Result<(), Error> { /// Convenience function to encode a `select` instruction. /// /// # Note @@ -2112,7 +2112,7 @@ impl FuncTranslator { result: Register, condition: Register, reg_in: Register, - imm_in: impl Into, + imm_in: impl Into, make_instr: fn( result: Register, condition: Register, @@ -2172,7 +2172,7 @@ impl FuncTranslator { make_instr_param: fn(Const32) -> Instruction, ) -> Result<(), Error> where - T: Copy + Into, + T: Copy + Into, Const32: TryFrom, { match >::try_from(imm_in) { @@ -2234,7 +2234,7 @@ impl FuncTranslator { } let result = self.alloc.stack.push_dynamic()?; match rhs.ty() { - ValueType::I32 => encode_select_imm32( + ValType::I32 => encode_select_imm32( self, result, condition, @@ -2242,7 +2242,7 @@ impl FuncTranslator { i32::from(rhs), Instruction::select, ), - ValueType::F32 => encode_select_imm32( + ValType::F32 => encode_select_imm32( self, result, condition, @@ -2250,7 +2250,7 @@ impl FuncTranslator { f32::from(rhs), Instruction::select, ), - ValueType::I64 => encode_select_imm64( + ValType::I64 => encode_select_imm64( self, result, condition, @@ -2259,7 +2259,7 @@ impl FuncTranslator { Instruction::select, Instruction::i64const32, ), - ValueType::F64 => encode_select_imm64( + ValType::F64 => encode_select_imm64( self, result, condition, @@ -2268,7 +2268,7 @@ impl FuncTranslator { Instruction::select, Instruction::f64const32, ), - ValueType::FuncRef | ValueType::ExternRef => encode_select_imm( + ValType::FuncRef | ValType::ExternRef => encode_select_imm( self, result, condition, @@ -2284,7 +2284,7 @@ impl FuncTranslator { } let result = self.alloc.stack.push_dynamic()?; match lhs.ty() { - ValueType::I32 => encode_select_imm32( + ValType::I32 => encode_select_imm32( self, result, condition, @@ -2292,7 +2292,7 @@ impl FuncTranslator { i32::from(lhs), Instruction::select_rev, ), - ValueType::F32 => encode_select_imm32( + ValType::F32 => encode_select_imm32( self, result, condition, @@ -2300,7 +2300,7 @@ impl FuncTranslator { f32::from(lhs), Instruction::select_rev, ), - ValueType::I64 => encode_select_imm64( + ValType::I64 => encode_select_imm64( self, result, condition, @@ -2309,7 +2309,7 @@ impl FuncTranslator { Instruction::select_rev, Instruction::i64const32, ), - ValueType::F64 => encode_select_imm64( + ValType::F64 => encode_select_imm64( self, result, condition, @@ -2318,7 +2318,7 @@ impl FuncTranslator { Instruction::select_rev, Instruction::f64const32, ), - ValueType::FuncRef | ValueType::ExternRef => encode_select_imm( + ValType::FuncRef | ValType::ExternRef => encode_select_imm( self, result, condition, @@ -2371,7 +2371,7 @@ impl FuncTranslator { make_param: fn(Const32) -> Instruction, ) -> Result<(), Error> where - T: Copy + Into, + T: Copy + Into, Const32: TryFrom, { let lhs32 = >::try_from(lhs).ok(); @@ -2425,7 +2425,7 @@ impl FuncTranslator { rhs: T, ) -> Result<(), Error> where - T: Into, + T: Into, { let lhs = this.alloc.stack.alloc_const(lhs)?; let rhs = this.alloc.stack.alloc_const(rhs)?; @@ -2453,7 +2453,7 @@ impl FuncTranslator { } let result = self.alloc.stack.push_dynamic()?; match lhs.ty() { - ValueType::I32 => { + ValType::I32 => { encode_select_imm32( self, result, @@ -2463,7 +2463,7 @@ impl FuncTranslator { )?; Ok(()) } - ValueType::F32 => { + ValType::F32 => { encode_select_imm32( self, result, @@ -2473,7 +2473,7 @@ impl FuncTranslator { )?; Ok(()) } - ValueType::I64 => encode_select_imm64( + ValType::I64 => encode_select_imm64( self, result, condition, @@ -2482,7 +2482,7 @@ impl FuncTranslator { Instruction::select_i64imm32, Instruction::i64const32, ), - ValueType::F64 => encode_select_imm64( + ValType::F64 => encode_select_imm64( self, result, condition, @@ -2491,7 +2491,7 @@ impl FuncTranslator { Instruction::select_f64imm32, Instruction::f64const32, ), - ValueType::FuncRef | ValueType::ExternRef => { + ValType::FuncRef | ValType::ExternRef => { encode_select_imm(self, result, condition, lhs, rhs) } } @@ -2502,7 +2502,7 @@ impl FuncTranslator { } /// Translates a Wasm `reinterpret` instruction. - fn translate_reinterpret(&mut self, ty: ValueType) -> Result<(), Error> { + fn translate_reinterpret(&mut self, ty: ValType) -> Result<(), Error> { bail_unreachable!(self); if let TypedProvider::Register(_) = self.alloc.stack.peek() { // Nothing to do. diff --git a/crates/wasmi/src/engine/translator/stack/consts.rs b/crates/wasmi/src/engine/translator/stack/consts.rs index e03357b56f..0fd8c6827e 100644 --- a/crates/wasmi/src/engine/translator/stack/consts.rs +++ b/crates/wasmi/src/engine/translator/stack/consts.rs @@ -1,5 +1,5 @@ use super::Register; -use crate::{core::UntypedValue, engine::TranslationError, Error}; +use crate::{core::UntypedVal, engine::TranslationError, Error}; use core::{iter::Rev, slice::Iter as SliceIter}; use std::{ collections::{btree_map, BTreeMap}, @@ -16,10 +16,10 @@ use std::{ /// underlying constant values. #[derive(Debug, Default)] pub struct FuncLocalConsts { - /// Mapping from constant [`UntypedValue`] values to [`Register`] indices. - const2idx: BTreeMap, - /// Mapping from [`Register`] indices to constant [`UntypedValue`] values. - idx2const: Vec, + /// Mapping from constant [`UntypedVal`] values to [`Register`] indices. + const2idx: BTreeMap, + /// Mapping from [`Register`] indices to constant [`UntypedVal`] values. + idx2const: Vec, /// The [`Register`] index for the next allocated function local constant value. next_idx: i16, } @@ -68,7 +68,7 @@ impl FuncLocalConsts { /// # Errors /// /// If too many constant values have been allocated for this [`FuncLocalConsts`]. - pub fn alloc(&mut self, value: UntypedValue) -> Result { + pub fn alloc(&mut self, value: UntypedVal) -> Result { if self.next_idx == Self::last_index() { return Err(Error::from(TranslationError::TooManyFuncLocalConstValues)); } @@ -84,8 +84,8 @@ impl FuncLocalConsts { } } - /// Returns the function local constant [`UntypedValue`] of the [`Register`] if any. - pub fn get(&self, register: Register) -> Option { + /// Returns the function local constant [`UntypedVal`] of the [`Register`] if any. + pub fn get(&self, register: Register) -> Option { if !register.is_const() { return None; } @@ -106,11 +106,11 @@ impl FuncLocalConsts { /// Iterator yielding all allocated function local constant values. pub struct FuncLocalConstsIter<'a> { /// The underlying iterator. - iter: Rev>, + iter: Rev>, } impl<'a> FuncLocalConstsIter<'a> { - /// Creates a new [`FuncLocalConstsIter`] from the given slice of [`UntypedValue`]. + /// Creates a new [`FuncLocalConstsIter`] from the given slice of [`UntypedVal`]. pub fn new(consts: &'a FuncLocalConsts) -> Self { // Note: we need to revert the iteration since we allocate new // function local constants in reverse order of their absolute @@ -122,7 +122,7 @@ impl<'a> FuncLocalConstsIter<'a> { } impl<'a> Iterator for FuncLocalConstsIter<'a> { - type Item = UntypedValue; + type Item = UntypedVal; fn next(&mut self) -> Option { self.iter.next().copied() diff --git a/crates/wasmi/src/engine/translator/stack/mod.rs b/crates/wasmi/src/engine/translator/stack/mod.rs index 1bf7960acd..102f1340e0 100644 --- a/crates/wasmi/src/engine/translator/stack/mod.rs +++ b/crates/wasmi/src/engine/translator/stack/mod.rs @@ -9,9 +9,9 @@ pub use self::{ provider::{ProviderStack, TaggedProvider}, register_alloc::{RegisterAlloc, RegisterSpace}, }; -use super::{PreservedLocal, TypedValue}; +use super::{PreservedLocal, TypedVal}; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{ bytecode::{Provider, Register, RegisterSpan, UntypedProvider}, TranslationError, @@ -23,20 +23,20 @@ use std::vec::Vec; /// Typed inputs to Wasmi bytecode instructions. /// -/// Either a [`Register`] or a constant [`UntypedValue`]. +/// Either a [`Register`] or a constant [`UntypedVal`]. /// /// # Note /// /// The [`TypedProvider`] is used primarily during translation of a Wasmi /// function where types of constant values play an important role. -pub type TypedProvider = Provider; +pub type TypedProvider = Provider; impl TypedProvider { /// Converts the [`TypedProvider`] to a resolved [`UntypedProvider`]. pub fn into_untyped(self) -> UntypedProvider { match self { Self::Register(register) => UntypedProvider::Register(register), - Self::Const(value) => UntypedProvider::Const(UntypedValue::from(value)), + Self::Const(value) => UntypedProvider::Const(UntypedVal::from(value)), } } @@ -177,7 +177,7 @@ impl ValueStack { /// Constant values allocated this way are deduplicated and return shared [`Register`]. pub fn alloc_const(&mut self, value: T) -> Result where - T: Into, + T: Into, { self.consts.alloc(value.into()) } @@ -211,7 +211,7 @@ impl ValueStack { /// Pushes a constant value to the [`ProviderStack`]. pub fn push_const(&mut self, value: T) where - T: Into, + T: Into, { self.providers.push_const_value(value) } diff --git a/crates/wasmi/src/engine/translator/stack/provider.rs b/crates/wasmi/src/engine/translator/stack/provider.rs index d9bcf49bf2..bffda6c975 100644 --- a/crates/wasmi/src/engine/translator/stack/provider.rs +++ b/crates/wasmi/src/engine/translator/stack/provider.rs @@ -1,4 +1,4 @@ -use super::{LocalRefs, RegisterAlloc, TypedValue}; +use super::{LocalRefs, RegisterAlloc, TypedVal}; use crate::{ engine::{bytecode::Register, translator::PreservedLocal}, Error, @@ -7,11 +7,11 @@ use arrayvec::ArrayVec; use std::vec::Vec; #[cfg(doc)] -use crate::core::UntypedValue; +use crate::core::UntypedVal; /// Tagged providers are inputs to Wasmi bytecode instructions. /// -/// Either a [`Register`] or a constant [`UntypedValue`]. +/// Either a [`Register`] or a constant [`UntypedVal`]. #[derive(Debug, Copy, Clone)] pub enum TaggedProvider { /// A register referring to a function local constant value. @@ -23,7 +23,7 @@ pub enum TaggedProvider { /// A register referring to a preservation allocated register. Preserved(Register), /// An untyped constant value. - ConstValue(TypedValue), + ConstValue(TypedVal), } /// The stack of providers. @@ -364,7 +364,7 @@ impl ProviderStack { /// Pushes a constant value to the [`ProviderStack`]. pub fn push_const_value(&mut self, value: T) where - T: Into, + T: Into, { self.push(TaggedProvider::ConstValue(value.into())); } diff --git a/crates/wasmi/src/engine/translator/tests/display_wasm.rs b/crates/wasmi/src/engine/translator/tests/display_wasm.rs index af0633ca2c..d5d151b0ec 100644 --- a/crates/wasmi/src/engine/translator/tests/display_wasm.rs +++ b/crates/wasmi/src/engine/translator/tests/display_wasm.rs @@ -1,4 +1,4 @@ -use crate::{core::ValueType, Value}; +use crate::{core::ValType, Val}; use core::{ fmt, fmt::Display, @@ -67,11 +67,11 @@ macro_rules! impl_display_for_float { impl_display_for_float!(f32); impl_display_for_float!(f64); -/// Wasm [`Display`] wrapper for [`ValueType`]. -pub struct DisplayValueType(ValueType); +/// Wasm [`Display`] wrapper for [`ValType`]. +pub struct DisplayValueType(ValType); -impl From for DisplayValueType { - fn from(ty: ValueType) -> Self { +impl From for DisplayValueType { + fn from(ty: ValType) -> Self { Self(ty) } } @@ -79,21 +79,21 @@ impl From for DisplayValueType { impl Display for DisplayValueType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { - ValueType::I64 => write!(f, "i64"), - ValueType::I32 => write!(f, "i32"), - ValueType::F32 => write!(f, "f32"), - ValueType::F64 => write!(f, "f64"), - ValueType::FuncRef => write!(f, "funcref"), - ValueType::ExternRef => write!(f, "externref"), + ValType::I64 => write!(f, "i64"), + ValType::I32 => write!(f, "i32"), + ValType::F32 => write!(f, "f32"), + ValType::F64 => write!(f, "f64"), + ValType::FuncRef => write!(f, "funcref"), + ValType::ExternRef => write!(f, "externref"), } } } -/// Wasm [`Display`] wrapper for [`Value`]. -pub struct DisplayValue(Value); +/// Wasm [`Display`] wrapper for [`Val`]. +pub struct DisplayValue(Val); -impl From for DisplayValue { - fn from(ty: Value) -> Self { +impl From for DisplayValue { + fn from(ty: Val) -> Self { Self(ty) } } @@ -101,17 +101,17 @@ impl From for DisplayValue { impl Display for DisplayValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { - Value::I64(value) => write!(f, "{value}"), - Value::I32(value) => write!(f, "{value}"), - Value::F32(value) => write!(f, "{}", DisplayWasm::from(f32::from(value))), - Value::F64(value) => write!(f, "{}", DisplayWasm::from(f64::from(value))), - Value::FuncRef(value) => { + Val::I64(value) => write!(f, "{value}"), + Val::I32(value) => write!(f, "{value}"), + Val::F32(value) => write!(f, "{}", DisplayWasm::from(f32::from(value))), + Val::F64(value) => write!(f, "{}", DisplayWasm::from(f64::from(value))), + Val::FuncRef(value) => { if value.is_null() { return write!(f, "null"); } unimplemented!("wasm funcref types other than null cannot be displayed") } - Value::ExternRef(value) => { + Val::ExternRef(value) => { if value.is_null() { return write!(f, "null"); } diff --git a/crates/wasmi/src/engine/translator/tests/driver.rs b/crates/wasmi/src/engine/translator/tests/driver.rs index 174960d517..1ec9e46cdc 100644 --- a/crates/wasmi/src/engine/translator/tests/driver.rs +++ b/crates/wasmi/src/engine/translator/tests/driver.rs @@ -1,6 +1,6 @@ use super::create_module; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{bytecode::Instruction, CompiledFunc, DedupFuncType}, Config, Engine, @@ -36,7 +36,7 @@ pub struct ExpectedFunc { /// The instructions of the expected function. instrs: Vec, /// The function local constant values. - consts: Vec, + consts: Vec, } impl ExpectedFunc { @@ -70,7 +70,7 @@ impl ExpectedFunc { pub fn consts(mut self, consts: I) -> Self where I: IntoIterator, - T: Into, + T: Into, { assert!( self.expected_consts().is_empty(), @@ -90,7 +90,7 @@ impl ExpectedFunc { } /// Returns the expected function local constant values of the [`ExpectedFunc`] as slice. - fn expected_consts(&self) -> &[UntypedValue] { + fn expected_consts(&self) -> &[UntypedVal] { &self.consts } diff --git a/crates/wasmi/src/engine/translator/tests/mod.rs b/crates/wasmi/src/engine/translator/tests/mod.rs index 0d80fecf0c..18911dc1f2 100644 --- a/crates/wasmi/src/engine/translator/tests/mod.rs +++ b/crates/wasmi/src/engine/translator/tests/mod.rs @@ -11,7 +11,7 @@ use self::{ driver::{ExpectedFunc, TranslationTest}, }; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::bytecode::{AnyConst32, Const16, Const32, Instruction, Register}, Config, Engine, @@ -82,27 +82,27 @@ pub enum WasmOp { } impl WasmOp { - /// Create a new binary [`WasmOp`] for the given [`ValueType`]: `fn(T, T) -> T` + /// Create a new binary [`WasmOp`] for the given [`ValType`]: `fn(T, T) -> T` pub const fn binary(ty: WasmType, op: &'static str) -> Self { Self::Binary { ty, op } } - /// Create a new compare [`WasmOp`] for the given [`ValueType`]: `fn(T, T) -> i32` + /// Create a new compare [`WasmOp`] for the given [`ValType`]: `fn(T, T) -> i32` pub const fn cmp(ty: WasmType, op: &'static str) -> Self { Self::Cmp { ty, op } } - /// Create a new `load` [`WasmOp`] for the given [`ValueType`]. + /// Create a new `load` [`WasmOp`] for the given [`ValType`]. pub const fn load(ty: WasmType, op: &'static str) -> Self { Self::Load { ty, op } } - /// Create a new `store` [`WasmOp`] for the given [`ValueType`]. + /// Create a new `store` [`WasmOp`] for the given [`ValType`]. pub const fn store(ty: WasmType, op: &'static str) -> Self { Self::Store { ty, op } } - /// Returns the parameter [`ValueType`] of the [`WasmOp`]. + /// Returns the parameter [`ValType`] of the [`WasmOp`]. pub fn param_ty(&self) -> WasmType { match self { Self::Binary { ty, op: _ } => *ty, @@ -112,7 +112,7 @@ impl WasmOp { } } - /// Returns the result [`ValueType`] of the [`WasmOp`]. + /// Returns the result [`ValType`] of the [`WasmOp`]. pub fn result_ty(&self) -> WasmType { match self { Self::Binary { ty, op: _ } => *ty, @@ -122,7 +122,7 @@ impl WasmOp { } } - /// Returns the display [`ValueType`] of the [`WasmOp`]. + /// Returns the display [`ValType`] of the [`WasmOp`]. pub fn display_ty(&self) -> WasmType { match self { Self::Binary { .. } => self.param_ty(), @@ -287,7 +287,7 @@ fn test_binary_reg_imm32( value: T, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { let expected = [ @@ -309,7 +309,7 @@ fn test_binary_reg_imm32_rev( value: T, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { let expected = [ @@ -331,7 +331,7 @@ fn test_binary_reg_imm32_rev_commutative( value: T, make_instr: fn(result: Register, lhs: Register, rhs: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { let expected = [ diff --git a/crates/wasmi/src/engine/translator/tests/op/block.rs b/crates/wasmi/src/engine/translator/tests/op/block.rs index 6b980e6c50..7dc471ab3d 100644 --- a/crates/wasmi/src/engine/translator/tests/op/block.rs +++ b/crates/wasmi/src/engine/translator/tests/op/block.rs @@ -1,7 +1,7 @@ use super::*; use crate::engine::{ bytecode::{BranchOffset, BranchOffset16, RegisterSpan}, - translator::tests::wasm_type::WasmType, + translator::tests::wasm_type::WasmTy, }; use std::fmt::Display; @@ -146,7 +146,7 @@ fn branched_block_1() { fn testcase_branched_block_1_imm(value: T) -> TranslationTest where - T: Copy + WasmType, + T: Copy + WasmTy, DisplayWasm: Display, { let display_type = DisplayValueType::from(T::VALUE_TYPE); diff --git a/crates/wasmi/src/engine/translator/tests/op/br.rs b/crates/wasmi/src/engine/translator/tests/op/br.rs index 6c3103fb27..93035ecfd5 100644 --- a/crates/wasmi/src/engine/translator/tests/op/br.rs +++ b/crates/wasmi/src/engine/translator/tests/op/br.rs @@ -1,7 +1,7 @@ use super::*; use crate::{ - core::UntypedValue, - engine::{bytecode::BranchOffset, translator::tests::wasm_type::WasmType}, + core::UntypedVal, + engine::{bytecode::BranchOffset, translator::tests::wasm_type::WasmTy}, }; use core::fmt::Display; @@ -39,10 +39,10 @@ fn as_return_1() { fn as_return_1_imm() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(value); let wasm = format!( r" @@ -76,10 +76,10 @@ fn as_return_1_imm() { fn as_return_1_imm32() { fn test_for(value: T) where - T: WasmType + Into, + T: WasmTy + Into, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(value); let wasm = format!( r" @@ -179,7 +179,7 @@ fn test_br_as_return_values() { Instruction::branch(BranchOffset::from(1)), Instruction::return_reg2(-1, 0), ]) - .consts([UntypedValue::from(2_i32)]), + .consts([UntypedVal::from(2_i32)]), ) .run() } diff --git a/crates/wasmi/src/engine/translator/tests/op/br_if.rs b/crates/wasmi/src/engine/translator/tests/op/br_if.rs index df50edd51c..b4862ec663 100644 --- a/crates/wasmi/src/engine/translator/tests/op/br_if.rs +++ b/crates/wasmi/src/engine/translator/tests/op/br_if.rs @@ -1,9 +1,9 @@ use super::*; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{ bytecode::{BranchOffset, BranchOffset16, RegisterSpan}, - translator::tests::wasm_type::WasmType, + translator::tests::wasm_type::WasmTy, }, }; use core::fmt::Display; @@ -64,15 +64,15 @@ fn consteval_return_1() { fn consteval_return_1_imm() { fn test_for(condition: bool, if_true: T, if_false: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { - let expected: UntypedValue = match condition { + let expected: UntypedVal = match condition { true => if_true.into(), false => if_false.into(), }; let condition = DisplayWasm::from(i32::from(condition)); - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_if_true = DisplayWasm::from(if_true); let display_if_false = DisplayWasm::from(if_false); let wasm = format!( @@ -97,7 +97,7 @@ fn consteval_return_1_imm() { /// Run the test for both sign polarities of the `br_if` condition. fn test_for_both(if_true: T, if_false: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { test_for::(true, if_true, if_false); @@ -114,7 +114,7 @@ fn consteval_return_1_imm() { fn consteval_return_1_imm32() { fn test_for(condition: bool, if_true: T, if_false: T) where - T: WasmType + Into, + T: WasmTy + Into, DisplayWasm: Display, { let expected: AnyConst32 = match condition { @@ -122,7 +122,7 @@ fn consteval_return_1_imm32() { false => if_false.into(), }; let condition = DisplayWasm::from(i32::from(condition)); - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_if_true = DisplayWasm::from(if_true); let display_if_false = DisplayWasm::from(if_false); let wasm = format!( @@ -144,7 +144,7 @@ fn consteval_return_1_imm32() { /// Run the test for both sign polarities of the `br_if` condition. fn test_for_both(if_true: T, if_false: T) where - T: WasmType + Into, + T: WasmTy + Into, DisplayWasm: Display, { test_for::(true, if_true, if_false); @@ -319,10 +319,10 @@ fn return_if_results_1() { fn return_if_results_1_imm() { fn test_for(returned_value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(returned_value); let wasm = format!( r" @@ -363,10 +363,10 @@ fn return_if_results_1_imm() { fn return_if_results_1_imm32() { fn test_for(returned_value: T) where - T: WasmType + Into, + T: WasmTy + Into, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(returned_value); let wasm = format!( r" diff --git a/crates/wasmi/src/engine/translator/tests/op/cmp_br.rs b/crates/wasmi/src/engine/translator/tests/op/cmp_br.rs index a3727ddf0e..b8fc157454 100644 --- a/crates/wasmi/src/engine/translator/tests/op/cmp_br.rs +++ b/crates/wasmi/src/engine/translator/tests/op/cmp_br.rs @@ -1,6 +1,6 @@ -use super::{wasm_type::WasmType, *}; +use super::{wasm_type::WasmTy, *}; use crate::{ - core::ValueType, + core::ValType, engine::bytecode::{BranchOffset, BranchOffset16, GlobalIdx}, }; use std::fmt::{Debug, Display}; @@ -9,7 +9,7 @@ use std::fmt::{Debug, Display}; #[cfg_attr(miri, ignore)] fn loop_backward() { fn test_for( - ty: ValueType, + ty: ValType, op: &str, expect_instr: fn(Register, Register, BranchOffset16) -> Instruction, ) { @@ -39,44 +39,44 @@ fn loop_backward() { .run() } - test_for(ValueType::I32, "and", Instruction::branch_i32_and); - test_for(ValueType::I32, "or", Instruction::branch_i32_or); - test_for(ValueType::I32, "xor", Instruction::branch_i32_xor); - test_for(ValueType::I32, "eq", Instruction::branch_i32_eq); - test_for(ValueType::I32, "ne", Instruction::branch_i32_ne); - test_for(ValueType::I32, "lt_s", Instruction::branch_i32_lt_s); - test_for(ValueType::I32, "lt_u", Instruction::branch_i32_lt_u); - test_for(ValueType::I32, "le_s", Instruction::branch_i32_le_s); - test_for(ValueType::I32, "le_u", Instruction::branch_i32_le_u); - test_for(ValueType::I32, "gt_s", Instruction::branch_i32_gt_s); - test_for(ValueType::I32, "gt_u", Instruction::branch_i32_gt_u); - test_for(ValueType::I32, "ge_s", Instruction::branch_i32_ge_s); - test_for(ValueType::I32, "ge_u", Instruction::branch_i32_ge_u); + test_for(ValType::I32, "and", Instruction::branch_i32_and); + test_for(ValType::I32, "or", Instruction::branch_i32_or); + test_for(ValType::I32, "xor", Instruction::branch_i32_xor); + test_for(ValType::I32, "eq", Instruction::branch_i32_eq); + test_for(ValType::I32, "ne", Instruction::branch_i32_ne); + test_for(ValType::I32, "lt_s", Instruction::branch_i32_lt_s); + test_for(ValType::I32, "lt_u", Instruction::branch_i32_lt_u); + test_for(ValType::I32, "le_s", Instruction::branch_i32_le_s); + test_for(ValType::I32, "le_u", Instruction::branch_i32_le_u); + test_for(ValType::I32, "gt_s", Instruction::branch_i32_gt_s); + test_for(ValType::I32, "gt_u", Instruction::branch_i32_gt_u); + test_for(ValType::I32, "ge_s", Instruction::branch_i32_ge_s); + test_for(ValType::I32, "ge_u", Instruction::branch_i32_ge_u); - test_for(ValueType::I64, "eq", Instruction::branch_i64_eq); - test_for(ValueType::I64, "ne", Instruction::branch_i64_ne); - test_for(ValueType::I64, "lt_s", Instruction::branch_i64_lt_s); - test_for(ValueType::I64, "lt_u", Instruction::branch_i64_lt_u); - test_for(ValueType::I64, "le_s", Instruction::branch_i64_le_s); - test_for(ValueType::I64, "le_u", Instruction::branch_i64_le_u); - test_for(ValueType::I64, "gt_s", Instruction::branch_i64_gt_s); - test_for(ValueType::I64, "gt_u", Instruction::branch_i64_gt_u); - test_for(ValueType::I64, "ge_s", Instruction::branch_i64_ge_s); - test_for(ValueType::I64, "ge_u", Instruction::branch_i64_ge_u); + test_for(ValType::I64, "eq", Instruction::branch_i64_eq); + test_for(ValType::I64, "ne", Instruction::branch_i64_ne); + test_for(ValType::I64, "lt_s", Instruction::branch_i64_lt_s); + test_for(ValType::I64, "lt_u", Instruction::branch_i64_lt_u); + test_for(ValType::I64, "le_s", Instruction::branch_i64_le_s); + test_for(ValType::I64, "le_u", Instruction::branch_i64_le_u); + test_for(ValType::I64, "gt_s", Instruction::branch_i64_gt_s); + test_for(ValType::I64, "gt_u", Instruction::branch_i64_gt_u); + test_for(ValType::I64, "ge_s", Instruction::branch_i64_ge_s); + test_for(ValType::I64, "ge_u", Instruction::branch_i64_ge_u); - test_for(ValueType::F32, "eq", Instruction::branch_f32_eq); - test_for(ValueType::F32, "ne", Instruction::branch_f32_ne); - test_for(ValueType::F32, "lt", Instruction::branch_f32_lt); - test_for(ValueType::F32, "le", Instruction::branch_f32_le); - test_for(ValueType::F32, "gt", Instruction::branch_f32_gt); - test_for(ValueType::F32, "ge", Instruction::branch_f32_ge); + test_for(ValType::F32, "eq", Instruction::branch_f32_eq); + test_for(ValType::F32, "ne", Instruction::branch_f32_ne); + test_for(ValType::F32, "lt", Instruction::branch_f32_lt); + test_for(ValType::F32, "le", Instruction::branch_f32_le); + test_for(ValType::F32, "gt", Instruction::branch_f32_gt); + test_for(ValType::F32, "ge", Instruction::branch_f32_ge); - test_for(ValueType::F64, "eq", Instruction::branch_f64_eq); - test_for(ValueType::F64, "ne", Instruction::branch_f64_ne); - test_for(ValueType::F64, "lt", Instruction::branch_f64_lt); - test_for(ValueType::F64, "le", Instruction::branch_f64_le); - test_for(ValueType::F64, "gt", Instruction::branch_f64_gt); - test_for(ValueType::F64, "ge", Instruction::branch_f64_ge); + test_for(ValType::F64, "eq", Instruction::branch_f64_eq); + test_for(ValType::F64, "ne", Instruction::branch_f64_ne); + test_for(ValType::F64, "lt", Instruction::branch_f64_lt); + test_for(ValType::F64, "le", Instruction::branch_f64_le); + test_for(ValType::F64, "gt", Instruction::branch_f64_gt); + test_for(ValType::F64, "ge", Instruction::branch_f64_ge); } #[test] @@ -87,7 +87,7 @@ fn loop_backward_imm() { value: T, expect_instr: fn(Register, Const16, BranchOffset16) -> Instruction, ) where - T: WasmType, + T: WasmTy, Const16: TryFrom + Debug, DisplayWasm: Display, { @@ -176,7 +176,7 @@ fn loop_backward_imm_eqz() { #[cfg_attr(miri, ignore)] fn block_forward() { fn test_for( - ty: ValueType, + ty: ValType, op: &str, expect_instr: fn(Register, Register, BranchOffset16) -> Instruction, ) { @@ -206,51 +206,51 @@ fn block_forward() { .run() } - test_for(ValueType::I32, "and", Instruction::branch_i32_and); - test_for(ValueType::I32, "or", Instruction::branch_i32_or); - test_for(ValueType::I32, "xor", Instruction::branch_i32_xor); - test_for(ValueType::I32, "eq", Instruction::branch_i32_eq); - test_for(ValueType::I32, "ne", Instruction::branch_i32_ne); - test_for(ValueType::I32, "lt_s", Instruction::branch_i32_lt_s); - test_for(ValueType::I32, "lt_u", Instruction::branch_i32_lt_u); - test_for(ValueType::I32, "le_s", Instruction::branch_i32_le_s); - test_for(ValueType::I32, "le_u", Instruction::branch_i32_le_u); - test_for(ValueType::I32, "gt_s", Instruction::branch_i32_gt_s); - test_for(ValueType::I32, "gt_u", Instruction::branch_i32_gt_u); - test_for(ValueType::I32, "ge_s", Instruction::branch_i32_ge_s); - test_for(ValueType::I32, "ge_u", Instruction::branch_i32_ge_u); + test_for(ValType::I32, "and", Instruction::branch_i32_and); + test_for(ValType::I32, "or", Instruction::branch_i32_or); + test_for(ValType::I32, "xor", Instruction::branch_i32_xor); + test_for(ValType::I32, "eq", Instruction::branch_i32_eq); + test_for(ValType::I32, "ne", Instruction::branch_i32_ne); + test_for(ValType::I32, "lt_s", Instruction::branch_i32_lt_s); + test_for(ValType::I32, "lt_u", Instruction::branch_i32_lt_u); + test_for(ValType::I32, "le_s", Instruction::branch_i32_le_s); + test_for(ValType::I32, "le_u", Instruction::branch_i32_le_u); + test_for(ValType::I32, "gt_s", Instruction::branch_i32_gt_s); + test_for(ValType::I32, "gt_u", Instruction::branch_i32_gt_u); + test_for(ValType::I32, "ge_s", Instruction::branch_i32_ge_s); + test_for(ValType::I32, "ge_u", Instruction::branch_i32_ge_u); - test_for(ValueType::I64, "eq", Instruction::branch_i64_eq); - test_for(ValueType::I64, "ne", Instruction::branch_i64_ne); - test_for(ValueType::I64, "lt_s", Instruction::branch_i64_lt_s); - test_for(ValueType::I64, "lt_u", Instruction::branch_i64_lt_u); - test_for(ValueType::I64, "le_s", Instruction::branch_i64_le_s); - test_for(ValueType::I64, "le_u", Instruction::branch_i64_le_u); - test_for(ValueType::I64, "gt_s", Instruction::branch_i64_gt_s); - test_for(ValueType::I64, "gt_u", Instruction::branch_i64_gt_u); - test_for(ValueType::I64, "ge_s", Instruction::branch_i64_ge_s); - test_for(ValueType::I64, "ge_u", Instruction::branch_i64_ge_u); + test_for(ValType::I64, "eq", Instruction::branch_i64_eq); + test_for(ValType::I64, "ne", Instruction::branch_i64_ne); + test_for(ValType::I64, "lt_s", Instruction::branch_i64_lt_s); + test_for(ValType::I64, "lt_u", Instruction::branch_i64_lt_u); + test_for(ValType::I64, "le_s", Instruction::branch_i64_le_s); + test_for(ValType::I64, "le_u", Instruction::branch_i64_le_u); + test_for(ValType::I64, "gt_s", Instruction::branch_i64_gt_s); + test_for(ValType::I64, "gt_u", Instruction::branch_i64_gt_u); + test_for(ValType::I64, "ge_s", Instruction::branch_i64_ge_s); + test_for(ValType::I64, "ge_u", Instruction::branch_i64_ge_u); - test_for(ValueType::F32, "eq", Instruction::branch_f32_eq); - test_for(ValueType::F32, "ne", Instruction::branch_f32_ne); - test_for(ValueType::F32, "lt", Instruction::branch_f32_lt); - test_for(ValueType::F32, "le", Instruction::branch_f32_le); - test_for(ValueType::F32, "gt", Instruction::branch_f32_gt); - test_for(ValueType::F32, "ge", Instruction::branch_f32_ge); + test_for(ValType::F32, "eq", Instruction::branch_f32_eq); + test_for(ValType::F32, "ne", Instruction::branch_f32_ne); + test_for(ValType::F32, "lt", Instruction::branch_f32_lt); + test_for(ValType::F32, "le", Instruction::branch_f32_le); + test_for(ValType::F32, "gt", Instruction::branch_f32_gt); + test_for(ValType::F32, "ge", Instruction::branch_f32_ge); - test_for(ValueType::F64, "eq", Instruction::branch_f64_eq); - test_for(ValueType::F64, "ne", Instruction::branch_f64_ne); - test_for(ValueType::F64, "lt", Instruction::branch_f64_lt); - test_for(ValueType::F64, "le", Instruction::branch_f64_le); - test_for(ValueType::F64, "gt", Instruction::branch_f64_gt); - test_for(ValueType::F64, "ge", Instruction::branch_f64_ge); + test_for(ValType::F64, "eq", Instruction::branch_f64_eq); + test_for(ValType::F64, "ne", Instruction::branch_f64_ne); + test_for(ValType::F64, "lt", Instruction::branch_f64_lt); + test_for(ValType::F64, "le", Instruction::branch_f64_le); + test_for(ValType::F64, "gt", Instruction::branch_f64_gt); + test_for(ValType::F64, "ge", Instruction::branch_f64_ge); } #[test] #[cfg_attr(miri, ignore)] fn block_forward_nop_copy() { fn test_for( - ty: ValueType, + ty: ValType, op: &str, expect_instr: fn(Register, Register, BranchOffset16) -> Instruction, ) { @@ -286,51 +286,51 @@ fn block_forward_nop_copy() { .run() } - test_for(ValueType::I32, "and", Instruction::branch_i32_and); - test_for(ValueType::I32, "or", Instruction::branch_i32_or); - test_for(ValueType::I32, "xor", Instruction::branch_i32_xor); - test_for(ValueType::I32, "eq", Instruction::branch_i32_eq); - test_for(ValueType::I32, "ne", Instruction::branch_i32_ne); - test_for(ValueType::I32, "lt_s", Instruction::branch_i32_lt_s); - test_for(ValueType::I32, "lt_u", Instruction::branch_i32_lt_u); - test_for(ValueType::I32, "le_s", Instruction::branch_i32_le_s); - test_for(ValueType::I32, "le_u", Instruction::branch_i32_le_u); - test_for(ValueType::I32, "gt_s", Instruction::branch_i32_gt_s); - test_for(ValueType::I32, "gt_u", Instruction::branch_i32_gt_u); - test_for(ValueType::I32, "ge_s", Instruction::branch_i32_ge_s); - test_for(ValueType::I32, "ge_u", Instruction::branch_i32_ge_u); + test_for(ValType::I32, "and", Instruction::branch_i32_and); + test_for(ValType::I32, "or", Instruction::branch_i32_or); + test_for(ValType::I32, "xor", Instruction::branch_i32_xor); + test_for(ValType::I32, "eq", Instruction::branch_i32_eq); + test_for(ValType::I32, "ne", Instruction::branch_i32_ne); + test_for(ValType::I32, "lt_s", Instruction::branch_i32_lt_s); + test_for(ValType::I32, "lt_u", Instruction::branch_i32_lt_u); + test_for(ValType::I32, "le_s", Instruction::branch_i32_le_s); + test_for(ValType::I32, "le_u", Instruction::branch_i32_le_u); + test_for(ValType::I32, "gt_s", Instruction::branch_i32_gt_s); + test_for(ValType::I32, "gt_u", Instruction::branch_i32_gt_u); + test_for(ValType::I32, "ge_s", Instruction::branch_i32_ge_s); + test_for(ValType::I32, "ge_u", Instruction::branch_i32_ge_u); - test_for(ValueType::I64, "eq", Instruction::branch_i64_eq); - test_for(ValueType::I64, "ne", Instruction::branch_i64_ne); - test_for(ValueType::I64, "lt_s", Instruction::branch_i64_lt_s); - test_for(ValueType::I64, "lt_u", Instruction::branch_i64_lt_u); - test_for(ValueType::I64, "le_s", Instruction::branch_i64_le_s); - test_for(ValueType::I64, "le_u", Instruction::branch_i64_le_u); - test_for(ValueType::I64, "gt_s", Instruction::branch_i64_gt_s); - test_for(ValueType::I64, "gt_u", Instruction::branch_i64_gt_u); - test_for(ValueType::I64, "ge_s", Instruction::branch_i64_ge_s); - test_for(ValueType::I64, "ge_u", Instruction::branch_i64_ge_u); + test_for(ValType::I64, "eq", Instruction::branch_i64_eq); + test_for(ValType::I64, "ne", Instruction::branch_i64_ne); + test_for(ValType::I64, "lt_s", Instruction::branch_i64_lt_s); + test_for(ValType::I64, "lt_u", Instruction::branch_i64_lt_u); + test_for(ValType::I64, "le_s", Instruction::branch_i64_le_s); + test_for(ValType::I64, "le_u", Instruction::branch_i64_le_u); + test_for(ValType::I64, "gt_s", Instruction::branch_i64_gt_s); + test_for(ValType::I64, "gt_u", Instruction::branch_i64_gt_u); + test_for(ValType::I64, "ge_s", Instruction::branch_i64_ge_s); + test_for(ValType::I64, "ge_u", Instruction::branch_i64_ge_u); - test_for(ValueType::F32, "eq", Instruction::branch_f32_eq); - test_for(ValueType::F32, "ne", Instruction::branch_f32_ne); - test_for(ValueType::F32, "lt", Instruction::branch_f32_lt); - test_for(ValueType::F32, "le", Instruction::branch_f32_le); - test_for(ValueType::F32, "gt", Instruction::branch_f32_gt); - test_for(ValueType::F32, "ge", Instruction::branch_f32_ge); + test_for(ValType::F32, "eq", Instruction::branch_f32_eq); + test_for(ValType::F32, "ne", Instruction::branch_f32_ne); + test_for(ValType::F32, "lt", Instruction::branch_f32_lt); + test_for(ValType::F32, "le", Instruction::branch_f32_le); + test_for(ValType::F32, "gt", Instruction::branch_f32_gt); + test_for(ValType::F32, "ge", Instruction::branch_f32_ge); - test_for(ValueType::F64, "eq", Instruction::branch_f64_eq); - test_for(ValueType::F64, "ne", Instruction::branch_f64_ne); - test_for(ValueType::F64, "lt", Instruction::branch_f64_lt); - test_for(ValueType::F64, "le", Instruction::branch_f64_le); - test_for(ValueType::F64, "gt", Instruction::branch_f64_gt); - test_for(ValueType::F64, "ge", Instruction::branch_f64_ge); + test_for(ValType::F64, "eq", Instruction::branch_f64_eq); + test_for(ValType::F64, "ne", Instruction::branch_f64_ne); + test_for(ValType::F64, "lt", Instruction::branch_f64_lt); + test_for(ValType::F64, "le", Instruction::branch_f64_le); + test_for(ValType::F64, "gt", Instruction::branch_f64_gt); + test_for(ValType::F64, "ge", Instruction::branch_f64_ge); } #[test] #[cfg_attr(miri, ignore)] fn if_forward_multi_value() { fn test_for( - ty: ValueType, + ty: ValType, op: &str, expect_instr: fn(Register, Register, BranchOffset16) -> Instruction, ) { @@ -366,37 +366,37 @@ fn if_forward_multi_value() { .run() } - test_for(ValueType::I32, "and", Instruction::branch_i32_and_eqz); - test_for(ValueType::I32, "or", Instruction::branch_i32_or_eqz); - test_for(ValueType::I32, "xor", Instruction::branch_i32_xor_eqz); - test_for(ValueType::I32, "eq", Instruction::branch_i32_ne); - test_for(ValueType::I32, "ne", Instruction::branch_i32_eq); - test_for(ValueType::I32, "lt_s", Instruction::branch_i32_ge_s); - test_for(ValueType::I32, "lt_u", Instruction::branch_i32_ge_u); - test_for(ValueType::I32, "le_s", Instruction::branch_i32_gt_s); - test_for(ValueType::I32, "le_u", Instruction::branch_i32_gt_u); - test_for(ValueType::I32, "gt_s", Instruction::branch_i32_le_s); - test_for(ValueType::I32, "gt_u", Instruction::branch_i32_le_u); - test_for(ValueType::I32, "ge_s", Instruction::branch_i32_lt_s); - test_for(ValueType::I32, "ge_u", Instruction::branch_i32_lt_u); + test_for(ValType::I32, "and", Instruction::branch_i32_and_eqz); + test_for(ValType::I32, "or", Instruction::branch_i32_or_eqz); + test_for(ValType::I32, "xor", Instruction::branch_i32_xor_eqz); + test_for(ValType::I32, "eq", Instruction::branch_i32_ne); + test_for(ValType::I32, "ne", Instruction::branch_i32_eq); + test_for(ValType::I32, "lt_s", Instruction::branch_i32_ge_s); + test_for(ValType::I32, "lt_u", Instruction::branch_i32_ge_u); + test_for(ValType::I32, "le_s", Instruction::branch_i32_gt_s); + test_for(ValType::I32, "le_u", Instruction::branch_i32_gt_u); + test_for(ValType::I32, "gt_s", Instruction::branch_i32_le_s); + test_for(ValType::I32, "gt_u", Instruction::branch_i32_le_u); + test_for(ValType::I32, "ge_s", Instruction::branch_i32_lt_s); + test_for(ValType::I32, "ge_u", Instruction::branch_i32_lt_u); - test_for(ValueType::I64, "eq", Instruction::branch_i64_ne); - test_for(ValueType::I64, "ne", Instruction::branch_i64_eq); - test_for(ValueType::I64, "lt_s", Instruction::branch_i64_ge_s); - test_for(ValueType::I64, "lt_u", Instruction::branch_i64_ge_u); - test_for(ValueType::I64, "le_s", Instruction::branch_i64_gt_s); - test_for(ValueType::I64, "le_u", Instruction::branch_i64_gt_u); - test_for(ValueType::I64, "gt_s", Instruction::branch_i64_le_s); - test_for(ValueType::I64, "gt_u", Instruction::branch_i64_le_u); - test_for(ValueType::I64, "ge_s", Instruction::branch_i64_lt_s); - test_for(ValueType::I64, "ge_u", Instruction::branch_i64_lt_u); + test_for(ValType::I64, "eq", Instruction::branch_i64_ne); + test_for(ValType::I64, "ne", Instruction::branch_i64_eq); + test_for(ValType::I64, "lt_s", Instruction::branch_i64_ge_s); + test_for(ValType::I64, "lt_u", Instruction::branch_i64_ge_u); + test_for(ValType::I64, "le_s", Instruction::branch_i64_gt_s); + test_for(ValType::I64, "le_u", Instruction::branch_i64_gt_u); + test_for(ValType::I64, "gt_s", Instruction::branch_i64_le_s); + test_for(ValType::I64, "gt_u", Instruction::branch_i64_le_u); + test_for(ValType::I64, "ge_s", Instruction::branch_i64_lt_s); + test_for(ValType::I64, "ge_u", Instruction::branch_i64_lt_u); } #[test] #[cfg_attr(miri, ignore)] fn if_forward() { fn test_for( - ty: ValueType, + ty: ValType, op: &str, expect_instr: fn(Register, Register, BranchOffset16) -> Instruction, ) { @@ -427,30 +427,30 @@ fn if_forward() { .run() } - test_for(ValueType::I32, "and", Instruction::branch_i32_and_eqz); - test_for(ValueType::I32, "or", Instruction::branch_i32_or_eqz); - test_for(ValueType::I32, "xor", Instruction::branch_i32_xor_eqz); - test_for(ValueType::I32, "eq", Instruction::branch_i32_ne); - test_for(ValueType::I32, "ne", Instruction::branch_i32_eq); - test_for(ValueType::I32, "lt_s", Instruction::branch_i32_ge_s); - test_for(ValueType::I32, "lt_u", Instruction::branch_i32_ge_u); - test_for(ValueType::I32, "le_s", Instruction::branch_i32_gt_s); - test_for(ValueType::I32, "le_u", Instruction::branch_i32_gt_u); - test_for(ValueType::I32, "gt_s", Instruction::branch_i32_le_s); - test_for(ValueType::I32, "gt_u", Instruction::branch_i32_le_u); - test_for(ValueType::I32, "ge_s", Instruction::branch_i32_lt_s); - test_for(ValueType::I32, "ge_u", Instruction::branch_i32_lt_u); + test_for(ValType::I32, "and", Instruction::branch_i32_and_eqz); + test_for(ValType::I32, "or", Instruction::branch_i32_or_eqz); + test_for(ValType::I32, "xor", Instruction::branch_i32_xor_eqz); + test_for(ValType::I32, "eq", Instruction::branch_i32_ne); + test_for(ValType::I32, "ne", Instruction::branch_i32_eq); + test_for(ValType::I32, "lt_s", Instruction::branch_i32_ge_s); + test_for(ValType::I32, "lt_u", Instruction::branch_i32_ge_u); + test_for(ValType::I32, "le_s", Instruction::branch_i32_gt_s); + test_for(ValType::I32, "le_u", Instruction::branch_i32_gt_u); + test_for(ValType::I32, "gt_s", Instruction::branch_i32_le_s); + test_for(ValType::I32, "gt_u", Instruction::branch_i32_le_u); + test_for(ValType::I32, "ge_s", Instruction::branch_i32_lt_s); + test_for(ValType::I32, "ge_u", Instruction::branch_i32_lt_u); - test_for(ValueType::I64, "eq", Instruction::branch_i64_ne); - test_for(ValueType::I64, "ne", Instruction::branch_i64_eq); - test_for(ValueType::I64, "lt_s", Instruction::branch_i64_ge_s); - test_for(ValueType::I64, "lt_u", Instruction::branch_i64_ge_u); - test_for(ValueType::I64, "le_s", Instruction::branch_i64_gt_s); - test_for(ValueType::I64, "le_u", Instruction::branch_i64_gt_u); - test_for(ValueType::I64, "gt_s", Instruction::branch_i64_le_s); - test_for(ValueType::I64, "gt_u", Instruction::branch_i64_le_u); - test_for(ValueType::I64, "ge_s", Instruction::branch_i64_lt_s); - test_for(ValueType::I64, "ge_u", Instruction::branch_i64_lt_u); + test_for(ValType::I64, "eq", Instruction::branch_i64_ne); + test_for(ValType::I64, "ne", Instruction::branch_i64_eq); + test_for(ValType::I64, "lt_s", Instruction::branch_i64_ge_s); + test_for(ValType::I64, "lt_u", Instruction::branch_i64_ge_u); + test_for(ValType::I64, "le_s", Instruction::branch_i64_gt_s); + test_for(ValType::I64, "le_u", Instruction::branch_i64_gt_u); + test_for(ValType::I64, "gt_s", Instruction::branch_i64_le_s); + test_for(ValType::I64, "gt_u", Instruction::branch_i64_le_u); + test_for(ValType::I64, "ge_s", Instruction::branch_i64_lt_s); + test_for(ValType::I64, "ge_u", Instruction::branch_i64_lt_u); } #[test] diff --git a/crates/wasmi/src/engine/translator/tests/op/global_get.rs b/crates/wasmi/src/engine/translator/tests/op/global_get.rs index 5ffccf2b65..5dc2a90253 100644 --- a/crates/wasmi/src/engine/translator/tests/op/global_get.rs +++ b/crates/wasmi/src/engine/translator/tests/op/global_get.rs @@ -2,7 +2,7 @@ use super::*; use crate::engine::bytecode::GlobalIdx; use core::fmt::Display; -use wasm_type::WasmType; +use wasm_type::WasmTy; /// Test for `global.get` of internally defined mutable global variables. /// @@ -13,7 +13,7 @@ use wasm_type::WasmType; /// during program execution. fn test_mutable(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::NAME; @@ -68,7 +68,7 @@ fn mutable_f64() { /// value of the global variable can be applied always. fn test_immutable(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::NAME; @@ -84,7 +84,7 @@ where "#, ); let mut testcase = TranslationTest::from_wat(&wasm); - let instr = ::return_imm_instr(&value); + let instr = ::return_imm_instr(&value); match instr { Instruction::ReturnReg { value: register } => { assert!(register.is_const()); @@ -130,7 +130,7 @@ fn immutable_f64() { /// to being imported. fn test_imported() where - T: WasmType, + T: WasmTy, { let ty = T::NAME; let wasm = format!( diff --git a/crates/wasmi/src/engine/translator/tests/op/global_set.rs b/crates/wasmi/src/engine/translator/tests/op/global_set.rs index 0259ee59b5..a5222f0d14 100644 --- a/crates/wasmi/src/engine/translator/tests/op/global_set.rs +++ b/crates/wasmi/src/engine/translator/tests/op/global_set.rs @@ -1,12 +1,12 @@ use super::*; -use crate::{core::ValueType, engine::bytecode::GlobalIdx}; +use crate::{core::ValType, engine::bytecode::GlobalIdx}; use core::fmt::Display; -use wasm_type::WasmType; +use wasm_type::WasmTy; fn test_reg() where - T: WasmType + Default, + T: WasmTy + Default, DisplayWasm: Display, { let ty = T::NAME; @@ -41,7 +41,7 @@ fn reg() { fn test_imm(value: T) where - T: WasmType + Default, + T: WasmTy + Default, DisplayWasm: Display, { let display_ty = DisplayValueType::from(T::VALUE_TYPE); @@ -82,7 +82,7 @@ fn imm() { } fn test_i32imm16(value: i32) { - let display_ty = DisplayValueType::from(ValueType::I32); + let display_ty = DisplayValueType::from(ValType::I32); let display_value = DisplayWasm::from(value); let wasm = format!( r#" @@ -116,7 +116,7 @@ fn i32imm16() { } fn test_i64imm16(value: i64) { - let display_ty = DisplayValueType::from(ValueType::I64); + let display_ty = DisplayValueType::from(ValType::I64); let display_value = DisplayWasm::from(value); let wasm = format!( r#" diff --git a/crates/wasmi/src/engine/translator/tests/op/if_.rs b/crates/wasmi/src/engine/translator/tests/op/if_.rs index 12cdaba9c5..90843535ff 100644 --- a/crates/wasmi/src/engine/translator/tests/op/if_.rs +++ b/crates/wasmi/src/engine/translator/tests/op/if_.rs @@ -1,6 +1,6 @@ use super::*; use crate::{ - core::{TrapCode, UntypedValue}, + core::{TrapCode, UntypedVal}, engine::{ bytecode::{BranchOffset, BranchOffset16, GlobalIdx, RegisterSpan}, CompiledFunc, @@ -546,7 +546,7 @@ fn test_if_without_else_has_result() { TranslationTest::from_wat(wasm) .expect_func( ExpectedFunc::new([Instruction::return_reg2(-1, -2)]) - .consts([UntypedValue::from(1_i64), UntypedValue::from(0_i32)]), + .consts([UntypedVal::from(1_i64), UntypedVal::from(0_i32)]), ) .expect_func_instrs([ Instruction::call_internal_0( diff --git a/crates/wasmi/src/engine/translator/tests/op/return_.rs b/crates/wasmi/src/engine/translator/tests/op/return_.rs index 43036e193c..be31e42b98 100644 --- a/crates/wasmi/src/engine/translator/tests/op/return_.rs +++ b/crates/wasmi/src/engine/translator/tests/op/return_.rs @@ -1,5 +1,5 @@ use super::*; -use crate::engine::{bytecode::RegisterSpan, translator::tests::wasm_type::WasmType}; +use crate::engine::{bytecode::RegisterSpan, translator::tests::wasm_type::WasmTy}; use core::fmt::Display; #[test] @@ -36,10 +36,10 @@ fn return_1() { fn return_1_imm() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(value); let wasm = format!( r" @@ -72,10 +72,10 @@ fn return_1_imm() { fn return_1_imm32() { fn test_for(value: T) where - T: WasmType + Into, + T: WasmTy + Into, DisplayWasm: Display, { - let display_ty = DisplayValueType::from(::VALUE_TYPE); + let display_ty = DisplayValueType::from(::VALUE_TYPE); let display_value = DisplayWasm::from(value); let wasm = format!( r" diff --git a/crates/wasmi/src/engine/translator/tests/op/select.rs b/crates/wasmi/src/engine/translator/tests/op/select.rs index 81269d02e9..a240929a67 100644 --- a/crates/wasmi/src/engine/translator/tests/op/select.rs +++ b/crates/wasmi/src/engine/translator/tests/op/select.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{core::ValueType, engine::translator::tests::wasm_type::WasmType}; +use crate::{core::ValType, engine::translator::tests::wasm_type::WasmTy}; use core::{fmt, fmt::Display}; /// Tells which kind of `select` instruction to test. @@ -17,12 +17,12 @@ struct DisplaySelect { /// The kind of the `select` instruction. kind: SelectKind, /// The `result` type of the `select` instruction. - ty: ValueType, + ty: ValType, } impl DisplaySelect { /// Creates a new [`DisplaySelect`]. - fn new(kind: SelectKind, ty: ValueType) -> Self { + fn new(kind: SelectKind, ty: ValType) -> Self { Self { kind, ty } } } @@ -41,7 +41,7 @@ impl Display for DisplaySelect { #[test] #[cfg_attr(miri, ignore)] fn reg() { - fn test_reg(kind: SelectKind, result_ty: ValueType) { + fn test_reg(kind: SelectKind, result_ty: ValType) { let display_ty = DisplayValueType::from(result_ty); let display_select = DisplaySelect::new(kind, result_ty); let wasm = format!( @@ -72,21 +72,21 @@ fn reg() { .run(); } fn test_for(kind: SelectKind) { - test_reg(kind, ValueType::I32); - test_reg(kind, ValueType::I64); - test_reg(kind, ValueType::F32); - test_reg(kind, ValueType::F64); + test_reg(kind, ValType::I32); + test_reg(kind, ValType::I64); + test_reg(kind, ValType::F32); + test_reg(kind, ValType::F64); } test_for(SelectKind::Select); test_for(SelectKind::TypedSelect); - test_reg(SelectKind::TypedSelect, ValueType::FuncRef); - test_reg(SelectKind::TypedSelect, ValueType::ExternRef); + test_reg(SelectKind::TypedSelect, ValType::FuncRef); + test_reg(SelectKind::TypedSelect, ValType::ExternRef); } #[test] #[cfg_attr(miri, ignore)] fn same_reg() { - fn test_same_reg(kind: SelectKind, result_ty: ValueType) { + fn test_same_reg(kind: SelectKind, result_ty: ValType) { let display_ty = DisplayValueType::from(result_ty); let display_select = DisplaySelect::new(kind, result_ty); let wasm = format!( @@ -106,20 +106,20 @@ fn same_reg() { .run(); } fn test_for(kind: SelectKind) { - test_same_reg(kind, ValueType::I32); - test_same_reg(kind, ValueType::I64); - test_same_reg(kind, ValueType::F32); - test_same_reg(kind, ValueType::F64); + test_same_reg(kind, ValType::I32); + test_same_reg(kind, ValType::I64); + test_same_reg(kind, ValType::F32); + test_same_reg(kind, ValType::F64); } test_for(SelectKind::Select); test_for(SelectKind::TypedSelect); - test_same_reg(SelectKind::TypedSelect, ValueType::FuncRef); - test_same_reg(SelectKind::TypedSelect, ValueType::ExternRef); + test_same_reg(SelectKind::TypedSelect, ValType::FuncRef); + test_same_reg(SelectKind::TypedSelect, ValType::ExternRef); } fn test_same_imm(kind: SelectKind, input: T) -> TranslationTest where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::VALUE_TYPE; @@ -146,7 +146,7 @@ where fn same_imm32() { fn test_for_kind(kind: SelectKind, value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -158,7 +158,7 @@ fn same_imm32() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -234,7 +234,7 @@ fn same_f64imm32() { fn same_imm() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let instrs = [Instruction::return_reg(Register::from_i16(-1))]; @@ -264,7 +264,7 @@ fn same_imm() { fn test_reg_imm(kind: SelectKind, rhs: T) -> TranslationTest where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::VALUE_TYPE; @@ -291,7 +291,7 @@ where fn reg_imm32() { fn test_for_kind(kind: SelectKind, value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -308,7 +308,7 @@ fn reg_imm32() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -342,7 +342,7 @@ fn reg_imm32() { fn reg_imm() { fn test_for_kind(kind: SelectKind, value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let result = Register::from_i16(2); @@ -359,7 +359,7 @@ fn reg_imm() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { test_for_kind(SelectKind::Select, value); @@ -443,7 +443,7 @@ fn reg_f64imm32() { fn test_imm_reg(kind: SelectKind, lhs: T) -> TranslationTest where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::VALUE_TYPE; @@ -470,7 +470,7 @@ where fn imm32_reg() { fn test_for_kind(kind: SelectKind, value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -487,7 +487,7 @@ fn imm32_reg() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -521,7 +521,7 @@ fn imm32_reg() { fn imm_reg() { fn test_for_kind(kind: SelectKind, value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let result = Register::from_i16(2); @@ -538,7 +538,7 @@ fn imm_reg() { fn test_for(value: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { test_for_kind(SelectKind::Select, value); @@ -622,7 +622,7 @@ fn f64imm32_reg() { fn test_both_imm(kind: SelectKind, lhs: T, rhs: T) -> TranslationTest where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let ty = T::VALUE_TYPE; @@ -650,7 +650,7 @@ where fn both_imm32() { fn test_for_kind(kind: SelectKind, lhs: T, rhs: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -670,7 +670,7 @@ fn both_imm32() { fn test_for(lhs: T, rhs: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, AnyConst32: From, { @@ -696,7 +696,7 @@ fn both_imm32() { fn both_imm() { fn test_for_kind(kind: SelectKind, lhs: T, rhs: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { let result = Register::from_i16(1); @@ -715,7 +715,7 @@ fn both_imm() { fn test_for(lhs: T, rhs: T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { test_for_kind(SelectKind::Select, lhs, rhs); diff --git a/crates/wasmi/src/engine/translator/tests/op/store/mod.rs b/crates/wasmi/src/engine/translator/tests/op/store/mod.rs index b086a8eea0..f771fdd533 100644 --- a/crates/wasmi/src/engine/translator/tests/op/store/mod.rs +++ b/crates/wasmi/src/engine/translator/tests/op/store/mod.rs @@ -1,7 +1,7 @@ //! Translation tests for all Wasm `store` instructions. use super::*; -use crate::core::UntypedValue; +use crate::core::UntypedVal; mod f32_store; mod f64_store; @@ -94,7 +94,7 @@ fn test_store_offset16_imm_for( value: T, make_instr: fn(ptr: Register, offset: u16, value: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { let param_ty = wasm_op.param_ty(); @@ -127,7 +127,7 @@ fn test_store_offset16_imm( value: T, make_instr: fn(ptr: Register, offset: u16, value: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { test_store_offset16_imm_for(wasm_op, 0, value, make_instr); @@ -185,7 +185,7 @@ fn test_store_imm_for( value: T, make_instr: fn(ptr: Register, offset: Const32) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { assert!( @@ -223,7 +223,7 @@ fn test_store_imm( value: T, make_instr: fn(ptr: Register, offset: Const32) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { test_store_imm_for(wasm_op, u32::from(u16::MAX) + 1, value, make_instr); @@ -312,7 +312,7 @@ fn test_store_at_imm_for( value: T, make_instr: fn(address: Const32, value: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { let address = ptr @@ -348,7 +348,7 @@ fn test_store_at_imm( value: T, make_instr: fn(address: Const32, value: Register) -> Instruction, ) where - T: Copy + Into, + T: Copy + Into, DisplayWasm: Display, { test_store_at_imm_for(wasm_op, 0, 0, value, make_instr); diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_copy.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_copy.rs index 09388363b1..0136fe1b53 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_copy.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_copy.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_copy(ty: ValueType) { +fn test_copy(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -33,11 +33,11 @@ fn test_copy(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn copy() { - test_copy(ValueType::FuncRef); - test_copy(ValueType::ExternRef); + test_copy(ValType::FuncRef); + test_copy(ValType::ExternRef); } -fn testcase_copy_exact(ty: ValueType, len: u32) -> TranslationTest { +fn testcase_copy_exact(ty: ValType, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -55,7 +55,7 @@ fn testcase_copy_exact(ty: ValueType, len: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_copy_exact16(ty: ValueType, len: u32) { +fn test_copy_exact16(ty: ValType, len: u32) { testcase_copy_exact(ty, len) .expect_func_instrs([ Instruction::table_copy_exact( @@ -74,8 +74,8 @@ fn test_copy_exact16(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn copy_exact16() { fn test_for(len: u32) { - test_copy_exact16(ValueType::FuncRef, len); - test_copy_exact16(ValueType::ExternRef, len); + test_copy_exact16(ValType::FuncRef, len); + test_copy_exact16(ValType::ExternRef, len); } test_for(0); test_for(1); @@ -83,7 +83,7 @@ fn copy_exact16() { test_for(u32::from(u16::MAX)); } -fn test_copy_exact(ty: ValueType, len: u32) { +fn test_copy_exact(ty: ValType, len: u32) { testcase_copy_exact(ty, len) .expect_func( ExpectedFunc::new([ @@ -105,14 +105,14 @@ fn test_copy_exact(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn copy_exact() { fn test_for(len: u32) { - test_copy_exact(ValueType::FuncRef, len); - test_copy_exact(ValueType::ExternRef, len); + test_copy_exact(ValType::FuncRef, len); + test_copy_exact(ValType::ExternRef, len); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_copy_from(ty: ValueType, src: u32) -> TranslationTest { +fn testcase_copy_from(ty: ValType, src: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -130,7 +130,7 @@ fn testcase_copy_from(ty: ValueType, src: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_copy_from16(ty: ValueType, src: u32) { +fn test_copy_from16(ty: ValType, src: u32) { testcase_copy_from(ty, src) .expect_func_instrs([ Instruction::table_copy_from( @@ -149,14 +149,14 @@ fn test_copy_from16(ty: ValueType, src: u32) { #[cfg_attr(miri, ignore)] fn copy_from16() { fn test_for(src: u32) { - test_copy_from16(ValueType::FuncRef, src); - test_copy_from16(ValueType::ExternRef, src); + test_copy_from16(ValType::FuncRef, src); + test_copy_from16(ValType::ExternRef, src); } test_for(0); test_for(u32::from(u16::MAX)); } -fn test_copy_from(ty: ValueType, src: u32) { +fn test_copy_from(ty: ValType, src: u32) { testcase_copy_from(ty, src) .expect_func( ExpectedFunc::new([ @@ -178,14 +178,14 @@ fn test_copy_from(ty: ValueType, src: u32) { #[cfg_attr(miri, ignore)] fn copy_from() { fn test_for(src: u32) { - test_copy_from(ValueType::FuncRef, src); - test_copy_from(ValueType::ExternRef, src); + test_copy_from(ValType::FuncRef, src); + test_copy_from(ValType::ExternRef, src); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_copy_to(ty: ValueType, dst: u32) -> TranslationTest { +fn testcase_copy_to(ty: ValType, dst: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -203,7 +203,7 @@ fn testcase_copy_to(ty: ValueType, dst: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_copy_to16(ty: ValueType, dst: u32) { +fn test_copy_to16(ty: ValType, dst: u32) { testcase_copy_to(ty, dst) .expect_func_instrs([ Instruction::table_copy_to(u32imm16(dst), Register::from_i16(0), Register::from_i16(1)), @@ -218,14 +218,14 @@ fn test_copy_to16(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn copy_to16() { fn test_for(dst: u32) { - test_copy_to16(ValueType::FuncRef, dst); - test_copy_to16(ValueType::ExternRef, dst); + test_copy_to16(ValType::FuncRef, dst); + test_copy_to16(ValType::ExternRef, dst); } test_for(0); test_for(u32::from(u16::MAX)); } -fn test_copy_to(ty: ValueType, dst: u32) { +fn test_copy_to(ty: ValType, dst: u32) { testcase_copy_to(ty, dst) .expect_func( ExpectedFunc::new([ @@ -247,14 +247,14 @@ fn test_copy_to(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn copy_to() { fn test_for(dst: u32) { - test_copy_to(ValueType::FuncRef, dst); - test_copy_to(ValueType::ExternRef, dst); + test_copy_to(ValType::FuncRef, dst); + test_copy_to(ValType::ExternRef, dst); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_copy_from_to(ty: ValueType, dst: u32, src: u32) -> TranslationTest { +fn testcase_copy_from_to(ty: ValType, dst: u32, src: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -272,7 +272,7 @@ fn testcase_copy_from_to(ty: ValueType, dst: u32, src: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_copy_from_to16(ty: ValueType, dst: u32, src: u32) { +fn test_copy_from_to16(ty: ValType, dst: u32, src: u32) { testcase_copy_from_to(ty, dst, src) .expect_func_instrs([ Instruction::table_copy_from_to(u32imm16(dst), u32imm16(src), Register::from_i16(0)), @@ -287,8 +287,8 @@ fn test_copy_from_to16(ty: ValueType, dst: u32, src: u32) { #[cfg_attr(miri, ignore)] fn copy_from_to16() { fn test_for(dst: u32, src: u32) { - test_copy_from_to16(ValueType::FuncRef, dst, src); - test_copy_from_to16(ValueType::ExternRef, dst, src); + test_copy_from_to16(ValType::FuncRef, dst, src); + test_copy_from_to16(ValType::ExternRef, dst, src); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -298,7 +298,7 @@ fn copy_from_to16() { } } -fn test_copy_from_to(ty: ValueType, dst: u32, src: u32) { +fn test_copy_from_to(ty: ValType, dst: u32, src: u32) { testcase_copy_from_to(ty, dst, src) .expect_func( ExpectedFunc::new([ @@ -320,8 +320,8 @@ fn test_copy_from_to(ty: ValueType, dst: u32, src: u32) { #[cfg_attr(miri, ignore)] fn copy_from_to() { fn test_for(dst: u32, src: u32) { - test_copy_from_to(ValueType::FuncRef, dst, src); - test_copy_from_to(ValueType::ExternRef, dst, src); + test_copy_from_to(ValType::FuncRef, dst, src); + test_copy_from_to(ValType::ExternRef, dst, src); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -338,7 +338,7 @@ fn copy_from_to() { } } -fn testcase_copy_to_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest { +fn testcase_copy_to_exact(ty: ValType, dst: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -356,7 +356,7 @@ fn testcase_copy_to_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest TranslationTest::from_wat(&wasm) } -fn test_copy_to_exact16(ty: ValueType, dst: u32, len: u32) { +fn test_copy_to_exact16(ty: ValType, dst: u32, len: u32) { testcase_copy_to_exact(ty, dst, len) .expect_func_instrs([ Instruction::table_copy_to_exact(u32imm16(dst), Register::from_i16(0), u32imm16(len)), @@ -371,8 +371,8 @@ fn test_copy_to_exact16(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_to_exact16() { fn test_for(dst: u32, len: u32) { - test_copy_to_exact16(ValueType::FuncRef, dst, len); - test_copy_to_exact16(ValueType::ExternRef, dst, len); + test_copy_to_exact16(ValType::FuncRef, dst, len); + test_copy_to_exact16(ValType::ExternRef, dst, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -382,7 +382,7 @@ fn copy_to_exact16() { } } -fn test_copy_to_exact(ty: ValueType, dst: u32, len: u32) { +fn test_copy_to_exact(ty: ValType, dst: u32, len: u32) { testcase_copy_to_exact(ty, dst, len) .expect_func( ExpectedFunc::new([ @@ -404,8 +404,8 @@ fn test_copy_to_exact(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_to_exact() { fn test_for(dst: u32, len: u32) { - test_copy_to_exact(ValueType::FuncRef, dst, len); - test_copy_to_exact(ValueType::ExternRef, dst, len); + test_copy_to_exact(ValType::FuncRef, dst, len); + test_copy_to_exact(ValType::ExternRef, dst, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -422,7 +422,7 @@ fn copy_to_exact() { } } -fn testcase_copy_from_exact(ty: ValueType, src: u32, len: u32) -> TranslationTest { +fn testcase_copy_from_exact(ty: ValType, src: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -440,7 +440,7 @@ fn testcase_copy_from_exact(ty: ValueType, src: u32, len: u32) -> TranslationTes TranslationTest::from_wat(&wasm) } -fn test_copy_from_exact16(ty: ValueType, src: u32, len: u32) { +fn test_copy_from_exact16(ty: ValType, src: u32, len: u32) { testcase_copy_from_exact(ty, src, len) .expect_func_instrs([ Instruction::table_copy_from_exact(Register::from_i16(0), u32imm16(src), u32imm16(len)), @@ -455,8 +455,8 @@ fn test_copy_from_exact16(ty: ValueType, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_from_exact16() { fn test_for(dst: u32, len: u32) { - test_copy_from_exact16(ValueType::FuncRef, dst, len); - test_copy_from_exact16(ValueType::ExternRef, dst, len); + test_copy_from_exact16(ValType::FuncRef, dst, len); + test_copy_from_exact16(ValType::ExternRef, dst, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -466,7 +466,7 @@ fn copy_from_exact16() { } } -fn test_copy_from_exact(ty: ValueType, src: u32, len: u32) { +fn test_copy_from_exact(ty: ValType, src: u32, len: u32) { testcase_copy_from_exact(ty, src, len) .expect_func( ExpectedFunc::new([ @@ -488,8 +488,8 @@ fn test_copy_from_exact(ty: ValueType, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_from_exact() { fn test_for(src: u32, len: u32) { - test_copy_from_exact(ValueType::FuncRef, src, len); - test_copy_from_exact(ValueType::ExternRef, src, len); + test_copy_from_exact(ValType::FuncRef, src, len); + test_copy_from_exact(ValType::ExternRef, src, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -506,7 +506,7 @@ fn copy_from_exact() { } } -fn testcase_copy_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) -> TranslationTest { +fn testcase_copy_from_to_exact(ty: ValType, dst: u32, src: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -524,7 +524,7 @@ fn testcase_copy_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) -> T TranslationTest::from_wat(&wasm) } -fn test_copy_from_to_exact16(ty: ValueType, dst: u32, src: u32, len: u32) { +fn test_copy_from_to_exact16(ty: ValType, dst: u32, src: u32, len: u32) { testcase_copy_from_to_exact(ty, dst, src, len) .expect_func_instrs([ Instruction::table_copy_from_to_exact(u32imm16(dst), u32imm16(src), u32imm16(len)), @@ -539,8 +539,8 @@ fn test_copy_from_to_exact16(ty: ValueType, dst: u32, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_from_to_exact16() { fn test_for(dst: u32, src: u32, len: u32) { - test_copy_from_to_exact16(ValueType::FuncRef, dst, src, len); - test_copy_from_to_exact16(ValueType::ExternRef, dst, src, len); + test_copy_from_to_exact16(ValType::FuncRef, dst, src, len); + test_copy_from_to_exact16(ValType::ExternRef, dst, src, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -552,7 +552,7 @@ fn copy_from_to_exact16() { } } -fn test_copy_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) { +fn test_copy_from_to_exact(ty: ValType, dst: u32, src: u32, len: u32) { testcase_copy_from_to_exact(ty, dst, src, len) .expect_func( ExpectedFunc::new([ @@ -574,8 +574,8 @@ fn test_copy_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn copy_from_to_exact() { fn test_for(dst: u32, src: u32, len: u32) { - test_copy_from_to_exact(ValueType::FuncRef, dst, src, len); - test_copy_from_to_exact(ValueType::ExternRef, dst, src, len); + test_copy_from_to_exact(ValType::FuncRef, dst, src, len); + test_copy_from_to_exact(ValType::ExternRef, dst, src, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_fill.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_fill.rs index 2b85814c01..72bb738012 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_fill.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_fill.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_fill(ty: ValueType) { +fn test_fill(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -31,11 +31,11 @@ fn test_fill(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn fill() { - test_fill(ValueType::FuncRef); - test_fill(ValueType::ExternRef); + test_fill(ValType::FuncRef); + test_fill(ValType::ExternRef); } -fn testcase_fill_exact(ty: ValueType, len: u32) -> TranslationTest { +fn testcase_fill_exact(ty: ValType, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -52,7 +52,7 @@ fn testcase_fill_exact(ty: ValueType, len: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_fill_exact16(ty: ValueType, len: u32) { +fn test_fill_exact16(ty: ValType, len: u32) { testcase_fill_exact(ty, len) .expect_func_instrs([ Instruction::table_fill_exact( @@ -70,8 +70,8 @@ fn test_fill_exact16(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn fill_exact16() { fn test_for(len: u32) { - test_fill_exact16(ValueType::FuncRef, len); - test_fill_exact16(ValueType::ExternRef, len); + test_fill_exact16(ValType::FuncRef, len); + test_fill_exact16(ValType::ExternRef, len); } test_for(0); test_for(1); @@ -79,7 +79,7 @@ fn fill_exact16() { test_for(u32::from(u16::MAX)); } -fn test_fill_exact(ty: ValueType, len: u32) { +fn test_fill_exact(ty: ValType, len: u32) { testcase_fill_exact(ty, len) .expect_func( ExpectedFunc::new([ @@ -100,14 +100,14 @@ fn test_fill_exact(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn fill_exact() { fn test_for(len: u32) { - test_fill_exact(ValueType::FuncRef, len); - test_fill_exact(ValueType::ExternRef, len); + test_fill_exact(ValType::FuncRef, len); + test_fill_exact(ValType::ExternRef, len); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_fill_at(ty: ValueType, dst: u32) -> TranslationTest { +fn testcase_fill_at(ty: ValType, dst: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -124,7 +124,7 @@ fn testcase_fill_at(ty: ValueType, dst: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_fill_at16(ty: ValueType, dst: u32) { +fn test_fill_at16(ty: ValType, dst: u32) { testcase_fill_at(ty, dst) .expect_func_instrs([ Instruction::table_fill_at(u32imm16(dst), Register::from_i16(1), Register::from_i16(0)), @@ -138,14 +138,14 @@ fn test_fill_at16(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn fill_at16() { fn test_for(dst: u32) { - test_fill_at16(ValueType::FuncRef, dst); - test_fill_at16(ValueType::ExternRef, dst); + test_fill_at16(ValType::FuncRef, dst); + test_fill_at16(ValType::ExternRef, dst); } test_for(0); test_for(u32::from(u16::MAX)); } -fn test_fill_at(ty: ValueType, dst: u32) { +fn test_fill_at(ty: ValType, dst: u32) { testcase_fill_at(ty, dst) .expect_func( ExpectedFunc::new([ @@ -166,14 +166,14 @@ fn test_fill_at(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn fill_at() { fn test_for(dst: u32) { - test_fill_at(ValueType::FuncRef, dst); - test_fill_at(ValueType::ExternRef, dst); + test_fill_at(ValType::FuncRef, dst); + test_fill_at(ValType::ExternRef, dst); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_fill_at_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest { +fn testcase_fill_at_exact(ty: ValType, dst: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -190,7 +190,7 @@ fn testcase_fill_at_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest TranslationTest::from_wat(&wasm) } -fn test_fill_at_exact16(ty: ValueType, dst: u32, len: u32) { +fn test_fill_at_exact16(ty: ValType, dst: u32, len: u32) { testcase_fill_at_exact(ty, dst, len) .expect_func_instrs([ Instruction::table_fill_at_exact(u32imm16(dst), u32imm16(len), Register::from_i16(0)), @@ -204,8 +204,8 @@ fn test_fill_at_exact16(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn fill_at_exact16() { fn test_for(dst: u32, len: u32) { - test_fill_at_exact16(ValueType::FuncRef, dst, len); - test_fill_at_exact16(ValueType::ExternRef, dst, len); + test_fill_at_exact16(ValType::FuncRef, dst, len); + test_fill_at_exact16(ValType::ExternRef, dst, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -215,7 +215,7 @@ fn fill_at_exact16() { } } -fn test_fill_at_exact(ty: ValueType, dst: u32, len: u32) { +fn test_fill_at_exact(ty: ValType, dst: u32, len: u32) { testcase_fill_at_exact(ty, dst, len) .expect_func( ExpectedFunc::new([ @@ -236,8 +236,8 @@ fn test_fill_at_exact(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn fill_at_exact() { fn test_for(dst: u32, len: u32) { - test_fill_at_exact(ValueType::FuncRef, dst, len); - test_fill_at_exact(ValueType::ExternRef, dst, len); + test_fill_at_exact(ValType::FuncRef, dst, len); + test_fill_at_exact(ValType::ExternRef, dst, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -254,11 +254,11 @@ fn fill_at_exact() { } } -fn testcase_fill_at_exact_imm(ty: ValueType, dst: u32, len: u32) -> TranslationTest { +fn testcase_fill_at_exact_imm(ty: ValType, dst: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let ref_ty = match ty { - ValueType::FuncRef => "func", - ValueType::ExternRef => "extern", + ValType::FuncRef => "func", + ValType::ExternRef => "extern", _ => panic!("invalid Wasm reftype"), }; let wasm = format!( @@ -276,7 +276,7 @@ fn testcase_fill_at_exact_imm(ty: ValueType, dst: u32, len: u32) -> TranslationT TranslationTest::from_wat(&wasm) } -fn test_fill_at_exact_imm(ty: ValueType, dst: u32, len: u32) { +fn test_fill_at_exact_imm(ty: ValType, dst: u32, len: u32) { testcase_fill_at_exact_imm(ty, dst, len) .expect_func( ExpectedFunc::new([ @@ -297,8 +297,8 @@ fn test_fill_at_exact_imm(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn fill_at_exact_exact() { fn test_for(dst: u32, len: u32) { - test_fill_at_exact_imm(ValueType::FuncRef, dst, len); - test_fill_at_exact_imm(ValueType::ExternRef, dst, len); + test_fill_at_exact_imm(ValType::FuncRef, dst, len); + test_fill_at_exact_imm(ValType::ExternRef, dst, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_get.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_get.rs index 2b116308d6..1334b3d6c0 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_get.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_get.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_reg(ty: ValueType) { +fn test_reg(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -25,11 +25,11 @@ fn test_reg(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn reg() { - test_reg(ValueType::FuncRef); - test_reg(ValueType::ExternRef); + test_reg(ValType::FuncRef); + test_reg(ValType::ExternRef); } -fn test_imm(ty: ValueType, index: u32) { +fn test_imm(ty: ValType, index: u32) { let display_ty = DisplayValueType::from(ty); let display_index = DisplayWasm::from(index); let wasm = format!( @@ -55,8 +55,8 @@ fn test_imm(ty: ValueType, index: u32) { #[cfg_attr(miri, ignore)] fn imm() { fn test_for(index: u32) { - test_imm(ValueType::FuncRef, index); - test_imm(ValueType::ExternRef, index); + test_imm(ValType::FuncRef, index); + test_imm(ValType::ExternRef, index); } test_for(0); test_for(1); diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_grow.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_grow.rs index c18c572b5c..0514f4d99a 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_grow.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_grow.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_reg(ty: ValueType) { +fn test_reg(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -30,11 +30,11 @@ fn test_reg(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn reg() { - test_reg(ValueType::FuncRef); - test_reg(ValueType::ExternRef); + test_reg(ValType::FuncRef); + test_reg(ValType::ExternRef); } -fn test_imm16(ty: ValueType, delta: u32) { +fn test_imm16(ty: ValType, delta: u32) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -64,8 +64,8 @@ fn test_imm16(ty: ValueType, delta: u32) { #[cfg_attr(miri, ignore)] fn imm16() { fn test_for(delta: u32) { - test_imm16(ValueType::FuncRef, delta); - test_imm16(ValueType::ExternRef, delta); + test_imm16(ValType::FuncRef, delta); + test_imm16(ValType::ExternRef, delta); } test_for(1); test_for(42); @@ -73,7 +73,7 @@ fn imm16() { test_for(u32::from(u16::MAX)); } -fn test_imm_zero(ty: ValueType) { +fn test_imm_zero(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -97,15 +97,15 @@ fn test_imm_zero(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn imm_zero() { - test_imm_zero(ValueType::FuncRef); - test_imm_zero(ValueType::ExternRef); + test_imm_zero(ValType::FuncRef); + test_imm_zero(ValType::ExternRef); } -fn test_imm_value_and_zero(ty: ValueType) { +fn test_imm_value_and_zero(ty: ValType) { let display_ty: DisplayValueType = DisplayValueType::from(ty); let ref_ty = match ty { - ValueType::FuncRef => "func", - ValueType::ExternRef => "extern", + ValType::FuncRef => "func", + ValType::ExternRef => "extern", _ => panic!("invalid Wasm reftype"), }; let wasm = format!( @@ -130,11 +130,11 @@ fn test_imm_value_and_zero(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn imm_value_and_zero() { - test_imm_value_and_zero(ValueType::FuncRef); - test_imm_value_and_zero(ValueType::ExternRef); + test_imm_value_and_zero(ValType::FuncRef); + test_imm_value_and_zero(ValType::ExternRef); } -fn test_imm(ty: ValueType, delta: u32) { +fn test_imm(ty: ValType, delta: u32) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -167,8 +167,8 @@ fn test_imm(ty: ValueType, delta: u32) { #[cfg_attr(miri, ignore)] fn imm() { fn test_for(delta: u32) { - test_imm(ValueType::FuncRef, delta); - test_imm(ValueType::ExternRef, delta); + test_imm(ValType::FuncRef, delta); + test_imm(ValType::ExternRef, delta); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX - 1); diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_init.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_init.rs index aaac54f5c2..c1c1142ecd 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_init.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_init.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_init(ty: ValueType) { +fn test_init(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -33,11 +33,11 @@ fn test_init(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn init() { - test_init(ValueType::FuncRef); - test_init(ValueType::ExternRef); + test_init(ValType::FuncRef); + test_init(ValType::ExternRef); } -fn testcase_init_exact(ty: ValueType, len: u32) -> TranslationTest { +fn testcase_init_exact(ty: ValType, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -55,7 +55,7 @@ fn testcase_init_exact(ty: ValueType, len: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_init_exact16(ty: ValueType, len: u32) { +fn test_init_exact16(ty: ValType, len: u32) { testcase_init_exact(ty, len) .expect_func_instrs([ Instruction::table_init_exact( @@ -74,8 +74,8 @@ fn test_init_exact16(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn init_exact16() { fn test_for(len: u32) { - test_init_exact16(ValueType::FuncRef, len); - test_init_exact16(ValueType::ExternRef, len); + test_init_exact16(ValType::FuncRef, len); + test_init_exact16(ValType::ExternRef, len); } test_for(0); test_for(1); @@ -83,7 +83,7 @@ fn init_exact16() { test_for(u32::from(u16::MAX)); } -fn test_init_exact(ty: ValueType, len: u32) { +fn test_init_exact(ty: ValType, len: u32) { testcase_init_exact(ty, len) .expect_func( ExpectedFunc::new([ @@ -105,14 +105,14 @@ fn test_init_exact(ty: ValueType, len: u32) { #[cfg_attr(miri, ignore)] fn init_exact() { fn test_for(len: u32) { - test_init_exact(ValueType::FuncRef, len); - test_init_exact(ValueType::ExternRef, len); + test_init_exact(ValType::FuncRef, len); + test_init_exact(ValType::ExternRef, len); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_init_from(ty: ValueType, src: u32) -> TranslationTest { +fn testcase_init_from(ty: ValType, src: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -130,7 +130,7 @@ fn testcase_init_from(ty: ValueType, src: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_init_from16(ty: ValueType, src: u32) { +fn test_init_from16(ty: ValType, src: u32) { testcase_init_from(ty, src) .expect_func_instrs([ Instruction::table_init_from( @@ -149,14 +149,14 @@ fn test_init_from16(ty: ValueType, src: u32) { #[cfg_attr(miri, ignore)] fn init_from16() { fn test_for(src: u32) { - test_init_from16(ValueType::FuncRef, src); - test_init_from16(ValueType::ExternRef, src); + test_init_from16(ValType::FuncRef, src); + test_init_from16(ValType::ExternRef, src); } test_for(0); test_for(u32::from(u16::MAX)); } -fn test_init_from(ty: ValueType, src: u32) { +fn test_init_from(ty: ValType, src: u32) { testcase_init_from(ty, src) .expect_func( ExpectedFunc::new([ @@ -178,14 +178,14 @@ fn test_init_from(ty: ValueType, src: u32) { #[cfg_attr(miri, ignore)] fn init_from() { fn test_for(src: u32) { - test_init_from(ValueType::FuncRef, src); - test_init_from(ValueType::ExternRef, src); + test_init_from(ValType::FuncRef, src); + test_init_from(ValType::ExternRef, src); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_init_to(ty: ValueType, dst: u32) -> TranslationTest { +fn testcase_init_to(ty: ValType, dst: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -203,7 +203,7 @@ fn testcase_init_to(ty: ValueType, dst: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_init_to16(ty: ValueType, dst: u32) { +fn test_init_to16(ty: ValType, dst: u32) { testcase_init_to(ty, dst) .expect_func_instrs([ Instruction::table_init_to(u32imm16(dst), Register::from_i16(0), Register::from_i16(1)), @@ -218,14 +218,14 @@ fn test_init_to16(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn init_to16() { fn test_for(dst: u32) { - test_init_to16(ValueType::FuncRef, dst); - test_init_to16(ValueType::ExternRef, dst); + test_init_to16(ValType::FuncRef, dst); + test_init_to16(ValType::ExternRef, dst); } test_for(0); test_for(u32::from(u16::MAX)); } -fn test_init_to(ty: ValueType, dst: u32) { +fn test_init_to(ty: ValType, dst: u32) { testcase_init_to(ty, dst) .expect_func( ExpectedFunc::new([ @@ -247,14 +247,14 @@ fn test_init_to(ty: ValueType, dst: u32) { #[cfg_attr(miri, ignore)] fn init_to() { fn test_for(dst: u32) { - test_init_to(ValueType::FuncRef, dst); - test_init_to(ValueType::ExternRef, dst); + test_init_to(ValType::FuncRef, dst); + test_init_to(ValType::ExternRef, dst); } test_for(u32::from(u16::MAX) + 1); test_for(u32::MAX); } -fn testcase_init_from_to(ty: ValueType, dst: u32, src: u32) -> TranslationTest { +fn testcase_init_from_to(ty: ValType, dst: u32, src: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -272,7 +272,7 @@ fn testcase_init_from_to(ty: ValueType, dst: u32, src: u32) -> TranslationTest { TranslationTest::from_wat(&wasm) } -fn test_init_from_to16(ty: ValueType, dst: u32, src: u32) { +fn test_init_from_to16(ty: ValType, dst: u32, src: u32) { testcase_init_from_to(ty, dst, src) .expect_func_instrs([ Instruction::table_init_from_to(u32imm16(dst), u32imm16(src), Register::from_i16(0)), @@ -287,8 +287,8 @@ fn test_init_from_to16(ty: ValueType, dst: u32, src: u32) { #[cfg_attr(miri, ignore)] fn init_from_to16() { fn test_for(dst: u32, src: u32) { - test_init_from_to16(ValueType::FuncRef, dst, src); - test_init_from_to16(ValueType::ExternRef, dst, src); + test_init_from_to16(ValType::FuncRef, dst, src); + test_init_from_to16(ValType::ExternRef, dst, src); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -298,7 +298,7 @@ fn init_from_to16() { } } -fn test_init_from_to(ty: ValueType, dst: u32, src: u32) { +fn test_init_from_to(ty: ValType, dst: u32, src: u32) { testcase_init_from_to(ty, dst, src) .expect_func( ExpectedFunc::new([ @@ -320,8 +320,8 @@ fn test_init_from_to(ty: ValueType, dst: u32, src: u32) { #[cfg_attr(miri, ignore)] fn init_from_to() { fn test_for(dst: u32, src: u32) { - test_init_from_to(ValueType::FuncRef, dst, src); - test_init_from_to(ValueType::ExternRef, dst, src); + test_init_from_to(ValType::FuncRef, dst, src); + test_init_from_to(ValType::ExternRef, dst, src); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -338,7 +338,7 @@ fn init_from_to() { } } -fn testcase_init_to_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest { +fn testcase_init_to_exact(ty: ValType, dst: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -356,7 +356,7 @@ fn testcase_init_to_exact(ty: ValueType, dst: u32, len: u32) -> TranslationTest TranslationTest::from_wat(&wasm) } -fn test_init_to_exact16(ty: ValueType, dst: u32, len: u32) { +fn test_init_to_exact16(ty: ValType, dst: u32, len: u32) { testcase_init_to_exact(ty, dst, len) .expect_func_instrs([ Instruction::table_init_to_exact(u32imm16(dst), Register::from_i16(0), u32imm16(len)), @@ -371,8 +371,8 @@ fn test_init_to_exact16(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_to_exact16() { fn test_for(dst: u32, len: u32) { - test_init_to_exact16(ValueType::FuncRef, dst, len); - test_init_to_exact16(ValueType::ExternRef, dst, len); + test_init_to_exact16(ValType::FuncRef, dst, len); + test_init_to_exact16(ValType::ExternRef, dst, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -382,7 +382,7 @@ fn init_to_exact16() { } } -fn test_init_to_exact(ty: ValueType, dst: u32, len: u32) { +fn test_init_to_exact(ty: ValType, dst: u32, len: u32) { testcase_init_to_exact(ty, dst, len) .expect_func( ExpectedFunc::new([ @@ -404,8 +404,8 @@ fn test_init_to_exact(ty: ValueType, dst: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_to_exact() { fn test_for(dst: u32, len: u32) { - test_init_to_exact(ValueType::FuncRef, dst, len); - test_init_to_exact(ValueType::ExternRef, dst, len); + test_init_to_exact(ValType::FuncRef, dst, len); + test_init_to_exact(ValType::ExternRef, dst, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -422,7 +422,7 @@ fn init_to_exact() { } } -fn testcase_init_from_exact(ty: ValueType, src: u32, len: u32) -> TranslationTest { +fn testcase_init_from_exact(ty: ValType, src: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -440,7 +440,7 @@ fn testcase_init_from_exact(ty: ValueType, src: u32, len: u32) -> TranslationTes TranslationTest::from_wat(&wasm) } -fn test_init_from_exact16(ty: ValueType, src: u32, len: u32) { +fn test_init_from_exact16(ty: ValType, src: u32, len: u32) { testcase_init_from_exact(ty, src, len) .expect_func_instrs([ Instruction::table_init_from_exact(Register::from_i16(0), u32imm16(src), u32imm16(len)), @@ -455,8 +455,8 @@ fn test_init_from_exact16(ty: ValueType, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_from_exact16() { fn test_for(dst: u32, len: u32) { - test_init_from_exact16(ValueType::FuncRef, dst, len); - test_init_from_exact16(ValueType::ExternRef, dst, len); + test_init_from_exact16(ValType::FuncRef, dst, len); + test_init_from_exact16(ValType::ExternRef, dst, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -466,7 +466,7 @@ fn init_from_exact16() { } } -fn test_init_from_exact(ty: ValueType, src: u32, len: u32) { +fn test_init_from_exact(ty: ValType, src: u32, len: u32) { testcase_init_from_exact(ty, src, len) .expect_func( ExpectedFunc::new([ @@ -488,8 +488,8 @@ fn test_init_from_exact(ty: ValueType, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_from_exact() { fn test_for(src: u32, len: u32) { - test_init_from_exact(ValueType::FuncRef, src, len); - test_init_from_exact(ValueType::ExternRef, src, len); + test_init_from_exact(ValType::FuncRef, src, len); + test_init_from_exact(ValType::ExternRef, src, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { @@ -506,7 +506,7 @@ fn init_from_exact() { } } -fn testcase_init_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) -> TranslationTest { +fn testcase_init_from_to_exact(ty: ValType, dst: u32, src: u32, len: u32) -> TranslationTest { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -524,7 +524,7 @@ fn testcase_init_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) -> T TranslationTest::from_wat(&wasm) } -fn test_init_from_to_exact16(ty: ValueType, dst: u32, src: u32, len: u32) { +fn test_init_from_to_exact16(ty: ValType, dst: u32, src: u32, len: u32) { testcase_init_from_to_exact(ty, dst, src, len) .expect_func_instrs([ Instruction::table_init_from_to_exact(u32imm16(dst), u32imm16(src), u32imm16(len)), @@ -539,8 +539,8 @@ fn test_init_from_to_exact16(ty: ValueType, dst: u32, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_from_to_exact16() { fn test_for(dst: u32, src: u32, len: u32) { - test_init_from_to_exact16(ValueType::FuncRef, dst, src, len); - test_init_from_to_exact16(ValueType::ExternRef, dst, src, len); + test_init_from_to_exact16(ValType::FuncRef, dst, src, len); + test_init_from_to_exact16(ValType::ExternRef, dst, src, len); } let values = [0, 1, u32::from(u16::MAX) - 1, u32::from(u16::MAX)]; for dst in values { @@ -552,7 +552,7 @@ fn init_from_to_exact16() { } } -fn test_init_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) { +fn test_init_from_to_exact(ty: ValType, dst: u32, src: u32, len: u32) { testcase_init_from_to_exact(ty, dst, src, len) .expect_func( ExpectedFunc::new([ @@ -574,8 +574,8 @@ fn test_init_from_to_exact(ty: ValueType, dst: u32, src: u32, len: u32) { #[cfg_attr(miri, ignore)] fn init_from_to_exact() { fn test_for(dst: u32, src: u32, len: u32) { - test_init_from_to_exact(ValueType::FuncRef, dst, src, len); - test_init_from_to_exact(ValueType::ExternRef, dst, src, len); + test_init_from_to_exact(ValType::FuncRef, dst, src, len); + test_init_from_to_exact(ValType::ExternRef, dst, src, len); } let values = [u32::from(u16::MAX) + 1, u32::MAX - 1, u32::MAX]; for dst in values { diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_set.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_set.rs index baf1d39098..49daf3ba27 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_set.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_set.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_reg(ty: ValueType) { +fn test_reg(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -26,11 +26,11 @@ fn test_reg(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn reg() { - test_reg(ValueType::FuncRef); - test_reg(ValueType::ExternRef); + test_reg(ValType::FuncRef); + test_reg(ValType::ExternRef); } -fn test_reg_at(index: u32, value_type: ValueType) { +fn test_reg_at(index: u32, value_type: ValType) { let display_ty = DisplayValueType::from(value_type); let display_index = DisplayWasm::from(index); let wasm = format!( @@ -57,8 +57,8 @@ fn test_reg_at(index: u32, value_type: ValueType) { #[cfg_attr(miri, ignore)] fn reg_at() { fn test_for(index: u32) { - test_reg_at(index, ValueType::FuncRef); - test_reg_at(index, ValueType::ExternRef); + test_reg_at(index, ValType::FuncRef); + test_reg_at(index, ValType::ExternRef); } test_for(0); test_for(u32::MAX); @@ -113,11 +113,11 @@ fn at_imm_funcref() { test_at_imm_funcref(u32::MAX); } -fn test_imm_null(value_type: ValueType) { +fn test_imm_null(value_type: ValType) { let display_ty = DisplayValueType::from(value_type); let ref_id = match value_type { - ValueType::FuncRef => "func", - ValueType::ExternRef => "extern", + ValType::FuncRef => "func", + ValType::ExternRef => "extern", _ => panic!("invalid Wasm reftype"), }; let wasm = format!( @@ -144,15 +144,15 @@ fn test_imm_null(value_type: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn imm_null() { - test_imm_null(ValueType::FuncRef); - test_imm_null(ValueType::ExternRef); + test_imm_null(ValType::FuncRef); + test_imm_null(ValType::ExternRef); } -fn test_at_imm_null(index: u32, value_type: ValueType) { +fn test_at_imm_null(index: u32, value_type: ValType) { let display_ty = DisplayValueType::from(value_type); let ref_id = match value_type { - ValueType::FuncRef => "func", - ValueType::ExternRef => "extern", + ValType::FuncRef => "func", + ValType::ExternRef => "extern", _ => panic!("invalid Wasm reftype"), }; let wasm = format!( @@ -180,8 +180,8 @@ fn test_at_imm_null(index: u32, value_type: ValueType) { #[cfg_attr(miri, ignore)] fn at_imm_null() { fn test_for(index: u32) { - test_at_imm_null(index, ValueType::FuncRef); - test_at_imm_null(index, ValueType::ExternRef); + test_at_imm_null(index, ValType::FuncRef); + test_at_imm_null(index, ValType::ExternRef); } test_for(0); test_for(u32::MAX); diff --git a/crates/wasmi/src/engine/translator/tests/op/table/table_size.rs b/crates/wasmi/src/engine/translator/tests/op/table/table_size.rs index 44c55dcc11..c36b89dbd2 100644 --- a/crates/wasmi/src/engine/translator/tests/op/table/table_size.rs +++ b/crates/wasmi/src/engine/translator/tests/op/table/table_size.rs @@ -1,7 +1,7 @@ use super::*; -use crate::core::ValueType; +use crate::core::ValType; -fn test_reg(ty: ValueType) { +fn test_reg(ty: ValType) { let display_ty = DisplayValueType::from(ty); let wasm = format!( r" @@ -23,6 +23,6 @@ fn test_reg(ty: ValueType) { #[test] #[cfg_attr(miri, ignore)] fn reg() { - test_reg(ValueType::FuncRef); - test_reg(ValueType::ExternRef); + test_reg(ValType::FuncRef); + test_reg(ValType::ExternRef); } diff --git a/crates/wasmi/src/engine/translator/tests/op/unary/conversion.rs b/crates/wasmi/src/engine/translator/tests/op/unary/conversion.rs index a67b88d87d..d74ae0fc08 100644 --- a/crates/wasmi/src/engine/translator/tests/op/unary/conversion.rs +++ b/crates/wasmi/src/engine/translator/tests/op/unary/conversion.rs @@ -94,7 +94,7 @@ macro_rules! signed_trunc_tests { #[test] #[cfg_attr(miri, ignore)] fn imm_ok() { fn consteval_ok(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::from(input).$name().expect("testcase expects Ok result")) + <$output_ty>::from(UntypedVal::from(input).$name().expect("testcase expects Ok result")) } conversion_imm::<$input_ty, $output_ty>(OP, 0.0, consteval_ok); @@ -106,7 +106,7 @@ macro_rules! signed_trunc_tests { #[test] #[cfg_attr(miri, ignore)] fn imm_err() { fn consteval_err(input: $input_ty) -> TrapCode { - UntypedValue::from(input).$name().expect_err("testcase expects Err result") + UntypedVal::from(input).$name().expect_err("testcase expects Err result") } fallible_conversion_imm_err::<$input_ty, $output_ty>(OP, <$input_ty>::NAN, consteval_err); @@ -143,7 +143,7 @@ macro_rules! unsigned_trunc_tests { #[test] #[cfg_attr(miri, ignore)] fn imm_ok() { fn consteval_ok(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::from(input).$name().expect("testcase expects Ok result")) + <$output_ty>::from(UntypedVal::from(input).$name().expect("testcase expects Ok result")) } conversion_imm::<$input_ty, $output_ty>(OP, 0.0, consteval_ok); @@ -154,7 +154,7 @@ macro_rules! unsigned_trunc_tests { #[test] #[cfg_attr(miri, ignore)] fn imm_err() { fn consteval_err(input: $input_ty) -> TrapCode { - UntypedValue::from(input).$name().expect_err("testcase expects Err result") + UntypedVal::from(input).$name().expect_err("testcase expects Err result") } fallible_conversion_imm_err::<$input_ty, $output_ty>(OP, -42.5, consteval_err); @@ -192,7 +192,7 @@ macro_rules! trunc_sat_tests { #[test] #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::$name(input.into())) + <$output_ty>::from(UntypedVal::$name(input.into())) } conversion_imm::<$input_ty, $output_ty>(OP, 0.0, consteval); @@ -236,7 +236,7 @@ macro_rules! convert_tests { #[test] #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::$name(input.into())) + <$output_ty>::from(UntypedVal::$name(input.into())) } conversion_imm::<$input_ty, $output_ty>(OP, 0, consteval); @@ -274,7 +274,7 @@ mod f32_demote_f64 { #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: f64) -> f32 { - f32::from(UntypedValue::from(input).f32_demote_f64()) + f32::from(UntypedVal::from(input).f32_demote_f64()) } conversion_imm::(OP, 0.0, consteval); @@ -300,7 +300,7 @@ mod f64_promote_f32 { #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: f32) -> f64 { - f64::from(UntypedValue::from(input).f64_promote_f32()) + f64::from(UntypedVal::from(input).f64_promote_f32()) } conversion_imm::(OP, 0.0, consteval); @@ -327,7 +327,7 @@ macro_rules! iN_reinterpret_fN_tests { #[test] #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::from(input)) + <$output_ty>::from(UntypedVal::from(input)) } conversion_imm::<$input_ty, $output_ty>(OP, 0.0, consteval); @@ -361,7 +361,7 @@ macro_rules! fN_reinterpret_iN_tests { #[test] #[cfg_attr(miri, ignore)] fn imm() { fn consteval(input: $input_ty) -> $output_ty { - <$output_ty>::from(UntypedValue::from(input)) + <$output_ty>::from(UntypedVal::from(input)) } conversion_imm::<$input_ty, $output_ty>(OP, 0, consteval); diff --git a/crates/wasmi/src/engine/translator/tests/op/unary/mod.rs b/crates/wasmi/src/engine/translator/tests/op/unary/mod.rs index b23b1309e5..cf8bc158d5 100644 --- a/crates/wasmi/src/engine/translator/tests/op/unary/mod.rs +++ b/crates/wasmi/src/engine/translator/tests/op/unary/mod.rs @@ -4,19 +4,19 @@ mod conversion; mod op; use super::*; -use crate::core::{TrapCode, UntypedValue}; +use crate::core::{TrapCode, UntypedVal}; use std::fmt::Display; -use wasm_type::WasmType; +use wasm_type::WasmTy; /// Asserts that the unary Wasm operator `wasm_op` translates properly to a unary Wasmi instruction. fn conversion_reg_with(wasm_op: &str, expected: E) where - I: WasmType, - O: WasmType, + I: WasmTy, + O: WasmTy, E: IntoIterator, { - let param_ty = ::NAME; - let result_ty = ::NAME; + let param_ty = ::NAME; + let result_ty = ::NAME; let wasm = format!( r#" (module @@ -37,8 +37,8 @@ fn conversion_reg( wasm_op: &str, make_instr: fn(result: Register, input: Register) -> Instruction, ) where - I: WasmType, - O: WasmType, + I: WasmTy, + O: WasmTy, { let expected = [ make_instr(Register::from_i16(1), Register::from_i16(0)), @@ -50,7 +50,7 @@ fn conversion_reg( /// Asserts that the unary Wasm operator `wasm_op` translates properly to a unary Wasmi instruction. fn unary_reg(wasm_op: &str, make_instr: fn(result: Register, input: Register) -> Instruction) where - T: WasmType, + T: WasmTy, { conversion_reg::(wasm_op, make_instr) } @@ -58,12 +58,12 @@ where /// Asserts that the unary Wasm operator `wasm_op` translates properly to a unary Wasmi instruction. fn conversion_imm(wasm_op: &str, input: I, eval: fn(input: I) -> O) where - I: WasmType, - O: WasmType, + I: WasmTy, + O: WasmTy, DisplayWasm: Display, { - let param_ty = ::NAME; - let result_ty = ::NAME; + let param_ty = ::NAME; + let result_ty = ::NAME; let wasm_input = DisplayWasm::from(input); let wasm = format!( r#" @@ -76,7 +76,7 @@ where "#, ); let result = eval(input); - let instr = ::return_imm_instr(&result); + let instr = ::return_imm_instr(&result); let mut testcase = TranslationTest::from_wat(&wasm); if let Instruction::ReturnReg { value } = &instr { assert!(value.is_const()); @@ -90,7 +90,7 @@ where /// Asserts that the unary Wasm operator `wasm_op` translates properly to a unary Wasmi instruction. fn unary_imm(wasm_op: &str, input: T, eval: fn(input: T) -> T) where - T: WasmType, + T: WasmTy, DisplayWasm: Display, { conversion_imm::(wasm_op, input, eval) @@ -99,12 +99,12 @@ where /// Asserts that the unary Wasm operator `wasm_op` translates properly to a unary Wasmi instruction. fn fallible_conversion_imm_err(wasm_op: &str, input: I, eval: fn(input: I) -> TrapCode) where - I: WasmType, - O: WasmType, + I: WasmTy, + O: WasmTy, DisplayWasm: Display, { - let param_ty = ::NAME; - let result_ty = ::NAME; + let param_ty = ::NAME; + let result_ty = ::NAME; let wasm_input = DisplayWasm::from(input); let wasm = format!( r#" diff --git a/crates/wasmi/src/engine/translator/tests/op/unary/op.rs b/crates/wasmi/src/engine/translator/tests/op/unary/op.rs index bb287e8f74..dd49321fc6 100644 --- a/crates/wasmi/src/engine/translator/tests/op/unary/op.rs +++ b/crates/wasmi/src/engine/translator/tests/op/unary/op.rs @@ -208,7 +208,7 @@ mod f32_nearest { /// /// More information here: https://github.com/rust-lang/rust/issues/96710 fn f32_nearest(input: f32) -> f32 { - f32::from(UntypedValue::f32_nearest(UntypedValue::from(input))) + f32::from(UntypedVal::f32_nearest(UntypedVal::from(input))) } #[test] @@ -356,7 +356,7 @@ mod f64_nearest { /// /// More information here: https://github.com/rust-lang/rust/issues/96710 fn f64_nearest(input: f64) -> f64 { - f64::from(UntypedValue::f64_nearest(UntypedValue::from(input))) + f64::from(UntypedVal::f64_nearest(UntypedVal::from(input))) } #[test] @@ -394,7 +394,7 @@ mod f64_sqrt { macro_rules! wrap_untyped { ($name:ident) => { - |input| <_>::from(UntypedValue::$name(UntypedValue::from(input))) + |input| <_>::from(UntypedVal::$name(UntypedVal::from(input))) }; } diff --git a/crates/wasmi/src/engine/translator/tests/wasm_type.rs b/crates/wasmi/src/engine/translator/tests/wasm_type.rs index c013e93177..3ecd7be4d2 100644 --- a/crates/wasmi/src/engine/translator/tests/wasm_type.rs +++ b/crates/wasmi/src/engine/translator/tests/wasm_type.rs @@ -1,39 +1,39 @@ -use crate::core::ValueType; +use crate::core::ValType; use crate::{ - core::{UntypedValue, F32}, + core::{UntypedVal, F32}, engine::bytecode::{Const32, Instruction, Register}, }; use core::fmt::Display; -pub trait WasmType: Copy + Display + Into + From { +pub trait WasmTy: Copy + Display + Into + From { const NAME: &'static str; - const VALUE_TYPE: ValueType; + const VALUE_TYPE: ValType; fn return_imm_instr(&self) -> Instruction; } -impl WasmType for u32 { +impl WasmTy for u32 { const NAME: &'static str = "i32"; - const VALUE_TYPE: ValueType = ValueType::I32; + const VALUE_TYPE: ValType = ValType::I32; fn return_imm_instr(&self) -> Instruction { Instruction::return_imm32(*self) } } -impl WasmType for i32 { +impl WasmTy for i32 { const NAME: &'static str = "i32"; - const VALUE_TYPE: ValueType = ValueType::I32; + const VALUE_TYPE: ValType = ValType::I32; fn return_imm_instr(&self) -> Instruction { Instruction::return_imm32(*self) } } -impl WasmType for u64 { +impl WasmTy for u64 { const NAME: &'static str = "i64"; - const VALUE_TYPE: ValueType = ValueType::I64; + const VALUE_TYPE: ValType = ValType::I64; fn return_imm_instr(&self) -> Instruction { match >::try_from(*self as i64).ok() { @@ -43,9 +43,9 @@ impl WasmType for u64 { } } -impl WasmType for i64 { +impl WasmTy for i64 { const NAME: &'static str = "i64"; - const VALUE_TYPE: ValueType = ValueType::I64; + const VALUE_TYPE: ValType = ValType::I64; fn return_imm_instr(&self) -> Instruction { match >::try_from(*self).ok() { @@ -55,18 +55,18 @@ impl WasmType for i64 { } } -impl WasmType for f32 { +impl WasmTy for f32 { const NAME: &'static str = "f32"; - const VALUE_TYPE: ValueType = ValueType::F32; + const VALUE_TYPE: ValType = ValType::F32; fn return_imm_instr(&self) -> Instruction { Instruction::return_imm32(F32::from(*self)) } } -impl WasmType for f64 { +impl WasmTy for f64 { const NAME: &'static str = "f64"; - const VALUE_TYPE: ValueType = ValueType::F64; + const VALUE_TYPE: ValType = ValType::F64; fn return_imm_instr(&self) -> Instruction { match >::try_from(*self).ok() { diff --git a/crates/wasmi/src/engine/translator/typed_value.rs b/crates/wasmi/src/engine/translator/typed_value.rs index 47495498c0..50a2aecb4a 100644 --- a/crates/wasmi/src/engine/translator/typed_value.rs +++ b/crates/wasmi/src/engine/translator/typed_value.rs @@ -1,5 +1,5 @@ use crate::{ - core::{TrapCode, UntypedValue, ValueType, F32, F64}, + core::{TrapCode, UntypedVal, ValType, F32, F64}, ExternRef, FuncRef, }; @@ -7,80 +7,80 @@ use crate::{ /// Types that are associated to a static Wasm type. pub trait Typed { /// The static associated Wasm type. - const TY: ValueType; + const TY: ValType; } macro_rules! impl_typed_for { ( $( $ty:ty => $value_ty:expr );* $(;)? ) => { $( impl Typed for $ty { - const TY: ValueType = $value_ty; + const TY: ValType = $value_ty; } )* }; } impl_typed_for! { - bool => ValueType::I32; - i32 => ValueType::I32; - u32 => ValueType::I32; - i64 => ValueType::I64; - u64 => ValueType::I64; - f32 => ValueType::F32; - f64 => ValueType::F64; - F32 => ValueType::F32; - F64 => ValueType::F64; - FuncRef => ValueType::FuncRef; - ExternRef => ValueType::ExternRef; + bool => ValType::I32; + i32 => ValType::I32; + u32 => ValType::I32; + i64 => ValType::I64; + u64 => ValType::I64; + f32 => ValType::F32; + f64 => ValType::F64; + F32 => ValType::F32; + F64 => ValType::F64; + FuncRef => ValType::FuncRef; + ExternRef => ValType::ExternRef; } -impl From for UntypedValue { - fn from(typed_value: TypedValue) -> Self { +impl From for UntypedVal { + fn from(typed_value: TypedVal) -> Self { typed_value.value } } -/// An [`UntypedValue`] with its assumed [`ValueType`]. +/// An [`UntypedVal`] with its assumed [`ValType`]. /// /// # Note /// -/// We explicitly do not make use of the existing [`Value`] -/// abstraction since [`Value`] is optimized towards being a -/// user facing type whereas [`TypedValue`] is focusing on +/// We explicitly do not make use of the existing [`Val`] +/// abstraction since [`Val`] is optimized towards being a +/// user facing type whereas [`TypedVal`] is focusing on /// performance and efficiency in computations. /// -/// [`Value`]: [`crate::core::Value`] +/// [`Val`]: [`crate::core::Value`] #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct TypedValue { +pub struct TypedVal { /// The type of the value. - ty: ValueType, + ty: ValType, /// The underlying raw value. - value: UntypedValue, + value: UntypedVal, } -impl TypedValue { - /// Create a new [`TypedValue`]. - pub fn new(ty: ValueType, value: UntypedValue) -> Self { +impl TypedVal { + /// Create a new [`TypedVal`]. + pub fn new(ty: ValType, value: UntypedVal) -> Self { Self { ty, value } } - /// Returns the [`ValueType`] of the [`TypedValue`]. - pub fn ty(&self) -> ValueType { + /// Returns the [`ValType`] of the [`TypedVal`]. + pub fn ty(&self) -> ValType { self.ty } - /// Changes the [`ValueType`] of `self` to `ty`. + /// Changes the [`ValType`] of `self` to `ty`. /// /// # Note /// /// This acts similar to a Wasm reinterpret cast and /// the underlying `value` bits are unchanged. - pub fn reinterpret(self, ty: ValueType) -> Self { + pub fn reinterpret(self, ty: ValType) -> Self { Self { ty, ..self } } } -impl From for TypedValue +impl From for TypedVal where - T: Typed + Into, + T: Typed + Into, { fn from(value: T) -> Self { Self::new(::TY, value.into()) @@ -102,8 +102,8 @@ impl ResultType for Result { macro_rules! impl_from_typed_value_for { ( $( impl From for $ty:ty );* $(;)? ) => { $( - impl From for $ty { - fn from(typed_value: TypedValue) -> Self { + impl From for $ty { + fn from(typed_value: TypedVal) -> Self { // # Note // // We only use a `debug_assert` here instead of a proper `assert` @@ -143,7 +143,7 @@ macro_rules! impl_forwarding { debug_assert!(matches!(other.ty(), <$rhs_ty as Typed>::TY)); Ok(Self::new( <<$result_ty as ResultType>::Ok as Typed>::TY, - UntypedValue::$name(UntypedValue::from(self), UntypedValue::from(other))?, + UntypedVal::$name(UntypedVal::from(self), UntypedVal::from(other))?, )) } }; @@ -153,7 +153,7 @@ macro_rules! impl_forwarding { debug_assert!(matches!(other.ty(), <$rhs_ty as Typed>::TY)); Self::new( <$result_ty as Typed>::TY, - UntypedValue::$name(UntypedValue::from(self), UntypedValue::from(other)), + UntypedVal::$name(UntypedVal::from(self), UntypedVal::from(other)), ) } }; @@ -162,7 +162,7 @@ macro_rules! impl_forwarding { debug_assert!(matches!(self.ty(), <$input_ty as Typed>::TY)); Ok(Self::new( <<$result_ty as ResultType>::Ok as Typed>::TY, - UntypedValue::$name(UntypedValue::from(self))?, + UntypedVal::$name(UntypedVal::from(self))?, )) } }; @@ -171,12 +171,12 @@ macro_rules! impl_forwarding { debug_assert!(matches!(self.ty(), <$input_ty as Typed>::TY)); Self::new( <$result_ty as Typed>::TY, - UntypedValue::$name(UntypedValue::from(self)), + UntypedVal::$name(UntypedVal::from(self)), ) } }; } -impl TypedValue { +impl TypedVal { impl_forwarding! { // Comparison Instructions diff --git a/crates/wasmi/src/engine/translator/utils.rs b/crates/wasmi/src/engine/translator/utils.rs index 947812955a..3b212f1c6c 100644 --- a/crates/wasmi/src/engine/translator/utils.rs +++ b/crates/wasmi/src/engine/translator/utils.rs @@ -1,4 +1,4 @@ -use super::{stack::ValueStack, TypedProvider, TypedValue}; +use super::{stack::ValueStack, TypedProvider, TypedVal}; use crate::{ engine::bytecode::{AnyConst16, Const16, Provider, Register, RegisterSpanIter, Sign}, Error, @@ -10,7 +10,7 @@ use crate::{ /// /// This trait provides some utility methods useful for translation. pub trait WasmInteger: - Copy + Eq + From + Into + TryInto + TryInto> + Copy + Eq + From + Into + TryInto + TryInto> { /// Returns the `i16` shift amount. /// @@ -72,7 +72,7 @@ impl WasmInteger for u64 { /// # Note /// /// This trait provides some utility methods useful for translation. -pub trait WasmFloat: Copy + Into + From { +pub trait WasmFloat: Copy + Into + From { /// Returns `true` if `self` is any kind of NaN value. fn is_nan(self) -> bool; diff --git a/crates/wasmi/src/engine/translator/visit.rs b/crates/wasmi/src/engine/translator/visit.rs index c43bbf2da2..3ce93d3394 100644 --- a/crates/wasmi/src/engine/translator/visit.rs +++ b/crates/wasmi/src/engine/translator/visit.rs @@ -14,10 +14,10 @@ use super::{ FuelInfo, FuncTranslator, LabelRef, - TypedValue, + TypedVal, }; use crate::{ - core::{TrapCode, ValueType, F32, F64}, + core::{TrapCode, ValType, F32, F64}, engine::{ bytecode::{self, Const16, Instruction, Provider, Register, SignatureIdx}, translator::AcquiredTarget, @@ -865,7 +865,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { if let Some(value) = init_expr.eval_const() { // Optimization: Access to immutable internally defined global variables // can be replaced with their constant initialization value. - self.alloc.stack.push_const(TypedValue::new(content, value)); + self.alloc.stack.push_const(TypedVal::new(content, value)); return Ok(()); } if let Some(func_index) = init_expr.funcref() { @@ -899,7 +899,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { .get_global(module::GlobalIdx::from(global_index)); debug_assert_eq!(global_type.content(), input.ty()); match global_type.content() { - ValueType::I32 => { + ValType::I32 => { if let Ok(value) = Const16::try_from(i32::from(input)) { self.push_fueled_instr( Instruction::global_set_i32imm16(global, value), @@ -908,7 +908,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { return Ok(()); } } - ValueType::I64 => { + ValType::I64 => { if let Ok(value) = Const16::try_from(i64::from(input)) { self.push_fueled_instr( Instruction::global_set_i64imm16(global, value), @@ -1207,8 +1207,8 @@ impl<'a> VisitOperator<'a> for FuncTranslator { bail_unreachable!(self); let type_hint = WasmiValueType::from(ty).into_inner(); let null = match type_hint { - ValueType::FuncRef => TypedValue::from(FuncRef::null()), - ValueType::ExternRef => TypedValue::from(ExternRef::null()), + ValType::FuncRef => TypedVal::from(FuncRef::null()), + ValType::ExternRef => TypedVal::from(ExternRef::null()), _ => panic!("must be a Wasm reftype"), }; self.alloc.stack.push_const(null); @@ -1246,7 +1246,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative::( Instruction::i32_eq, Instruction::i32_eq_imm16, - TypedValue::i32_eq, + TypedVal::i32_eq, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x == x` is always `true` @@ -1263,7 +1263,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative::( Instruction::i32_ne, Instruction::i32_ne_imm16, - TypedValue::i32_ne, + TypedVal::i32_ne, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x != x` is always `false` @@ -1281,7 +1281,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_lt_s, Instruction::i32_lt_s_imm16, swap_ops!(Instruction::i32_gt_s_imm16), - TypedValue::i32_lt_s, + TypedVal::i32_lt_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -1314,7 +1314,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_lt_u, Instruction::i32_lt_u_imm16, swap_ops!(Instruction::i32_gt_u_imm16), - TypedValue::i32_lt_u, + TypedVal::i32_lt_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -1347,7 +1347,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_gt_s, Instruction::i32_gt_s_imm16, swap_ops!(Instruction::i32_lt_s_imm16), - TypedValue::i32_gt_s, + TypedVal::i32_gt_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -1380,7 +1380,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_gt_u, Instruction::i32_gt_u_imm16, swap_ops!(Instruction::i32_lt_u_imm16), - TypedValue::i32_gt_u, + TypedVal::i32_gt_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -1413,7 +1413,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_le_s, Instruction::i32_le_s_imm16, swap_ops!(Instruction::i32_ge_s_imm16), - TypedValue::i32_le_s, + TypedVal::i32_le_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x <= x` is always `true` @@ -1446,7 +1446,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_le_u, Instruction::i32_le_u_imm16, swap_ops!(Instruction::i32_ge_u_imm16), - TypedValue::i32_le_u, + TypedVal::i32_le_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x <= x` is always `true` @@ -1479,7 +1479,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_ge_s, Instruction::i32_ge_s_imm16, swap_ops!(Instruction::i32_le_s_imm16), - TypedValue::i32_ge_s, + TypedVal::i32_ge_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x >= x` is always `true` @@ -1512,7 +1512,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_ge_u, Instruction::i32_ge_u_imm16, swap_ops!(Instruction::i32_le_u_imm16), - TypedValue::i32_ge_u, + TypedVal::i32_ge_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x >= x` is always `true` @@ -1551,7 +1551,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative::( Instruction::i64_eq, Instruction::i64_eq_imm16, - TypedValue::i64_eq, + TypedVal::i64_eq, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x == x` is always `true` @@ -1568,7 +1568,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative::( Instruction::i64_ne, Instruction::i64_ne_imm16, - TypedValue::i64_ne, + TypedVal::i64_ne, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x != x` is always `false` @@ -1586,7 +1586,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_lt_s, Instruction::i64_lt_s_imm16, swap_ops!(Instruction::i64_gt_s_imm16), - TypedValue::i64_lt_s, + TypedVal::i64_lt_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -1619,7 +1619,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_lt_u, Instruction::i64_lt_u_imm16, swap_ops!(Instruction::i64_gt_u_imm16), - TypedValue::i64_lt_u, + TypedVal::i64_lt_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -1652,7 +1652,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_gt_s, Instruction::i64_gt_s_imm16, swap_ops!(Instruction::i64_lt_s_imm16), - TypedValue::i64_gt_s, + TypedVal::i64_gt_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -1685,7 +1685,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_gt_u, Instruction::i64_gt_u_imm16, swap_ops!(Instruction::i64_lt_u_imm16), - TypedValue::i64_gt_u, + TypedVal::i64_gt_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -1718,7 +1718,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_le_s, Instruction::i64_le_s_imm16, swap_ops!(Instruction::i64_ge_s_imm16), - TypedValue::i64_le_s, + TypedVal::i64_le_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x <= x` is always `true` @@ -1751,7 +1751,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_le_u, Instruction::i64_le_u_imm16, swap_ops!(Instruction::i64_ge_u_imm16), - TypedValue::i64_le_u, + TypedVal::i64_le_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x <= x` is always `true` @@ -1784,7 +1784,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_ge_s, Instruction::i64_ge_s_imm16, swap_ops!(Instruction::i64_le_s_imm16), - TypedValue::i64_ge_s, + TypedVal::i64_ge_s, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x >= x` is always `true` @@ -1817,7 +1817,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_ge_u, Instruction::i64_ge_u_imm16, swap_ops!(Instruction::i64_le_u_imm16), - TypedValue::i64_ge_u, + TypedVal::i64_ge_u, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x >= x` is always `true` @@ -1848,7 +1848,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_eq(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f32_eq, - TypedValue::f32_eq, + TypedVal::f32_eq, Self::no_custom_opt, |this, _reg_in: Register, imm_in: f32| { if imm_in.is_nan() { @@ -1864,7 +1864,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_ne(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f32_ne, - TypedValue::f32_ne, + TypedVal::f32_ne, Self::no_custom_opt, |this, _reg_in: Register, imm_in: f32| { if imm_in.is_nan() { @@ -1880,7 +1880,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_lt(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f32_lt, - TypedValue::f32_lt, + TypedVal::f32_lt, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -1921,7 +1921,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_gt(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f32_gt, - TypedValue::f32_gt, + TypedVal::f32_gt, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -1962,7 +1962,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_le(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f32_le, - TypedValue::f32_le, + TypedVal::f32_le, Self::no_custom_opt, |this, _lhs: Register, rhs: f32| { if rhs.is_nan() { @@ -1986,7 +1986,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_ge(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f32_ge, - TypedValue::f32_ge, + TypedVal::f32_ge, Self::no_custom_opt, |this, _lhs: Register, rhs: f32| { if rhs.is_nan() { @@ -2010,7 +2010,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_eq(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f64_eq, - TypedValue::f64_eq, + TypedVal::f64_eq, Self::no_custom_opt, |this, _reg_in: Register, imm_in: f64| { if imm_in.is_nan() { @@ -2026,7 +2026,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_ne(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f64_ne, - TypedValue::f64_ne, + TypedVal::f64_ne, Self::no_custom_opt, |this, _reg_in: Register, imm_in: f64| { if imm_in.is_nan() { @@ -2042,7 +2042,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_lt(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f64_lt, - TypedValue::f64_lt, + TypedVal::f64_lt, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x < x` is always `false` @@ -2083,7 +2083,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_gt(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f64_gt, - TypedValue::f64_gt, + TypedVal::f64_gt, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `x > x` is always `false` @@ -2124,7 +2124,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_le(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f64_le, - TypedValue::f64_le, + TypedVal::f64_le, Self::no_custom_opt, |this, _lhs: Register, rhs: f64| { if rhs.is_nan() { @@ -2148,7 +2148,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_ge(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f64_ge, - TypedValue::f64_ge, + TypedVal::f64_ge, Self::no_custom_opt, |this, _lhs: Register, rhs: f64| { if rhs.is_nan() { @@ -2170,22 +2170,22 @@ impl<'a> VisitOperator<'a> for FuncTranslator { } fn visit_i32_clz(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_clz, TypedValue::i32_clz) + self.translate_unary(Instruction::i32_clz, TypedVal::i32_clz) } fn visit_i32_ctz(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_ctz, TypedValue::i32_ctz) + self.translate_unary(Instruction::i32_ctz, TypedVal::i32_ctz) } fn visit_i32_popcnt(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_popcnt, TypedValue::i32_popcnt) + self.translate_unary(Instruction::i32_popcnt, TypedVal::i32_popcnt) } fn visit_i32_add(&mut self) -> Self::Output { self.translate_binary_commutative( Instruction::i32_add, Instruction::i32_add_imm16, - TypedValue::i32_add, + TypedVal::i32_add, Self::no_custom_opt, |this, reg: Register, value: i32| { if value == 0 { @@ -2203,7 +2203,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_sub, |_, _, _| unreachable!("`i32.sub r c` is translated as `i32.add r -c`"), Instruction::i32_sub_imm16_rev, - TypedValue::i32_sub, + TypedVal::i32_sub, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `sub x - x` is always `0` @@ -2237,7 +2237,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i32_mul, Instruction::i32_mul_imm16, - TypedValue::i32_mul, + TypedVal::i32_mul, Self::no_custom_opt, |this, reg: Register, value: i32| { if value == 0 { @@ -2260,7 +2260,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_div_s, Instruction::i32_div_s_imm16, Instruction::i32_div_s_imm16_rev, - TypedValue::i32_div_s, + TypedVal::i32_div_s, Self::no_custom_opt, |this, lhs: Register, rhs: i32| { if rhs == 1 { @@ -2278,7 +2278,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_div_u, Instruction::i32_div_u_imm16, Instruction::i32_div_u_imm16_rev, - TypedValue::i32_div_u, + TypedVal::i32_div_u, Self::no_custom_opt, |this, lhs: Register, rhs: u32| { if rhs == 1 { @@ -2296,7 +2296,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_rem_s, Instruction::i32_rem_s_imm16, Instruction::i32_rem_s_imm16_rev, - TypedValue::i32_rem_s, + TypedVal::i32_rem_s, Self::no_custom_opt, |this, _lhs: Register, rhs: i32| { if rhs == 1 || rhs == -1 { @@ -2314,7 +2314,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_rem_u, Instruction::i32_rem_u_imm16, Instruction::i32_rem_u_imm16_rev, - TypedValue::i32_rem_u, + TypedVal::i32_rem_u, Self::no_custom_opt, |this, _lhs: Register, rhs: u32| { if rhs == 1 { @@ -2331,7 +2331,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i32_and, Instruction::i32_and_imm16, - TypedValue::i32_and, + TypedVal::i32_and, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x & x` is always just `x` @@ -2363,7 +2363,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i32_or, Instruction::i32_or_imm16, - TypedValue::i32_or, + TypedVal::i32_or, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x | x` is always just `x` @@ -2395,7 +2395,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i32_xor, Instruction::i32_xor_imm16, - TypedValue::i32_xor, + TypedVal::i32_xor, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x ^ x` is always `0` @@ -2420,7 +2420,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_shl, Instruction::i32_shl_imm, Instruction::i32_shl_imm16_rev, - TypedValue::i32_shl, + TypedVal::i32_shl, Self::no_custom_opt, ) } @@ -2430,7 +2430,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_shr_s, Instruction::i32_shr_s_imm, Instruction::i32_shr_s_imm16_rev, - TypedValue::i32_shr_s, + TypedVal::i32_shr_s, |this, lhs: i32, _rhs: Register| { if lhs == -1 { // Optimization: `-1 >> x` is always `-1` for every valid `x` @@ -2447,7 +2447,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_shr_u, Instruction::i32_shr_u_imm, Instruction::i32_shr_u_imm16_rev, - TypedValue::i32_shr_u, + TypedVal::i32_shr_u, Self::no_custom_opt, ) } @@ -2457,7 +2457,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_rotl, Instruction::i32_rotl_imm, Instruction::i32_rotl_imm16_rev, - TypedValue::i32_rotl, + TypedVal::i32_rotl, |this, lhs: i32, _rhs: Register| { if lhs == -1 { // Optimization: `-1.rotate_left(x)` is always `-1` for every valid `x` @@ -2474,7 +2474,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i32_rotr, Instruction::i32_rotr_imm, Instruction::i32_rotr_imm16_rev, - TypedValue::i32_rotr, + TypedVal::i32_rotr, |this, lhs: i32, _rhs: Register| { if lhs == -1 { // Optimization: `-1.rotate_right(x)` is always `-1` for every valid `x` @@ -2487,22 +2487,22 @@ impl<'a> VisitOperator<'a> for FuncTranslator { } fn visit_i64_clz(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_clz, TypedValue::i64_clz) + self.translate_unary(Instruction::i64_clz, TypedVal::i64_clz) } fn visit_i64_ctz(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_ctz, TypedValue::i64_ctz) + self.translate_unary(Instruction::i64_ctz, TypedVal::i64_ctz) } fn visit_i64_popcnt(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_popcnt, TypedValue::i64_popcnt) + self.translate_unary(Instruction::i64_popcnt, TypedVal::i64_popcnt) } fn visit_i64_add(&mut self) -> Self::Output { self.translate_binary_commutative( Instruction::i64_add, Instruction::i64_add_imm16, - TypedValue::i64_add, + TypedVal::i64_add, Self::no_custom_opt, |this, reg: Register, value: i64| { if value == 0 { @@ -2520,7 +2520,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_sub, |_, _, _| unreachable!("`i64.sub r c` is translated as `i64.add r -c`"), Instruction::i64_sub_imm16_rev, - TypedValue::i64_sub, + TypedVal::i64_sub, |this, lhs: Register, rhs: Register| { if lhs == rhs { // Optimization: `sub x - x` is always `0` @@ -2554,7 +2554,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i64_mul, Instruction::i64_mul_imm16, - TypedValue::i64_mul, + TypedVal::i64_mul, Self::no_custom_opt, |this, reg: Register, value: i64| { if value == 0 { @@ -2577,7 +2577,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_div_s, Instruction::i64_div_s_imm16, Instruction::i64_div_s_imm16_rev, - TypedValue::i64_div_s, + TypedVal::i64_div_s, Self::no_custom_opt, |this, lhs: Register, rhs: i64| { if rhs == 1 { @@ -2595,7 +2595,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_div_u, Instruction::i64_div_u_imm16, Instruction::i64_div_u_imm16_rev, - TypedValue::i64_div_u, + TypedVal::i64_div_u, Self::no_custom_opt, |this, lhs: Register, rhs: u64| { if rhs == 1 { @@ -2613,7 +2613,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_rem_s, Instruction::i64_rem_s_imm16, Instruction::i64_rem_s_imm16_rev, - TypedValue::i64_rem_s, + TypedVal::i64_rem_s, Self::no_custom_opt, |this, _lhs: Register, rhs: i64| { if rhs == 1 || rhs == -1 { @@ -2631,7 +2631,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_rem_u, Instruction::i64_rem_u_imm16, Instruction::i64_rem_u_imm16_rev, - TypedValue::i64_rem_u, + TypedVal::i64_rem_u, Self::no_custom_opt, |this, _lhs: Register, rhs: u64| { if rhs == 1 { @@ -2648,7 +2648,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i64_and, Instruction::i64_and_imm16, - TypedValue::i64_and, + TypedVal::i64_and, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x & x` is always just `x` @@ -2680,7 +2680,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i64_or, Instruction::i64_or_imm16, - TypedValue::i64_or, + TypedVal::i64_or, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x | x` is always just `x` @@ -2712,7 +2712,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_binary_commutative( Instruction::i64_xor, Instruction::i64_xor_imm16, - TypedValue::i64_xor, + TypedVal::i64_xor, |this, lhs, rhs| { if lhs == rhs { // Optimization: `x ^ x` is always `0` @@ -2737,7 +2737,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_shl, Instruction::i64_shl_imm, Instruction::i64_shl_imm16_rev, - TypedValue::i64_shl, + TypedVal::i64_shl, Self::no_custom_opt, ) } @@ -2747,7 +2747,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_shr_s, Instruction::i64_shr_s_imm, Instruction::i64_shr_s_imm16_rev, - TypedValue::i64_shr_s, + TypedVal::i64_shr_s, |this, lhs: i64, _rhs: Register| { if lhs == -1 { // Optimization: `-1 >> x` is always `-1` for every valid `x` @@ -2764,7 +2764,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_shr_u, Instruction::i64_shr_u_imm, Instruction::i64_shr_u_imm16_rev, - TypedValue::i64_shr_u, + TypedVal::i64_shr_u, Self::no_custom_opt, ) } @@ -2774,7 +2774,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_rotl, Instruction::i64_rotl_imm, Instruction::i64_rotl_imm16_rev, - TypedValue::i64_rotl, + TypedVal::i64_rotl, |this, lhs: i64, _rhs: Register| { if lhs == -1 { // Optimization: `-1 >> x` is always `-1` for every valid `x` @@ -2791,7 +2791,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { Instruction::i64_rotr, Instruction::i64_rotr_imm, Instruction::i64_rotr_imm16_rev, - TypedValue::i64_rotr, + TypedVal::i64_rotr, |this, lhs: i64, _rhs: Register| { if lhs == -1 { // Optimization: `-1 >> x` is always `-1` for every valid `x` @@ -2804,37 +2804,37 @@ impl<'a> VisitOperator<'a> for FuncTranslator { } fn visit_f32_abs(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_abs, TypedValue::f32_abs) + self.translate_unary(Instruction::f32_abs, TypedVal::f32_abs) } fn visit_f32_neg(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_neg, TypedValue::f32_neg) + self.translate_unary(Instruction::f32_neg, TypedVal::f32_neg) } fn visit_f32_ceil(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_ceil, TypedValue::f32_ceil) + self.translate_unary(Instruction::f32_ceil, TypedVal::f32_ceil) } fn visit_f32_floor(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_floor, TypedValue::f32_floor) + self.translate_unary(Instruction::f32_floor, TypedVal::f32_floor) } fn visit_f32_trunc(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_trunc, TypedValue::f32_trunc) + self.translate_unary(Instruction::f32_trunc, TypedVal::f32_trunc) } fn visit_f32_nearest(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_nearest, TypedValue::f32_nearest) + self.translate_unary(Instruction::f32_nearest, TypedVal::f32_nearest) } fn visit_f32_sqrt(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_sqrt, TypedValue::f32_sqrt) + self.translate_unary(Instruction::f32_sqrt, TypedVal::f32_sqrt) } fn visit_f32_add(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f32_add, - TypedValue::f32_add, + TypedVal::f32_add, Self::no_custom_opt, Self::no_custom_opt::, ) @@ -2843,7 +2843,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_sub(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f32_sub, - TypedValue::f32_sub, + TypedVal::f32_sub, Self::no_custom_opt, Self::no_custom_opt::, // Unfortunately we cannot optimize for the case that `lhs == 0.0` @@ -2856,7 +2856,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_mul(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f32_mul, - TypedValue::f32_mul, + TypedVal::f32_mul, Self::no_custom_opt, // Unfortunately we cannot apply `x * 0` or `0 * x` optimizations // since Wasm mandates different behaviors if `x` is infinite or @@ -2868,7 +2868,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_div(&mut self) -> Self::Output { self.translate_fbinary::( Instruction::f32_div, - TypedValue::f32_div, + TypedVal::f32_div, Self::no_custom_opt, Self::no_custom_opt, Self::no_custom_opt, @@ -2878,7 +2878,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_min(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f32_min, - TypedValue::f32_min, + TypedVal::f32_min, Self::no_custom_opt, |this, reg: Register, value: f32| { if value.is_infinite() && value.is_sign_positive() { @@ -2894,7 +2894,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f32_max(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f32_max, - TypedValue::f32_max, + TypedVal::f32_max, Self::no_custom_opt, |this, reg: Register, value: f32| { if value.is_infinite() && value.is_sign_negative() { @@ -2911,42 +2911,42 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_fcopysign::( Instruction::f32_copysign, Instruction::f32_copysign_imm, - TypedValue::f32_copysign, + TypedVal::f32_copysign, ) } fn visit_f64_abs(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_abs, TypedValue::f64_abs) + self.translate_unary(Instruction::f64_abs, TypedVal::f64_abs) } fn visit_f64_neg(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_neg, TypedValue::f64_neg) + self.translate_unary(Instruction::f64_neg, TypedVal::f64_neg) } fn visit_f64_ceil(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_ceil, TypedValue::f64_ceil) + self.translate_unary(Instruction::f64_ceil, TypedVal::f64_ceil) } fn visit_f64_floor(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_floor, TypedValue::f64_floor) + self.translate_unary(Instruction::f64_floor, TypedVal::f64_floor) } fn visit_f64_trunc(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_trunc, TypedValue::f64_trunc) + self.translate_unary(Instruction::f64_trunc, TypedVal::f64_trunc) } fn visit_f64_nearest(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_nearest, TypedValue::f64_nearest) + self.translate_unary(Instruction::f64_nearest, TypedVal::f64_nearest) } fn visit_f64_sqrt(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_sqrt, TypedValue::f64_sqrt) + self.translate_unary(Instruction::f64_sqrt, TypedVal::f64_sqrt) } fn visit_f64_add(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f64_add, - TypedValue::f64_add, + TypedVal::f64_add, Self::no_custom_opt, Self::no_custom_opt::, ) @@ -2955,7 +2955,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_sub(&mut self) -> Self::Output { self.translate_fbinary( Instruction::f64_sub, - TypedValue::f64_sub, + TypedVal::f64_sub, Self::no_custom_opt, Self::no_custom_opt::, // Unfortunately we cannot optimize for the case that `lhs == 0.0` @@ -2968,7 +2968,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_mul(&mut self) -> Self::Output { self.translate_fbinary_commutative::( Instruction::f64_mul, - TypedValue::f64_mul, + TypedVal::f64_mul, Self::no_custom_opt, // Unfortunately we cannot apply `x * 0` or `0 * x` optimizations // since Wasm mandates different behaviors if `x` is infinite or @@ -2980,7 +2980,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_div(&mut self) -> Self::Output { self.translate_fbinary::( Instruction::f64_div, - TypedValue::f64_div, + TypedVal::f64_div, Self::no_custom_opt, Self::no_custom_opt, Self::no_custom_opt, @@ -2990,7 +2990,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_min(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f64_min, - TypedValue::f64_min, + TypedVal::f64_min, Self::no_custom_opt, |this, reg: Register, value: f64| { if value.is_infinite() && value.is_sign_positive() { @@ -3006,7 +3006,7 @@ impl<'a> VisitOperator<'a> for FuncTranslator { fn visit_f64_max(&mut self) -> Self::Output { self.translate_fbinary_commutative( Instruction::f64_max, - TypedValue::f64_max, + TypedVal::f64_max, Self::no_custom_opt, |this, reg: Register, value: f64| { if value.is_infinite() && value.is_sign_negative() { @@ -3023,207 +3023,183 @@ impl<'a> VisitOperator<'a> for FuncTranslator { self.translate_fcopysign::( Instruction::f64_copysign, Instruction::f64_copysign_imm, - TypedValue::f64_copysign, + TypedVal::f64_copysign, ) } fn visit_i32_wrap_i64(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_wrap_i64, TypedValue::i32_wrap_i64) + self.translate_unary(Instruction::i32_wrap_i64, TypedVal::i32_wrap_i64) } fn visit_i32_trunc_f32_s(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i32_trunc_f32_s, TypedValue::i32_trunc_f32_s) + self.translate_unary_fallible(Instruction::i32_trunc_f32_s, TypedVal::i32_trunc_f32_s) } fn visit_i32_trunc_f32_u(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i32_trunc_f32_u, TypedValue::i32_trunc_f32_u) + self.translate_unary_fallible(Instruction::i32_trunc_f32_u, TypedVal::i32_trunc_f32_u) } fn visit_i32_trunc_f64_s(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i32_trunc_f64_s, TypedValue::i32_trunc_f64_s) + self.translate_unary_fallible(Instruction::i32_trunc_f64_s, TypedVal::i32_trunc_f64_s) } fn visit_i32_trunc_f64_u(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i32_trunc_f64_u, TypedValue::i32_trunc_f64_u) + self.translate_unary_fallible(Instruction::i32_trunc_f64_u, TypedVal::i32_trunc_f64_u) } fn visit_i64_extend_i32_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_extend_i32_s, TypedValue::i64_extend_i32_s) + self.translate_unary(Instruction::i64_extend_i32_s, TypedVal::i64_extend_i32_s) } fn visit_i64_extend_i32_u(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_extend_i32_u, TypedValue::i64_extend_i32_u) + self.translate_unary(Instruction::i64_extend_i32_u, TypedVal::i64_extend_i32_u) } fn visit_i64_trunc_f32_s(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i64_trunc_f32_s, TypedValue::i64_trunc_f32_s) + self.translate_unary_fallible(Instruction::i64_trunc_f32_s, TypedVal::i64_trunc_f32_s) } fn visit_i64_trunc_f32_u(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i64_trunc_f32_u, TypedValue::i64_trunc_f32_u) + self.translate_unary_fallible(Instruction::i64_trunc_f32_u, TypedVal::i64_trunc_f32_u) } fn visit_i64_trunc_f64_s(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i64_trunc_f64_s, TypedValue::i64_trunc_f64_s) + self.translate_unary_fallible(Instruction::i64_trunc_f64_s, TypedVal::i64_trunc_f64_s) } fn visit_i64_trunc_f64_u(&mut self) -> Self::Output { - self.translate_unary_fallible(Instruction::i64_trunc_f64_u, TypedValue::i64_trunc_f64_u) + self.translate_unary_fallible(Instruction::i64_trunc_f64_u, TypedVal::i64_trunc_f64_u) } fn visit_f32_convert_i32_s(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f32_convert_i32_s, - TypedValue::f32_convert_i32_s, - ) + self.translate_unary(Instruction::f32_convert_i32_s, TypedVal::f32_convert_i32_s) } fn visit_f32_convert_i32_u(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f32_convert_i32_u, - TypedValue::f32_convert_i32_u, - ) + self.translate_unary(Instruction::f32_convert_i32_u, TypedVal::f32_convert_i32_u) } fn visit_f32_convert_i64_s(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f32_convert_i64_s, - TypedValue::f32_convert_i64_s, - ) + self.translate_unary(Instruction::f32_convert_i64_s, TypedVal::f32_convert_i64_s) } fn visit_f32_convert_i64_u(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f32_convert_i64_u, - TypedValue::f32_convert_i64_u, - ) + self.translate_unary(Instruction::f32_convert_i64_u, TypedVal::f32_convert_i64_u) } fn visit_f32_demote_f64(&mut self) -> Self::Output { - self.translate_unary(Instruction::f32_demote_f64, TypedValue::f32_demote_f64) + self.translate_unary(Instruction::f32_demote_f64, TypedVal::f32_demote_f64) } fn visit_f64_convert_i32_s(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f64_convert_i32_s, - TypedValue::f64_convert_i32_s, - ) + self.translate_unary(Instruction::f64_convert_i32_s, TypedVal::f64_convert_i32_s) } fn visit_f64_convert_i32_u(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f64_convert_i32_u, - TypedValue::f64_convert_i32_u, - ) + self.translate_unary(Instruction::f64_convert_i32_u, TypedVal::f64_convert_i32_u) } fn visit_f64_convert_i64_s(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f64_convert_i64_s, - TypedValue::f64_convert_i64_s, - ) + self.translate_unary(Instruction::f64_convert_i64_s, TypedVal::f64_convert_i64_s) } fn visit_f64_convert_i64_u(&mut self) -> Self::Output { - self.translate_unary( - Instruction::f64_convert_i64_u, - TypedValue::f64_convert_i64_u, - ) + self.translate_unary(Instruction::f64_convert_i64_u, TypedVal::f64_convert_i64_u) } fn visit_f64_promote_f32(&mut self) -> Self::Output { - self.translate_unary(Instruction::f64_promote_f32, TypedValue::f64_promote_f32) + self.translate_unary(Instruction::f64_promote_f32, TypedVal::f64_promote_f32) } fn visit_i32_reinterpret_f32(&mut self) -> Self::Output { - self.translate_reinterpret(ValueType::I32) + self.translate_reinterpret(ValType::I32) } fn visit_i64_reinterpret_f64(&mut self) -> Self::Output { - self.translate_reinterpret(ValueType::I64) + self.translate_reinterpret(ValType::I64) } fn visit_f32_reinterpret_i32(&mut self) -> Self::Output { - self.translate_reinterpret(ValueType::F32) + self.translate_reinterpret(ValType::F32) } fn visit_f64_reinterpret_i64(&mut self) -> Self::Output { - self.translate_reinterpret(ValueType::F64) + self.translate_reinterpret(ValType::F64) } fn visit_i32_extend8_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_extend8_s, TypedValue::i32_extend8_s) + self.translate_unary(Instruction::i32_extend8_s, TypedVal::i32_extend8_s) } fn visit_i32_extend16_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i32_extend16_s, TypedValue::i32_extend16_s) + self.translate_unary(Instruction::i32_extend16_s, TypedVal::i32_extend16_s) } fn visit_i64_extend8_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_extend8_s, TypedValue::i64_extend8_s) + self.translate_unary(Instruction::i64_extend8_s, TypedVal::i64_extend8_s) } fn visit_i64_extend16_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_extend16_s, TypedValue::i64_extend16_s) + self.translate_unary(Instruction::i64_extend16_s, TypedVal::i64_extend16_s) } fn visit_i64_extend32_s(&mut self) -> Self::Output { - self.translate_unary(Instruction::i64_extend32_s, TypedValue::i64_extend32_s) + self.translate_unary(Instruction::i64_extend32_s, TypedVal::i64_extend32_s) } fn visit_i32_trunc_sat_f32_s(&mut self) -> Self::Output { self.translate_unary( Instruction::i32_trunc_sat_f32_s, - TypedValue::i32_trunc_sat_f32_s, + TypedVal::i32_trunc_sat_f32_s, ) } fn visit_i32_trunc_sat_f32_u(&mut self) -> Self::Output { self.translate_unary( Instruction::i32_trunc_sat_f32_u, - TypedValue::i32_trunc_sat_f32_u, + TypedVal::i32_trunc_sat_f32_u, ) } fn visit_i32_trunc_sat_f64_s(&mut self) -> Self::Output { self.translate_unary( Instruction::i32_trunc_sat_f64_s, - TypedValue::i32_trunc_sat_f64_s, + TypedVal::i32_trunc_sat_f64_s, ) } fn visit_i32_trunc_sat_f64_u(&mut self) -> Self::Output { self.translate_unary( Instruction::i32_trunc_sat_f64_u, - TypedValue::i32_trunc_sat_f64_u, + TypedVal::i32_trunc_sat_f64_u, ) } fn visit_i64_trunc_sat_f32_s(&mut self) -> Self::Output { self.translate_unary( Instruction::i64_trunc_sat_f32_s, - TypedValue::i64_trunc_sat_f32_s, + TypedVal::i64_trunc_sat_f32_s, ) } fn visit_i64_trunc_sat_f32_u(&mut self) -> Self::Output { self.translate_unary( Instruction::i64_trunc_sat_f32_u, - TypedValue::i64_trunc_sat_f32_u, + TypedVal::i64_trunc_sat_f32_u, ) } fn visit_i64_trunc_sat_f64_s(&mut self) -> Self::Output { self.translate_unary( Instruction::i64_trunc_sat_f64_s, - TypedValue::i64_trunc_sat_f64_s, + TypedVal::i64_trunc_sat_f64_s, ) } fn visit_i64_trunc_sat_f64_u(&mut self) -> Self::Output { self.translate_unary( Instruction::i64_trunc_sat_f64_u, - TypedValue::i64_trunc_sat_f64_u, + TypedVal::i64_trunc_sat_f64_u, ) } diff --git a/crates/wasmi/src/externref.rs b/crates/wasmi/src/externref.rs index a6d3763f0a..0bd1a80074 100644 --- a/crates/wasmi/src/externref.rs +++ b/crates/wasmi/src/externref.rs @@ -1,6 +1,6 @@ use crate::{ collections::arena::ArenaIndex, - core::UntypedValue, + core::UntypedVal, reftype::Transposer, store::Stored, AsContextMut, @@ -105,33 +105,33 @@ fn externref_sizeof() { // size_of(ExternRef) == size_of(ExternObject) == size_of(UntypedValue) use core::mem::size_of; assert_eq!(size_of::(), size_of::()); - assert_eq!(size_of::(), size_of::()); + assert_eq!(size_of::(), size_of::()); assert_eq!(size_of::(), size_of::()); } #[test] fn externref_null_to_zero() { - assert_eq!(UntypedValue::from(ExternRef::null()), UntypedValue::from(0)); - assert!(ExternRef::from(UntypedValue::from(0)).is_null()); + assert_eq!(UntypedVal::from(ExternRef::null()), UntypedVal::from(0)); + assert!(ExternRef::from(UntypedVal::from(0)).is_null()); } -impl From for ExternRef { - fn from(untyped: UntypedValue) -> Self { +impl From for ExternRef { + fn from(untyped: UntypedVal) -> Self { // Safety: This operation is safe since there are no invalid // bit patterns for [`ExternRef`] instances. Therefore // this operation cannot produce invalid [`ExternRef`] - // instances even though the input [`UntypedValue`] + // instances even though the input [`UntypedVal`] // was modified arbitrarily. unsafe { >::from(untyped).reftype }.canonicalize() } } -impl From for UntypedValue { +impl From for UntypedVal { fn from(externref: ExternRef) -> Self { let externref = externref.canonicalize(); // Safety: This operation is safe since there are no invalid - // bit patterns for [`UntypedValue`] instances. Therefore - // this operation cannot produce invalid [`UntypedValue`] + // bit patterns for [`UntypedVal`] instances. Therefore + // this operation cannot produce invalid [`UntypedVal`] // instances even if it was possible to arbitrarily modify // the input [`ExternRef`] instance. Self::from(unsafe { >::new(externref).value }) diff --git a/crates/wasmi/src/func/caller.rs b/crates/wasmi/src/func/caller.rs index 4551adbcf4..9ae8723305 100644 --- a/crates/wasmi/src/func/caller.rs +++ b/crates/wasmi/src/func/caller.rs @@ -17,7 +17,7 @@ impl<'a, T> Caller<'a, T> { /// Creates a new [`Caller`] from the given store context and [`Instance`] handle. pub(crate) fn new(ctx: &'a mut C, instance: Option<&Instance>) -> Self where - C: AsContextMut, + C: AsContextMut, { Self { ctx: ctx.as_context_mut(), @@ -73,22 +73,22 @@ impl<'a, T> Caller<'a, T> { } impl AsContext for Caller<'_, T> { - type UserState = T; + type Data = T; #[inline] - fn as_context(&self) -> StoreContext<'_, Self::UserState> { + fn as_context(&self) -> StoreContext<'_, Self::Data> { self.ctx.as_context() } } impl AsContextMut for Caller<'_, T> { #[inline] - fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { + fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data> { self.ctx.as_context_mut() } } -impl<'a, T: AsContextMut> From<&'a mut T> for Caller<'a, T::UserState> { +impl<'a, T: AsContextMut> From<&'a mut T> for Caller<'a, T::Data> { #[inline] fn from(ctx: &'a mut T) -> Self { Self { diff --git a/crates/wasmi/src/func/func_type.rs b/crates/wasmi/src/func/func_type.rs index a1b70fc79c..357ecd6242 100644 --- a/crates/wasmi/src/func/func_type.rs +++ b/crates/wasmi/src/func/func_type.rs @@ -1,4 +1,4 @@ -use crate::{core::ValueType, func::FuncError, Value}; +use crate::{core::ValType, func::FuncError, Val}; use core::fmt; use std::{sync::Arc, vec::Vec}; @@ -23,14 +23,14 @@ pub enum FuncTypeInner { /// The number of results. len_results: u8, /// The parameter types, followed by the result types, followed by unspecified elements. - params_results: [ValueType; Self::INLINE_SIZE], + params_results: [ValType; Self::INLINE_SIZE], }, /// Stores the value types of the parameters and results on the heap. Big { /// The number of parameters. len_params: u32, /// Combined parameter and result types allocated on the heap. - params_results: Arc<[ValueType]>, + params_results: Arc<[ValType]>, }, } @@ -60,8 +60,8 @@ impl FuncTypeInner { where P: IntoIterator, R: IntoIterator, -

::IntoIter: Iterator + ExactSizeIterator, - ::IntoIter: Iterator + ExactSizeIterator, +

::IntoIter: Iterator + ExactSizeIterator, + ::IntoIter: Iterator + ExactSizeIterator, { let mut params = params.into_iter(); let mut results = results.into_iter(); @@ -89,8 +89,8 @@ impl FuncTypeInner { /// - Does not mutate `params` or `results` if this method returns `None`. pub fn try_new_small(params: &mut P, results: &mut R) -> Option where - P: Iterator + ExactSizeIterator, - R: Iterator + ExactSizeIterator, + P: Iterator + ExactSizeIterator, + R: Iterator + ExactSizeIterator, { let params = params.into_iter(); let results = results.into_iter(); @@ -100,7 +100,7 @@ impl FuncTypeInner { if usize::from(len) > Self::INLINE_SIZE { return None; } - let mut params_results = [ValueType::I32; Self::INLINE_SIZE]; + let mut params_results = [ValType::I32; Self::INLINE_SIZE]; params_results .iter_mut() .zip(params.chain(results)) @@ -115,7 +115,7 @@ impl FuncTypeInner { } /// Returns the parameter types of the function type. - pub fn params(&self) -> &[ValueType] { + pub fn params(&self) -> &[ValType] { match self { FuncTypeInner::Inline { len_params, @@ -130,7 +130,7 @@ impl FuncTypeInner { } /// Returns the result types of the function type. - pub fn results(&self) -> &[ValueType] { + pub fn results(&self) -> &[ValType] { match self { FuncTypeInner::Inline { len_params, @@ -165,7 +165,7 @@ impl FuncTypeInner { } /// Returns the pair of parameter and result types of the function type. - pub(crate) fn params_results(&self) -> (&[ValueType], &[ValueType]) { + pub(crate) fn params_results(&self) -> (&[ValType], &[ValType]) { match self { FuncTypeInner::Inline { len_params, @@ -207,8 +207,8 @@ impl FuncType { where P: IntoIterator, R: IntoIterator, -

::IntoIter: Iterator + ExactSizeIterator, - ::IntoIter: Iterator + ExactSizeIterator, +

::IntoIter: Iterator + ExactSizeIterator, + ::IntoIter: Iterator + ExactSizeIterator, { Self { inner: FuncTypeInner::new(params, results), @@ -216,12 +216,12 @@ impl FuncType { } /// Returns the parameter types of the function type. - pub fn params(&self) -> &[ValueType] { + pub fn params(&self) -> &[ValType] { self.inner.params() } /// Returns the result types of the function type. - pub fn results(&self) -> &[ValueType] { + pub fn results(&self) -> &[ValType] { self.inner.results() } @@ -231,7 +231,7 @@ impl FuncType { } /// Returns the pair of parameter and result types of the function type. - pub(crate) fn params_results(&self) -> (&[ValueType], &[ValueType]) { + pub(crate) fn params_results(&self) -> (&[ValType], &[ValType]) { self.inner.params_results() } @@ -298,13 +298,13 @@ impl FuncType { /// # Panics /// /// If the number of items in `outputs` does not match the number of results of the [`FuncType`]. - pub(crate) fn prepare_outputs(&self, outputs: &mut [Value]) { + pub(crate) fn prepare_outputs(&self, outputs: &mut [Val]) { assert_eq!( self.results().len(), outputs.len(), "must have the same number of items in outputs as results of the function type" ); - let init_values = self.results().iter().copied().map(Value::default); + let init_values = self.results().iter().copied().map(Val::default); outputs .iter_mut() .zip(init_values) @@ -312,24 +312,24 @@ impl FuncType { } } -/// Types that have a [`ValueType`]. +/// Types that have a [`ValType`]. /// /// # Note /// /// Primarily used to allow `match_params` and `match_results` -/// to be called with both [`Value`] and [`ValueType`] parameters. +/// to be called with both [`Val`] and [`ValType`] parameters. pub(crate) trait Ty { - fn ty(&self) -> ValueType; + fn ty(&self) -> ValType; } -impl Ty for ValueType { - fn ty(&self) -> ValueType { +impl Ty for ValType { + fn ty(&self) -> ValType { *self } } -impl Ty for Value { - fn ty(&self) -> ValueType { +impl Ty for Val { + fn ty(&self) -> ValType { self.ty() } } @@ -350,34 +350,24 @@ mod tests { #[test] fn new_works() { let types = [ - &[ValueType::I32][..], - &[ValueType::I64][..], - &[ValueType::F32][..], - &[ValueType::F64][..], - &[ValueType::I32, ValueType::I32][..], - &[ValueType::I32, ValueType::I32, ValueType::I32][..], + &[ValType::I32][..], + &[ValType::I64][..], + &[ValType::F32][..], + &[ValType::F64][..], + &[ValType::I32, ValType::I32][..], + &[ValType::I32, ValType::I32, ValType::I32][..], + &[ValType::I32, ValType::I32, ValType::I32, ValType::I32][..], &[ - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ][..], - &[ - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ValueType::I32, - ][..], - &[ - ValueType::I32, - ValueType::I64, - ValueType::F32, - ValueType::F64, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, ][..], + &[ValType::I32, ValType::I64, ValType::F32, ValType::F64][..], ]; for params in types { for results in types { diff --git a/crates/wasmi/src/func/funcref.rs b/crates/wasmi/src/func/funcref.rs index c1e496c9fe..974b31d339 100644 --- a/crates/wasmi/src/func/funcref.rs +++ b/crates/wasmi/src/func/funcref.rs @@ -1,5 +1,5 @@ use super::Func; -use crate::{core::UntypedValue, reftype::Transposer}; +use crate::{core::UntypedVal, reftype::Transposer}; /// A nullable [`Func`] reference. #[derive(Debug, Default, Copy, Clone)] @@ -23,33 +23,33 @@ fn funcref_sizeof() { // size_of(Func) == size_of(UntypedValue) == size_of(FuncRef) use core::mem::size_of; assert_eq!(size_of::(), size_of::()); - assert_eq!(size_of::(), size_of::()); + assert_eq!(size_of::(), size_of::()); assert_eq!(size_of::(), size_of::()); } #[test] fn funcref_null_to_zero() { - assert_eq!(UntypedValue::from(FuncRef::null()), UntypedValue::from(0)); - assert!(FuncRef::from(UntypedValue::from(0)).is_null()); + assert_eq!(UntypedVal::from(FuncRef::null()), UntypedVal::from(0)); + assert!(FuncRef::from(UntypedVal::from(0)).is_null()); } -impl From for FuncRef { - fn from(untyped: UntypedValue) -> Self { +impl From for FuncRef { + fn from(untyped: UntypedVal) -> Self { // Safety: This union access is safe since there are no invalid // bit patterns for [`FuncRef`] instances. Therefore // this operation cannot produce invalid [`FuncRef`] - // instances even though the input [`UntypedValue`] + // instances even though the input [`UntypedVal`] // was modified arbitrarily. unsafe { >::from(untyped).reftype }.canonicalize() } } -impl From for UntypedValue { +impl From for UntypedVal { fn from(funcref: FuncRef) -> Self { let funcref = funcref.canonicalize(); // Safety: This operation is safe since there are no invalid - // bit patterns for [`UntypedValue`] instances. Therefore - // this operation cannot produce invalid [`UntypedValue`] + // bit patterns for [`UntypedVal`] instances. Therefore + // this operation cannot produce invalid [`UntypedVal`] // instances even if it was possible to arbitrarily modify // the input [`FuncRef`] instance. Self::from(unsafe { >::new(funcref).value }) diff --git a/crates/wasmi/src/func/into_func.rs b/crates/wasmi/src/func/into_func.rs index 023724e053..2da45e3624 100644 --- a/crates/wasmi/src/func/into_func.rs +++ b/crates/wasmi/src/func/into_func.rs @@ -3,7 +3,7 @@ use super::{ TrampolineEntity, }; use crate::{ - core::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedValue, ValueType, F32, F64}, + core::{DecodeUntypedSlice, EncodeUntypedSlice, UntypedVal, ValType, F32, F64}, Caller, Error, ExternRef, @@ -16,10 +16,10 @@ use core::{array, iter::FusedIterator}; pub trait IntoFunc: Send + Sync + 'static { /// The parameters of the host function. #[doc(hidden)] - type Params: WasmTypeList; + type Params: WasmTyList; /// The results of the host function. #[doc(hidden)] - type Results: WasmTypeList; + type Results: WasmTyList; /// Converts the function into its Wasmi signature and its trampoline. #[doc(hidden)] @@ -33,7 +33,7 @@ macro_rules! impl_into_func { F: Fn($($tuple),*) -> R, F: Send + Sync + 'static, $( - $tuple: WasmType, + $tuple: WasmTy, )* R: WasmRet, { @@ -60,7 +60,7 @@ macro_rules! impl_into_func { F: Fn(Caller, $($tuple),*) -> R, F: Send + Sync + 'static, $( - $tuple: WasmType, + $tuple: WasmTy, )* R: WasmRet, { @@ -70,8 +70,8 @@ macro_rules! impl_into_func { #[allow(non_snake_case)] fn into_func(self) -> (FuncType, TrampolineEntity) { let signature = FuncType::new( - ::types(), - ::types(), + ::types(), + ::types(), ); let trampoline = TrampolineEntity::new( move |caller: Caller, params_results: FuncParams| -> Result { @@ -91,7 +91,7 @@ for_each_tuple!(impl_into_func); /// Types and type sequences that can be used as return values of host functions. pub trait WasmRet { #[doc(hidden)] - type Ok: WasmTypeList; + type Ok: WasmTyList; #[doc(hidden)] fn into_fallible(self) -> Result<::Ok, Error>; @@ -99,7 +99,7 @@ pub trait WasmRet { impl WasmRet for T1 where - T1: WasmType, + T1: WasmTy, { type Ok = T1; @@ -111,7 +111,7 @@ where impl WasmRet for Result where - T1: WasmType, + T1: WasmTy, { type Ok = T1; @@ -126,7 +126,7 @@ macro_rules! impl_wasm_return_type { impl<$($tuple),*> WasmRet for ($($tuple,)*) where $( - $tuple: WasmType + $tuple: WasmTy ),* { type Ok = ($($tuple,)*); @@ -140,7 +140,7 @@ macro_rules! impl_wasm_return_type { impl<$($tuple),*> WasmRet for Result<($($tuple,)*), Error> where $( - $tuple: WasmType + $tuple: WasmTy ),* { type Ok = ($($tuple,)*); @@ -155,19 +155,19 @@ macro_rules! impl_wasm_return_type { for_each_tuple!(impl_wasm_return_type); /// Types that can be used as parameters or results of host functions. -pub trait WasmType: From + Into + Send { +pub trait WasmTy: From + Into + Send { /// Returns the value type of the Wasm type. #[doc(hidden)] - fn ty() -> ValueType; + fn ty() -> ValType; } macro_rules! impl_wasm_type { ( $( type $rust_type:ty = $wasmi_type:ident );* $(;)? ) => { $( - impl WasmType for $rust_type { + impl WasmTy for $rust_type { #[inline] - fn ty() -> ValueType { - ValueType::$wasmi_type + fn ty() -> ValType { + ValType::$wasmi_type } } )* @@ -184,7 +184,7 @@ impl_wasm_type! { type ExternRef = ExternRef; } -/// A list of [`WasmType`] types. +/// A list of [`WasmTy`] types. /// /// # Note /// @@ -194,75 +194,75 @@ impl_wasm_type! { /// - Write host function results into a region of the value stack. /// - Iterate over the value types of the Wasm type sequence /// - This is useful to construct host function signatures. -pub trait WasmTypeList: DecodeUntypedSlice + EncodeUntypedSlice + Sized + Send { +pub trait WasmTyList: DecodeUntypedSlice + EncodeUntypedSlice + Sized + Send { /// The number of Wasm types in the list. #[doc(hidden)] const LEN: usize; - /// The [`ValueType`] sequence as array. + /// The [`ValType`] sequence as array. #[doc(hidden)] - type Types: IntoIterator - + AsRef<[ValueType]> - + AsMut<[ValueType]> + type Types: IntoIterator + + AsRef<[ValType]> + + AsMut<[ValType]> + Copy + Clone; - /// The iterator type of the sequence of [`ValueType`]. + /// The iterator type of the sequence of [`ValType`]. #[doc(hidden)] - type TypesIter: ExactSizeIterator + DoubleEndedIterator + FusedIterator; + type TypesIter: ExactSizeIterator + DoubleEndedIterator + FusedIterator; - /// The [`UntypedValue`] sequence as array. + /// The [`UntypedVal`] sequence as array. #[doc(hidden)] - type Values: IntoIterator - + AsRef<[UntypedValue]> - + AsMut<[UntypedValue]> + type Values: IntoIterator + + AsRef<[UntypedVal]> + + AsMut<[UntypedVal]> + Copy + Clone; - /// The iterator type of the sequence of [`Value`]. + /// The iterator type of the sequence of [`Val`]. /// - /// [`Value`]: [`crate::core::Value`] + /// [`Val`]: [`crate::core::Value`] #[doc(hidden)] - type ValuesIter: ExactSizeIterator + DoubleEndedIterator + FusedIterator; + type ValuesIter: ExactSizeIterator + DoubleEndedIterator + FusedIterator; - /// Returns an array representing the [`ValueType`] sequence of `Self`. + /// Returns an array representing the [`ValType`] sequence of `Self`. #[doc(hidden)] fn types() -> Self::Types; - /// Returns an array representing the [`UntypedValue`] sequence of `self`. + /// Returns an array representing the [`UntypedVal`] sequence of `self`. #[doc(hidden)] fn values(self) -> Self::Values; - /// Consumes the [`UntypedValue`] iterator and creates `Self` if possible. + /// Consumes the [`UntypedVal`] iterator and creates `Self` if possible. /// /// Returns `None` if construction of `Self` is impossible. #[doc(hidden)] - fn from_values(values: &[UntypedValue]) -> Option; + fn from_values(values: &[UntypedVal]) -> Option; } -impl WasmTypeList for T1 +impl WasmTyList for T1 where - T1: WasmType, + T1: WasmTy, { const LEN: usize = 1; - type Types = [ValueType; 1]; - type TypesIter = array::IntoIter; - type Values = [UntypedValue; 1]; - type ValuesIter = array::IntoIter; + type Types = [ValType; 1]; + type TypesIter = array::IntoIter; + type Values = [UntypedVal; 1]; + type ValuesIter = array::IntoIter; #[inline] fn types() -> Self::Types { - [::ty()] + [::ty()] } #[inline] fn values(self) -> Self::Values { - [>::into(self)] + [>::into(self)] } #[inline] - fn from_values(values: &[UntypedValue]) -> Option { + fn from_values(values: &[UntypedVal]) -> Option { if let [value] = *values { return Some(value.into()); } @@ -272,23 +272,23 @@ where macro_rules! impl_wasm_type_list { ( $n:literal $( $tuple:ident )* ) => { - impl<$($tuple),*> WasmTypeList for ($($tuple,)*) + impl<$($tuple),*> WasmTyList for ($($tuple,)*) where $( - $tuple: WasmType + $tuple: WasmTy ),* { const LEN: usize = $n; - type Types = [ValueType; $n]; - type TypesIter = array::IntoIter; - type Values = [UntypedValue; $n]; - type ValuesIter = array::IntoIter; + type Types = [ValType; $n]; + type TypesIter = array::IntoIter; + type Values = [UntypedVal; $n]; + type ValuesIter = array::IntoIter; #[inline] fn types() -> Self::Types { [$( - <$tuple as WasmType>::ty() + <$tuple as WasmTy>::ty() ),*] } @@ -297,13 +297,13 @@ macro_rules! impl_wasm_type_list { fn values(self) -> Self::Values { let ($($tuple,)*) = self; [$( - <$tuple as Into>::into($tuple) + <$tuple as Into>::into($tuple) ),*] } #[inline] #[allow(non_snake_case)] - fn from_values(values: &[UntypedValue]) -> Option { + fn from_values(values: &[UntypedVal]) -> Option { if let [$($tuple),*] = *values { return Some( ( $( Into::into($tuple), )* ) diff --git a/crates/wasmi/src/func/mod.rs b/crates/wasmi/src/func/mod.rs index 4d302a891c..03fb08958e 100644 --- a/crates/wasmi/src/func/mod.rs +++ b/crates/wasmi/src/func/mod.rs @@ -11,7 +11,7 @@ pub use self::{ error::FuncError, func_type::FuncType, funcref::FuncRef, - into_func::{IntoFunc, WasmRet, WasmType, WasmTypeList}, + into_func::{IntoFunc, WasmRet, WasmTy, WasmTyList}, typed_func::{TypedFunc, WasmParams, WasmResults}, }; use super::{ @@ -22,7 +22,7 @@ use super::{ StoreContext, Stored, }; -use crate::{collections::arena::ArenaIndex, engine::ResumableCall, Error, Value}; +use crate::{collections::arena::ArenaIndex, engine::ResumableCall, Error, Val}; use core::{fmt, fmt::Debug, num::NonZeroU32}; use std::{boxed::Box, sync::Arc}; @@ -199,19 +199,16 @@ impl HostFuncTrampolineEntity { pub fn new( // engine: &Engine, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Value], &mut [Value]) -> Result<(), Error> - + Send - + Sync - + 'static, + func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Self { // Preprocess parameters and results buffers so that we can reuse those // computations within the closure implementation. We put both parameters // and results into a single buffer which we can split to minimize the // amount of allocations per trampoline invokation. - let params_iter = ty.params().iter().copied().map(Value::default); - let results_iter = ty.results().iter().copied().map(Value::default); + let params_iter = ty.params().iter().copied().map(Val::default); + let results_iter = ty.results().iter().copied().map(Val::default); let len_params = ty.params().len(); - let params_results: Box<[Value]> = params_iter.chain(results_iter).collect(); + let params_results: Box<[Val]> = params_iter.chain(results_iter).collect(); let trampoline = >::new(move |caller, args| { // We are required to clone the buffer because we are operating within a `Fn`. // This way the trampoline closure only has to own a single slice buffer. @@ -274,7 +271,7 @@ impl TrampolineEntity { /// The result is written back into the `outputs` buffer. pub fn call( &self, - mut ctx: impl AsContextMut, + mut ctx: impl AsContextMut, instance: Option<&Instance>, params: FuncParams, ) -> Result { @@ -331,12 +328,9 @@ impl Func { /// created using this constructor have runtime overhead for every invocation that /// can be avoided by using [`Func::wrap`]. pub fn new( - mut ctx: impl AsContextMut, + mut ctx: impl AsContextMut, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Value], &mut [Value]) -> Result<(), Error> - + Send - + Sync - + 'static, + func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Self { let engine = ctx.as_context().store.engine(); let host_func = HostFuncTrampolineEntity::new(ty, func); @@ -351,7 +345,7 @@ impl Func { /// Creates a new host function from the given closure. pub fn wrap( - mut ctx: impl AsContextMut, + mut ctx: impl AsContextMut, func: impl IntoFunc, ) -> Self { let engine = ctx.as_context().store.engine(); @@ -396,9 +390,9 @@ impl Func { /// outputs required by the function signature of `self`. pub fn call( &self, - mut ctx: impl AsContextMut, - inputs: &[Value], - outputs: &mut [Value], + mut ctx: impl AsContextMut, + inputs: &[Val], + outputs: &mut [Val], ) -> Result<(), Error> { self.verify_and_prepare_inputs_outputs(ctx.as_context(), inputs, outputs)?; // Note: Cloning an [`Engine`] is intentionally a cheap operation. @@ -436,9 +430,9 @@ impl Func { /// outputs required by the function signature of `self`. pub fn call_resumable( &self, - mut ctx: impl AsContextMut, - inputs: &[Value], - outputs: &mut [Value], + mut ctx: impl AsContextMut, + inputs: &[Val], + outputs: &mut [Val], ) -> Result { self.verify_and_prepare_inputs_outputs(ctx.as_context(), inputs, outputs)?; // Note: Cloning an [`Engine`] is intentionally a cheap operation. @@ -467,8 +461,8 @@ impl Func { fn verify_and_prepare_inputs_outputs( &self, ctx: impl AsContext, - inputs: &[Value], - outputs: &mut [Value], + inputs: &[Val], + outputs: &mut [Val], ) -> Result<(), FuncError> { let fn_type = self.ty_dedup(ctx.as_context()); ctx.as_context() diff --git a/crates/wasmi/src/func/typed_func.rs b/crates/wasmi/src/func/typed_func.rs index 2a82581e4b..cad323039e 100644 --- a/crates/wasmi/src/func/typed_func.rs +++ b/crates/wasmi/src/func/typed_func.rs @@ -1,6 +1,6 @@ -use super::{into_func::WasmTypeList, Func}; +use super::{into_func::WasmTyList, Func}; use crate::{ - core::UntypedValue, + core::UntypedVal, engine::{CallParams, CallResults}, AsContext, AsContextMut, @@ -68,8 +68,8 @@ where pub(crate) fn new(ctx: impl AsContext, func: Func) -> Result { let func_type = func.ty(&ctx); let (actual_params, actual_results) = ( - ::types(), - ::types(), + ::types(), + ::types(), ); func_type.match_params(actual_params.as_ref())?; func_type.match_results(actual_results.as_ref(), true)?; @@ -142,11 +142,11 @@ impl CallParams for Params where Params: WasmParams, { - type Params = ::ValuesIter; + type Params = ::ValuesIter; #[inline] fn call_params(self) -> Self::Params { - ::values(self).into_iter() + ::values(self).into_iter() } } @@ -184,19 +184,19 @@ where type Results = Results; fn len_results(&self) -> usize { - ::LEN + ::LEN } - fn call_results(self, results: &[UntypedValue]) -> Self::Results { - ::from_values(results) + fn call_results(self, results: &[UntypedVal]) -> Self::Results { + ::from_values(results) .expect("unable to construct typed results from call results") } } /// The typed parameters of a [`TypedFunc`]. -pub trait WasmParams: WasmTypeList {} -impl WasmParams for T where T: WasmTypeList {} +pub trait WasmParams: WasmTyList {} +impl WasmParams for T where T: WasmTyList {} /// The typed results of a [`TypedFunc`]. -pub trait WasmResults: WasmTypeList {} -impl WasmResults for T where T: WasmTypeList {} +pub trait WasmResults: WasmTyList {} +impl WasmResults for T where T: WasmTyList {} diff --git a/crates/wasmi/src/global.rs b/crates/wasmi/src/global.rs index a2e7142f09..e95dc02c0a 100644 --- a/crates/wasmi/src/global.rs +++ b/crates/wasmi/src/global.rs @@ -1,9 +1,9 @@ use super::{AsContext, AsContextMut, Stored}; use crate::{ collections::arena::ArenaIndex, - core::{UntypedValue, ValueType}, + core::{UntypedVal, ValType}, value::WithType, - Value, + Val, }; use core::{fmt, fmt::Display, ptr::NonNull}; @@ -33,9 +33,9 @@ pub enum GlobalError { /// Occurs when trying writing a value with mismatching type to a global variable. TypeMismatch { /// The type of the global variable. - expected: ValueType, + expected: ValType, /// The type of the new value that mismatches the type of the global variable. - encountered: ValueType, + encountered: ValType, }, /// Occurs when a global type does not satisfy the constraints of another. UnsatisfyingGlobalType { @@ -99,22 +99,22 @@ impl Mutability { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct GlobalType { /// The value type of the global variable. - content: ValueType, + content: ValType, /// The mutability of the global variable. mutability: Mutability, } impl GlobalType { - /// Creates a new [`GlobalType`] from the given [`ValueType`] and [`Mutability`]. - pub fn new(content: ValueType, mutability: Mutability) -> Self { + /// Creates a new [`GlobalType`] from the given [`ValType`] and [`Mutability`]. + pub fn new(content: ValType, mutability: Mutability) -> Self { Self { content, mutability, } } - /// Returns the [`ValueType`] of the global variable. - pub fn content(&self) -> ValueType { + /// Returns the [`ValType`] of the global variable. + pub fn content(&self) -> ValType { self.content } @@ -144,14 +144,14 @@ impl GlobalType { #[derive(Debug)] pub struct GlobalEntity { /// The current value of the global variable. - value: UntypedValue, + value: UntypedVal, /// The type of the global variable. ty: GlobalType, } impl GlobalEntity { /// Creates a new global entity with the given initial value and mutability. - pub fn new(initial_value: Value, mutability: Mutability) -> Self { + pub fn new(initial_value: Val, mutability: Mutability) -> Self { Self { ty: GlobalType::new(initial_value.ty(), mutability), value: initial_value.into(), @@ -169,7 +169,7 @@ impl GlobalEntity { /// /// - If the global variable is immutable. /// - If there is a type mismatch between the global variable and the new value. - pub fn set(&mut self, new_value: Value) -> Result<(), GlobalError> { + pub fn set(&mut self, new_value: Val) -> Result<(), GlobalError> { if !self.ty().mutability().is_mut() { return Err(GlobalError::ImmutableWrite); } @@ -191,22 +191,22 @@ impl GlobalEntity { /// for efficient `global.set` through the interpreter which is /// safe since the interpreter only handles validated Wasm code /// where the checks in [`Global::set`] cannot fail. - pub(crate) fn set_untyped(&mut self, new_value: UntypedValue) { + pub(crate) fn set_untyped(&mut self, new_value: UntypedVal) { self.value = new_value; } /// Returns the current value of the global variable. - pub fn get(&self) -> Value { + pub fn get(&self) -> Val { self.get_untyped().with_type(self.ty().content()) } /// Returns the current untyped value of the global variable. - pub(crate) fn get_untyped(&self) -> UntypedValue { + pub(crate) fn get_untyped(&self) -> UntypedVal { self.value } /// Returns a pointer to the untyped value of the global variable. - pub(crate) fn get_untyped_ptr(&mut self) -> NonNull { + pub(crate) fn get_untyped_ptr(&mut self) -> NonNull { NonNull::from(&mut self.value) } } @@ -234,7 +234,7 @@ impl Global { } /// Creates a new global variable to the store. - pub fn new(mut ctx: impl AsContextMut, initial_value: Value, mutability: Mutability) -> Self { + pub fn new(mut ctx: impl AsContextMut, initial_value: Val, mutability: Mutability) -> Self { ctx.as_context_mut() .store .inner @@ -256,7 +256,7 @@ impl Global { /// # Panics /// /// Panics if `ctx` does not own this [`Global`]. - pub fn set(&self, mut ctx: impl AsContextMut, new_value: Value) -> Result<(), GlobalError> { + pub fn set(&self, mut ctx: impl AsContextMut, new_value: Val) -> Result<(), GlobalError> { ctx.as_context_mut() .store .inner @@ -269,7 +269,7 @@ impl Global { /// # Panics /// /// Panics if `ctx` does not own this [`Global`]. - pub fn get(&self, ctx: impl AsContext) -> Value { + pub fn get(&self, ctx: impl AsContext) -> Val { ctx.as_context().store.inner.resolve_global(self).get() } } diff --git a/crates/wasmi/src/lib.rs b/crates/wasmi/src/lib.rs index bc55d08dbf..e62f8816c4 100644 --- a/crates/wasmi/src/lib.rs +++ b/crates/wasmi/src/lib.rs @@ -150,8 +150,8 @@ pub use self::{ WasmParams, WasmResults, WasmRet, - WasmType, - WasmTypeList, + WasmTy, + WasmTyList, }, global::{Global, GlobalType, Mutability}, instance::{Export, ExportsIter, Extern, ExternType, Instance}, @@ -169,7 +169,7 @@ pub use self::{ }, store::{AsContext, AsContextMut, Store, StoreContext, StoreContextMut}, table::{Table, TableType}, - value::Value, + value::Val, }; use self::{ func::{FuncEntity, FuncIdx}, diff --git a/crates/wasmi/src/linker.rs b/crates/wasmi/src/linker.rs index 970e9821e5..f47495cc7a 100644 --- a/crates/wasmi/src/linker.rs +++ b/crates/wasmi/src/linker.rs @@ -17,7 +17,7 @@ use crate::{ MemoryType, Module, TableType, - Value, + Val, }; use core::{ borrow::Borrow, @@ -514,7 +514,7 @@ impl Definition { /// defined host function. /// - This unifies handling of [`Definition::Extern(Extern::Func)`] and /// [`Definition::HostFunc`]. - pub fn as_func(&self, mut ctx: impl AsContextMut) -> Option { + pub fn as_func(&self, mut ctx: impl AsContextMut) -> Option { match self { Definition::Extern(Extern::Func(func)) => Some(*func), Definition::HostFunc(host_func) => { @@ -643,10 +643,7 @@ impl Linker { module: &str, name: &str, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Value], &mut [Value]) -> Result<(), Error> - + Send - + Sync - + 'static, + func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Result<&mut Self, LinkerError> { self.ensure_undefined(module, name)?; let func = HostFuncTrampolineEntity::new(ty, func); @@ -699,7 +696,7 @@ impl Linker { /// If the [`Engine`] of this [`Linker`] and the [`Engine`] of `context` are not the same. pub fn get( &self, - context: impl AsContext, + context: impl AsContext, module: &str, name: &str, ) -> Option { @@ -718,7 +715,7 @@ impl Linker { /// If the [`Engine`] of this [`Linker`] and the [`Engine`] of `context` are not the same. fn get_definition( &self, - context: impl AsContext, + context: impl AsContext, module: &str, name: &str, ) -> Option<&Definition> { @@ -746,7 +743,7 @@ impl Linker { /// - If any imported item does not satisfy its type requirements. pub fn instantiate( &self, - mut context: impl AsContextMut, + mut context: impl AsContextMut, module: &Module, ) -> Result { assert!(Engine::same(self.engine(), context.as_context().engine())); @@ -770,7 +767,7 @@ impl Linker { /// If the imported item does not satisfy constraints set by the [`Module`]. fn process_import( &self, - mut context: impl AsContextMut, + mut context: impl AsContextMut, import: ImportType, ) -> Result { assert!(Engine::same(self.engine(), context.as_context().engine())); @@ -925,10 +922,7 @@ impl LinkerBuilder { module: &str, name: &str, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Value], &mut [Value]) -> Result<(), Error> - + Send - + Sync - + 'static, + func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Result<&mut Self, LinkerError> { self.inner_mut().func_new(module, name, ty, func)?; Ok(self) @@ -1054,10 +1048,7 @@ impl LinkerInner { module: &str, name: &str, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Value], &mut [Value]) -> Result<(), Error> - + Send - + Sync - + 'static, + func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Result<&mut Self, LinkerError> { let func = HostFuncTrampolineEntity::new(ty, func); let key = self.new_import_key(module, name); @@ -1121,7 +1112,7 @@ impl LinkerInner { #[cfg(test)] mod tests { - use crate::core::ValueType; + use crate::core::ValType; use super::*; use crate::Store; @@ -1139,9 +1130,9 @@ mod tests { .func_new( "host", "get_a", - FuncType::new([], [ValueType::I32]), - |ctx: Caller, _params: &[Value], results: &mut [Value]| { - results[0] = Value::from(ctx.data().a); + FuncType::new([], [ValType::I32]), + |ctx: Caller, _params: &[Val], results: &mut [Val]| { + results[0] = Val::from(ctx.data().a); Ok(()) }, ) @@ -1150,8 +1141,8 @@ mod tests { .func_new( "host", "set_a", - FuncType::new([ValueType::I32], []), - |mut ctx: Caller, params: &[Value], _results: &mut [Value]| { + FuncType::new([ValType::I32], []), + |mut ctx: Caller, params: &[Val], _results: &mut [Val]| { ctx.data_mut().a = params[0].i32().unwrap(); Ok(()) }, diff --git a/crates/wasmi/src/module/element.rs b/crates/wasmi/src/module/element.rs index 65333100f3..c083745d53 100644 --- a/crates/wasmi/src/module/element.rs +++ b/crates/wasmi/src/module/element.rs @@ -1,5 +1,5 @@ use super::{ConstExpr, TableIdx}; -use crate::{core::ValueType, module::utils::WasmiValueType}; +use crate::{core::ValType, module::utils::WasmiValueType}; use std::sync::Arc; /// A table element segment within a [`Module`]. @@ -10,7 +10,7 @@ pub struct ElementSegment { /// The kind of the [`ElementSegment`]. kind: ElementSegmentKind, /// The type of elements of the [`ElementSegment`]. - ty: ValueType, + ty: ValType, /// The items of the [`ElementSegment`]. items: ElementSegmentItems, } @@ -127,8 +127,8 @@ impl ElementSegment { &self.kind } - /// Returns the [`ValueType`] of the [`ElementSegment`]. - pub fn ty(&self) -> ValueType { + /// Returns the [`ValType`] of the [`ElementSegment`]. + pub fn ty(&self) -> ValType { self.ty } diff --git a/crates/wasmi/src/module/init_expr.rs b/crates/wasmi/src/module/init_expr.rs index 72cb16c170..5e5b58de18 100644 --- a/crates/wasmi/src/module/init_expr.rs +++ b/crates/wasmi/src/module/init_expr.rs @@ -8,10 +8,10 @@ use super::FuncIdx; use crate::{ - core::{UntypedValue, F32, F64}, + core::{UntypedVal, F32, F64}, ExternRef, FuncRef, - Value, + Val, }; use core::fmt; use smallvec::SmallVec; @@ -20,15 +20,15 @@ use std::boxed::Box; /// Types that allow evluation given an evaluation context. pub trait Eval { /// Evaluates `self` given an [`EvalContext`]. - fn eval(&self, ctx: &dyn EvalContext) -> Option; + fn eval(&self, ctx: &dyn EvalContext) -> Option; } /// A [`ConstExpr`] evaluation context. /// /// Required for evaluating a [`ConstExpr`]. pub trait EvalContext { - /// Returns the [`Value`] of the global value at `index` if any. - fn get_global(&self, index: u32) -> Option; + /// Returns the [`Val`] of the global value at `index` if any. + fn get_global(&self, index: u32) -> Option; /// Returns the [`FuncRef`] of the function at `index` if any. fn get_func(&self, index: u32) -> Option; } @@ -37,7 +37,7 @@ pub trait EvalContext { pub struct EmptyEvalContext; impl EvalContext for EmptyEvalContext { - fn get_global(&self, _index: u32) -> Option { + fn get_global(&self, _index: u32) -> Option { None } @@ -71,11 +71,11 @@ pub enum Op { #[derive(Debug)] pub struct ConstOp { /// The underlying precomputed untyped value. - value: UntypedValue, + value: UntypedVal, } impl Eval for ConstOp { - fn eval(&self, _ctx: &dyn EvalContext) -> Option { + fn eval(&self, _ctx: &dyn EvalContext) -> Option { Some(self.value) } } @@ -89,8 +89,8 @@ pub struct GlobalOp { } impl Eval for GlobalOp { - fn eval(&self, ctx: &dyn EvalContext) -> Option { - ctx.get_global(self.global_index).map(UntypedValue::from) + fn eval(&self, ctx: &dyn EvalContext) -> Option { + ctx.get_global(self.global_index).map(UntypedVal::from) } } @@ -103,8 +103,8 @@ pub struct FuncRefOp { } impl Eval for FuncRefOp { - fn eval(&self, ctx: &dyn EvalContext) -> Option { - ctx.get_func(self.function_index).map(UntypedValue::from) + fn eval(&self, ctx: &dyn EvalContext) -> Option { + ctx.get_func(self.function_index).map(UntypedVal::from) } } @@ -121,7 +121,7 @@ impl Eval for FuncRefOp { #[allow(clippy::type_complexity)] pub struct ExprOp { /// The underlying closure that implements the expression. - expr: Box Option + Send + Sync>, + expr: Box Option + Send + Sync>, } impl fmt::Debug for ExprOp { @@ -131,7 +131,7 @@ impl fmt::Debug for ExprOp { } impl Eval for ExprOp { - fn eval(&self, ctx: &dyn EvalContext) -> Option { + fn eval(&self, ctx: &dyn EvalContext) -> Option { (self.expr)(ctx) } } @@ -140,7 +140,7 @@ impl Op { /// Creates a new constant operator for the given `value`. pub fn constant(value: T) -> Self where - T: Into, + T: Into, { Self::Const(ConstOp { value: value.into().into(), @@ -160,7 +160,7 @@ impl Op { /// Creates a new expression operator for the given `expr`. pub fn expr(expr: T) -> Self where - T: Fn(&dyn EvalContext) -> Option + Send + Sync + 'static, + T: Fn(&dyn EvalContext) -> Option + Send + Sync + 'static, { Self::Expr(ExprOp { expr: Box::new(expr), @@ -169,7 +169,7 @@ impl Op { } impl Eval for Op { - fn eval(&self, ctx: &dyn EvalContext) -> Option { + fn eval(&self, ctx: &dyn EvalContext) -> Option { match self { Op::Const(op) => op.eval(ctx), Op::Global(op) => op.eval(ctx), @@ -191,14 +191,14 @@ pub struct ConstExpr { } impl Eval for ConstExpr { - fn eval(&self, ctx: &dyn EvalContext) -> Option { + fn eval(&self, ctx: &dyn EvalContext) -> Option { self.op.eval(ctx) } } macro_rules! def_expr { ($lhs:ident, $rhs:ident, $expr:expr) => {{ - Op::expr(move |ctx: &dyn EvalContext| -> Option { + Op::expr(move |ctx: &dyn EvalContext| -> Option { let lhs = $lhs.eval(ctx)?; let rhs = $rhs.eval(ctx)?; Some($expr(lhs, rhs)) @@ -217,10 +217,7 @@ impl ConstExpr { /// A buffer required for translation of Wasm const expressions. type TranslationBuffer = SmallVec<[Op; 3]>; /// Convenience function to create the various expression operators. - fn expr_op( - stack: &mut TranslationBuffer, - expr: fn(UntypedValue, UntypedValue) -> UntypedValue, - ) { + fn expr_op(stack: &mut TranslationBuffer, expr: fn(UntypedVal, UntypedVal) -> UntypedVal) { let rhs = stack .pop() .expect("must have rhs operator on the stack due to Wasm validation"); @@ -272,8 +269,8 @@ impl ConstExpr { } wasmparser::Operator::RefNull { ty } => { let value = match ty { - wasmparser::ValType::FuncRef => Value::from(FuncRef::null()), - wasmparser::ValType::ExternRef => Value::from(ExternRef::null()), + wasmparser::ValType::FuncRef => Val::from(FuncRef::null()), + wasmparser::ValType::ExternRef => Val::from(ExternRef::null()), ty => panic!("encountered invalid value type for RefNull: {ty:?}"), }; stack.push(Op::constant(value)); @@ -281,12 +278,12 @@ impl ConstExpr { wasmparser::Operator::RefFunc { function_index } => { stack.push(Op::funcref(function_index)); } - wasmparser::Operator::I32Add => expr_op(&mut stack, UntypedValue::i32_add), - wasmparser::Operator::I32Sub => expr_op(&mut stack, UntypedValue::i32_sub), - wasmparser::Operator::I32Mul => expr_op(&mut stack, UntypedValue::i32_mul), - wasmparser::Operator::I64Add => expr_op(&mut stack, UntypedValue::i64_add), - wasmparser::Operator::I64Sub => expr_op(&mut stack, UntypedValue::i64_sub), - wasmparser::Operator::I64Mul => expr_op(&mut stack, UntypedValue::i64_mul), + wasmparser::Operator::I32Add => expr_op(&mut stack, UntypedVal::i32_add), + wasmparser::Operator::I32Sub => expr_op(&mut stack, UntypedVal::i32_sub), + wasmparser::Operator::I32Mul => expr_op(&mut stack, UntypedVal::i32_mul), + wasmparser::Operator::I64Add => expr_op(&mut stack, UntypedVal::i64_add), + wasmparser::Operator::I64Sub => expr_op(&mut stack, UntypedVal::i64_sub), + wasmparser::Operator::I64Mul => expr_op(&mut stack, UntypedVal::i64_mul), wasmparser::Operator::End => break, op => panic!("encountered invalid Wasm const expression operator: {op:?}"), }; @@ -331,7 +328,7 @@ impl ConstExpr { /// /// This is useful for evaluations during Wasm translation to /// perform optimizations on the translated bytecode. - pub fn eval_const(&self) -> Option { + pub fn eval_const(&self) -> Option { self.eval(&EmptyEvalContext) } @@ -343,9 +340,9 @@ impl ConstExpr { /// # Note /// /// This is useful for evaluation of [`ConstExpr`] during bytecode execution. - pub fn eval_with_context(&self, global_get: G, func_get: F) -> Option + pub fn eval_with_context(&self, global_get: G, func_get: F) -> Option where - G: Fn(u32) -> Value, + G: Fn(u32) -> Val, F: Fn(u32) -> FuncRef, { /// Context that wraps closures representing partial evaluation contexts. @@ -357,10 +354,10 @@ impl ConstExpr { } impl EvalContext for WrappedEvalContext where - G: Fn(u32) -> Value, + G: Fn(u32) -> Val, F: Fn(u32) -> FuncRef, { - fn get_global(&self, index: u32) -> Option { + fn get_global(&self, index: u32) -> Option { Some((self.global_get)(index)) } diff --git a/crates/wasmi/src/module/instantiate/mod.rs b/crates/wasmi/src/module/instantiate/mod.rs index 22674f3f22..67edd779c4 100644 --- a/crates/wasmi/src/module/instantiate/mod.rs +++ b/crates/wasmi/src/module/instantiate/mod.rs @@ -7,7 +7,7 @@ mod tests; pub use self::{error::InstantiationError, pre::InstancePre}; use super::{element::ElementSegmentKind, export, ConstExpr, DataSegmentKind, Module}; use crate::{ - core::UntypedValue, + core::UntypedVal, func::WasmFuncEntity, memory::{DataSegment, MemoryError}, value::WithType, @@ -25,7 +25,7 @@ use crate::{ InstanceEntityBuilder, Memory, Table, - Value, + Val, }; impl Module { @@ -196,7 +196,7 @@ impl Module { .store .check_new_tables_limit(self.len_tables())?; for table_type in self.internal_tables().copied() { - let init = Value::default(table_type.element()); + let init = Val::default(table_type.element()); let table = Table::new(context.as_context_mut(), table_type, init)?; builder.push_table(table); } @@ -252,7 +252,7 @@ impl Module { context: impl AsContext, builder: &InstanceEntityBuilder, init_expr: &ConstExpr, - ) -> UntypedValue { + ) -> UntypedVal { init_expr .eval_with_context( |global_index| builder.get_global(global_index).get(&context), diff --git a/crates/wasmi/src/module/instantiate/tests.rs b/crates/wasmi/src/module/instantiate/tests.rs index 159cb984fd..f5bbd7b27c 100644 --- a/crates/wasmi/src/module/instantiate/tests.rs +++ b/crates/wasmi/src/module/instantiate/tests.rs @@ -7,7 +7,7 @@ //! instances with more than 1 memory (or table) if the Wasm module imported //! those entities. -use crate::core::ValueType; +use crate::core::ValType; use crate::{ instance::InstanceEntity, @@ -21,7 +21,7 @@ use crate::{ Store, Table, TableType, - Value, + Val, }; fn try_instantiate_from_wat(wat: &str) -> Result<(Store<()>, Instance), Error> { @@ -35,8 +35,8 @@ fn try_instantiate_from_wat(wat: &str) -> Result<(Store<()>, Instance), Error> { let memory = Memory::new(&mut store, memory_type)?; linker.define("env", "memory", memory)?; // Define one table that can be used by the tests as import. - let table_type = TableType::new(ValueType::FuncRef, 4, None); - let init = Value::default(table_type.element()); + let table_type = TableType::new(ValType::FuncRef, 4, None); + let init = Val::default(table_type.element()); let table = Table::new(&mut store, table_type, init)?; linker.define("env", "table", table)?; let instance = linker diff --git a/crates/wasmi/src/module/utils.rs b/crates/wasmi/src/module/utils.rs index b5af772d5d..be13ecdb06 100644 --- a/crates/wasmi/src/module/utils.rs +++ b/crates/wasmi/src/module/utils.rs @@ -1,4 +1,4 @@ -use crate::{core::ValueType, FuncType, GlobalType, MemoryType, Mutability, TableType}; +use crate::{core::ValType, FuncType, GlobalType, MemoryType, Mutability, TableType}; impl TableType { /// Creates a new [`TableType`] from the given `wasmparser` primitive. @@ -70,12 +70,12 @@ impl FuncType { /// We do not use the `From` trait here so that this conversion /// routine does not become part of the public API of [`FuncType`]. pub(crate) fn from_wasmparser(func_type: wasmparser::FuncType) -> Self { - /// Returns the [`ValueType`] from the given [`wasmparser::Type`]. + /// Returns the [`ValType`] from the given [`wasmparser::Type`]. /// /// # Panics /// /// If the [`wasmparser::Type`] is not supported by Wasmi. - fn extract_value_type(value_type: &wasmparser::ValType) -> ValueType { + fn extract_value_type(value_type: &wasmparser::ValType) -> ValType { WasmiValueType::from(*value_type).into_inner() } let params = func_type.params().iter().map(extract_value_type); @@ -84,24 +84,24 @@ impl FuncType { } } -/// A Wasmi [`ValueType`]. +/// A Wasmi [`ValType`]. /// /// # Note /// /// This new-type wrapper exists so that we can implement the `From` trait. pub struct WasmiValueType { - inner: ValueType, + inner: ValType, } impl WasmiValueType { - /// Returns the inner [`ValueType`]. - pub fn into_inner(self) -> ValueType { + /// Returns the inner [`ValType`]. + pub fn into_inner(self) -> ValType { self.inner } } -impl From for WasmiValueType { - fn from(value: ValueType) -> Self { +impl From for WasmiValueType { + fn from(value: ValType) -> Self { Self { inner: value } } } @@ -109,13 +109,13 @@ impl From for WasmiValueType { impl From for WasmiValueType { fn from(value_type: wasmparser::ValType) -> Self { match value_type { - wasmparser::ValType::I32 => Self::from(ValueType::I32), - wasmparser::ValType::I64 => Self::from(ValueType::I64), - wasmparser::ValType::F32 => Self::from(ValueType::F32), - wasmparser::ValType::F64 => Self::from(ValueType::F64), + wasmparser::ValType::I32 => Self::from(ValType::I32), + wasmparser::ValType::I64 => Self::from(ValType::I64), + wasmparser::ValType::F32 => Self::from(ValType::F32), + wasmparser::ValType::F64 => Self::from(ValType::F64), wasmparser::ValType::V128 => panic!("wasmi does not support the `simd` Wasm proposal"), - wasmparser::ValType::FuncRef => Self::from(ValueType::FuncRef), - wasmparser::ValType::ExternRef => Self::from(ValueType::ExternRef), + wasmparser::ValType::FuncRef => Self::from(ValType::FuncRef), + wasmparser::ValType::ExternRef => Self::from(ValType::ExternRef), } } } diff --git a/crates/wasmi/src/reftype.rs b/crates/wasmi/src/reftype.rs index 6e25639b4f..40bb065801 100644 --- a/crates/wasmi/src/reftype.rs +++ b/crates/wasmi/src/reftype.rs @@ -1,6 +1,6 @@ -use crate::core::UntypedValue; +use crate::core::UntypedVal; -/// Utility type used to convert between `reftype` and [`UntypedValue`]. +/// Utility type used to convert between `reftype` and [`UntypedVal`]. /// /// # Note /// @@ -29,8 +29,8 @@ impl Transposer { } } -impl From for Transposer { - fn from(untyped: UntypedValue) -> Self { +impl From for Transposer { + fn from(untyped: UntypedVal) -> Self { Transposer { value: u64::from(untyped), } diff --git a/crates/wasmi/src/store.rs b/crates/wasmi/src/store.rs index 91929c6115..41f4c9ab51 100644 --- a/crates/wasmi/src/store.rs +++ b/crates/wasmi/src/store.rs @@ -980,16 +980,16 @@ impl Store { /// A trait used to get shared access to a [`Store`] in Wasmi. pub trait AsContext { /// The user state associated with the [`Store`], aka the `T` in `Store`. - type UserState; + type Data; /// Returns the store context that this type provides access to. - fn as_context(&self) -> StoreContext; + fn as_context(&self) -> StoreContext; } /// A trait used to get exclusive access to a [`Store`] in Wasmi. pub trait AsContextMut: AsContext { /// Returns the store context that this type provides access to. - fn as_context_mut(&mut self) -> StoreContextMut; + fn as_context_mut(&mut self) -> StoreContextMut; } /// A temporary handle to a [`&Store`][`Store`]. @@ -1027,21 +1027,21 @@ impl<'a, T> StoreContext<'a, T> { } } -impl<'a, T: AsContext> From<&'a T> for StoreContext<'a, T::UserState> { +impl<'a, T: AsContext> From<&'a T> for StoreContext<'a, T::Data> { #[inline] fn from(ctx: &'a T) -> Self { ctx.as_context() } } -impl<'a, T: AsContext> From<&'a mut T> for StoreContext<'a, T::UserState> { +impl<'a, T: AsContext> From<&'a mut T> for StoreContext<'a, T::Data> { #[inline] fn from(ctx: &'a mut T) -> Self { T::as_context(ctx) } } -impl<'a, T: AsContextMut> From<&'a mut T> for StoreContextMut<'a, T::UserState> { +impl<'a, T: AsContextMut> From<&'a mut T> for StoreContextMut<'a, T::Data> { #[inline] fn from(ctx: &'a mut T) -> Self { ctx.as_context_mut() @@ -1105,10 +1105,10 @@ impl AsContext for &'_ T where T: AsContext, { - type UserState = T::UserState; + type Data = T::Data; #[inline] - fn as_context(&self) -> StoreContext<'_, T::UserState> { + fn as_context(&self) -> StoreContext<'_, T::Data> { T::as_context(*self) } } @@ -1117,10 +1117,10 @@ impl AsContext for &'_ mut T where T: AsContext, { - type UserState = T::UserState; + type Data = T::Data; #[inline] - fn as_context(&self) -> StoreContext<'_, T::UserState> { + fn as_context(&self) -> StoreContext<'_, T::Data> { T::as_context(*self) } } @@ -1130,32 +1130,32 @@ where T: AsContextMut, { #[inline] - fn as_context_mut(&mut self) -> StoreContextMut<'_, T::UserState> { + fn as_context_mut(&mut self) -> StoreContextMut<'_, T::Data> { T::as_context_mut(*self) } } impl AsContext for StoreContext<'_, T> { - type UserState = T; + type Data = T; #[inline] - fn as_context(&self) -> StoreContext<'_, Self::UserState> { + fn as_context(&self) -> StoreContext<'_, Self::Data> { StoreContext { store: self.store } } } impl AsContext for StoreContextMut<'_, T> { - type UserState = T; + type Data = T; #[inline] - fn as_context(&self) -> StoreContext<'_, Self::UserState> { + fn as_context(&self) -> StoreContext<'_, Self::Data> { StoreContext { store: self.store } } } impl AsContextMut for StoreContextMut<'_, T> { #[inline] - fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { + fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data> { StoreContextMut { store: &mut *self.store, } @@ -1163,17 +1163,17 @@ impl AsContextMut for StoreContextMut<'_, T> { } impl AsContext for Store { - type UserState = T; + type Data = T; #[inline] - fn as_context(&self) -> StoreContext<'_, Self::UserState> { + fn as_context(&self) -> StoreContext<'_, Self::Data> { StoreContext { store: self } } } impl AsContextMut for Store { #[inline] - fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::UserState> { + fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data> { StoreContextMut { store: self } } } diff --git a/crates/wasmi/src/table/element.rs b/crates/wasmi/src/table/element.rs index e117c5284a..1888c6356d 100644 --- a/crates/wasmi/src/table/element.rs +++ b/crates/wasmi/src/table/element.rs @@ -1,6 +1,6 @@ use crate::{ collections::arena::ArenaIndex, - core::ValueType, + core::ValType, module, module::{ConstExpr, ElementSegmentItems}, store::Stored, @@ -82,8 +82,8 @@ impl ElementSegment { /// a need to have an instantiated representation of data segments. #[derive(Debug)] pub struct ElementSegmentEntity { - /// The [`ValueType`] of elements of this [`ElementSegmentEntity`]. - ty: ValueType, + /// The [`ValType`] of elements of this [`ElementSegmentEntity`]. + ty: ValType, /// The underlying items of the instance element segment. /// /// # Note @@ -109,12 +109,12 @@ impl From<&'_ module::ElementSegment> for ElementSegmentEntity { impl ElementSegmentEntity { /// Create an empty [`ElementSegmentEntity`] representing dropped element segments. - fn empty(ty: ValueType) -> Self { + fn empty(ty: ValType) -> Self { Self { ty, items: None } } - /// Returns the [`ValueType`] of elements in the [`ElementSegmentEntity`]. - pub fn ty(&self) -> ValueType { + /// Returns the [`ValType`] of elements in the [`ElementSegmentEntity`]. + pub fn ty(&self) -> ValType { self.ty } diff --git a/crates/wasmi/src/table/error.rs b/crates/wasmi/src/table/error.rs index c04f806665..075f014a9b 100644 --- a/crates/wasmi/src/table/error.rs +++ b/crates/wasmi/src/table/error.rs @@ -1,5 +1,5 @@ use super::TableType; -use crate::core::ValueType; +use crate::core::ValType; use core::{fmt, fmt::Display}; /// Errors that may occur upon operating with table entities. @@ -18,9 +18,9 @@ pub enum TableError { /// Occurs when operating with a [`Table`](crate::Table) and mismatching element types. ElementTypeMismatch { /// Expected element type for the [`Table`](crate::Table). - expected: ValueType, + expected: ValType, /// Encountered element type. - actual: ValueType, + actual: ValType, }, /// Occurs when accessing the table out of bounds. AccessOutOfBounds { diff --git a/crates/wasmi/src/table/mod.rs b/crates/wasmi/src/table/mod.rs index 825ccd3969..9f549689a8 100644 --- a/crates/wasmi/src/table/mod.rs +++ b/crates/wasmi/src/table/mod.rs @@ -5,14 +5,14 @@ pub use self::{ use super::{AsContext, AsContextMut, Stored}; use crate::{ collections::arena::ArenaIndex, - core::{TrapCode, UntypedValue, ValueType}, + core::{TrapCode, UntypedVal, ValType}, error::EntityGrowError, module::FuncIdx, store::{Fuel, FuelError, ResourceLimiterRef}, value::WithType, Func, FuncRef, - Value, + Val, }; use core::cmp::max; use std::{vec, vec::Vec}; @@ -44,7 +44,7 @@ impl ArenaIndex for TableIdx { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct TableType { /// The type of values stored in the [`Table`]. - element: ValueType, + element: ValType, /// The minimum number of elements the [`Table`] must have. min: u32, /// The optional maximum number of elements the [`Table`] can have. @@ -59,15 +59,15 @@ impl TableType { /// # Panics /// /// If `min` is greater than `max`. - pub fn new(element: ValueType, min: u32, max: Option) -> Self { + pub fn new(element: ValType, min: u32, max: Option) -> Self { if let Some(max) = max { assert!(min <= max); } Self { element, min, max } } - /// Returns the [`ValueType`] of elements stored in the [`Table`]. - pub fn element(&self) -> ValueType { + /// Returns the [`ValType`] of elements stored in the [`Table`]. + pub fn element(&self) -> ValType { self.element } @@ -83,8 +83,8 @@ impl TableType { self.max } - /// Returns a [`TableError`] if `ty` does not match the [`Table`] element [`ValueType`]. - fn matches_element_type(&self, ty: ValueType) -> Result<(), TableError> { + /// Returns a [`TableError`] if `ty` does not match the [`Table`] element [`ValType`]. + fn matches_element_type(&self, ty: ValType) -> Result<(), TableError> { let expected = self.element(); let actual = ty; if actual != expected { @@ -144,7 +144,7 @@ impl TableType { #[derive(Debug)] pub struct TableEntity { ty: TableType, - elements: Vec, + elements: Vec, } impl TableEntity { @@ -155,7 +155,7 @@ impl TableEntity { /// If `init` does not match the [`TableType`] element type. pub fn new( ty: TableType, - init: Value, + init: Val, limiter: &mut ResourceLimiterRef<'_>, ) -> Result { ty.matches_element_type(init.ty())?; @@ -203,7 +203,7 @@ impl TableEntity { /// /// # Note /// - /// The newly added elements are initialized to the `init` [`Value`]. + /// The newly added elements are initialized to the `init` [`Val`]. /// /// # Errors /// @@ -212,7 +212,7 @@ impl TableEntity { pub fn grow( &mut self, delta: u32, - init: Value, + init: Val, fuel: Option<&mut Fuel>, limiter: &mut ResourceLimiterRef<'_>, ) -> Result { @@ -230,7 +230,7 @@ impl TableEntity { /// /// This is an internal API that exists for efficiency purposes. /// - /// The newly added elements are initialized to the `init` [`Value`]. + /// The newly added elements are initialized to the `init` [`Val`]. /// /// # Errors /// @@ -238,7 +238,7 @@ impl TableEntity { pub fn grow_untyped( &mut self, delta: u32, - init: UntypedValue, + init: UntypedVal, fuel: Option<&mut Fuel>, limiter: &mut ResourceLimiterRef<'_>, ) -> Result { @@ -283,15 +283,15 @@ impl TableEntity { Ok(current) } - /// Converts the internal [`UntypedValue`] into a [`Value`] for this [`Table`] element type. - fn make_typed(&self, untyped: UntypedValue) -> Value { + /// Converts the internal [`UntypedVal`] into a [`Val`] for this [`Table`] element type. + fn make_typed(&self, untyped: UntypedVal) -> Val { untyped.with_type(self.ty().element()) } /// Returns the [`Table`] element value at `index`. /// /// Returns `None` if `index` is out of bounds. - pub fn get(&self, index: u32) -> Option { + pub fn get(&self, index: u32) -> Option { self.get_untyped(index) .map(|untyped| self.make_typed(untyped)) } @@ -304,27 +304,27 @@ impl TableEntity { /// /// This is a more efficient version of [`Table::get`] for /// internal use only. - pub fn get_untyped(&self, index: u32) -> Option { + pub fn get_untyped(&self, index: u32) -> Option { self.elements.get(index as usize).copied() } - /// Sets the [`Value`] of this [`Table`] at `index`. + /// Sets the [`Val`] of this [`Table`] at `index`. /// /// # Errors /// /// - If `index` is out of bounds. /// - If `value` does not match the [`Table`] element type. - pub fn set(&mut self, index: u32, value: Value) -> Result<(), TableError> { + pub fn set(&mut self, index: u32, value: Val) -> Result<(), TableError> { self.ty().matches_element_type(value.ty())?; self.set_untyped(index, value.into()) } - /// Returns the [`UntypedValue`] of the [`Table`] at `index`. + /// Returns the [`UntypedVal`] of the [`Table`] at `index`. /// /// # Errors /// /// If `index` is out of bounds. - pub fn set_untyped(&mut self, index: u32, value: UntypedValue) -> Result<(), TableError> { + pub fn set_untyped(&mut self, index: u32, value: UntypedVal) -> Result<(), TableError> { let current = self.size(); let untyped = self.elements @@ -395,14 +395,14 @@ impl TableEntity { } // Perform the actual table initialization. match table_type.element() { - ValueType::FuncRef => { + ValType::FuncRef => { // Initialize element interpreted as Wasm `funrefs`. dst_items.iter_mut().zip(src_items).for_each(|(dst, src)| { let func_or_null = src.funcref().map(FuncIdx::into_u32).map(&get_func); *dst = FuncRef::new(func_or_null).into(); }); } - ValueType::ExternRef => { + ValType::ExternRef => { // Initialize element interpreted as Wasm `externrefs`. dst_items.iter_mut().zip(src_items).for_each(|(dst, src)| { *dst = src.eval_const().expect("must evaluate to some value"); @@ -498,7 +498,7 @@ impl TableEntity { pub fn fill( &mut self, dst: u32, - val: Value, + val: Val, len: u32, fuel: Option<&mut Fuel>, ) -> Result<(), TrapCode> { @@ -526,7 +526,7 @@ impl TableEntity { pub fn fill_untyped( &mut self, dst: u32, - val: UntypedValue, + val: UntypedVal, len: u32, fuel: Option<&mut Fuel>, ) -> Result<(), TrapCode> { @@ -566,7 +566,7 @@ impl Table { /// # Errors /// /// If `init` does not match the [`TableType`] element type. - pub fn new(mut ctx: impl AsContextMut, ty: TableType, init: Value) -> Result { + pub fn new(mut ctx: impl AsContextMut, ty: TableType, init: Val) -> Result { let (inner, mut resource_limiter) = ctx .as_context_mut() .store @@ -618,7 +618,7 @@ impl Table { /// /// # Note /// - /// The newly added elements are initialized to the `init` [`Value`]. + /// The newly added elements are initialized to the `init` [`Val`]. /// /// # Errors /// @@ -632,7 +632,7 @@ impl Table { &self, mut ctx: impl AsContextMut, delta: u32, - init: Value, + init: Val, ) -> Result { let (inner, mut limiter) = ctx .as_context_mut() @@ -657,11 +657,11 @@ impl Table { /// # Panics /// /// Panics if `ctx` does not own this [`Table`]. - pub fn get(&self, ctx: impl AsContext, index: u32) -> Option { + pub fn get(&self, ctx: impl AsContext, index: u32) -> Option { ctx.as_context().store.inner.resolve_table(self).get(index) } - /// Sets the [`Value`] of this [`Table`] at `index`. + /// Sets the [`Val`] of this [`Table`] at `index`. /// /// # Errors /// @@ -675,7 +675,7 @@ impl Table { &self, mut ctx: impl AsContextMut, index: u32, - value: Value, + value: Val, ) -> Result<(), TableError> { ctx.as_context_mut() .store @@ -758,7 +758,7 @@ impl Table { &self, mut ctx: impl AsContextMut, dst: u32, - val: Value, + val: Val, len: u32, ) -> Result<(), TrapCode> { ctx.as_context_mut() diff --git a/crates/wasmi/src/table/tests.rs b/crates/wasmi/src/table/tests.rs index 1abe2f2acd..721d9b64f9 100644 --- a/crates/wasmi/src/table/tests.rs +++ b/crates/wasmi/src/table/tests.rs @@ -1,10 +1,10 @@ use super::*; -fn table_type(element: ValueType, minimum: u32, maximum: impl Into>) -> TableType { +fn table_type(element: ValType, minimum: u32, maximum: impl Into>) -> TableType { TableType::new(element, minimum, maximum.into()) } -use ValueType::{F64, I32}; +use ValType::{F64, I32}; #[test] fn subtyping_works() { diff --git a/crates/wasmi/src/value.rs b/crates/wasmi/src/value.rs index 469a98e4fc..68fd7c2344 100644 --- a/crates/wasmi/src/value.rs +++ b/crates/wasmi/src/value.rs @@ -1,5 +1,5 @@ use crate::{ - core::{UntypedValue, ValueType, F32, F64}, + core::{UntypedVal, ValType, F32, F64}, ExternRef, Func, FuncRef, @@ -11,38 +11,38 @@ pub trait WithType { type Output; /// Converts `self` to [`Self::Output`] using `ty`. - fn with_type(self, ty: ValueType) -> Self::Output; + fn with_type(self, ty: ValType) -> Self::Output; } -impl WithType for UntypedValue { - type Output = Value; +impl WithType for UntypedVal { + type Output = Val; - fn with_type(self, ty: ValueType) -> Self::Output { + fn with_type(self, ty: ValType) -> Self::Output { match ty { - ValueType::I32 => Value::I32(self.into()), - ValueType::I64 => Value::I64(self.into()), - ValueType::F32 => Value::F32(self.into()), - ValueType::F64 => Value::F64(self.into()), - ValueType::FuncRef => Value::FuncRef(self.into()), - ValueType::ExternRef => Value::ExternRef(self.into()), + ValType::I32 => Val::I32(self.into()), + ValType::I64 => Val::I64(self.into()), + ValType::F32 => Val::F32(self.into()), + ValType::F64 => Val::F64(self.into()), + ValType::FuncRef => Val::FuncRef(self.into()), + ValType::ExternRef => Val::ExternRef(self.into()), } } } -impl From for UntypedValue { - fn from(value: Value) -> Self { +impl From for UntypedVal { + fn from(value: Val) -> Self { match value { - Value::I32(value) => value.into(), - Value::I64(value) => value.into(), - Value::F32(value) => value.into(), - Value::F64(value) => value.into(), - Value::FuncRef(value) => value.into(), - Value::ExternRef(value) => value.into(), + Val::I32(value) => value.into(), + Val::I64(value) => value.into(), + Val::F32(value) => value.into(), + Val::F64(value) => value.into(), + Val::FuncRef(value) => value.into(), + Val::ExternRef(value) => value.into(), } } } -/// Runtime representation of a value. +/// Runtime representation of a Wasm value. /// /// Wasm code manipulate values of the four basic value types: /// integers and floating-point (IEEE 754-2008) data of 32 or 64 bit width each, respectively. @@ -50,7 +50,7 @@ impl From for UntypedValue { /// There is no distinction between signed and unsigned integer types. Instead, integers are /// interpreted by respective operations as either unsigned or signed in two’s complement representation. #[derive(Clone, Debug)] -pub enum Value { +pub enum Val { /// Value of 32-bit signed or unsigned integer. I32(i32), /// Value of 64-bit signed or unsigned integer. @@ -65,30 +65,30 @@ pub enum Value { ExternRef(ExternRef), } -impl Value { +impl Val { /// Creates new default value of given type. #[inline] - pub fn default(value_type: ValueType) -> Self { + pub fn default(value_type: ValType) -> Self { match value_type { - ValueType::I32 => Self::I32(0), - ValueType::I64 => Self::I64(0), - ValueType::F32 => Self::F32(0f32.into()), - ValueType::F64 => Self::F64(0f64.into()), - ValueType::FuncRef => Self::from(FuncRef::null()), - ValueType::ExternRef => Self::from(ExternRef::null()), + ValType::I32 => Self::I32(0), + ValType::I64 => Self::I64(0), + ValType::F32 => Self::F32(0f32.into()), + ValType::F64 => Self::F64(0f64.into()), + ValType::FuncRef => Self::from(FuncRef::null()), + ValType::ExternRef => Self::from(ExternRef::null()), } } /// Get variable type for this value. #[inline] - pub fn ty(&self) -> ValueType { + pub fn ty(&self) -> ValType { match *self { - Self::I32(_) => ValueType::I32, - Self::I64(_) => ValueType::I64, - Self::F32(_) => ValueType::F32, - Self::F64(_) => ValueType::F64, - Self::FuncRef(_) => ValueType::FuncRef, - Self::ExternRef(_) => ValueType::ExternRef, + Self::I32(_) => ValType::I32, + Self::I64(_) => ValType::I64, + Self::F32(_) => ValType::F32, + Self::F64(_) => ValType::F64, + Self::FuncRef(_) => ValType::FuncRef, + Self::ExternRef(_) => ValType::ExternRef, } } @@ -141,49 +141,49 @@ impl Value { } } -impl From for Value { +impl From for Val { #[inline] fn from(val: i32) -> Self { Self::I32(val) } } -impl From for Value { +impl From for Val { #[inline] fn from(val: i64) -> Self { Self::I64(val) } } -impl From for Value { +impl From for Val { #[inline] fn from(val: F32) -> Self { Self::F32(val) } } -impl From for Value { +impl From for Val { #[inline] fn from(val: F64) -> Self { Self::F64(val) } } -impl From for Value { +impl From for Val { #[inline] fn from(funcref: FuncRef) -> Self { Self::FuncRef(funcref) } } -impl From for Value { +impl From for Val { #[inline] fn from(func: Func) -> Self { Self::FuncRef(FuncRef::new(func)) } } -impl From for Value { +impl From for Val { #[inline] fn from(externref: ExternRef) -> Self { Self::ExternRef(externref) diff --git a/crates/wasmi/tests/e2e/v1/func.rs b/crates/wasmi/tests/e2e/v1/func.rs index ec4c276228..6dc6bad911 100644 --- a/crates/wasmi/tests/e2e/v1/func.rs +++ b/crates/wasmi/tests/e2e/v1/func.rs @@ -9,9 +9,9 @@ use wasmi::{ Func, FuncType, Store, - Value, + Val, }; -use wasmi_core::{ValueType, F32, F64}; +use wasmi_core::{ValType, F32, F64}; fn test_setup() -> Store<()> { let engine = Engine::default(); @@ -37,8 +37,8 @@ fn setup_add2() -> (Store<()>, Func, Func) { let add2 = Func::wrap(&mut store, |lhs: i32, rhs: i32| lhs + rhs); let add2_dyn = Func::new( &mut store, - FuncType::new([ValueType::I32, ValueType::I32], [ValueType::I32]), - |_caller, inputs: &[Value], results: &mut [Value]| { + FuncType::new([ValType::I32, ValType::I32], [ValType::I32]), + |_caller, inputs: &[Val], results: &mut [Val]| { assert_eq!(inputs.len(), 2); assert_eq!(results.len(), 1); let lhs = &inputs[0].i32().unwrap(); @@ -55,14 +55,14 @@ fn dynamic_add2_works() { let (mut store, add2, add2_dyn) = setup_add2(); for a in 0..10 { for b in 0..10 { - let params = [Value::I32(a), Value::I32(b)]; + let params = [Val::I32(a), Val::I32(b)]; let expected = a + b; - let mut result = Value::I32(0); + let mut result = Val::I32(0); // Call to Func with statically typed closure. add2.call(&mut store, ¶ms, slice::from_mut(&mut result)) .unwrap(); // Reset result before execution. - result = Value::I32(0); + result = Val::I32(0); // Call to Func with dynamically typed closure. add2_dyn .call(&mut store, ¶ms, slice::from_mut(&mut result)) @@ -92,11 +92,8 @@ fn setup_add3() -> (Store<()>, Func, Func) { let add3 = Func::wrap(&mut store, |v0: i32, v1: i32, v2: i32| v0 + v1 + v2); let add3_dyn = Func::new( &mut store, - FuncType::new( - [ValueType::I32, ValueType::I32, ValueType::I32], - [ValueType::I32], - ), - |_caller, inputs: &[Value], results: &mut [Value]| { + FuncType::new([ValType::I32, ValType::I32, ValType::I32], [ValType::I32]), + |_caller, inputs: &[Val], results: &mut [Val]| { assert_eq!(inputs.len(), 3); assert_eq!(results.len(), 1); let a = &inputs[0].i32().unwrap(); @@ -115,15 +112,15 @@ fn dynamic_add3_works() { for a in 0..5 { for b in 0..5 { for c in 0..5 { - let params = [Value::I32(a), Value::I32(b), Value::I32(c)]; + let params = [Val::I32(a), Val::I32(b), Val::I32(c)]; let expected = a + b + c; - let mut result = Value::I32(0); + let mut result = Val::I32(0); // Call to Func with statically typed closure. add3.call(&mut store, ¶ms, slice::from_mut(&mut result)) .unwrap(); assert_eq!(result.i32(), Some(expected)); // Reset result before execution. - result = Value::I32(0); + result = Val::I32(0); // Call to Func with dynamically typed closure. add3_dyn .call(&mut store, ¶ms, slice::from_mut(&mut result)) @@ -156,8 +153,8 @@ fn setup_duplicate() -> (Store<()>, Func, Func) { let duplicate = Func::wrap(&mut store, |value: i32| (value, value)); let duplicate_dyn = Func::new( &mut store, - FuncType::new([ValueType::I32], [ValueType::I32, ValueType::I32]), - |_caller, inputs: &[Value], results: &mut [Value]| { + FuncType::new([ValType::I32], [ValType::I32, ValType::I32]), + |_caller, inputs: &[Val], results: &mut [Val]| { assert_eq!(inputs.len(), 1); assert_eq!(results.len(), 2); let input = inputs[0].i32().unwrap(); @@ -173,15 +170,15 @@ fn setup_duplicate() -> (Store<()>, Func, Func) { fn dynamic_duplicate_works() { let (mut store, duplicate, duplicate_dyn) = setup_duplicate(); for input in 0..10 { - let params = [Value::I32(input)]; - let expected = [Value::I32(input), Value::I32(input)]; - let mut results = [Value::I32(0), Value::I32(0)]; + let params = [Val::I32(input)]; + let expected = [Val::I32(input), Val::I32(input)]; + let mut results = [Val::I32(0), Val::I32(0)]; // Call to Func with statically typed closure. duplicate.call(&mut store, ¶ms, &mut results).unwrap(); assert_eq!(results[0].i32(), expected[0].i32()); assert_eq!(results[1].i32(), expected[1].i32()); // Reset result before execution. - results = [Value::I32(0), Value::I32(0)]; + results = [Val::I32(0), Val::I32(0)]; // Call to Func with dynamically typed closure. duplicate_dyn .call(&mut store, ¶ms, &mut results) @@ -262,22 +259,22 @@ fn dynamic_many_params_works() { func.call( &mut store, &[ - Value::I32(0), - Value::I32(1), - Value::I32(2), - Value::I32(3), - Value::I32(4), - Value::I32(5), - Value::I32(6), - Value::I32(7), - Value::I32(8), - Value::I32(9), - Value::I32(10), - Value::I32(11), - Value::I32(12), - Value::I32(13), - Value::I32(14), - Value::I32(15), + Val::I32(0), + Val::I32(1), + Val::I32(2), + Val::I32(3), + Val::I32(4), + Val::I32(5), + Val::I32(6), + Val::I32(7), + Val::I32(8), + Val::I32(9), + Val::I32(10), + Val::I32(11), + Val::I32(12), + Val::I32(13), + Val::I32(14), + Val::I32(15), ], &mut [], ) @@ -303,11 +300,11 @@ fn setup_many_results() -> (Store<()>, Func) { #[test] fn dynamic_many_results_works() { let (mut store, func) = setup_many_results(); - let mut results = [0; 16].map(Value::I32); + let mut results = [0; 16].map(Val::I32); func.call(&mut store, &[], &mut results).unwrap(); let mut i = 0; let expected = [0; 16].map(|_| { - let value = Value::I32(i as _); + let value = Val::I32(i as _); i += 1; value }); @@ -358,8 +355,8 @@ fn setup_many_params_many_results() -> (Store<()>, Func) { #[test] fn dynamic_many_params_many_results_works() { let (mut store, func) = setup_many_params_many_results(); - let mut results = [0; 16].map(Value::I32); - let inputs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].map(Value::I32); + let mut results = [0; 16].map(Val::I32); + let inputs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].map(Val::I32); func.call(&mut store, &inputs, &mut results).unwrap(); assert_eq!( results.map(|result| result.i32().unwrap()), @@ -384,14 +381,14 @@ fn dynamic_many_types_works() { &mut store, |v0: i32, v1: u32, v2: i64, v3: u64, v4: F32, v5: F64| (v0, v1, v2, v3, v4, v5), ); - let mut results = [0; 6].map(Value::I32); + let mut results = [0; 6].map(Val::I32); let inputs = [ - Value::I32(0), - Value::I32(1), - Value::I64(2), - Value::I64(3), - Value::F32(4.0.into()), - Value::F64(5.0.into()), + Val::I32(0), + Val::I32(1), + Val::I64(2), + Val::I64(3), + Val::F32(4.0.into()), + Val::F64(5.0.into()), ]; func.call(&mut store, &inputs, &mut results).unwrap(); assert_eq!(results[0].i32(), Some(0)); @@ -422,7 +419,7 @@ fn static_many_types_works() { fn dynamic_type_check_works() { let mut store = test_setup(); let identity = Func::wrap(&mut store, |value: i32| value); - let mut result = Value::I32(0); + let mut result = Val::I32(0); // Case: Too few inputs given to function. assert_matches!( identity @@ -436,7 +433,7 @@ fn dynamic_type_check_works() { identity .call( &mut store, - &[Value::I32(0), Value::I32(1)], + &[Val::I32(0), Val::I32(1)], core::slice::from_mut(&mut result) ) .unwrap_err() @@ -446,7 +443,7 @@ fn dynamic_type_check_works() { // Case: Too few outputs given to function. assert_matches!( identity - .call(&mut store, &[Value::I32(0)], &mut [],) + .call(&mut store, &[Val::I32(0)], &mut [],) .unwrap_err() .kind(), ErrorKind::Func(FuncError::MismatchingResultLen) @@ -454,21 +451,13 @@ fn dynamic_type_check_works() { // Case: Too many outputs given to function. assert_matches!( identity - .call( - &mut store, - &[Value::I32(0)], - &mut [Value::I32(0), Value::I32(1)], - ) + .call(&mut store, &[Val::I32(0)], &mut [Val::I32(0), Val::I32(1)],) .unwrap_err() .kind(), ErrorKind::Func(FuncError::MismatchingResultLen) ); // Case: Mismatching type given as input to function. - for input in &[ - Value::I64(0), - Value::F32(0.0.into()), - Value::F64(0.0.into()), - ] { + for input in &[Val::I64(0), Val::F32(0.0.into()), Val::F64(0.0.into())] { assert_matches!( identity .call( @@ -485,7 +474,7 @@ fn dynamic_type_check_works() { // // The result type will be overwritten anyways. assert_matches!( - identity.call(&mut store, &[Value::I32(0)], &mut [Value::I64(0)]), + identity.call(&mut store, &[Val::I32(0)], &mut [Val::I64(0)]), Ok(_) ); } diff --git a/crates/wasmi/tests/e2e/v1/resumable_call.rs b/crates/wasmi/tests/e2e/v1/resumable_call.rs index 2e53564ec2..06624c431a 100644 --- a/crates/wasmi/tests/e2e/v1/resumable_call.rs +++ b/crates/wasmi/tests/e2e/v1/resumable_call.rs @@ -2,7 +2,7 @@ use core::slice; use wasmi::{ - core::{TrapCode, ValueType}, + core::{TrapCode, ValType}, errors::ErrorKind, Caller, Config, @@ -18,7 +18,7 @@ use wasmi::{ TypedFunc, TypedResumableCall, TypedResumableInvocation, - Value, + Val, }; fn test_setup(remaining: u32) -> (Store, Linker) { @@ -96,7 +96,7 @@ fn resumable_call_smoldot_01() { "#, ); let invocation = wasm_fn.call_resumable(&mut store, ()).unwrap_resumable(); - match invocation.resume(&mut store, &[Value::I32(42)]).unwrap() { + match invocation.resume(&mut store, &[Val::I32(42)]).unwrap() { TypedResumableCall::Finished(result) => assert_eq!(result, 42), TypedResumableCall::Resumable(_) => panic!("expected TypeResumableCall::Finished"), } @@ -139,7 +139,7 @@ fn resumable_call_smoldot_tail_02() { "#, ); let invocation = wasm_fn.call_resumable(&mut store, ()).unwrap_resumable(); - match invocation.resume(&mut store, &[Value::I32(42)]).unwrap() { + match invocation.resume(&mut store, &[Val::I32(42)]).unwrap() { TypedResumableCall::Finished(result) => assert_eq!(result, 42), TypedResumableCall::Resumable(_) => panic!("expected TypeResumableCall::Finished"), } @@ -165,7 +165,7 @@ fn resumable_call_smoldot_02() { "#, ); let invocation = wasm_fn.call_resumable(&mut store, ()).unwrap_resumable(); - match invocation.resume(&mut store, &[Value::I32(42)]).unwrap() { + match invocation.resume(&mut store, &[Val::I32(42)]).unwrap() { TypedResumableCall::Finished(result) => assert_eq!(result, 11), TypedResumableCall::Resumable(_) => panic!("expected TypeResumableCall::Finished"), } @@ -253,7 +253,7 @@ trait AssertResumable { self, store: &Store, exit_status: i32, - host_results: &[ValueType], + host_results: &[ValType], ) -> Self::Invocation; fn assert_finish(self) -> Self::Results; } @@ -266,7 +266,7 @@ impl AssertResumable for ResumableCall { self, store: &Store, exit_status: i32, - host_results: &[ValueType], + host_results: &[ValType], ) -> Self::Invocation { match self { Self::Resumable(invocation) => { @@ -287,20 +287,20 @@ impl AssertResumable for ResumableCall { } fn run_test(wasm_fn: Func, mut store: &mut Store, wasm_trap: bool) { - let mut results = Value::I32(0); + let mut results = Val::I32(0); let invocation = wasm_fn .call_resumable( &mut store, - &[Value::I32(wasm_trap as i32)], + &[Val::I32(wasm_trap as i32)], slice::from_mut(&mut results), ) .unwrap() - .assert_resumable(store, 10, &[ValueType::I32]); + .assert_resumable(store, 10, &[ValType::I32]); let invocation = invocation - .resume(&mut store, &[Value::I32(2)], slice::from_mut(&mut results)) + .resume(&mut store, &[Val::I32(2)], slice::from_mut(&mut results)) .unwrap() - .assert_resumable(store, 20, &[ValueType::I32]); - let call = invocation.resume(&mut store, &[Value::I32(3)], slice::from_mut(&mut results)); + .assert_resumable(store, 20, &[ValType::I32]); + let call = invocation.resume(&mut store, &[Val::I32(3)], slice::from_mut(&mut results)); if wasm_trap { match call.unwrap_err().kind() { ErrorKind::TrapCode(trap) => { @@ -322,7 +322,7 @@ impl AssertResumable for TypedResumableCall { self, store: &Store, exit_status: i32, - host_results: &[ValueType], + host_results: &[ValType], ) -> Self::Invocation { match self { Self::Resumable(invocation) => { @@ -348,12 +348,12 @@ fn run_test_typed(wasm_fn: Func, mut store: &mut Store, wasm_trap: boo .unwrap() .call_resumable(&mut store, wasm_trap as i32) .unwrap() - .assert_resumable(store, 10, &[ValueType::I32]); + .assert_resumable(store, 10, &[ValType::I32]); let invocation = invocation - .resume(&mut store, &[Value::I32(2)]) + .resume(&mut store, &[Val::I32(2)]) .unwrap() - .assert_resumable(store, 20, &[ValueType::I32]); - let call = invocation.resume(&mut store, &[Value::I32(3)]); + .assert_resumable(store, 20, &[ValType::I32]); + let call = invocation.resume(&mut store, &[Val::I32(3)]); if wasm_trap { match call.unwrap_err().kind() { ErrorKind::TrapCode(trap) => { diff --git a/crates/wasmi/tests/spec/context.rs b/crates/wasmi/tests/spec/context.rs index 6bfe188cc9..2bfabe20c1 100644 --- a/crates/wasmi/tests/spec/context.rs +++ b/crates/wasmi/tests/spec/context.rs @@ -16,9 +16,9 @@ use wasmi::{ Store, Table, TableType, - Value, + Val, }; -use wasmi_core::{ValueType, F32, F64}; +use wasmi_core::{ValType, F32, F64}; use wast::token::{Id, Span}; /// The context of a single Wasm test spec suite run. @@ -39,7 +39,7 @@ pub struct TestContext<'a> { /// Profiling during the Wasm spec test run. profile: TestProfile, /// Intermediate results buffer that can be reused for calling Wasm functions. - results: Vec, + results: Vec, /// The descriptor of the test. /// /// Useful for printing better debug messages in case of failure. @@ -56,14 +56,14 @@ impl<'a> TestContext<'a> { let default_memory = Memory::new(&mut store, MemoryType::new(1, Some(2)).unwrap()).unwrap(); let default_table = Table::new( &mut store, - TableType::new(ValueType::FuncRef, 10, Some(20)), - Value::default(ValueType::FuncRef), + TableType::new(ValType::FuncRef, 10, Some(20)), + Val::default(ValType::FuncRef), ) .unwrap(); - let global_i32 = Global::new(&mut store, Value::I32(666), Mutability::Const); - let global_i64 = Global::new(&mut store, Value::I64(666), Mutability::Const); - let global_f32 = Global::new(&mut store, Value::F32(666.0.into()), Mutability::Const); - let global_f64 = Global::new(&mut store, Value::F64(666.0.into()), Mutability::Const); + let global_i32 = Global::new(&mut store, Val::I32(666), Mutability::Const); + let global_i64 = Global::new(&mut store, Val::I64(666), Mutability::Const); + let global_f32 = Global::new(&mut store, Val::F32(666.0.into()), Mutability::Const); + let global_f64 = Global::new(&mut store, Val::F64(666.0.into()), Mutability::Const); let print = Func::wrap(&mut store, || { println!("print"); }); @@ -242,8 +242,8 @@ impl TestContext<'_> { &mut self, module_name: Option<&str>, func_name: &str, - args: &[Value], - ) -> Result<&[Value], TestError> { + args: &[Val], + ) -> Result<&[Val], TestError> { let instance = self.instance_by_name_or_last(module_name)?; let func = instance .get_export(&self.store, func_name) @@ -254,7 +254,7 @@ impl TestContext<'_> { })?; let len_results = func.ty(&self.store).results().len(); self.results.clear(); - self.results.resize(len_results, Value::I32(0)); + self.results.resize(len_results, Val::I32(0)); func.call(&mut self.store, args, &mut self.results)?; Ok(&self.results) } @@ -265,11 +265,7 @@ impl TestContext<'_> { /// /// - If no module instances can be found. /// - If no global variable identifier with `global_name` can be found. - pub fn get_global( - &self, - module_name: Option, - global_name: &str, - ) -> Result { + pub fn get_global(&self, module_name: Option, global_name: &str) -> Result { let module_name = module_name.map(|id| id.name()); let instance = self.instance_by_name_or_last(module_name)?; let global = instance diff --git a/crates/wasmi/tests/spec/run.rs b/crates/wasmi/tests/spec/run.rs index 489ec91533..27628beeb4 100644 --- a/crates/wasmi/tests/spec/run.rs +++ b/crates/wasmi/tests/spec/run.rs @@ -1,6 +1,6 @@ use super::{error::TestError, TestContext, TestDescriptor}; use anyhow::Result; -use wasmi::{Config, ExternRef, FuncRef, Instance, Value}; +use wasmi::{Config, ExternRef, FuncRef, Instance, Val}; use wasmi_core::{F32, F64}; use wast::{ core::{HeapType, NanPattern, WastRetCore}, @@ -226,7 +226,7 @@ fn assert_trap(test_context: &TestContext, span: Span, error: TestError, message } /// Asserts that `results` match the `expected` values. -fn assert_results(context: &TestContext, span: Span, results: &[Value], expected: &[WastRet]) { +fn assert_results(context: &TestContext, span: Span, results: &[Val], expected: &[WastRet]) { assert_eq!(results.len(), expected.len()); let expected = expected.iter().map(|expected| match expected { WastRet::Core(expected) => expected, @@ -237,13 +237,13 @@ fn assert_results(context: &TestContext, span: Span, results: &[Value], expected }); for (result, expected) in results.iter().zip(expected) { match (result, expected) { - (Value::I32(result), WastRetCore::I32(expected)) => { + (Val::I32(result), WastRetCore::I32(expected)) => { assert_eq!(result, expected, "in {}", context.spanned(span)) } - (Value::I64(result), WastRetCore::I64(expected)) => { + (Val::I64(result), WastRetCore::I64(expected)) => { assert_eq!(result, expected, "in {}", context.spanned(span)) } - (Value::F32(result), WastRetCore::F32(expected)) => match expected { + (Val::F32(result), WastRetCore::F32(expected)) => match expected { NanPattern::CanonicalNan | NanPattern::ArithmeticNan => assert!(result.is_nan()), NanPattern::Value(expected) => { assert_eq!( @@ -254,7 +254,7 @@ fn assert_results(context: &TestContext, span: Span, results: &[Value], expected ); } }, - (Value::F64(result), WastRetCore::F64(expected)) => match expected { + (Val::F64(result), WastRetCore::F64(expected)) => match expected { NanPattern::CanonicalNan | NanPattern::ArithmeticNan => { assert!(result.is_nan(), "in {}", context.spanned(span)) } @@ -267,13 +267,13 @@ fn assert_results(context: &TestContext, span: Span, results: &[Value], expected ); } }, - (Value::FuncRef(funcref), WastRetCore::RefNull(Some(HeapType::Func))) => { + (Val::FuncRef(funcref), WastRetCore::RefNull(Some(HeapType::Func))) => { assert!(funcref.is_null()); } - (Value::ExternRef(externref), WastRetCore::RefNull(Some(HeapType::Extern))) => { + (Val::ExternRef(externref), WastRetCore::RefNull(Some(HeapType::Extern))) => { assert!(externref.is_null()); } - (Value::ExternRef(externref), WastRetCore::RefExtern(Some(expected))) => { + (Val::ExternRef(externref), WastRetCore::RefExtern(Some(expected))) => { let value = externref .data(context.store()) .expect("unexpected null element") @@ -281,7 +281,7 @@ fn assert_results(context: &TestContext, span: Span, results: &[Value], expected .expect("unexpected non-u32 data"); assert_eq!(value, expected); } - (Value::ExternRef(externref), WastRetCore::RefExtern(None)) => { + (Val::ExternRef(externref), WastRetCore::RefExtern(None)) => { assert!(externref.is_null()); } (result, expected) => panic!( @@ -344,7 +344,7 @@ fn execute_wast_execute( context: &mut TestContext, span: Span, execute: WastExecute, -) -> Result, TestError> { +) -> Result, TestError> { match execute { WastExecute::Invoke(invoke) => { execute_wast_invoke(context, span, invoke).map_err(Into::into) @@ -366,10 +366,10 @@ fn execute_wast_invoke( context: &mut TestContext, span: Span, invoke: WastInvoke, -) -> Result, TestError> { +) -> Result, TestError> { let module_name = invoke.module.map(|id| id.name()); let field_name = invoke.name; - let mut args = >::new(); + let mut args = >::new(); for arg in invoke.args { let value = match arg { wast::WastArg::Core(arg) => value(context.store_mut(), &arg).unwrap_or_else(|| { @@ -391,15 +391,15 @@ fn execute_wast_invoke( } /// Converts the [`WastArgCore`][`wast::core::WastArgCore`] into a [`wasmi::Value`] if possible. -fn value(ctx: &mut wasmi::Store<()>, value: &wast::core::WastArgCore) -> Option { +fn value(ctx: &mut wasmi::Store<()>, value: &wast::core::WastArgCore) -> Option { Some(match value { - wast::core::WastArgCore::I32(arg) => Value::I32(*arg), - wast::core::WastArgCore::I64(arg) => Value::I64(*arg), - wast::core::WastArgCore::F32(arg) => Value::F32(F32::from_bits(arg.bits)), - wast::core::WastArgCore::F64(arg) => Value::F64(F64::from_bits(arg.bits)), - wast::core::WastArgCore::RefNull(HeapType::Func) => Value::FuncRef(FuncRef::null()), - wast::core::WastArgCore::RefNull(HeapType::Extern) => Value::ExternRef(ExternRef::null()), - wast::core::WastArgCore::RefExtern(value) => Value::ExternRef(ExternRef::new(ctx, *value)), + wast::core::WastArgCore::I32(arg) => Val::I32(*arg), + wast::core::WastArgCore::I64(arg) => Val::I64(*arg), + wast::core::WastArgCore::F32(arg) => Val::F32(F32::from_bits(arg.bits)), + wast::core::WastArgCore::F64(arg) => Val::F64(F64::from_bits(arg.bits)), + wast::core::WastArgCore::RefNull(HeapType::Func) => Val::FuncRef(FuncRef::null()), + wast::core::WastArgCore::RefNull(HeapType::Extern) => Val::ExternRef(ExternRef::null()), + wast::core::WastArgCore::RefExtern(value) => Val::ExternRef(ExternRef::new(ctx, *value)), _ => return None, }) } diff --git a/fuzz/fuzz_targets/differential.rs b/fuzz/fuzz_targets/differential.rs index 72d7e8e835..b64c8185b7 100644 --- a/fuzz/fuzz_targets/differential.rs +++ b/fuzz/fuzz_targets/differential.rs @@ -47,8 +47,8 @@ trait DifferentialTarget: Sized { struct WasmiRegister { store: wasmi_reg::Store, instance: wasmi_reg::Instance, - params: Vec, - results: Vec, + params: Vec, + results: Vec, } impl WasmiRegister { @@ -68,7 +68,7 @@ impl WasmiRegister { exports } - fn type_to_value(ty: &wasmi_reg::core::ValueType) -> wasmi_reg::Value { + fn type_to_value(ty: &wasmi_reg::core::ValType) -> wasmi_reg::Val { ty_to_val(ty) } } @@ -669,13 +669,13 @@ impl PartialEq for FuzzValue { } } -impl<'a> From<&'a wasmi_reg::Value> for FuzzValue { - fn from(value: &wasmi_reg::Value) -> Self { +impl<'a> From<&'a wasmi_reg::Val> for FuzzValue { + fn from(value: &wasmi_reg::Val) -> Self { match value { - wasmi_reg::Value::I32(value) => Self::I32(*value), - wasmi_reg::Value::I64(value) => Self::I64(*value), - wasmi_reg::Value::F32(value) => Self::F32(*value), - wasmi_reg::Value::F64(value) => Self::F64(*value), + wasmi_reg::Val::I32(value) => Self::I32(*value), + wasmi_reg::Val::I64(value) => Self::I64(*value), + wasmi_reg::Val::F32(value) => Self::F32(*value), + wasmi_reg::Val::F64(value) => Self::F64(*value), _ => panic!("unsupported value type"), } } diff --git a/fuzz/fuzz_targets/utils.rs b/fuzz/fuzz_targets/utils.rs index cdc9d87e0e..f8c1740883 100644 --- a/fuzz/fuzz_targets/utils.rs +++ b/fuzz/fuzz_targets/utils.rs @@ -1,5 +1,5 @@ use arbitrary::Arbitrary; -use wasmi::{core::ValueType, Value}; +use wasmi::{core::ValType, Val}; /// The configuration used to produce Wasmi compatible fuzzing Wasm modules. #[derive(Debug, Arbitrary)] @@ -59,19 +59,19 @@ impl wasm_smith::Config for ExecConfig { } } -/// Converts a [`ValueType`] into a [`Value`] with default initialization of 1. +/// Converts a [`ValType`] into a [`Val`] with default initialization of 1. /// /// # ToDo /// /// We actually want the bytes buffer given by the `Arbitrary` crate to influence -/// the values chosen for the resulting [`Value`]. Also we ideally want to produce +/// the values chosen for the resulting [`Val`]. Also we ideally want to produce /// zeroed, positive, negative and NaN values for their respective types. -pub fn ty_to_val(ty: &ValueType) -> Value { +pub fn ty_to_val(ty: &ValType) -> Val { match ty { - ValueType::I32 => Value::I32(1), - ValueType::I64 => Value::I64(1), - ValueType::F32 => Value::F32(1.0.into()), - ValueType::F64 => Value::F64(1.0.into()), + ValType::I32 => Val::I32(1), + ValType::I64 => Val::I64(1), + ValType::F32 => Val::F32(1.0.into()), + ValType::F64 => Val::F64(1.0.into()), unsupported => panic!( "execution fuzzing does not support reference types, yet but found: {unsupported:?}" ),