Skip to content
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
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 0 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion cranelift/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
24 changes: 13 additions & 11 deletions cranelift/wasm/src/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
}
Operator::BrIf { relative_depth } => translate_br_if(*relative_depth, builder, state),
Operator::BrTable { table } => {
let mut depths = table.targets().collect::<Result<Vec<_>, _>>()?;
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 = {
Expand All @@ -460,12 +460,13 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
}
};
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()
Expand All @@ -486,12 +487,13 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
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)
}
};
Expand Down
11 changes: 10 additions & 1 deletion cranelift/wasm/src/sections_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,16 @@ fn read_elems(items: &ElementItems) -> WasmResult<Box<[FuncIndex]>> {
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);
Expand Down
2 changes: 1 addition & 1 deletion crates/cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
21 changes: 18 additions & 3 deletions crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
}

Expand Down
4 changes: 2 additions & 2 deletions crates/fuzzing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion crates/wasmtime/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
12 changes: 10 additions & 2 deletions crates/wasmtime/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
34 changes: 26 additions & 8 deletions crates/wasmtime/src/types/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,44 @@ 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<u32>,
) -> 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",
)?;
Ok(())
}

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<u64>,
) -> Result<()> {
match_bool(
expected.shared,
actual.shared,
Expand All @@ -72,7 +90,7 @@ impl MatchCx<'_> {
match_limits(
expected.minimum,
expected.maximum,
actual.minimum,
actual_runtime_size.unwrap_or(actual.minimum),
actual.maximum,
"memory",
)?;
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions tests/all/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
},
Expand Down
5 changes: 5 additions & 0 deletions tests/misc_testsuite/linking-errors.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)))
Expand Down
8 changes: 0 additions & 8 deletions tests/misc_testsuite/reference-types/linking-errors.wast

This file was deleted.

2 changes: 1 addition & 1 deletion tests/spec_testsuite
Submodule spec_testsuite updated 102 files