diff --git a/Cargo.lock b/Cargo.lock index b3499921b4e5..118d6600f5c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3343,15 +3343,15 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.80.1" +version = "0.81.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92b6dcaa5af4b2a176b29be3bf1402fab9e69d313141185099c7d1684f2dca" +checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc" [[package]] name = "wasmprinter" -version = "0.2.29" +version = "0.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f62f18810edc34db799bcb3d555835b2eecc9b6b221f8ee74fdb5aae0bffa176" +checksum = "a00ad4a51ba74183137c776ab37dea50b9f71db7454d7b654c2ba69ac5d9b223" dependencies = [ "anyhow", "wasmparser", diff --git a/Cargo.toml b/Cargo.toml index d69e3ac062e6..9f8aa6cc2418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ libc = "0.2.60" log = "0.4.8" rayon = "1.5.0" humantime = "2.0.0" -wasmparser = "0.80.0" +wasmparser = "0.81.0" lazy_static = "1.4.0" [target.'cfg(unix)'.dependencies] diff --git a/build.rs b/build.rs index d5f21e032f3d..ee11d9572b79 100644 --- a/build.rs +++ b/build.rs @@ -24,8 +24,6 @@ fn main() -> anyhow::Result<()> { with_test_module(&mut out, "misc", |out| { test_directory(out, "tests/misc_testsuite", strategy)?; - test_directory_module(out, "tests/misc_testsuite/bulk-memory-operations", strategy)?; - test_directory_module(out, "tests/misc_testsuite/reference-types", strategy)?; test_directory_module(out, "tests/misc_testsuite/multi-memory", strategy)?; test_directory_module(out, "tests/misc_testsuite/module-linking", strategy)?; test_directory_module(out, "tests/misc_testsuite/simd", strategy)?; @@ -40,16 +38,6 @@ fn main() -> anyhow::Result<()> { // out. if spec_tests > 0 { test_directory_module(out, "tests/spec_testsuite/proposals/simd", strategy)?; - test_directory_module( - out, - "tests/spec_testsuite/proposals/reference-types", - strategy, - )?; - test_directory_module( - out, - "tests/spec_testsuite/proposals/bulk-memory-operations", - strategy, - )?; test_directory_module(out, "tests/spec_testsuite/proposals/memory64", strategy)?; } else { println!( diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index cd45a4faac76..f4d36f878b3e 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["webassembly", "wasm"] edition = "2018" [dependencies] -wasmparser = { version = "0.80", default-features = false } +wasmparser = { version = "0.81", default-features = false } cranelift-codegen = { path = "../codegen", version = "0.77.0", default-features = false } cranelift-entity = { path = "../entity", version = "0.77.0" } cranelift-frontend = { path = "../frontend", version = "0.77.0", default-features = false } diff --git a/cranelift/wasm/src/code_translator.rs b/cranelift/wasm/src/code_translator.rs index 2ee9df7fbbe9..445c6ae64ea1 100644 --- a/cranelift/wasm/src/code_translator.rs +++ b/cranelift/wasm/src/code_translator.rs @@ -442,12 +442,12 @@ pub fn translate_operator( } Operator::BrIf { relative_depth } => translate_br_if(*relative_depth, builder, state), Operator::BrTable { table } => { - let mut depths = table.targets().collect::, _>>()?; - let default = depths.pop().unwrap().0; + let default = table.default(); let mut min_depth = default; - for (depth, _) in depths.iter() { - if *depth < min_depth { - min_depth = *depth; + for depth in table.targets() { + let depth = depth?; + if depth < min_depth { + min_depth = depth; } } let jump_args_count = { @@ -460,12 +460,13 @@ pub fn translate_operator( } }; let val = state.pop1(); - let mut data = JumpTableData::with_capacity(depths.len()); + let mut data = JumpTableData::with_capacity(table.len() as usize); if jump_args_count == 0 { // No jump arguments - for (depth, _) in depths.iter() { + for depth in table.targets() { + let depth = depth?; let block = { - let i = state.control_stack.len() - 1 - (*depth as usize); + let i = state.control_stack.len() - 1 - (depth as usize); let frame = &mut state.control_stack[i]; frame.set_branched_to_exit(); frame.br_destination() @@ -486,12 +487,13 @@ pub fn translate_operator( let return_count = jump_args_count; let mut dest_block_sequence = vec![]; let mut dest_block_map = HashMap::new(); - for (depth, _) in depths.iter() { - let branch_block = match dest_block_map.entry(*depth as usize) { + for depth in table.targets() { + let depth = depth?; + let branch_block = match dest_block_map.entry(depth as usize) { hash_map::Entry::Occupied(entry) => *entry.get(), hash_map::Entry::Vacant(entry) => { let block = builder.create_block(); - dest_block_sequence.push((*depth as usize, block)); + dest_block_sequence.push((depth as usize, block)); *entry.insert(block) } }; diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index e38afc2f05b4..53bc7d792689 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -337,7 +337,16 @@ fn read_elems(items: &ElementItems) -> WasmResult> { let mut elems = Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap()); for item in items_reader { let elem = match item? { - ElementItem::Null(_ty) => FuncIndex::reserved_value(), + ElementItem::Expr(init) => match init.get_binary_reader().read_operator()? { + Operator::RefNull { .. } => FuncIndex::reserved_value(), + Operator::RefFunc { function_index } => FuncIndex::from_u32(function_index), + s => { + return Err(WasmError::Unsupported(format!( + "unsupported init expr in element section: {:?}", + s + ))); + } + }, ElementItem::Func(index) => FuncIndex::from_u32(index), }; elems.push(elem); diff --git a/crates/cranelift/Cargo.toml b/crates/cranelift/Cargo.toml index 6e76c0d9f00a..9339b71fee9f 100644 --- a/crates/cranelift/Cargo.toml +++ b/crates/cranelift/Cargo.toml @@ -19,7 +19,7 @@ cranelift-codegen = { path = "../../cranelift/codegen", version = "0.77.0" } cranelift-frontend = { path = "../../cranelift/frontend", version = "0.77.0" } cranelift-entity = { path = "../../cranelift/entity", version = "0.77.0" } cranelift-native = { path = '../../cranelift/native', version = '0.77.0' } -wasmparser = "0.80.0" +wasmparser = "0.81.0" target-lexicon = "0.12" gimli = { version = "0.25.0", default-features = false, features = ['read', 'std'] } object = { version = "0.26.0", default-features = false, features = ['write'] } diff --git a/crates/environ/Cargo.toml b/crates/environ/Cargo.toml index 1eedcb16ac4f..cc9756688f13 100644 --- a/crates/environ/Cargo.toml +++ b/crates/environ/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" anyhow = "1.0" cranelift-entity = { path = "../../cranelift/entity", version = "0.77.0" } wasmtime-types = { path = "../types", version = "0.30.0" } -wasmparser = "0.80" +wasmparser = "0.81" indexmap = { version = "1.0.2", features = ["serde-1"] } thiserror = "1.0.4" serde = { version = "1.0.94", features = ["derive"] } diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index a4a558e34aa7..33de486a6967 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -527,13 +527,28 @@ impl<'data> ModuleEnvironment<'data> { let mut elements = Vec::with_capacity(usize::try_from(items_reader.get_count()).unwrap()); for item in items_reader { - elements.push(match item? { - ElementItem::Func(f) => { + let func = match item? { + ElementItem::Func(f) => Some(f), + ElementItem::Expr(init) => { + match init.get_binary_reader().read_operator()? { + Operator::RefNull { .. } => None, + Operator::RefFunc { function_index } => Some(function_index), + s => { + return Err(WasmError::Unsupported(format!( + "unsupported init expr in element section: {:?}", + s + ))); + } + } + } + }; + elements.push(match func { + Some(f) => { let f = FuncIndex::from_u32(f); self.flag_func_escaped(f); f } - ElementItem::Null(_ty) => FuncIndex::reserved_value(), + None => FuncIndex::reserved_value(), }); } diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index fcdcfac483a1..ae7d73b50763 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -13,8 +13,8 @@ arbitrary = { version = "1.0.0", features = ["derive"] } env_logger = "0.8.1" log = "0.4.8" rayon = "1.2.1" -wasmparser = "0.80" -wasmprinter = "0.2.28" +wasmparser = "0.81" +wasmprinter = "0.2.31" wasmtime = { path = "../wasmtime" } wasmtime-wast = { path = "../wast" } wasm-encoder = "0.6.0" diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index f9d9a4dc088c..d881b14d1f74 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -16,7 +16,7 @@ wasmtime-runtime = { path = "../runtime", version = "0.30.0" } region = "2.2.0" thiserror = "1.0.4" target-lexicon = { version = "0.12.0", default-features = false } -wasmparser = "0.80" +wasmparser = "0.81" more-asserts = "0.2.1" anyhow = "1.0" cfg-if = "1.0" diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 6ebc22f09f21..d4a122479845 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -12,4 +12,4 @@ edition = "2018" cranelift-entity = { path = "../../cranelift/entity", version = "0.77.0", features = ['enable-serde'] } serde = { version = "1.0.94", features = ["derive"] } thiserror = "1.0.4" -wasmparser = { version = "0.80", default-features = false } +wasmparser = { version = "0.81", default-features = false } diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index b38205bfeb9f..a848d87f9d67 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -20,7 +20,7 @@ wasmtime-cache = { path = "../cache", version = "0.30.0", optional = true } wasmtime-fiber = { path = "../fiber", version = "0.30.0", optional = true } wasmtime-cranelift = { path = "../cranelift", version = "0.30.0", optional = true } target-lexicon = { version = "0.12.0", default-features = false } -wasmparser = "0.80" +wasmparser = "0.81" anyhow = "1.0.19" region = "2.2.0" libc = "0.2" diff --git a/crates/wasmtime/src/externals.rs b/crates/wasmtime/src/externals.rs index 5a5fe3eb9e56..6324bac13ee4 100644 --- a/crates/wasmtime/src/externals.rs +++ b/crates/wasmtime/src/externals.rs @@ -523,7 +523,10 @@ impl Table { /// /// Panics if `store` does not own this table. pub fn size(&self, store: impl AsContext) -> u32 { - let store = store.as_context(); + self.internal_size(store.as_context().0) + } + + pub(crate) fn internal_size(&self, store: &StoreOpaque) -> u32 { unsafe { (*store[self.0].definition).current_elements } } diff --git a/crates/wasmtime/src/memory.rs b/crates/wasmtime/src/memory.rs index 645ecaaa159a..a1b305118bdf 100644 --- a/crates/wasmtime/src/memory.rs +++ b/crates/wasmtime/src/memory.rs @@ -396,7 +396,11 @@ impl Memory { /// /// Panics if this memory doesn't belong to `store`. pub fn data_size(&self, store: impl AsContext) -> usize { - unsafe { (*store.as_context()[self.0].definition).current_length } + self.internal_data_size(store.as_context().0) + } + + pub(crate) fn internal_data_size(&self, store: &StoreOpaque) -> usize { + unsafe { (*store[self.0].definition).current_length } } /// Returns the size, in WebAssembly pages, of this wasm memory. @@ -405,7 +409,11 @@ impl Memory { /// /// Panics if this memory doesn't belong to `store`. pub fn size(&self, store: impl AsContext) -> u64 { - (self.data_size(store) / wasmtime_environ::WASM_PAGE_SIZE as usize) as u64 + self.internal_size(store.as_context().0) + } + + pub(crate) fn internal_size(&self, store: &StoreOpaque) -> u64 { + (self.internal_data_size(store) / wasmtime_environ::WASM_PAGE_SIZE as usize) as u64 } /// Grows this WebAssembly memory by `delta` pages. diff --git a/crates/wasmtime/src/types/matching.rs b/crates/wasmtime/src/types/matching.rs index d422acc1a484..4df6170394f5 100644 --- a/crates/wasmtime/src/types/matching.rs +++ b/crates/wasmtime/src/types/matching.rs @@ -35,15 +35,24 @@ impl MatchCx<'_> { } pub fn table(&self, expected: &Table, actual: &crate::Table) -> Result<()> { - self.table_ty(expected, actual.wasmtime_ty(self.store.store_data())) + self.table_ty( + expected, + actual.wasmtime_ty(self.store.store_data()), + Some(actual.internal_size(self.store)), + ) } - fn table_ty(&self, expected: &Table, actual: &Table) -> Result<()> { + fn table_ty( + &self, + expected: &Table, + actual: &Table, + actual_runtime_size: Option, + ) -> Result<()> { match_ty(expected.wasm_ty, actual.wasm_ty, "table")?; match_limits( expected.minimum.into(), expected.maximum.map(|i| i.into()), - actual.minimum.into(), + actual_runtime_size.unwrap_or(actual.minimum).into(), actual.maximum.map(|i| i.into()), "table", )?; @@ -51,10 +60,19 @@ impl MatchCx<'_> { } pub fn memory(&self, expected: &Memory, actual: &crate::Memory) -> Result<()> { - self.memory_ty(expected, actual.wasmtime_ty(self.store.store_data())) + self.memory_ty( + expected, + actual.wasmtime_ty(self.store.store_data()), + Some(actual.internal_size(self.store)), + ) } - fn memory_ty(&self, expected: &Memory, actual: &Memory) -> Result<()> { + fn memory_ty( + &self, + expected: &Memory, + actual: &Memory, + actual_runtime_size: Option, + ) -> Result<()> { match_bool( expected.shared, actual.shared, @@ -72,7 +90,7 @@ impl MatchCx<'_> { match_limits( expected.minimum, expected.maximum, - actual.minimum, + actual_runtime_size.unwrap_or(actual.minimum), actual.maximum, "memory", )?; @@ -280,11 +298,11 @@ impl MatchCx<'_> { _ => bail!("expected global, but found {}", actual_desc), }, EntityType::Table(expected) => match actual_ty { - EntityType::Table(actual) => self.table_ty(expected, actual), + EntityType::Table(actual) => self.table_ty(expected, actual, None), _ => bail!("expected table, but found {}", actual_desc), }, EntityType::Memory(expected) => match actual_ty { - EntityType::Memory(actual) => self.memory_ty(expected, actual), + EntityType::Memory(actual) => self.memory_ty(expected, actual, None), _ => bail!("expected memory, but found {}", actual_desc), }, EntityType::Function(expected) => match *actual_ty { diff --git a/tests/all/wast.rs b/tests/all/wast.rs index f70084219383..1d0bf0ef9683 100644 --- a/tests/all/wast.rs +++ b/tests/all/wast.rs @@ -19,16 +19,9 @@ fn run_wast(wast: &str, strategy: Strategy, pooling: bool) -> anyhow::Result<()> let multi_memory = feature_found(wast, "multi-memory"); let module_linking = feature_found(wast, "module-linking"); let threads = feature_found(wast, "threads"); - let bulk_mem = memory64 || multi_memory || feature_found(wast, "bulk-memory-operations"); - - // Some simd tests assume support for multiple tables, which are introduced - // by reference types. - let reftypes = simd || feature_found(wast, "reference-types"); let mut cfg = Config::new(); cfg.wasm_simd(simd) - .wasm_bulk_memory(bulk_mem) - .wasm_reference_types(reftypes || module_linking) .wasm_multi_memory(multi_memory || module_linking) .wasm_module_linking(module_linking) .wasm_threads(threads) @@ -90,7 +83,7 @@ fn run_wast(wast: &str, strategy: Strategy, pooling: bool) -> anyhow::Result<()> imported_globals: 11, memories: 2, tables: 4, - globals: 11, + globals: 13, memory_pages: 805, ..Default::default() }, diff --git a/tests/misc_testsuite/bulk-memory-operations/elem-ref-null.wast b/tests/misc_testsuite/elem-ref-null.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/elem-ref-null.wast rename to tests/misc_testsuite/elem-ref-null.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/elem_drop.wast b/tests/misc_testsuite/elem_drop.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/elem_drop.wast rename to tests/misc_testsuite/elem_drop.wast diff --git a/tests/misc_testsuite/reference-types/externref-id-function.wast b/tests/misc_testsuite/externref-id-function.wast similarity index 100% rename from tests/misc_testsuite/reference-types/externref-id-function.wast rename to tests/misc_testsuite/externref-id-function.wast diff --git a/tests/misc_testsuite/reference-types/externref-segment.wast b/tests/misc_testsuite/externref-segment.wast similarity index 100% rename from tests/misc_testsuite/reference-types/externref-segment.wast rename to tests/misc_testsuite/externref-segment.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/imported-memory-copy.wast b/tests/misc_testsuite/imported-memory-copy.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/imported-memory-copy.wast rename to tests/misc_testsuite/imported-memory-copy.wast diff --git a/tests/misc_testsuite/linking-errors.wast b/tests/misc_testsuite/linking-errors.wast index 653876d77e1f..122c9a2b3505 100644 --- a/tests/misc_testsuite/linking-errors.wast +++ b/tests/misc_testsuite/linking-errors.wast @@ -3,6 +3,7 @@ (global (export "g mut i32") (mut i32) (i32.const 0)) (table (export "t funcref") 0 funcref) + (table (export "t externref") 0 externref) (memory (export "mem") 0) (func (export "f")) @@ -32,6 +33,10 @@ (module (import "m" "t funcref" (table 1 funcref))) "expected table limits (min: 1, max: none) doesn't match provided table limits (min: 0, max: none)") +(assert_unlinkable + (module (import "m" "t externref" (table 0 funcref))) + "expected table of type `funcref`, found table of type `externref`") + ;; errors on memories (assert_unlinkable (module (import "m" "mem" (memory 1))) diff --git a/tests/misc_testsuite/reference-types/many_table_gets_lead_to_gc.wast b/tests/misc_testsuite/many_table_gets_lead_to_gc.wast similarity index 100% rename from tests/misc_testsuite/reference-types/many_table_gets_lead_to_gc.wast rename to tests/misc_testsuite/many_table_gets_lead_to_gc.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/memory-copy.wast b/tests/misc_testsuite/memory-copy.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/memory-copy.wast rename to tests/misc_testsuite/memory-copy.wast diff --git a/tests/misc_testsuite/reference-types/mutable_externref_globals.wast b/tests/misc_testsuite/mutable_externref_globals.wast similarity index 100% rename from tests/misc_testsuite/reference-types/mutable_externref_globals.wast rename to tests/misc_testsuite/mutable_externref_globals.wast diff --git a/tests/misc_testsuite/reference-types/no-mixup-stack-maps.wast b/tests/misc_testsuite/no-mixup-stack-maps.wast similarity index 100% rename from tests/misc_testsuite/reference-types/no-mixup-stack-maps.wast rename to tests/misc_testsuite/no-mixup-stack-maps.wast diff --git a/tests/misc_testsuite/reference-types/no-panic.wast b/tests/misc_testsuite/no-panic.wast similarity index 100% rename from tests/misc_testsuite/reference-types/no-panic.wast rename to tests/misc_testsuite/no-panic.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/partial-init-memory-segment.wast b/tests/misc_testsuite/partial-init-memory-segment.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/partial-init-memory-segment.wast rename to tests/misc_testsuite/partial-init-memory-segment.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/partial-init-table-segment.wast b/tests/misc_testsuite/partial-init-table-segment.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/partial-init-table-segment.wast rename to tests/misc_testsuite/partial-init-table-segment.wast diff --git a/tests/misc_testsuite/reference-types/linking-errors.wast b/tests/misc_testsuite/reference-types/linking-errors.wast deleted file mode 100644 index e07d0bb32aec..000000000000 --- a/tests/misc_testsuite/reference-types/linking-errors.wast +++ /dev/null @@ -1,8 +0,0 @@ -(module $m - (table (export "t externref") 0 externref) -) - -(assert_unlinkable - (module (import "m" "t externref" (table 0 funcref))) - "expected table of type `funcref`, found table of type `externref`") - diff --git a/tests/misc_testsuite/reference-types/simple_ref_is_null.wast b/tests/misc_testsuite/simple_ref_is_null.wast similarity index 100% rename from tests/misc_testsuite/reference-types/simple_ref_is_null.wast rename to tests/misc_testsuite/simple_ref_is_null.wast diff --git a/tests/misc_testsuite/bulk-memory-operations/table_copy.wast b/tests/misc_testsuite/table_copy.wast similarity index 100% rename from tests/misc_testsuite/bulk-memory-operations/table_copy.wast rename to tests/misc_testsuite/table_copy.wast diff --git a/tests/misc_testsuite/reference-types/table_copy_on_imported_tables.wast b/tests/misc_testsuite/table_copy_on_imported_tables.wast similarity index 100% rename from tests/misc_testsuite/reference-types/table_copy_on_imported_tables.wast rename to tests/misc_testsuite/table_copy_on_imported_tables.wast diff --git a/tests/misc_testsuite/reference-types/table_grow_with_funcref.wast b/tests/misc_testsuite/table_grow_with_funcref.wast similarity index 100% rename from tests/misc_testsuite/reference-types/table_grow_with_funcref.wast rename to tests/misc_testsuite/table_grow_with_funcref.wast diff --git a/tests/spec_testsuite b/tests/spec_testsuite index 5fddf13f296c..4fd2339b5e97 160000 --- a/tests/spec_testsuite +++ b/tests/spec_testsuite @@ -1 +1 @@ -Subproject commit 5fddf13f296cb08a7a8055f4f6d63632485cab14 +Subproject commit 4fd2339b5e9709e74b326797f69a88b13eac4d47