Skip to content

Commit

Permalink
deps: Upgrade wasmparser to 0.121.0
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Jan 31, 2024
1 parent 49a2123 commit 4ea7827
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 180 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ version = "4.2.5"
enumset = "1.1.0"
memoffset = "0.9.0"
wasmer-toml = "0.9.2"
wasmparser = { version = "0.121.0", default-features = false }
webc = { version = "5.8.0", default-features = false, features = ["package"] }
shared-buffer = "0.1.4"

Expand Down
19 changes: 8 additions & 11 deletions lib/c-api/src/wasm_c_api/unstable/parser/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,11 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::I32x4TruncSatF64x2SZero => Self::I32x4TruncSatF64x2SZero,
O::I32x4TruncSatF64x2UZero => Self::I32x4TruncSatF64x2UZero,
O::I8x16RelaxedSwizzle => Self::I8x16RelaxedSwizzle,
O::I32x4RelaxedTruncSatF32x4S => Self::I32x4RelaxedTruncSatF32x4S,
O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
O::F32x4RelaxedFma => Self::F32x4Fma,
O::F32x4RelaxedFnma => Self::F32x4Fms,
O::F64x2RelaxedFma => Self::F64x2Fma,
O::F64x2RelaxedFnma => Self::F64x2Fms,
O::I32x4RelaxedTruncF32x4S => Self::I32x4RelaxedTruncSatF32x4S,
O::I32x4RelaxedTruncF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
O::I32x4RelaxedTruncF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
O::I32x4RelaxedTruncF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
O::F32x4RelaxedMadd => Self::F32x4Fma,
O::I8x16RelaxedLaneselect => Self::I8x16LaneSelect,
O::I16x8RelaxedLaneselect => Self::I16x8LaneSelect,
O::I32x4RelaxedLaneselect => Self::I32x4LaneSelect,
Expand All @@ -1075,9 +1072,9 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
O::F64x2RelaxedMin => Self::F64x2RelaxedMin,
O::F64x2RelaxedMax => Self::F64x2RelaxedMax,
O::I16x8RelaxedQ15mulrS => Self::I16x8RelaxedQ15mulrS,
O::I16x8DotI8x16I7x16S => Self::I16x8DotI8x16I7x16S,
O::I32x4DotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS,
O::F32x4RelaxedDotBf16x8AddF32x4 => Self::F32x4RelaxedDotBf16x8AddF32x4,
_ => {
panic!("unimplemented operator {operator:?}");
}
}
}
}
8 changes: 4 additions & 4 deletions lib/compiler-cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Function, InstBuilder, Si
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use std::convert::TryFrom;
use wasmer_compiler::wasmparser::ValType;
use wasmer_compiler::wasmparser::HeapType;
use wasmer_types::entity::EntityRef;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::VMBuiltinFunctionIndex;
Expand Down Expand Up @@ -999,11 +999,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
fn translate_ref_null(
&mut self,
mut pos: cranelift_codegen::cursor::FuncCursor,
ty: ValType,
ty: HeapType,
) -> WasmResult<ir::Value> {
Ok(match ty {
ValType::FuncRef => pos.ins().null(self.reference_type()),
ValType::ExternRef => pos.ins().null(self.reference_type()),
HeapType::Func => pos.ins().null(self.reference_type()),
HeapType::Extern => pos.ins().null(self.reference_type()),
_ => {
return Err(WasmError::Unsupported(
"`ref.null T` that is not a `funcref` or an `externref`".into(),
Expand Down
104 changes: 76 additions & 28 deletions lib/compiler-cranelift/src/translator/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
* possible `Block`'s arguments values.
***********************************************************************************/
Operator::Block { blockty } => {
let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
let next = block_with_params(builder, results, environ)?;
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
let next = block_with_params(builder, results.iter(), environ)?;
state.push_block(next, params.len(), results.len());
}
Operator::Loop { blockty } => {
let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
let loop_body = block_with_params(builder, params, environ)?;
let next = block_with_params(builder, results, environ)?;
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
let loop_body = block_with_params(builder, params.iter(), environ)?;
let next = block_with_params(builder, results.iter(), environ)?;
canonicalise_then_jump(builder, loop_body, state.peekn(params.len()));
state.push_loop(loop_body, next, params.len(), results.len());

Expand All @@ -260,23 +260,23 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
Operator::If { blockty } => {
let val = state.pop1();

let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
let (destination, else_data) = if params == results {
// It is possible there is no `else` block, so we will only
// allocate a block for it if/when we find the `else`. For now,
// we if the condition isn't true, then we jump directly to the
// destination block following the whole `if...end`. If we do end
// up discovering an `else`, then we will allocate a block for it
// and go back and patch the jump.
let destination = block_with_params(builder, results, environ)?;
let destination = block_with_params(builder, results.iter(), environ)?;
let branch_inst =
canonicalise_then_brz(builder, val, destination, state.peekn(params.len()));
(destination, ElseData::NoElse { branch_inst })
} else {
// The `if` type signature is not valid without an `else` block,
// so we eagerly allocate the `else` block here.
let destination = block_with_params(builder, results, environ)?;
let else_block = block_with_params(builder, params, environ)?;
let destination = block_with_params(builder, results.iter(), environ)?;
let else_block = block_with_params(builder, params.iter(), environ)?;
canonicalise_then_brz(builder, val, else_block, state.peekn(params.len()));
builder.seal_block(else_block);
(destination, ElseData::WithElse { else_block })
Expand Down Expand Up @@ -326,10 +326,11 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
// already been pre-allocated, see `ElseData` for details).
let else_block = match *else_data {
ElseData::NoElse { branch_inst } => {
let (params, _results) =
module_translation_state.blocktype_params_results(blocktype)?;
let (params, _results) = module_translation_state
.blocktype_params_results(&blocktype)?;
debug_assert_eq!(params.len(), num_return_values);
let else_block = block_with_params(builder, params, environ)?;
let else_block =
block_with_params(builder, params.iter(), environ)?;
canonicalise_then_jump(
builder,
destination,
Expand Down Expand Up @@ -1039,7 +1040,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
Operator::F32Le | Operator::F64Le => {
translate_fcmp(FloatCC::LessThanOrEqual, builder, state)
}
Operator::RefNull { ty } => state.push1(environ.translate_ref_null(builder.cursor(), *ty)?),
Operator::RefNull { hty } => {
state.push1(environ.translate_ref_null(builder.cursor(), *hty)?)
}
Operator::RefIsNull => {
let value = state.pop1();
state.push1(environ.translate_ref_is_null(builder.cursor(), value)?);
Expand Down Expand Up @@ -2032,14 +2035,12 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
return Err(wasm_unsupported!("proposed tail-call operator {:?}", op));
}
Operator::I8x16RelaxedSwizzle
| Operator::I32x4RelaxedTruncSatF32x4S
| Operator::I32x4RelaxedTruncSatF32x4U
| Operator::I32x4RelaxedTruncSatF64x2SZero
| Operator::I32x4RelaxedTruncSatF64x2UZero
| Operator::F32x4RelaxedFma
| Operator::F32x4RelaxedFnma
| Operator::F64x2RelaxedFma
| Operator::F64x2RelaxedFnma
| Operator::I32x4RelaxedTruncF32x4S
| Operator::I32x4RelaxedTruncF32x4U
| Operator::I32x4RelaxedTruncF64x2SZero
| Operator::I32x4RelaxedTruncF64x2UZero
| Operator::F32x4RelaxedNmadd
| Operator::F32x4RelaxedMadd
| Operator::I8x16RelaxedLaneselect
| Operator::I16x8RelaxedLaneselect
| Operator::I32x4RelaxedLaneselect
Expand All @@ -2048,12 +2049,58 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::F32x4RelaxedMax
| Operator::F64x2RelaxedMin
| Operator::F64x2RelaxedMax
| Operator::F32x4RelaxedDotBf16x8AddF32x4
| Operator::I16x8RelaxedQ15mulrS
| Operator::I16x8DotI8x16I7x16S
| Operator::I32x4DotI8x16I7x16AddS => {
| Operator::F64x2RelaxedMadd
| Operator::F64x2RelaxedNmadd
| Operator::I16x8RelaxedDotI8x16I7x16S
| Operator::I32x4RelaxedDotI8x16I7x16AddS
| Operator::I16x8RelaxedQ15mulrS => {
return Err(wasm_unsupported!("proposed relaxed-simd operator {:?}", op));
}
Operator::TryTable { .. } | Operator::ThrowRef => {
return Err(wasm_unsupported!(
"exceptions are not supported (operator: {op:?})"
));
}
Operator::RefEq
| Operator::StructNew { .. }
| Operator::StructNewDefault { .. }
| Operator::StructGet { .. }
| Operator::StructGetS { .. }
| Operator::StructGetU { .. }
| Operator::StructSet { .. }
| Operator::ArrayNew { .. }
| Operator::ArrayNewDefault { .. }
| Operator::ArrayNewFixed { .. }
| Operator::ArrayNewData { .. }
| Operator::ArrayNewElem { .. }
| Operator::ArrayGet { .. }
| Operator::ArrayGetS { .. }
| Operator::ArrayGetU { .. }
| Operator::ArraySet { .. }
| Operator::ArrayLen
| Operator::ArrayFill { .. }
| Operator::ArrayCopy { .. }
| Operator::ArrayInitData { .. }
| Operator::ArrayInitElem { .. }
| Operator::RefTestNonNull { .. } => {}
Operator::RefTestNullable { .. }
| Operator::RefCastNonNull { .. }
| Operator::RefCastNullable { .. }
| Operator::BrOnCast { .. }
| Operator::BrOnCastFail { .. }
| Operator::AnyConvertExtern
| Operator::ExternConvertAny
| Operator::RefI31
| Operator::I31GetS
| Operator::I31GetU
| Operator::MemoryDiscard { .. }
| Operator::CallRef { .. }
| Operator::ReturnCallRef { .. }
| Operator::RefAsNonNull
| Operator::BrOnNull { .. }
| Operator::BrOnNonNull { .. } => {
return Err(wasm_unsupported!("GC proposal not (operator: {:?})", op));
}
};
Ok(())
}
Expand Down Expand Up @@ -2107,9 +2154,10 @@ fn translate_unreachable_operator<FE: FuncEnvironment + ?Sized>(

let else_block = match *else_data {
ElseData::NoElse { branch_inst } => {
let (params, _results) =
module_translation_state.blocktype_params_results(blocktype)?;
let else_block = block_with_params(builder, params, environ)?;
let (params, _results) = module_translation_state
.blocktype_params_results(&blocktype)?;
let else_block =
block_with_params(builder, params.iter(), environ)?;
let frame = state.control_stack.last().unwrap();
frame.truncate_value_stack_to_else_params(&mut state.stack);

Expand Down
4 changes: 2 additions & 2 deletions lib/compiler-cranelift/src/translator/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cranelift_codegen::ir::immediates::Offset32;
use cranelift_codegen::ir::{self, InstBuilder};
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::FunctionBuilder;
use wasmer_compiler::wasmparser::{Operator, ValType};
use wasmer_compiler::wasmparser::{HeapType, Operator};
use wasmer_types::{
FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, MemoryIndex, SignatureIndex,
TableIndex, Type as WasmerType, WasmResult,
Expand Down Expand Up @@ -359,7 +359,7 @@ pub trait FuncEnvironment: TargetEnvironment {
/// null sentinel is not a null reference type pointer for your type. If you
/// override this method, then you should also override
/// `translate_ref_is_null` as well.
fn translate_ref_null(&mut self, pos: FuncCursor, ty: ValType) -> WasmResult<ir::Value>;
fn translate_ref_null(&mut self, pos: FuncCursor, ty: HeapType) -> WasmResult<ir::Value>;
// {
// let _ = ty;
// Ok(pos.ins().null(self.reference_type(ty)))
Expand Down
11 changes: 8 additions & 3 deletions lib/compiler-cranelift/src/translator/func_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir::{self, Block, InstBuilder, ValueLabel};
use cranelift_codegen::timing;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
use wasmer_compiler::wasmparser;
use wasmer_compiler::{wasm_unsupported, wasmparser};
use wasmer_compiler::{wptype_to_type, FunctionBinaryReader, ModuleTranslationState};
use wasmer_types::{LocalFunctionIndex, WasmResult};

Expand Down Expand Up @@ -194,8 +194,13 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
let constant_handle = builder.func.dfg.constants.insert([0; 16].to_vec().into());
builder.ins().vconst(ir::types::I8X16, constant_handle)
}
ExternRef => builder.ins().null(environ.reference_type()),
FuncRef => builder.ins().null(environ.reference_type()),
Ref(ty) => {
if ty.is_func_ref() || ty.is_extern_ref() {
builder.ins().null(environ.reference_type())
} else {
return Err(wasm_unsupported!("unsupported reference type: {:?}", ty));
}
}
};

let wasmer_ty = wptype_to_type(wasm_type).unwrap();
Expand Down
17 changes: 12 additions & 5 deletions lib/compiler-cranelift/src/translator/translation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ pub fn irreloc_to_relocationkind(reloc: Reloc) -> RelocationKind {
}

/// Create a `Block` with the given Wasm parameters.
pub fn block_with_params<PE: TargetEnvironment + ?Sized>(
pub fn block_with_params<'a, PE: TargetEnvironment + ?Sized>(
builder: &mut FunctionBuilder,
params: &[wasmparser::ValType],
params: impl Iterator<Item = &'a wasmparser::ValType>,
environ: &PE,
) -> WasmResult<ir::Block> {
let block = builder.create_block();
for ty in params.iter() {
for ty in params.into_iter() {
match ty {
wasmparser::ValType::I32 => {
builder.append_block_param(block, ir::types::I32);
Expand All @@ -110,8 +110,15 @@ pub fn block_with_params<PE: TargetEnvironment + ?Sized>(
wasmparser::ValType::F64 => {
builder.append_block_param(block, ir::types::F64);
}
wasmparser::ValType::ExternRef | wasmparser::ValType::FuncRef => {
builder.append_block_param(block, environ.reference_type());
wasmparser::ValType::Ref(ty) => {
if ty.is_extern_ref() || ty.is_func_ref() {
builder.append_block_param(block, environ.reference_type());
} else {
return Err(WasmError::Unsupported(format!(
"unsupported reference type: {:?}",
ty
)));
}
}
wasmparser::ValType::V128 => {
builder.append_block_param(block, ir::types::I8X16);
Expand Down
16 changes: 8 additions & 8 deletions lib/compiler-llvm/src/translator/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::config::{CompiledKind, LLVM};
use crate::object_file::{load_object_file, CompiledFunction};
use wasmer_compiler::wasmparser::{MemArg, Operator};
use wasmer_compiler::{
from_binaryreadererror_wasmerror, wptype_to_type, FunctionBinaryReader, FunctionBodyData,
MiddlewareBinaryReader, ModuleMiddlewareChain, ModuleTranslationState,
from_binaryreadererror_wasmerror, wpheaptype_to_type, wptype_to_type, FunctionBinaryReader,
FunctionBodyData, MiddlewareBinaryReader, ModuleMiddlewareChain, ModuleTranslationState,
};
use wasmer_types::entity::PrimaryMap;
use wasmer_types::{
Expand Down Expand Up @@ -1439,7 +1439,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

let phis: SmallVec<[PhiValue<'ctx>; 1]> = self
.module_translation
.blocktype_params_results(blockty)?
.blocktype_params_results(&blockty)?
.1
.iter()
.map(|&wp_ty| {
Expand All @@ -1463,7 +1463,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
self.builder.build_unconditional_branch(loop_body);

self.builder.position_at_end(loop_next);
let blocktypes = self.module_translation.blocktype_params_results(blockty)?;
let blocktypes = self.module_translation.blocktype_params_results(&blockty)?;
let phis = blocktypes
.1
.iter()
Expand Down Expand Up @@ -1671,7 +1671,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {

let phis = self
.module_translation
.blocktype_params_results(blockty)?
.blocktype_params_results(&blockty)?
.1
.iter()
.map(|&wp_ty| {
Expand Down Expand Up @@ -1702,7 +1702,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
self.builder.position_at_end(if_else_block);
let block_param_types = self
.module_translation
.blocktype_params_results(blockty)?
.blocktype_params_results(&blockty)?
.0
.iter()
.map(|&wp_ty| {
Expand Down Expand Up @@ -11146,8 +11146,8 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
* Reference types.
* https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md
***************************/
Operator::RefNull { ty } => {
let ty = wptype_to_type(ty).map_err(to_compile_error)?;
Operator::RefNull { hty } => {
let ty = wpheaptype_to_type(hty).map_err(to_compile_error)?;
let ty = type_to_llvm(self.intrinsics, ty)?;
self.state.push1(ty.const_zero());
}
Expand Down
Loading

0 comments on commit 4ea7827

Please sign in to comment.