Store WasmFuncType in FuncType (#2365)
This commit updates `wasmtime::FuncType` to exactly store an internal `WasmFuncType` from the cranelift crates. This allows us to remove a translation layer when we are given a `FuncType` and want to get an internal cranelift type out as a result. The other major change from this commit was changing the constructor and accessors of `FuncType` to be iterator-based instead of exposing implementation details.
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn dummy_imports<'module>(
|
||||
/// Construct a dummy function for the given function type
|
||||
pub fn dummy_func(store: &Store, ty: FuncType) -> Func {
|
||||
Func::new(store, ty.clone(), move |_, _, results| {
|
||||
for (ret_ty, result) in ty.results().iter().zip(results) {
|
||||
for (ret_ty, result) in ty.results().zip(results) {
|
||||
*result = dummy_value(ret_ty)?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -33,7 +33,7 @@ pub fn dummy_func(store: &Store, ty: FuncType) -> Func {
|
||||
}
|
||||
|
||||
/// Construct a dummy value for the given value type.
|
||||
pub fn dummy_value(val_ty: &ValType) -> Result<Val, Trap> {
|
||||
pub fn dummy_value(val_ty: ValType) -> Result<Val, Trap> {
|
||||
Ok(match val_ty {
|
||||
ValType::I32 => Val::I32(0),
|
||||
ValType::I64 => Val::I64(0),
|
||||
@@ -58,19 +58,19 @@ pub fn dummy_value(val_ty: &ValType) -> Result<Val, Trap> {
|
||||
}
|
||||
|
||||
/// Construct a sequence of dummy values for the given types.
|
||||
pub fn dummy_values(val_tys: &[ValType]) -> Result<Vec<Val>, Trap> {
|
||||
val_tys.iter().map(dummy_value).collect()
|
||||
pub fn dummy_values(val_tys: impl IntoIterator<Item = ValType>) -> Result<Vec<Val>, Trap> {
|
||||
val_tys.into_iter().map(dummy_value).collect()
|
||||
}
|
||||
|
||||
/// Construct a dummy global for the given global type.
|
||||
pub fn dummy_global(store: &Store, ty: GlobalType) -> Result<Global, Trap> {
|
||||
let val = dummy_value(ty.content())?;
|
||||
let val = dummy_value(ty.content().clone())?;
|
||||
Ok(Global::new(store, ty, val).unwrap())
|
||||
}
|
||||
|
||||
/// Construct a dummy table for the given table type.
|
||||
pub fn dummy_table(store: &Store, ty: TableType) -> Result<Table, Trap> {
|
||||
let init_val = dummy_value(&ty.element())?;
|
||||
let init_val = dummy_value(ty.element().clone())?;
|
||||
Ok(Table::new(store, ty, init_val).unwrap())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user