Skip to content

Commit dab119b

Browse files
committed
deps: Upgrade wasmparser to 0.116
1 parent d18aa79 commit dab119b

File tree

20 files changed

+394
-192
lines changed

20 files changed

+394
-192
lines changed

Cargo.lock

+12-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ version = "4.2.3"
8787
webc = { version = "5.5.1", default-features = false, features = ["package"] }
8888
wasmer-toml = "0.8.0"
8989
memoffset = "0.9.0"
90+
wasmparser = { version = "0.116.0", default-features = false }
9091

9192
[build-dependencies]
9293
test-generator = { path = "tests/lib/test-generator" }

lib/api/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ wasmer-compiler-llvm = { path = "../compiler-llvm", version = "=4.2.3", optional
5252
wasm-bindgen = { version = "0.2.74", optional = true }
5353
js-sys = { version = "0.3.51", optional = true }
5454
rusty_jsc = { version = "0.1.0", optional = true }
55-
wasmparser = { version = "0.83", default-features = false, optional = true }
55+
wasmparser = { workspace = true, default-features = false, optional = true }
5656

5757
# - Mandatory dependencies for `sys` on Windows.
5858
[target.'cfg(all(not(target_arch = "wasm32"), target_os = "windows"))'.dependencies]
@@ -72,7 +72,7 @@ wasm-bindgen = "0.2.74"
7272
js-sys = "0.3.51"
7373
wasmer-derive = { path = "../derive", version = "=4.2.3" }
7474
# - Optional dependencies for `js`.
75-
wasmparser = { version = "0.95", default-features = false, optional = true }
75+
wasmparser = { workspace = true, default-features = false, optional = true }
7676
hashbrown = { version = "0.11", optional = true }
7777
serde-wasm-bindgen = { version = "0.4.5" }
7878
serde = { version = "1.0", features = ["derive"] }

lib/c-api/src/wasm_c_api/unstable/parser/operator.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ pub enum wasmer_parser_operator_t {
537537
I16x8DotI8x16I7x16S,
538538
I32x4DotI8x16I7x16AddS,
539539
F32x4RelaxedDotBf16x8AddF32x4,
540+
RefI31,
541+
I31GetS,
542+
I31GetU,
543+
MemoryDiscard,
544+
CallRef,
545+
ReturnCallRef,
546+
RefAsNonNull,
547+
BrOnNull,
548+
BrOnNonNull,
540549
}
541550

542551
impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
@@ -1058,14 +1067,14 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
10581067
O::I32x4TruncSatF64x2SZero => Self::I32x4TruncSatF64x2SZero,
10591068
O::I32x4TruncSatF64x2UZero => Self::I32x4TruncSatF64x2UZero,
10601069
O::I8x16RelaxedSwizzle => Self::I8x16RelaxedSwizzle,
1061-
O::I32x4RelaxedTruncSatF32x4S => Self::I32x4RelaxedTruncSatF32x4S,
1062-
O::I32x4RelaxedTruncSatF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
1063-
O::I32x4RelaxedTruncSatF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
1064-
O::I32x4RelaxedTruncSatF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
1065-
O::F32x4RelaxedFma => Self::F32x4Fma,
1066-
O::F32x4RelaxedFnma => Self::F32x4Fms,
1067-
O::F64x2RelaxedFma => Self::F64x2Fma,
1068-
O::F64x2RelaxedFnma => Self::F64x2Fms,
1070+
O::I32x4RelaxedTruncF32x4S => Self::I32x4RelaxedTruncSatF32x4S,
1071+
O::I32x4RelaxedTruncF32x4U => Self::I32x4RelaxedTruncSatF32x4U,
1072+
O::I32x4RelaxedTruncF64x2SZero => Self::I32x4RelaxedTruncSatF64x2SZero,
1073+
O::I32x4RelaxedTruncF64x2UZero => Self::I32x4RelaxedTruncSatF64x2UZero,
1074+
O::F32x4RelaxedMadd => Self::F32x4Fma,
1075+
O::F32x4RelaxedNmadd => Self::F32x4Fms,
1076+
O::F64x2RelaxedMadd => Self::F64x2Fma,
1077+
O::F64x2RelaxedNmadd => Self::F64x2Fms,
10691078
O::I8x16RelaxedLaneselect => Self::I8x16LaneSelect,
10701079
O::I16x8RelaxedLaneselect => Self::I16x8LaneSelect,
10711080
O::I32x4RelaxedLaneselect => Self::I32x4LaneSelect,
@@ -1075,9 +1084,17 @@ impl<'a> From<&Operator<'a>> for wasmer_parser_operator_t {
10751084
O::F64x2RelaxedMin => Self::F64x2RelaxedMin,
10761085
O::F64x2RelaxedMax => Self::F64x2RelaxedMax,
10771086
O::I16x8RelaxedQ15mulrS => Self::I16x8RelaxedQ15mulrS,
1078-
O::I16x8DotI8x16I7x16S => Self::I16x8DotI8x16I7x16S,
1079-
O::I32x4DotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS,
1080-
O::F32x4RelaxedDotBf16x8AddF32x4 => Self::F32x4RelaxedDotBf16x8AddF32x4,
1087+
O::I16x8RelaxedDotI8x16I7x16S => Self::I16x8DotI8x16I7x16S,
1088+
O::I32x4RelaxedDotI8x16I7x16AddS => Self::I32x4DotI8x16I7x16AddS,
1089+
O::RefI31 => Self::RefI31,
1090+
O::I31GetS => Self::I31GetS,
1091+
O::I31GetU => Self::I31GetU,
1092+
O::MemoryDiscard { .. } => Self::MemoryDiscard,
1093+
O::CallRef { .. } => Self::CallRef,
1094+
O::ReturnCallRef { .. } => Self::ReturnCallRef,
1095+
O::RefAsNonNull => Self::RefAsNonNull,
1096+
O::BrOnNull { .. } => Self::BrOnNull,
1097+
O::BrOnNonNull { .. } => Self::BrOnNonNull,
10811098
}
10821099
}
10831100
}

lib/compiler-cranelift/src/func_environ.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Function, InstBuilder, Si
1313
use cranelift_codegen::isa::TargetFrontendConfig;
1414
use cranelift_frontend::FunctionBuilder;
1515
use std::convert::TryFrom;
16-
use wasmer_compiler::wasmparser::ValType;
16+
use wasmer_compiler::wasmparser::HeapType;
1717
use wasmer_types::entity::EntityRef;
1818
use wasmer_types::entity::PrimaryMap;
1919
use wasmer_types::VMBuiltinFunctionIndex;
@@ -999,11 +999,11 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro
999999
fn translate_ref_null(
10001000
&mut self,
10011001
mut pos: cranelift_codegen::cursor::FuncCursor,
1002-
ty: ValType,
1002+
ty: &HeapType,
10031003
) -> WasmResult<ir::Value> {
10041004
Ok(match ty {
1005-
ValType::FuncRef => pos.ins().null(self.reference_type()),
1006-
ValType::ExternRef => pos.ins().null(self.reference_type()),
1005+
HeapType::Func => pos.ins().null(self.reference_type()),
1006+
HeapType::Extern => pos.ins().null(self.reference_type()),
10071007
_ => {
10081008
return Err(WasmError::Unsupported(
10091009
"`ref.null T` that is not a `funcref` or an `externref`".into(),

lib/compiler-cranelift/src/translator/code_translator.rs

+64-28
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
236236
* possible `Block`'s arguments values.
237237
***********************************************************************************/
238238
Operator::Block { blockty } => {
239-
let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
240-
let next = block_with_params(builder, results, environ)?;
239+
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
240+
let next = block_with_params(builder, results.iter(), environ)?;
241241
state.push_block(next, params.len(), results.len());
242242
}
243243
Operator::Loop { blockty } => {
244-
let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
245-
let loop_body = block_with_params(builder, params, environ)?;
246-
let next = block_with_params(builder, results, environ)?;
244+
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
245+
let loop_body = block_with_params(builder, params.iter(), environ)?;
246+
let next = block_with_params(builder, results.iter(), environ)?;
247247
canonicalise_then_jump(builder, loop_body, state.peekn(params.len()));
248248
state.push_loop(loop_body, next, params.len(), results.len());
249249

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

263-
let (params, results) = module_translation_state.blocktype_params_results(*blockty)?;
263+
let (params, results) = module_translation_state.blocktype_params_results(blockty)?;
264264
let (destination, else_data) = if params == results {
265265
// It is possible there is no `else` block, so we will only
266266
// allocate a block for it if/when we find the `else`. For now,
267267
// we if the condition isn't true, then we jump directly to the
268268
// destination block following the whole `if...end`. If we do end
269269
// up discovering an `else`, then we will allocate a block for it
270270
// and go back and patch the jump.
271-
let destination = block_with_params(builder, results, environ)?;
271+
let destination = block_with_params(builder, results.iter(), environ)?;
272272
let branch_inst =
273273
canonicalise_then_brz(builder, val, destination, state.peekn(params.len()));
274274
(destination, ElseData::NoElse { branch_inst })
275275
} else {
276276
// The `if` type signature is not valid without an `else` block,
277277
// so we eagerly allocate the `else` block here.
278-
let destination = block_with_params(builder, results, environ)?;
279-
let else_block = block_with_params(builder, params, environ)?;
278+
let destination = block_with_params(builder, results.iter(), environ)?;
279+
let else_block = block_with_params(builder, params.iter(), environ)?;
280280
canonicalise_then_brz(builder, val, else_block, state.peekn(params.len()));
281281
builder.seal_block(else_block);
282282
(destination, ElseData::WithElse { else_block })
@@ -326,10 +326,11 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
326326
// already been pre-allocated, see `ElseData` for details).
327327
let else_block = match *else_data {
328328
ElseData::NoElse { branch_inst } => {
329-
let (params, _results) =
330-
module_translation_state.blocktype_params_results(blocktype)?;
329+
let (params, _results) = module_translation_state
330+
.blocktype_params_results(&blocktype)?;
331331
debug_assert_eq!(params.len(), num_return_values);
332-
let else_block = block_with_params(builder, params, environ)?;
332+
let else_block =
333+
block_with_params(builder, params.iter(), environ)?;
333334
canonicalise_then_jump(
334335
builder,
335336
destination,
@@ -1039,7 +1040,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
10391040
Operator::F32Le | Operator::F64Le => {
10401041
translate_fcmp(FloatCC::LessThanOrEqual, builder, state)
10411042
}
1042-
Operator::RefNull { ty } => state.push1(environ.translate_ref_null(builder.cursor(), *ty)?),
1043+
Operator::RefNull { hty } => {
1044+
state.push1(environ.translate_ref_null(builder.cursor(), hty)?)
1045+
}
10431046
Operator::RefIsNull => {
10441047
let value = state.pop1();
10451048
state.push1(environ.translate_ref_is_null(builder.cursor(), value)?);
@@ -2032,14 +2035,14 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
20322035
return Err(wasm_unsupported!("proposed tail-call operator {:?}", op));
20332036
}
20342037
Operator::I8x16RelaxedSwizzle
2035-
| Operator::I32x4RelaxedTruncSatF32x4S
2036-
| Operator::I32x4RelaxedTruncSatF32x4U
2037-
| Operator::I32x4RelaxedTruncSatF64x2SZero
2038-
| Operator::I32x4RelaxedTruncSatF64x2UZero
2039-
| Operator::F32x4RelaxedFma
2040-
| Operator::F32x4RelaxedFnma
2041-
| Operator::F64x2RelaxedFma
2042-
| Operator::F64x2RelaxedFnma
2038+
| Operator::I32x4RelaxedTruncF32x4S
2039+
| Operator::I32x4RelaxedTruncF32x4U
2040+
| Operator::I32x4RelaxedTruncF64x2SZero
2041+
| Operator::I32x4RelaxedTruncF64x2UZero
2042+
| Operator::F32x4RelaxedMadd
2043+
| Operator::F32x4RelaxedNmadd
2044+
| Operator::F64x2RelaxedMadd
2045+
| Operator::F64x2RelaxedNmadd
20432046
| Operator::I8x16RelaxedLaneselect
20442047
| Operator::I16x8RelaxedLaneselect
20452048
| Operator::I32x4RelaxedLaneselect
@@ -2048,12 +2051,44 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
20482051
| Operator::F32x4RelaxedMax
20492052
| Operator::F64x2RelaxedMin
20502053
| Operator::F64x2RelaxedMax
2051-
| Operator::F32x4RelaxedDotBf16x8AddF32x4
2052-
| Operator::I16x8RelaxedQ15mulrS
2053-
| Operator::I16x8DotI8x16I7x16S
2054-
| Operator::I32x4DotI8x16I7x16AddS => {
2054+
| Operator::I16x8RelaxedDotI8x16I7x16S => todo!(),
2055+
Operator::I32x4RelaxedDotI8x16I7x16AddS => todo!(),
2056+
Operator::I16x8RelaxedQ15mulrS => {
20552057
return Err(wasm_unsupported!("proposed relaxed-simd operator {:?}", op));
20562058
}
2059+
Operator::RefI31 | Operator::I31GetS | Operator::I31GetU => {
2060+
return Err(wasm_unsupported!("proposed i31 operator {:?}", op));
2061+
}
2062+
Operator::MemoryDiscard { mem: _ } => {
2063+
return Err(wasm_unsupported!(
2064+
"proposed memory-discard operator {:?}",
2065+
op
2066+
));
2067+
}
2068+
Operator::CallRef { type_index: _ } => {
2069+
return Err(wasm_unsupported!("proposed call-ref operator {:?}", op));
2070+
}
2071+
Operator::ReturnCallRef { type_index: _ } => {
2072+
return Err(wasm_unsupported!(
2073+
"proposed return-call-ref operator {:?}",
2074+
op
2075+
));
2076+
}
2077+
Operator::RefAsNonNull => {
2078+
return Err(wasm_unsupported!(
2079+
"proposed ref-as-non-null operator {:?}",
2080+
op
2081+
));
2082+
}
2083+
Operator::BrOnNull { relative_depth: _ } => {
2084+
return Err(wasm_unsupported!("proposed br-on-null operator {:?}", op));
2085+
}
2086+
Operator::BrOnNonNull { relative_depth: _ } => {
2087+
return Err(wasm_unsupported!(
2088+
"proposed br-on-non-null operator {:?}",
2089+
op
2090+
));
2091+
}
20572092
};
20582093
Ok(())
20592094
}
@@ -2107,9 +2142,10 @@ fn translate_unreachable_operator<FE: FuncEnvironment + ?Sized>(
21072142

21082143
let else_block = match *else_data {
21092144
ElseData::NoElse { branch_inst } => {
2110-
let (params, _results) =
2111-
module_translation_state.blocktype_params_results(blocktype)?;
2112-
let else_block = block_with_params(builder, params, environ)?;
2145+
let (params, _results) = module_translation_state
2146+
.blocktype_params_results(&blocktype)?;
2147+
let else_block =
2148+
block_with_params(builder, params.iter(), environ)?;
21132149
let frame = state.control_stack.last().unwrap();
21142150
frame.truncate_value_stack_to_else_params(&mut state.stack);
21152151

lib/compiler-cranelift/src/translator/func_environ.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use cranelift_codegen::ir::immediates::Offset32;
1212
use cranelift_codegen::ir::{self, InstBuilder};
1313
use cranelift_codegen::isa::TargetFrontendConfig;
1414
use cranelift_frontend::FunctionBuilder;
15-
use wasmer_compiler::wasmparser::{Operator, ValType};
15+
use wasmer_compiler::wasmparser::{HeapType, Operator};
1616
use wasmer_types::{
1717
FunctionIndex, FunctionType, GlobalIndex, LocalFunctionIndex, MemoryIndex, SignatureIndex,
1818
TableIndex, Type as WasmerType, WasmResult,
@@ -359,7 +359,7 @@ pub trait FuncEnvironment: TargetEnvironment {
359359
/// null sentinel is not a null reference type pointer for your type. If you
360360
/// override this method, then you should also override
361361
/// `translate_ref_is_null` as well.
362-
fn translate_ref_null(&mut self, pos: FuncCursor, ty: ValType) -> WasmResult<ir::Value>;
362+
fn translate_ref_null(&mut self, pos: FuncCursor, ty: &HeapType) -> WasmResult<ir::Value>;
363363
// {
364364
// let _ = ty;
365365
// Ok(pos.ins().null(self.reference_type(ty)))

lib/compiler-cranelift/src/translator/func_translator.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use cranelift_codegen::entity::EntityRef;
1515
use cranelift_codegen::ir::{self, Block, InstBuilder, ValueLabel};
1616
use cranelift_codegen::timing;
1717
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
18-
use wasmer_compiler::wasmparser;
18+
use wasmer_compiler::wasmparser::{self, RefType};
1919
use wasmer_compiler::{wptype_to_type, FunctionBinaryReader, ModuleTranslationState};
20-
use wasmer_types::{LocalFunctionIndex, WasmResult};
20+
use wasmer_types::{LocalFunctionIndex, WasmError, WasmResult};
2121

2222
/// WebAssembly to Cranelift IR function translator.
2323
///
@@ -194,8 +194,16 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
194194
let constant_handle = builder.func.dfg.constants.insert([0; 16].to_vec().into());
195195
builder.ins().vconst(ir::types::I8X16, constant_handle)
196196
}
197-
ExternRef => builder.ins().null(environ.reference_type()),
198-
FuncRef => builder.ins().null(environ.reference_type()),
197+
Ref(rt) => match rt {
198+
RefType::FUNC => builder.ins().null(environ.reference_type()),
199+
RefType::EXTERN => builder.ins().null(environ.reference_type()),
200+
other => {
201+
return Err(WasmError::Unsupported(format!(
202+
"Unsupported reference type: {:?}",
203+
other
204+
)))
205+
}
206+
},
199207
};
200208

201209
let wasmer_ty = wptype_to_type(wasm_type).unwrap();

0 commit comments

Comments
 (0)