Skip to content

Commit 31c5811

Browse files
authored
Explicitly disallow 64-bit/shared memories/tables in components (#1970)
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.
1 parent 34c5c39 commit 31c5811

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

crates/wasmparser/src/validator/component.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,7 +2970,6 @@ impl ComponentState {
29702970
match self.core_instance_export(instance_index, name, types, offset)? {
29712971
$expected(ty) => {
29722972
self.$collection.push(*ty);
2973-
Ok(())
29742973
}
29752974
_ => {
29762975
bail!(
@@ -2992,7 +2991,7 @@ impl ComponentState {
29922991
"functions",
29932992
offset,
29942993
)?;
2995-
push_module_export!(EntityType::Func, core_funcs, "function")
2994+
push_module_export!(EntityType::Func, core_funcs, "function");
29962995
}
29972996
ExternalKind::Table => {
29982997
check_max(
@@ -3002,7 +3001,21 @@ impl ComponentState {
30023001
"tables",
30033002
offset,
30043003
)?;
3005-
push_module_export!(EntityType::Table, core_tables, "table")
3004+
push_module_export!(EntityType::Table, core_tables, "table");
3005+
3006+
let ty = self.core_tables.last().unwrap();
3007+
if ty.table64 {
3008+
bail!(
3009+
offset,
3010+
"64-bit tables are not compatible with components yet"
3011+
);
3012+
}
3013+
if ty.shared {
3014+
bail!(
3015+
offset,
3016+
"shared tables are not compatible with components yet"
3017+
);
3018+
}
30063019
}
30073020
ExternalKind::Memory => {
30083021
check_max(
@@ -3012,7 +3025,21 @@ impl ComponentState {
30123025
"memories",
30133026
offset,
30143027
)?;
3015-
push_module_export!(EntityType::Memory, core_memories, "memory")
3028+
push_module_export!(EntityType::Memory, core_memories, "memory");
3029+
3030+
let ty = self.core_memories.last().unwrap();
3031+
if ty.memory64 {
3032+
bail!(
3033+
offset,
3034+
"64-bit linear memories are not compatible with components yet"
3035+
);
3036+
}
3037+
if ty.shared {
3038+
bail!(
3039+
offset,
3040+
"shared linear memories are not compatible with components yet"
3041+
);
3042+
}
30163043
}
30173044
ExternalKind::Global => {
30183045
check_max(
@@ -3022,7 +3049,7 @@ impl ComponentState {
30223049
"globals",
30233050
offset,
30243051
)?;
3025-
push_module_export!(EntityType::Global, core_globals, "global")
3052+
push_module_export!(EntityType::Global, core_globals, "global");
30263053
}
30273054
ExternalKind::Tag => {
30283055
check_max(
@@ -3032,9 +3059,11 @@ impl ComponentState {
30323059
"tags",
30333060
offset,
30343061
)?;
3035-
push_module_export!(EntityType::Tag, core_tags, "tag")
3062+
push_module_export!(EntityType::Tag, core_tags, "tag");
30363063
}
30373064
}
3065+
3066+
Ok(())
30383067
}
30393068

30403069
fn alias_instance_export(

tests/local/component-model/memory64.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@
1919
(core instance $a (instantiate $A (with "" (instance $b))))
2020
)
2121
"mismatch in index type used for memories")
22+
23+
(assert_invalid
24+
(component
25+
(core module $A
26+
(memory (export "m") i64 1))
27+
(core instance $A (instantiate $A))
28+
(alias core export $A "m" (core memory $m))
29+
)
30+
"64-bit linear memories are not compatible with components yet")
31+
32+
(assert_invalid
33+
(component
34+
(core module $A
35+
(table (export "m") i64 1 funcref))
36+
(core instance $A (instantiate $A))
37+
(alias core export $A "m" (core table $m))
38+
)
39+
"64-bit tables are not compatible with components yet")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(assert_invalid
2+
(component
3+
(core module $A
4+
(memory (export "m") 1 2 shared))
5+
(core instance $A (instantiate $A))
6+
(alias core export $A "m" (core memory $m))
7+
)
8+
"shared linear memories are not compatible with components yet")
9+
10+
(assert_invalid
11+
(component
12+
(core module $A
13+
(table (export "m") shared 1 2 (ref null (shared func)))
14+
)
15+
(core instance $A (instantiate $A))
16+
(alias core export $A "m" (core table $m))
17+
)
18+
"shared tables are not compatible with components yet")

tests/snapshots/local/component-model/memory64.wast.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
"filename": "memory64.1.wasm",
1515
"module_type": "binary",
1616
"text": "mismatch in index type used for memories"
17+
},
18+
{
19+
"type": "assert_invalid",
20+
"line": 24,
21+
"filename": "memory64.2.wasm",
22+
"module_type": "binary",
23+
"text": "64-bit linear memories are not compatible with components yet"
24+
},
25+
{
26+
"type": "assert_invalid",
27+
"line": 33,
28+
"filename": "memory64.3.wasm",
29+
"module_type": "binary",
30+
"text": "64-bit tables are not compatible with components yet"
1731
}
1832
]
1933
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"source_filename": "tests/local/component-model/shared-everything-threads/not-accepted.wast",
3+
"commands": [
4+
{
5+
"type": "assert_invalid",
6+
"line": 2,
7+
"filename": "not-accepted.0.wasm",
8+
"module_type": "binary",
9+
"text": "shared linear memories are not compatible with components yet"
10+
},
11+
{
12+
"type": "assert_invalid",
13+
"line": 11,
14+
"filename": "not-accepted.1.wasm",
15+
"module_type": "binary",
16+
"text": "shared tables are not compatible with components yet"
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)