Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Upgrade wasmparser #4292

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
llvmPackages_15.llvm
libxml2
libffi

# Test runner
cargo-nextest
];
runtimeDependencies = with pkgs; [ ];

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
Loading
Loading