Skip to content

Commit

Permalink
Explicitly disallow 64-bit/shared memories/tables in components (#1970)
Browse files Browse the repository at this point in the history
These proposals are not specified how they work with the canonical ABI
just yet. Previously the proposals were not enabled by default so their
off-by-default status largely gated their usage in components but with
memory64 now being on-by-default it's possible to have components using
64-bit linear memories. More care will be needed to update components
and tooling for 64-bit linear memories so for now an error is added to
reject it saying that support is not added yet.
  • Loading branch information
alexcrichton authored Jan 8, 2025
1 parent 34c5c39 commit 31c5811
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
41 changes: 35 additions & 6 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2970,7 +2970,6 @@ impl ComponentState {
match self.core_instance_export(instance_index, name, types, offset)? {
$expected(ty) => {
self.$collection.push(*ty);
Ok(())
}
_ => {
bail!(
Expand All @@ -2992,7 +2991,7 @@ impl ComponentState {
"functions",
offset,
)?;
push_module_export!(EntityType::Func, core_funcs, "function")
push_module_export!(EntityType::Func, core_funcs, "function");
}
ExternalKind::Table => {
check_max(
Expand All @@ -3002,7 +3001,21 @@ impl ComponentState {
"tables",
offset,
)?;
push_module_export!(EntityType::Table, core_tables, "table")
push_module_export!(EntityType::Table, core_tables, "table");

let ty = self.core_tables.last().unwrap();
if ty.table64 {
bail!(
offset,
"64-bit tables are not compatible with components yet"
);
}
if ty.shared {
bail!(
offset,
"shared tables are not compatible with components yet"
);
}
}
ExternalKind::Memory => {
check_max(
Expand All @@ -3012,7 +3025,21 @@ impl ComponentState {
"memories",
offset,
)?;
push_module_export!(EntityType::Memory, core_memories, "memory")
push_module_export!(EntityType::Memory, core_memories, "memory");

let ty = self.core_memories.last().unwrap();
if ty.memory64 {
bail!(
offset,
"64-bit linear memories are not compatible with components yet"
);
}
if ty.shared {
bail!(
offset,
"shared linear memories are not compatible with components yet"
);
}
}
ExternalKind::Global => {
check_max(
Expand All @@ -3022,7 +3049,7 @@ impl ComponentState {
"globals",
offset,
)?;
push_module_export!(EntityType::Global, core_globals, "global")
push_module_export!(EntityType::Global, core_globals, "global");
}
ExternalKind::Tag => {
check_max(
Expand All @@ -3032,9 +3059,11 @@ impl ComponentState {
"tags",
offset,
)?;
push_module_export!(EntityType::Tag, core_tags, "tag")
push_module_export!(EntityType::Tag, core_tags, "tag");
}
}

Ok(())
}

fn alias_instance_export(
Expand Down
18 changes: 18 additions & 0 deletions tests/local/component-model/memory64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@
(core instance $a (instantiate $A (with "" (instance $b))))
)
"mismatch in index type used for memories")

(assert_invalid
(component
(core module $A
(memory (export "m") i64 1))
(core instance $A (instantiate $A))
(alias core export $A "m" (core memory $m))
)
"64-bit linear memories are not compatible with components yet")

(assert_invalid
(component
(core module $A
(table (export "m") i64 1 funcref))
(core instance $A (instantiate $A))
(alias core export $A "m" (core table $m))
)
"64-bit tables are not compatible with components yet")
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(assert_invalid
(component
(core module $A
(memory (export "m") 1 2 shared))
(core instance $A (instantiate $A))
(alias core export $A "m" (core memory $m))
)
"shared linear memories are not compatible with components yet")

(assert_invalid
(component
(core module $A
(table (export "m") shared 1 2 (ref null (shared func)))
)
(core instance $A (instantiate $A))
(alias core export $A "m" (core table $m))
)
"shared tables are not compatible with components yet")
14 changes: 14 additions & 0 deletions tests/snapshots/local/component-model/memory64.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
"filename": "memory64.1.wasm",
"module_type": "binary",
"text": "mismatch in index type used for memories"
},
{
"type": "assert_invalid",
"line": 24,
"filename": "memory64.2.wasm",
"module_type": "binary",
"text": "64-bit linear memories are not compatible with components yet"
},
{
"type": "assert_invalid",
"line": 33,
"filename": "memory64.3.wasm",
"module_type": "binary",
"text": "64-bit tables are not compatible with components yet"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source_filename": "tests/local/component-model/shared-everything-threads/not-accepted.wast",
"commands": [
{
"type": "assert_invalid",
"line": 2,
"filename": "not-accepted.0.wasm",
"module_type": "binary",
"text": "shared linear memories are not compatible with components yet"
},
{
"type": "assert_invalid",
"line": 11,
"filename": "not-accepted.1.wasm",
"module_type": "binary",
"text": "shared tables are not compatible with components yet"
}
]
}

0 comments on commit 31c5811

Please sign in to comment.