From 720ed9c738cd482b668809d62a8a650fb7442501 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 15:55:17 -0800 Subject: [PATCH 1/8] deps: update to wasmparser@0.100.0 --- Cargo.toml | 2 +- src/init_expr.rs | 2 +- src/ir/mod.rs | 25 +++- src/module/data.rs | 7 +- src/module/debug/expression.rs | 16 +- src/module/elements.rs | 27 ++-- src/module/exports.rs | 7 +- src/module/functions/local_function/emit.rs | 23 ++- src/module/functions/local_function/mod.rs | 154 +++++++++++--------- src/module/functions/mod.rs | 40 ++--- src/module/imports.rs | 33 ++--- src/module/mod.rs | 134 ++++++++--------- src/module/producers.rs | 2 +- src/module/types.rs | 11 +- src/ty.rs | 25 ++-- 15 files changed, 268 insertions(+), 240 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb3c7d78..a471a189 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ log = "0.4.8" rayon = { version = "1.1.0", optional = true } walrus-macro = { path = './crates/macro', version = '=0.19.0' } wasm-encoder = "0.41.0" -wasmparser = "0.80.2" +wasmparser = "0.100.0" gimli = "0.26.0" [features] diff --git a/src/init_expr.rs b/src/init_expr.rs index 5c9f9bc8..d32dc216 100644 --- a/src/init_expr.rs +++ b/src/init_expr.rs @@ -22,7 +22,7 @@ pub enum InitExpr { } impl InitExpr { - pub(crate) fn eval(init: &wasmparser::InitExpr, ids: &IndicesToIds) -> Result { + pub(crate) fn eval(init: &wasmparser::ConstExpr, ids: &IndicesToIds) -> Result { use wasmparser::Operator::*; let mut reader = init.get_operators_reader(); let val = match reader.read()? { diff --git a/src/ir/mod.rs b/src/ir/mod.rs index e02ef54f..ed70feb3 100644 --- a/src/ir/mod.rs +++ b/src/ir/mod.rs @@ -496,7 +496,7 @@ pub enum Instr { }, /// The `atomic.fence` instruction - AtomicFence {}, + AtomicFence, /// `table.get` TableGet { @@ -717,6 +717,10 @@ pub enum BinaryOp { I64x2ReplaceLane { idx: u8 }, F32x4ReplaceLane { idx: u8 }, F64x2ReplaceLane { idx: u8 }, + I8x16RelaxedLaneselect, + I16x8RelaxedLaneselect, + I32x4RelaxedLaneselect, + I64x2RelaxedLaneselect, I8x16Eq, I8x16Ne, @@ -817,6 +821,8 @@ pub enum BinaryOp { F32x4Max, F32x4PMin, F32x4PMax, + F32x4RelaxedFma, + F32x4RelaxedFnma, F64x2Add, F64x2Sub, F64x2Mul, @@ -825,13 +831,18 @@ pub enum BinaryOp { F64x2Max, F64x2PMin, F64x2PMax, + F64x2RelaxedFma, + F64x2RelaxedFnma, + F64x2MinRelaxed, + F64x2MaxRelaxed, + I8x16RelaxedSwizzle, I8x16NarrowI16x8S, I8x16NarrowI16x8U, I16x8NarrowI32x4S, I16x8NarrowI32x4U, - I8x16RoundingAverageU, - I16x8RoundingAverageU, + I8x16AvgrU, + I16x8AvgrU, I8x16MinS, I8x16MinU, @@ -970,6 +981,10 @@ pub enum UnaryOp { F32x4Floor, F32x4Trunc, F32x4Nearest, + F32x4FmaRelaxed, + F32x4FmsRelaxed, + F32x4MinRelaxed, + F32x4MaxRelaxed, F64x2Abs, F64x2Neg, F64x2Sqrt, @@ -982,6 +997,10 @@ pub enum UnaryOp { I16x8ExtAddPairwiseI8x16U, I32x4ExtAddPairwiseI16x8S, I32x4ExtAddPairwiseI16x8U, + I32x4TruncSatF32x4SRelaxed, + I32x4TruncSatF32x4URelaxed, + I32x4TruncSatF64x2SZeroRelaxed, + I32x4TruncSatF64x2UZeroRelaxed, I64x2ExtendLowI32x4S, I64x2ExtendHighI32x4S, I64x2ExtendLowI32x4U, diff --git a/src/module/data.rs b/src/module/data.rs index 57139227..9469d1ca 100644 --- a/src/module/data.rs +++ b/src/module/data.rs @@ -1,10 +1,11 @@ //! Data segments within a wasm module. use crate::emit::{Emit, EmitContext}; +use crate::init_expr::InitExpr; use crate::ir::Value; use crate::parse::IndicesToIds; use crate::tombstone_arena::{Id, Tombstone, TombstoneArena}; -use crate::{GlobalId, InitExpr, MemoryId, Module, Result, ValType}; +use crate::{GlobalId, MemoryId, Module, Result, ValType}; use anyhow::{bail, Context}; /// A passive element segment identifier @@ -222,7 +223,7 @@ impl Module { } wasmparser::DataKind::Active { memory_index, - init_expr, + offset_expr, } => { data.value = segment.data.to_vec(); @@ -230,7 +231,7 @@ impl Module { let memory = self.memories.get_mut(memory_id); memory.data_segments.insert(data.id); - let offset = InitExpr::eval(&init_expr, ids) + let offset = InitExpr::eval(&offset_expr, ids) .with_context(|| format!("in segment {}", i))?; data.kind = DataKind::Active(ActiveData { memory: memory_id, diff --git a/src/module/debug/expression.rs b/src/module/debug/expression.rs index 3c95bbd8..582ff828 100644 --- a/src/module/debug/expression.rs +++ b/src/module/debug/expression.rs @@ -1,6 +1,6 @@ use crate::{CodeTransform, Function, InstrLocId, ModuleFunctions}; use id_arena::Id; -use std::cmp::Ordering; +use std::{cmp::Ordering, ops::Range}; use super::dwarf::AddressSearchPreference; @@ -22,7 +22,7 @@ pub(crate) enum CodeAddress { /// Converts original code address to CodeAddress pub(crate) struct CodeAddressGenerator { /// Function range based convert table - address_convert_table: Vec<(wasmparser::Range, Id)>, + address_convert_table: Vec<(Range, Id)>, /// Instrument based convert table instrument_address_convert_table: Vec<(usize, InstrLocId)>, } @@ -31,7 +31,7 @@ impl CodeAddressGenerator { pub(crate) fn new(funcs: &ModuleFunctions) -> Self { let mut address_convert_table = funcs .iter_local() - .filter_map(|(func_id, func)| func.original_range.map(|range| (range, func_id))) + .filter_map(|(func_id, func)| func.original_range.clone().map(|range| (range, func_id))) .collect::>(); let mut instrument_address_convert_table = funcs @@ -75,7 +75,7 @@ impl CodeAddressGenerator { }; // If the address is not mapped to any instruction, falling back to function-range-based comparison. - let inclusive_range_comparor = |range: &(wasmparser::Range, Id)| { + let inclusive_range_comparor = |range: &(Range, Id)| { // range.start < address <= range.end if range.0.end < address { Ordering::Less @@ -85,7 +85,7 @@ impl CodeAddressGenerator { Ordering::Equal } }; - let exclusive_range_comparor = |range: &(wasmparser::Range, Id)| { + let exclusive_range_comparor = |range: &(Range, Id)| { // normal comparison: range.start <= address < range.end if range.0.end <= address { Ordering::Less @@ -189,7 +189,7 @@ mod tests { crate::FunctionBuilder::new(&mut module.types, &[], &[]), ); - func1.original_range = Some(wasmparser::Range { start: 20, end: 30 }); + func1.original_range = Some(Range { start: 20, end: 30 }); let id1 = module.funcs.add_local(func1); @@ -198,7 +198,7 @@ mod tests { crate::FunctionBuilder::new(&mut module.types, &[], &[]), ); - func2.original_range = Some(wasmparser::Range { start: 30, end: 50 }); + func2.original_range = Some(Range { start: 30, end: 50 }); let id2 = module.funcs.add_local(func2); @@ -262,7 +262,7 @@ mod tests { { code_transform .function_ranges - .push((id1, wasmparser::Range { start: 50, end: 80 })); + .push((id1, Range { start: 50, end: 80 })); code_transform.instruction_map.push((instr_id1, 60)); code_transform.instruction_map.push((instr_id2, 65)); } diff --git a/src/module/elements.rs b/src/module/elements.rs index e5e8750d..f2fba6e9 100644 --- a/src/module/elements.rs +++ b/src/module/elements.rs @@ -1,9 +1,10 @@ //! Table elements within a wasm module. use crate::emit::{Emit, EmitContext}; +use crate::init_expr::InitExpr; use crate::parse::IndicesToIds; use crate::tombstone_arena::{Id, Tombstone, TombstoneArena}; -use crate::{ir::Value, FunctionId, InitExpr, Module, Result, TableId, ValType}; +use crate::{ir::Value, FunctionId, Module, Result, TableId, ValType}; use anyhow::{bail, Context}; /// A passive element segment identifier @@ -116,17 +117,15 @@ impl Module { ValType::Funcref => {} _ => bail!("only funcref type allowed in element segments"), } - let members = segment - .items - .get_items_reader()? - .into_iter() - .map(|e| -> Result<_> { - Ok(match e? { - wasmparser::ElementItem::Func(f) => Some(ids.get_func(f)?), - wasmparser::ElementItem::Null(_) => None, - }) - }) - .collect::>()?; + let members = match segment.items { + wasmparser::ElementItems::Functions(funcs) => funcs + .into_iter() + .map(|f| Ok(Some(ids.get_func(f?)?))) + .collect::>()?, + wasmparser::ElementItems::Expressions(exprs) => { + exprs.into_iter().map(|_| Ok(None)).collect::>()? + } + }; let id = self.elements.arena.next_id(); let kind = match segment.kind { @@ -134,12 +133,12 @@ impl Module { wasmparser::ElementKind::Declared => ElementKind::Declared, wasmparser::ElementKind::Active { table_index, - init_expr, + offset_expr, } => { let table = ids.get_table(table_index)?; self.tables.get_mut(table).elem_segments.insert(id); - let offset = InitExpr::eval(&init_expr, ids) + let offset = InitExpr::eval(&offset_expr, ids) .with_context(|| format!("in segment {}", i))?; match offset { InitExpr::Value(Value::I32(_)) => {} diff --git a/src/module/exports.rs b/src/module/exports.rs index f51042f9..1416facc 100644 --- a/src/module/exports.rs +++ b/src/module/exports.rs @@ -164,20 +164,17 @@ impl Module { for entry in section { let entry = entry?; let item = match entry.kind { - Function => ExportItem::Function(ids.get_func(entry.index)?), + Func => ExportItem::Function(ids.get_func(entry.index)?), Table => ExportItem::Table(ids.get_table(entry.index)?), Memory => ExportItem::Memory(ids.get_memory(entry.index)?), Global => ExportItem::Global(ids.get_global(entry.index)?), - Type | Module | Instance => { - unimplemented!("module linking not supported"); - } Tag => { unimplemented!("exception handling not supported"); } }; self.exports.arena.alloc_with_id(|id| Export { id, - name: entry.field.to_string(), + name: entry.name.to_string(), item, }); } diff --git a/src/module/functions/local_function/emit.rs b/src/module/functions/local_function/emit.rs index 226f5a46..59b687d3 100644 --- a/src/module/functions/local_function/emit.rs +++ b/src/module/functions/local_function/emit.rs @@ -356,7 +356,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> { I8x16MinU => Instruction::I8x16MinU, I8x16MaxS => Instruction::I8x16MaxS, I8x16MaxU => Instruction::I8x16MaxU, - I8x16RoundingAverageU => Instruction::I8x16AvgrU, + I8x16AvgrU => Instruction::I8x16AvgrU, I16x8NarrowI32x4S => Instruction::I16x8NarrowI32x4S, I16x8NarrowI32x4U => Instruction::I16x8NarrowI32x4U, @@ -374,7 +374,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> { I16x8MinU => Instruction::I16x8MinU, I16x8MaxS => Instruction::I16x8MaxS, I16x8MaxU => Instruction::I16x8MaxU, - I16x8RoundingAverageU => Instruction::I16x8AvgrU, + I16x8AvgrU => Instruction::I16x8AvgrU, I32x4Shl => Instruction::I32x4Shl, I32x4ShrS => Instruction::I32x4ShrS, @@ -423,10 +423,21 @@ impl<'instr> Visitor<'instr> for Emit<'_> { I32x4ExtMulHighI16x8S => Instruction::I32x4ExtMulHighI16x8S, I32x4ExtMulLowI16x8U => Instruction::I32x4ExtMulLowI16x8U, I32x4ExtMulHighI16x8U => Instruction::I32x4ExtMulHighI16x8U, + I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle, I64x2ExtMulLowI32x4S => Instruction::I64x2ExtMulLowI32x4S, I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S, I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U, I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U, + I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect, + I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect, + I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect, + I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect, + F64x2RelaxedFma => Instruction::F64x2RelaxedMadd, + F64x2RelaxedFnma => Instruction::F64x2RelaxedNmadd, + F64x2MinRelaxed => Instruction::F64x2RelaxedMin, + F64x2MaxRelaxed => Instruction::F64x2RelaxedMax, + F32x4RelaxedFma => Instruction::F32x4RelaxedMadd, + F32x4RelaxedFnma => Instruction::F32x4RelaxedNmadd, } } @@ -586,6 +597,14 @@ impl<'instr> Visitor<'instr> for Emit<'_> { F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U, F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero, F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4, + I32x4TruncSatF32x4SRelaxed => Instruction::I32x4RelaxedTruncF32x4S, + I32x4TruncSatF32x4URelaxed => Instruction::I32x4RelaxedTruncF32x4U, + I32x4TruncSatF64x2SZeroRelaxed => Instruction::I32x4RelaxedTruncF64x2SZero, + I32x4TruncSatF64x2UZeroRelaxed => Instruction::I32x4RelaxedTruncF64x2UZero, + F32x4FmaRelaxed => Instruction::F32x4RelaxedMadd, + F32x4FmsRelaxed => Instruction::F32x4RelaxedNmadd, + F32x4MinRelaxed => Instruction::F32x4RelaxedMin, + F32x4MaxRelaxed => Instruction::F32x4RelaxedMax, } } diff --git a/src/module/functions/local_function/mod.rs b/src/module/functions/local_function/mod.rs index 19931cfc..853eec16 100644 --- a/src/module/functions/local_function/mod.rs +++ b/src/module/functions/local_function/mod.rs @@ -10,7 +10,8 @@ use crate::map::{IdHashMap, IdHashSet}; use crate::parse::IndicesToIds; use crate::{Data, DataId, FunctionBuilder, FunctionId, MemoryId, Module, Result, TypeId, ValType}; use std::collections::BTreeMap; -use wasmparser::{FuncValidator, Operator, Range, ValidatorResources}; +use std::ops::Range; +use wasmparser::{FuncValidator, FuncValidatorAllocations, Operator, ValidatorResources}; /// A function defined locally within the wasm module. #[derive(Debug)] @@ -25,7 +26,7 @@ pub struct LocalFunction { pub instruction_mapping: Vec<(usize, InstrLocId)>, /// Original function binary range. - pub original_range: Option, + pub original_range: Option>, } impl LocalFunction { @@ -52,7 +53,7 @@ impl LocalFunction { mut body: wasmparser::BinaryReader<'_>, on_instr_pos: Option<&(dyn Fn(&usize) -> InstrLocId + Sync + Send + 'static)>, mut validator: FuncValidator, - ) -> Result { + ) -> Result<(LocalFunction, FuncValidatorAllocations)> { let code_address_offset = module.funcs.code_section_offset; let function_body_size = body.range().end - body.range().start; let function_body_size_bit = @@ -62,7 +63,7 @@ impl LocalFunction { builder: FunctionBuilder::without_entry(ty), args, instruction_mapping: Vec::new(), - original_range: Some(wasmparser::Range { + original_range: Some(Range { start: body.range().start - code_address_offset - (function_body_size_bit as usize), end: body.range().end - code_address_offset, }), @@ -98,7 +99,7 @@ impl LocalFunction { debug_assert!(ctx.controls.is_empty()); - Ok(func) + Ok((func, validator.into_allocations())) } /// Get this function's type. @@ -276,26 +277,21 @@ impl LocalFunction { } } -fn block_result_tys( - ctx: &ValidationContext, - ty: wasmparser::TypeOrFuncType, -) -> Result> { +fn block_result_tys(ctx: &ValidationContext, ty: wasmparser::BlockType) -> Result> { match ty { - wasmparser::TypeOrFuncType::Type(ty) => ValType::from_wasmparser_type(ty).map(Into::into), - wasmparser::TypeOrFuncType::FuncType(idx) => { + wasmparser::BlockType::Type(ty) => ValType::from_wasmparser_type(ty).map(Into::into), + wasmparser::BlockType::FuncType(idx) => { let ty = ctx.indices.get_type(idx)?; Ok(ctx.module.types.results(ty).into()) } + wasmparser::BlockType::Empty => Ok([][..].into()), } } -fn block_param_tys( - ctx: &ValidationContext, - ty: wasmparser::TypeOrFuncType, -) -> Result> { +fn block_param_tys(ctx: &ValidationContext, ty: wasmparser::BlockType) -> Result> { match ty { - wasmparser::TypeOrFuncType::Type(_) => Ok([][..].into()), - wasmparser::TypeOrFuncType::FuncType(idx) => { + wasmparser::BlockType::Empty | wasmparser::BlockType::Type(_) => Ok([][..].into()), + wasmparser::BlockType::FuncType(idx) => { let ty = ctx.indices.get_type(idx)?; Ok(ctx.module.types.params(ty).into()) } @@ -325,16 +321,15 @@ fn append_instruction<'context>( ctx.alloc_instr(Binop { op }, loc); }; - let mem_arg = - |ctx: &mut ValidationContext, arg: &wasmparser::MemoryImmediate| -> (MemoryId, MemArg) { - ( - ctx.indices.get_memory(arg.memory).unwrap(), - MemArg { - align: 1 << (arg.align as i32), - offset: arg.offset as u32, - }, - ) - }; + let mem_arg = |ctx: &mut ValidationContext, arg: &wasmparser::MemArg| -> (MemoryId, MemArg) { + ( + ctx.indices.get_memory(arg.memory).unwrap(), + MemArg { + align: 1 << (arg.align as i32), + offset: arg.offset as u32, + }, + ) + }; let load = |ctx: &mut ValidationContext, arg, kind| { let (memory, arg) = mem_arg(ctx, &arg); @@ -373,8 +368,12 @@ fn append_instruction<'context>( let func = ctx.indices.get_func(function_index).unwrap(); ctx.alloc_instr(Call { func }, loc); } - Operator::CallIndirect { index, table_index } => { - let type_id = ctx.indices.get_type(index).unwrap(); + Operator::CallIndirect { + type_index, + table_index, + .. + } => { + let type_id = ctx.indices.get_type(type_index).unwrap(); let table = ctx.indices.get_table(table_index).unwrap(); ctx.alloc_instr(CallIndirect { table, ty: type_id }, loc); } @@ -562,25 +561,25 @@ fn append_instruction<'context>( ctx.alloc_instr(Unreachable {}, loc); ctx.unreachable(); } - Operator::Block { ty } => { - let param_tys = block_param_tys(ctx, ty).unwrap(); - let result_tys = block_result_tys(ctx, ty).unwrap(); + Operator::Block { blockty } => { + let param_tys = block_param_tys(ctx, blockty).unwrap(); + let result_tys = block_result_tys(ctx, blockty).unwrap(); let seq = ctx .push_control(BlockKind::Block, param_tys, result_tys) .unwrap(); ctx.alloc_instr_in_control(1, Block { seq }, loc).unwrap(); } - Operator::Loop { ty } => { - let result_tys = block_result_tys(ctx, ty).unwrap(); - let param_tys = block_param_tys(ctx, ty).unwrap(); + Operator::Loop { blockty } => { + let result_tys = block_result_tys(ctx, blockty).unwrap(); + let param_tys = block_param_tys(ctx, blockty).unwrap(); let seq = ctx .push_control(BlockKind::Loop, param_tys, result_tys) .unwrap(); ctx.alloc_instr_in_control(1, Loop { seq }, loc).unwrap(); } - Operator::If { ty } => { - let result_tys = block_result_tys(ctx, ty).unwrap(); - let param_tys = block_param_tys(ctx, ty).unwrap(); + Operator::If { blockty } => { + let result_tys = block_result_tys(ctx, blockty).unwrap(); + let param_tys = block_param_tys(ctx, blockty).unwrap(); let consequent = ctx .push_control(BlockKind::If, param_tys, result_tys) @@ -672,22 +671,18 @@ fn append_instruction<'context>( ctx.alloc_instr(BrIf { block }, loc); } - Operator::BrTable { table } => { - let mut blocks = Vec::with_capacity(table.len()); - let mut default = None; - for pair in table.targets() { - let (target, is_default) = pair.unwrap(); + Operator::BrTable { targets } => { + let mut blocks = Vec::with_capacity(targets.len() as usize); + for pair in targets.targets() { + let target = pair.unwrap(); let control = ctx.control(target as usize).unwrap(); - if is_default { - default = Some(control.block); - } else { - blocks.push(control.block); - } + blocks.push(control.block); } + let default = ctx.control(targets.default() as usize).unwrap().block; ctx.alloc_instr( BrTable { blocks: blocks.into(), - default: default.unwrap(), + default, }, loc, ); @@ -702,18 +697,18 @@ fn append_instruction<'context>( let memory = ctx.indices.get_memory(mem).unwrap(); ctx.alloc_instr(MemoryGrow { memory }, loc); } - Operator::MemoryInit { segment, mem } => { + Operator::MemoryInit { data_index, mem } => { let memory = ctx.indices.get_memory(mem).unwrap(); - let data = ctx.indices.get_data(segment).unwrap(); + let data = ctx.indices.get_data(data_index).unwrap(); ctx.alloc_instr(MemoryInit { memory, data }, loc); } - Operator::DataDrop { segment } => { - let data = ctx.indices.get_data(segment).unwrap(); + Operator::DataDrop { data_index } => { + let data = ctx.indices.get_data(data_index).unwrap(); ctx.alloc_instr(DataDrop { data }, loc); } - Operator::MemoryCopy { src, dst } => { - let src = ctx.indices.get_memory(src).unwrap(); - let dst = ctx.indices.get_memory(dst).unwrap(); + Operator::MemoryCopy { dst_mem, src_mem } => { + let src = ctx.indices.get_memory(src_mem).unwrap(); + let dst = ctx.indices.get_memory(dst_mem).unwrap(); ctx.alloc_instr(MemoryCopy { src, dst }, loc); } Operator::MemoryFill { mem } => { @@ -750,7 +745,7 @@ fn append_instruction<'context>( Operator::I64Store16 { memarg } => store(ctx, memarg, StoreKind::I64_16 { atomic: false }), Operator::I64Store32 { memarg } => store(ctx, memarg, StoreKind::I64_32 { atomic: false }), - Operator::AtomicFence { flags: _ } => ctx.alloc_instr(AtomicFence {}, loc), + Operator::AtomicFence => ctx.alloc_instr(AtomicFence {}, loc), Operator::I32AtomicLoad { memarg } => load(ctx, memarg, LoadKind::I32 { atomic: true }), Operator::I64AtomicLoad { memarg } => load(ctx, memarg, LoadKind::I64 { atomic: true }), @@ -1042,6 +1037,10 @@ fn append_instruction<'context>( Operator::F64x2Splat => unop(ctx, UnaryOp::F64x2Splat), Operator::F64x2ExtractLane { lane: idx } => unop(ctx, UnaryOp::F64x2ExtractLane { idx }), Operator::F64x2ReplaceLane { lane: idx } => binop(ctx, BinaryOp::F64x2ReplaceLane { idx }), + Operator::I8x16RelaxedLaneselect => binop(ctx, BinaryOp::I8x16RelaxedLaneselect), + Operator::I16x8RelaxedLaneselect => binop(ctx, BinaryOp::I16x8RelaxedLaneselect), + Operator::I32x4RelaxedLaneselect => binop(ctx, BinaryOp::I32x4RelaxedLaneselect), + Operator::I64x2RelaxedLaneselect => binop(ctx, BinaryOp::I64x2RelaxedLaneselect), Operator::I8x16Eq => binop(ctx, BinaryOp::I8x16Eq), Operator::I8x16Ne => binop(ctx, BinaryOp::I8x16Ne), @@ -1209,9 +1208,26 @@ fn append_instruction<'context>( Operator::F64x2Nearest => unop(ctx, UnaryOp::F64x2Nearest), Operator::F64x2PMin => binop(ctx, BinaryOp::F64x2PMin), Operator::F64x2PMax => binop(ctx, BinaryOp::F64x2PMax), + Operator::F64x2RelaxedFma => binop(ctx, BinaryOp::F64x2RelaxedFma), + Operator::F64x2RelaxedFnma => binop(ctx, BinaryOp::F64x2RelaxedFnma), + Operator::F32x4RelaxedFma => binop(ctx, BinaryOp::F32x4RelaxedFma), + Operator::F32x4RelaxedFnma => binop(ctx, BinaryOp::F32x4RelaxedFnma), + + Operator::F32x4RelaxedMin => todo!(), + Operator::F32x4RelaxedMax => todo!(), + Operator::F64x2RelaxedMin => binop(ctx, BinaryOp::F64x2MinRelaxed), + Operator::F64x2RelaxedMax => binop(ctx, BinaryOp::F64x2MaxRelaxed), Operator::I32x4TruncSatF32x4S => unop(ctx, UnaryOp::I32x4TruncSatF32x4S), Operator::I32x4TruncSatF32x4U => unop(ctx, UnaryOp::I32x4TruncSatF32x4U), + Operator::I32x4RelaxedTruncSatF32x4S => unop(ctx, UnaryOp::I32x4TruncSatF32x4SRelaxed), + Operator::I32x4RelaxedTruncSatF32x4U => unop(ctx, UnaryOp::I32x4TruncSatF32x4URelaxed), + Operator::I32x4RelaxedTruncSatF64x2SZero => { + unop(ctx, UnaryOp::I32x4TruncSatF64x2SZeroRelaxed) + } + Operator::I32x4RelaxedTruncSatF64x2UZero => { + unop(ctx, UnaryOp::I32x4TruncSatF64x2UZeroRelaxed) + } Operator::F32x4ConvertI32x4S => unop(ctx, UnaryOp::F32x4ConvertI32x4S), Operator::F32x4ConvertI32x4U => unop(ctx, UnaryOp::F32x4ConvertI32x4U), @@ -1257,6 +1273,7 @@ fn append_instruction<'context>( } Operator::I8x16NarrowI16x8S => binop(ctx, BinaryOp::I8x16NarrowI16x8S), Operator::I8x16NarrowI16x8U => binop(ctx, BinaryOp::I8x16NarrowI16x8U), + Operator::I8x16RelaxedSwizzle => binop(ctx, BinaryOp::I8x16RelaxedSwizzle), Operator::I16x8NarrowI32x4S => binop(ctx, BinaryOp::I16x8NarrowI32x4S), Operator::I16x8NarrowI32x4U => binop(ctx, BinaryOp::I16x8NarrowI32x4U), Operator::I16x8ExtendLowI8x16S => unop(ctx, UnaryOp::I16x8WidenLowI8x16S), @@ -1273,8 +1290,8 @@ fn append_instruction<'context>( Operator::V128Load16x4U { memarg } => load_simd(ctx, memarg, LoadSimdKind::V128Load16x4U), Operator::V128Load32x2S { memarg } => load_simd(ctx, memarg, LoadSimdKind::V128Load32x2S), Operator::V128Load32x2U { memarg } => load_simd(ctx, memarg, LoadSimdKind::V128Load32x2U), - Operator::I8x16RoundingAverageU => binop(ctx, BinaryOp::I8x16RoundingAverageU), - Operator::I16x8RoundingAverageU => binop(ctx, BinaryOp::I16x8RoundingAverageU), + Operator::I8x16AvgrU => binop(ctx, BinaryOp::I8x16AvgrU), + Operator::I16x8AvgrU => binop(ctx, BinaryOp::I16x8AvgrU), Operator::I8x16MinS => binop(ctx, BinaryOp::I8x16MinS), Operator::I8x16MinU => binop(ctx, BinaryOp::I8x16MinU), @@ -1305,26 +1322,31 @@ fn append_instruction<'context>( ctx.alloc_instr(TableCopy { src, dst }, loc); } - Operator::TableInit { segment, table } => { - let elem = ctx.indices.get_element(segment).unwrap(); + Operator::TableInit { elem_index, table } => { + let elem = ctx.indices.get_element(elem_index).unwrap(); let table = ctx.indices.get_table(table).unwrap(); ctx.alloc_instr(TableInit { elem, table }, loc); } - Operator::ElemDrop { segment } => { - let elem = ctx.indices.get_element(segment).unwrap(); + Operator::ElemDrop { elem_index } => { + let elem = ctx.indices.get_element(elem_index).unwrap(); ctx.alloc_instr(ElemDrop { elem }, loc); } Operator::ReturnCall { .. } | Operator::ReturnCallIndirect { .. } - | Operator::Try { ty: _ } - | Operator::Catch { index: _ } - | Operator::Throw { index: _ } + | Operator::Try { blockty: _ } + | Operator::Catch { tag_index: _ } + | Operator::Throw { tag_index: _ } | Operator::Rethrow { relative_depth: _ } | Operator::Delegate { relative_depth: _ } | Operator::CatchAll => { unimplemented!("not supported") } + Operator::I16x8RelaxedQ15mulrS => todo!(), + Operator::I16x8DotI8x16I7x16S => todo!(), + Operator::I32x4DotI8x16I7x16AddS => todo!(), + Operator::F32x4RelaxedDotBf16x8AddF32x4 => todo!(), + Operator::MemoryDiscard { mem } => todo!(), } } diff --git a/src/module/functions/mod.rs b/src/module/functions/mod.rs index 530ce720..dd78abb1 100644 --- a/src/module/functions/mod.rs +++ b/src/module/functions/mod.rs @@ -2,10 +2,11 @@ use std::cmp; use std::collections::BTreeMap; +use std::ops::Range; use anyhow::{bail, Context}; use wasm_encoder::Encode; -use wasmparser::{FuncValidator, FunctionBody, Range, ValidatorResources}; +use wasmparser::{FuncToValidate, FuncValidatorAllocations, FunctionBody, ValidatorResources}; #[cfg(feature = "parallel")] use rayon::prelude::*; @@ -337,19 +338,21 @@ impl Module { /// Add the locally defined functions in the wasm module to this instance. pub(crate) fn parse_local_functions( &mut self, - functions: Vec<(FunctionBody<'_>, FuncValidator)>, + functions: Vec<(FunctionBody<'_>, FuncToValidate)>, indices: &mut IndicesToIds, on_instr_pos: Option<&(dyn Fn(&usize) -> InstrLocId + Sync + Send + 'static)>, ) -> Result<()> { log::debug!("parse code section"); let num_imports = self.funcs.arena.len() - functions.len(); + let mut allocs = FuncValidatorAllocations::default(); + // First up serially create corresponding `LocalId` instances for all // functions as well as extract the operators parser for each function. // This is pretty tough to parallelize, but we can look into it later if // necessary and it's a bottleneck! let mut bodies = Vec::with_capacity(functions.len()); - for (i, (body, mut validator)) in functions.into_iter().enumerate() { + for (i, (body, to_validate)) in functions.into_iter().enumerate() { let index = (num_imports + i) as u32; let id = indices.get_func(index)?; let ty = match self.funcs.arena[id].kind { @@ -380,10 +383,11 @@ impl Module { // Next up comes all the locals of the function. let mut reader = body.get_binary_reader(); + let mut validator = to_validate.into_validator(Default::default()); for _ in 0..reader.read_var_u32()? { let pos = reader.original_position(); let count = reader.read_var_u32()?; - let ty = reader.read_type()?; + let ty = reader.read()?; validator.define_locals(pos, count, ty)?; let ty = ValType::parse(&ty)?; for _ in 0..count { @@ -395,7 +399,6 @@ impl Module { } } } - bodies.push((id, reader, args, ty, validator)); } @@ -403,19 +406,22 @@ impl Module { // take some time, so parse all function bodies in parallel. let results = maybe_parallel!(bodies.(into_iter | into_par_iter)) .map(|(id, body, args, ty, validator)| { - ( + match LocalFunction::parse( + self, + indices, id, - LocalFunction::parse( - self, - indices, - id, - ty, - args, - body, - on_instr_pos, - validator, - ), - ) + ty, + args, + body, + on_instr_pos, + validator, + ) { + Ok((func, func_allocs)) => { + allocs = func_allocs; + (id, Ok(func)) + } + Err(err) => (id, Err(err)), + } }) .collect::>(); diff --git a/src/module/imports.rs b/src/module/imports.rs index e7e02289..d4582ff1 100644 --- a/src/module/imports.rs +++ b/src/module/imports.rs @@ -153,53 +153,40 @@ impl Module { for entry in section { let entry = entry?; match entry.ty { - wasmparser::ImportSectionEntryType::Function(idx) => { + wasmparser::TypeRef::Func(idx) => { let ty = ids.get_type(idx)?; - let id = self.add_import_func( - entry.module, - entry.field.expect("module linking not supported"), - ty, - ); + let id = self.add_import_func(entry.module, entry.name, ty); ids.push_func(id.0); } - wasmparser::ImportSectionEntryType::Table(t) => { + wasmparser::TypeRef::Table(t) => { let ty = ValType::parse(&t.element_type)?; - let id = self.add_import_table( - entry.module, - entry.field.expect("module linking not supported"), - t.initial, - t.maximum, - ty, - ); + let id = + self.add_import_table(entry.module, entry.name, t.initial, t.maximum, ty); ids.push_table(id.0); } - wasmparser::ImportSectionEntryType::Memory(m) => { + wasmparser::TypeRef::Memory(m) => { if m.memory64 { bail!("64-bit memories not supported") }; let id = self.add_import_memory( entry.module, - entry.field.expect("module linking not supported"), + entry.name, m.shared, m.initial as u32, m.maximum.map(|m| m as u32), ); ids.push_memory(id.0); } - wasmparser::ImportSectionEntryType::Global(g) => { + wasmparser::TypeRef::Global(g) => { let id = self.add_import_global( entry.module, - entry.field.expect("module linking not supported"), + entry.name, ValType::parse(&g.content_type)?, g.mutable, ); ids.push_global(id.0); } - wasmparser::ImportSectionEntryType::Module(_) - | wasmparser::ImportSectionEntryType::Instance(_) => { - unimplemented!("component model not implemented"); - } - wasmparser::ImportSectionEntryType::Tag(_) => { + wasmparser::TypeRef::Tag(_) => { unimplemented!("exception handling not implemented"); } } diff --git a/src/module/mod.rs b/src/module/mod.rs index 881b30f9..1c762f3f 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -43,6 +43,7 @@ use id_arena::Id; use log::warn; use std::fs; use std::mem; +use std::ops::Range; use std::path::Path; use wasmparser::{Parser, Payload, Validator, WasmFeatures}; @@ -93,7 +94,7 @@ pub struct CodeTransform { pub code_section_start: usize, /// Emitted binary ranges of functions - pub function_ranges: Vec<(Id, wasmparser::Range)>, + pub function_ranges: Vec<(Id, Range)>, } impl Module { @@ -132,8 +133,7 @@ impl Module { let mut ret = Module::default(); ret.config = config.clone(); let mut indices = IndicesToIds::default(); - let mut validator = Validator::new(); - validator.wasm_features(WasmFeatures { + let mut validator = Validator::new_with_features(WasmFeatures { reference_types: !config.only_stable_features, multi_value: true, bulk_memory: !config.only_stable_features, @@ -148,8 +148,12 @@ impl Module { for payload in Parser::new(0).parse_all(wasm) { match payload? { - Payload::Version { num, range } => { - validator.version(num, &range)?; + Payload::Version { + num, + range, + encoding, + } => { + validator.version(num, encoding, &range)?; } Payload::DataSection(s) => { validator @@ -218,22 +222,21 @@ impl Module { ret.funcs.code_section_offset = range.start; } Payload::CodeSectionEntry(body) => { - let validator = validator.code_section_entry()?; + let validator = validator.code_section_entry(&body)?; local_functions.push((body, validator)); } - Payload::CustomSection { - name, - data, - data_offset, - range: _range, - } => { + Payload::CustomSection(custom_section) => { + let name = custom_section.name(); + let data = custom_section.data(); + let data_offset = custom_section.data_offset(); let result = match name { "producers" => wasmparser::ProducersSectionReader::new(data, data_offset) .map_err(anyhow::Error::from) .and_then(|s| ret.parse_producers_section(s)), - "name" => wasmparser::NameSectionReader::new(data, data_offset) - .map_err(anyhow::Error::from) - .and_then(|r| ret.parse_name_section(r, &indices)), + "name" => ret.parse_name_section( + wasmparser::NameSectionReader::new(data, data_offset), + &indices, + ), _ => { log::debug!("parsing custom section `{}`", name); if name.starts_with(".debug") { @@ -259,37 +262,29 @@ impl Module { unreachable!() } - Payload::End => validator.end()?, - - // the module linking proposal is not implemented yet. - Payload::AliasSection(s) => { - validator.alias_section(&s)?; - bail!("not supported yet"); + Payload::End(s) => { + validator.end(s)?; } + Payload::InstanceSection(s) => { validator.instance_section(&s)?; bail!("not supported yet"); } - Payload::ModuleSectionEntry { - parser: _, - range: _, - } => { - validator.module_section_entry(); - bail!("not supported yet"); - } - Payload::ModuleSectionStart { - count, - range, - size: _, - } => { - validator.module_section_start(count, &range)?; - bail!("not supported yet"); - } // exception handling is not implemented yet. Payload::TagSection(s) => { validator.tag_section(&s)?; bail!("not supported yet"); } + Payload::ComponentTypeSection(_) => bail!("not supported"), + Payload::ComponentImportSection(_) => bail!("not supported"), + Payload::ModuleSection { .. } => bail!("not supported"), + Payload::ComponentSection { .. } => bail!("not supported"), + Payload::ComponentExportSection(_) => bail!("not supported"), + Payload::ComponentStartSection { .. } => bail!("not supported"), + Payload::CoreTypeSection(_) => bail!("not supported"), + Payload::ComponentInstanceSection(_) => bail!("not supported"), + Payload::ComponentAliasSection(_) => bail!("not supported"), + Payload::ComponentCanonicalSection(_) => bail!("not supported"), } } @@ -415,13 +410,12 @@ impl Module { log::debug!("parse name section"); for name in names { match name? { - wasmparser::Name::Module(m) => { - self.name = Some(m.get_name()?.to_string()); + wasmparser::Name::Module { name, .. } => { + self.name = Some(name.to_string()); } - wasmparser::Name::Function(f) => { - let mut map = f.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Function(map) => { + for naming in map { + let naming = naming?; match indices.get_func(naming.index) { Ok(id) => self.funcs.get_mut(id).name = Some(naming.name.to_string()), // If some tool fails to GC function names properly, @@ -431,20 +425,18 @@ impl Module { } } } - wasmparser::Name::Type(t) => { - let mut map = t.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Type(map) => { + for naming in map { + let naming = naming?; match indices.get_type(naming.index) { Ok(id) => self.types.get_mut(id).name = Some(naming.name.to_string()), Err(e) => warn!("in name section: {}", e), } } } - wasmparser::Name::Memory(m) => { - let mut map = m.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Memory(map) => { + for naming in map { + let naming = naming?; match indices.get_memory(naming.index) { Ok(id) => { self.memories.get_mut(id).name = Some(naming.name.to_string()) @@ -453,30 +445,27 @@ impl Module { } } } - wasmparser::Name::Table(t) => { - let mut map = t.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Table(map) => { + for naming in map { + let naming = naming?; match indices.get_table(naming.index) { Ok(id) => self.tables.get_mut(id).name = Some(naming.name.to_string()), Err(e) => warn!("in name section: {}", e), } } } - wasmparser::Name::Data(d) => { - let mut map = d.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Data(map) => { + for naming in map { + let naming = naming?; match indices.get_data(naming.index) { Ok(id) => self.data.get_mut(id).name = Some(naming.name.to_string()), Err(e) => warn!("in name section: {}", e), } } } - wasmparser::Name::Element(e) => { - let mut map = e.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Element(map) => { + for naming in map { + let naming = naming?; match indices.get_element(naming.index) { Ok(id) => { self.elements.get_mut(id).name = Some(naming.name.to_string()) @@ -485,24 +474,21 @@ impl Module { } } } - wasmparser::Name::Global(e) => { - let mut map = e.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Global(map) => { + for naming in map { + let naming = naming?; match indices.get_global(naming.index) { Ok(id) => self.globals.get_mut(id).name = Some(naming.name.to_string()), Err(e) => warn!("in name section: {}", e), } } } - wasmparser::Name::Local(l) => { - let mut reader = l.get_indirect_map()?; - for _ in 0..reader.get_indirect_count() { - let name = reader.read()?; - let func_id = indices.get_func(name.indirect_index)?; - let mut map = name.get_map()?; - for _ in 0..map.get_count() { - let naming = map.read()?; + wasmparser::Name::Local(indirect_map) => { + for indirect_naming in indirect_map { + let indirect_naming = indirect_naming?; + let func_id = indices.get_func(indirect_naming.index)?; + for naming in indirect_naming.names { + let naming = naming?; // Looks like tools like `wat2wasm` generate empty // names for locals if they aren't specified, so // just ignore empty names which would in theory diff --git a/src/module/producers.rs b/src/module/producers.rs index d6570bfd..8dae0c96 100644 --- a/src/module/producers.rs +++ b/src/module/producers.rs @@ -83,7 +83,7 @@ impl Module { for field in data { let field = field?; let mut values = Vec::new(); - for value in field.get_producer_field_values_reader()? { + for value in field.values { let value = value?; values.push(Value { name: value.name.to_string(), diff --git a/src/module/types.rs b/src/module/types.rs index f48fcaae..84e37666 100644 --- a/src/module/types.rs +++ b/src/module/types.rs @@ -119,19 +119,16 @@ impl Module { ) -> Result<()> { log::debug!("parsing type section"); for ty in section { - let fun_ty = match ty? { - wasmparser::TypeDef::Func(ty) => ty, - _ => unimplemented!("module linking not supported"), - }; + let wasmparser::Type::Func(fun_ty) = ty?; let id = self.types.arena.next_id(); let params = fun_ty - .params + .params() .iter() - .map(ValType::parse) + .map(|t| ValType::parse(t)) .collect::>>()? .into_boxed_slice(); let results = fun_ty - .returns + .results() .iter() .map(ValType::parse) .collect::>>()? diff --git a/src/ty.rs b/src/ty.rs index bcbede96..4dd401c9 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -2,7 +2,6 @@ use crate::error::Result; use crate::tombstone_arena::Tombstone; -use anyhow::bail; use id_arena::Id; use std::cmp::Ordering; use std::fmt; @@ -142,11 +141,8 @@ pub enum ValType { } impl ValType { - pub(crate) fn from_wasmparser_type(ty: wasmparser::Type) -> Result> { - let v = match ty { - wasmparser::Type::EmptyBlockType => Vec::new(), - _ => vec![ValType::parse(&ty)?], - }; + pub(crate) fn from_wasmparser_type(ty: wasmparser::ValType) -> Result> { + let v = vec![ValType::parse(&ty)?]; Ok(v.into_boxed_slice()) } @@ -162,16 +158,15 @@ impl ValType { } } - pub(crate) fn parse(input: &wasmparser::Type) -> Result { + pub(crate) fn parse(input: &wasmparser::ValType) -> Result { match input { - wasmparser::Type::I32 => Ok(ValType::I32), - wasmparser::Type::I64 => Ok(ValType::I64), - wasmparser::Type::F32 => Ok(ValType::F32), - wasmparser::Type::F64 => Ok(ValType::F64), - wasmparser::Type::V128 => Ok(ValType::V128), - wasmparser::Type::ExternRef => Ok(ValType::Externref), - wasmparser::Type::FuncRef => Ok(ValType::Funcref), - _ => bail!("not a value type"), + wasmparser::ValType::I32 => Ok(ValType::I32), + wasmparser::ValType::I64 => Ok(ValType::I64), + wasmparser::ValType::F32 => Ok(ValType::F32), + wasmparser::ValType::F64 => Ok(ValType::F64), + wasmparser::ValType::V128 => Ok(ValType::V128), + wasmparser::ValType::ExternRef => Ok(ValType::Externref), + wasmparser::ValType::FuncRef => Ok(ValType::Funcref), } } } From 0700df97e2f6271188b4dd336f914ba51b8f37a0 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 15:58:17 -0800 Subject: [PATCH 2/8] fix warning --- src/module/functions/local_function/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module/functions/local_function/mod.rs b/src/module/functions/local_function/mod.rs index 853eec16..5aa288e0 100644 --- a/src/module/functions/local_function/mod.rs +++ b/src/module/functions/local_function/mod.rs @@ -1347,6 +1347,6 @@ fn append_instruction<'context>( Operator::I16x8DotI8x16I7x16S => todo!(), Operator::I32x4DotI8x16I7x16AddS => todo!(), Operator::F32x4RelaxedDotBf16x8AddF32x4 => todo!(), - Operator::MemoryDiscard { mem } => todo!(), + Operator::MemoryDiscard { mem: _ } => todo!(), } } From def8b516874a99521cabde549e8aacec9eef9998 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 16:31:09 -0800 Subject: [PATCH 3/8] runner updates --- crates/tests/tests/spec-tests.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/tests/tests/spec-tests.rs b/crates/tests/tests/spec-tests.rs index 1b1b9e28..2bccb127 100644 --- a/crates/tests/tests/spec-tests.rs +++ b/crates/tests/tests/spec-tests.rs @@ -22,18 +22,22 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> { .skip(1) .next() .map(|s| s.to_str().unwrap()); + + let mut config = walrus::ModuleConfig::new(); let extra_args: &[&str] = match proposal { // stable features None | Some("multi-value") | Some("nontrapping-float-to-int-conversions") | Some("sign-extension-ops") - | Some("mutable-global") => &[], + | Some("mutable-global") => { + config.only_stable_features(true); + &[] + } - Some("simd") => &["--enable-simd"], - Some("bulk-memory-operations") => &["--enable-bulk-memory"], + Some("bulk-memory-operations") | Some("simd") => &[], - Some("reference-types") => &["--enable-reference-types", "--enable-bulk-memory"], + Some("reference-types") => &["--enable-reference-types"], // TODO: should get threads working Some("threads") => return Ok(()), @@ -69,11 +73,6 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> { let test: Test = serde_json::from_str(&contents).context("failed to parse file")?; let mut files = Vec::new(); - let mut config = walrus::ModuleConfig::new(); - if extra_args.len() == 0 { - config.only_stable_features(true); - } - for command in test.commands { let filename = match command.get("filename") { Some(name) => name.as_str().unwrap().to_string(), From 7c20ef13d5e0e14c5593d012b04b285db4f12b37 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 17:25:27 -0800 Subject: [PATCH 4/8] use wasmparser 100 spec tests --- crates/tests/tests/spec-tests | 2 +- crates/tests/tests/spec-tests.rs | 17 ++++++++++++----- src/module/mod.rs | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/tests/tests/spec-tests b/crates/tests/tests/spec-tests index 01efde81..4f77306b 160000 --- a/crates/tests/tests/spec-tests +++ b/crates/tests/tests/spec-tests @@ -1 +1 @@ -Subproject commit 01efde81028c5b0d099eb836645a2dc5e7755449 +Subproject commit 4f77306bb63151631d84f58dedf67958eb9911b9 diff --git a/crates/tests/tests/spec-tests.rs b/crates/tests/tests/spec-tests.rs index 2bccb127..20ffa546 100644 --- a/crates/tests/tests/spec-tests.rs +++ b/crates/tests/tests/spec-tests.rs @@ -26,18 +26,25 @@ fn run(wast: &Path) -> Result<(), anyhow::Error> { let mut config = walrus::ModuleConfig::new(); let extra_args: &[&str] = match proposal { // stable features - None - | Some("multi-value") + Some("multi-value") | Some("nontrapping-float-to-int-conversions") | Some("sign-extension-ops") - | Some("mutable-global") => { + | Some("mutable-global") + | Some("simd") => { config.only_stable_features(true); &[] } - Some("bulk-memory-operations") | Some("simd") => &[], + None | Some("bulk-memory-operations") => &[], - Some("reference-types") => &["--enable-reference-types"], + Some("multi-memory") => &["--enable-multi-memory"], + + Some("reference-types") => &[], + + Some("extended-const") => &["--enable-extended-const"], + + Some("relaxed-simd") => return Ok(()), + Some("gc") => return Ok(()), // TODO: should get threads working Some("threads") => return Ok(()), diff --git a/src/module/mod.rs b/src/module/mod.rs index 1c762f3f..e42070bf 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -136,10 +136,10 @@ impl Module { let mut validator = Validator::new_with_features(WasmFeatures { reference_types: !config.only_stable_features, multi_value: true, - bulk_memory: !config.only_stable_features, - simd: !config.only_stable_features, + bulk_memory: true, + simd: true, threads: !config.only_stable_features, - multi_memory: !config.only_stable_features, + multi_memory: true, ..WasmFeatures::default() }); From 3034084ab0facf5a5c29ed22d4eeddb28dd33f3e Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 17:49:54 -0800 Subject: [PATCH 5/8] fixup wabt commit --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index daa88a39..9422bd53 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 with: repository: WebAssembly/wabt - ref: aa0515b3c808da880942db8658abeaa969534667 + ref: f02fa321d5f8392fcb02f0a5d path: wabt - name: Build wabt run: | From f7e58d80b915759be5b907102cc276d2d7cc3825 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 17:50:43 -0800 Subject: [PATCH 6/8] wabt 1.0.33 --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9422bd53..67c6481e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,8 +51,8 @@ jobs: - name: Install wabt run: | set -e - curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.13/wabt-1.0.13-linux.tar.gz | tar xzf - - echo "`pwd`/wabt-1.0.13" > $GITHUB_PATH + curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-linux.tar.gz | tar xzf - + echo "`pwd`/wabt-1.0.33" > $GITHUB_PATH - name: Install binaryen run: | set -e @@ -78,8 +78,8 @@ jobs: - name: Install wabt run: | set -e - curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.13/wabt-1.0.13-linux.tar.gz | tar xzf - - echo "`pwd`/wabt-1.0.13" > $GITHUB_PATH + curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-linux.tar.gz | tar xzf - + echo "`pwd`/wabt-1.0.33" > $GITHUB_PATH - name: Install binaryen run: | set -e From e55fa356f1afee56e944c0cccc7d9936d55fac47 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 17:52:17 -0800 Subject: [PATCH 7/8] update wabt url --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 67c6481e..60da9231 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,7 @@ jobs: - name: Install wabt run: | set -e - curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-linux.tar.gz | tar xzf - + curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-ubuntu.tar.gz | tar xzf - echo "`pwd`/wabt-1.0.33" > $GITHUB_PATH - name: Install binaryen run: | @@ -78,7 +78,7 @@ jobs: - name: Install wabt run: | set -e - curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-linux.tar.gz | tar xzf - + curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.33/wabt-1.0.33-ubuntu.tar.gz | tar xzf - echo "`pwd`/wabt-1.0.33" > $GITHUB_PATH - name: Install binaryen run: | From 4efdb5c8951a83deb64d02a8822f9442948a6401 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 28 Feb 2024 17:53:43 -0800 Subject: [PATCH 8/8] use full ref --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60da9231..f8dfe068 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 with: repository: WebAssembly/wabt - ref: f02fa321d5f8392fcb02f0a5d + ref: f02fa321d5f8392fcb02f0a5d5ff72b901e29a78 path: wabt - name: Build wabt run: |