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
6 changes: 6 additions & 0 deletions crates/wasmparser/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ define_wasm_features! {
/// Corresponds to the 🗺️ character in
/// <https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md>.
pub cm_map: CM_MAP(1 << 38) = false;

/// Support for 64-bit contexts in the component model proposal.
///
/// Corresponds to the 🐘 character in
/// <https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md>.
pub cm64: CM64(1 << 39) = false;
}
}

Expand Down
46 changes: 27 additions & 19 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,17 @@ impl ComponentState {
}

// Current MVP restriction of the component model.
if rep != ValType::I32 {
bail!(offset, "resources can only be represented by `i32`");
if rep == ValType::I64 && !component.features.cm64() {
bail!(
offset,
"resources with `i64` require the `cm64` feature to be enabled"
)
}
if rep != ValType::I32 && rep != ValType::I64 {
bail!(
offset,
"resources can only be represented by `i32` or `i64`"
);
}

// If specified validate that the destructor is both a valid
Expand Down Expand Up @@ -4351,25 +4360,24 @@ impl ComponentState {
/// Validates that the linear memory at `idx` is valid to use as a canonical
/// ABI memory.
///
/// At this time this requires that the memory is a plain 32-bit linear
/// memory. Notably this disallows shared memory and 64-bit linear memories.
/// At this time this requires that the memory is a plain 32-bit or 64-bit linear
/// memory. Notably this disallows shared memory.
fn cabi_memory_at(&self, idx: u32, offset: usize) -> Result<()> {
let ty = self.memory_at(idx, offset)?;
SubtypeCx::memory_type(
ty,
&MemoryType {
initial: 0,
maximum: None,
memory64: false,
shared: false,
page_size_log2: None,
},
offset,
)
.map_err(|mut e| {
e.add_context("canonical ABI memory is not a 32-bit linear memory".into());
e
})
let valid_memory_type = MemoryType {
initial: 0,
maximum: None,
memory64: ty.memory64,
shared: false,
page_size_log2: None,
};
if ty.memory64 && !self.features.cm64() {
bail!(
offset,
"64-bit memories require the `cm64` feature to be enabled"
);
}
SubtypeCx::memory_type(ty, &valid_memory_type, offset)
}

/// Completes the translation of this component, performing final
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/component-model/memory64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
(alias core export $A "m" (core memory $m))
(core func (canon lower (func $x) (memory $m)))
)
"canonical ABI memory is not a 32-bit linear memory")
Comment thread
michael-weigelt marked this conversation as resolved.
"64-bit memories require the `cm64` feature to be enabled")
10 changes: 10 additions & 0 deletions tests/cli/component-model/memory64/memory64.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; RUN: wast --assert default --snapshot tests/snapshots -f cm64 %

(component
(import "x" (func $x (param "x" string)))
(core module $A
(memory (export "m") i64 1))
(core instance $A (instantiate $A))
(alias core export $A "m" (core memory $m))
(core func (canon lower (func $x) (memory $m)))
)
71 changes: 71 additions & 0 deletions tests/cli/component-model/memory64/resources.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
;; RUN: wast --assert default --snapshot tests/snapshots -f cm64 %

(component
(type $x (resource (rep i64)))
)

(component
(type $x (resource (rep i64)))

(core func (canon resource.new $x))
(core func (canon resource.rep $x))
(core func (canon resource.drop $x))
)

(component
(core module $m
(func (export "dtor") (param i64))
)
(core instance $m (instantiate $m))
(type $x (resource (rep i64) (dtor (func $m "dtor"))))
(core func (canon resource.new $x))
)

(component
(type $x (resource (rep i64)))
(core func $f1 (canon resource.new $x))
(core func $f2 (canon resource.rep $x))
(core func $f3 (canon resource.drop $x))

(core module $m
(import "" "f1" (func (param i64) (result i32)))
(import "" "f2" (func (param i32) (result i64)))
(import "" "f3" (func (param i32)))
)

(core instance (instantiate $m
(with "" (instance
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f3" (func $f3))
))
))
)

(assert_invalid
(component
(core module $m
(func (export "dtor") (param i32))
)
(core instance $m (instantiate $m))
(type $x (resource (rep i64) (dtor (func $m "dtor"))))
(core func (canon resource.new $x))
)
"wrong signature for a destructor")

(assert_invalid
(component
(core module $m
(func (export "dtor") (param i64))
)
(core instance $m (instantiate $m))
(type $x (resource (rep i32) (dtor (func $m "dtor"))))
(core func (canon resource.new $x))
)
"wrong signature for a destructor")

(assert_invalid
(component
(type $x (resource (rep v128)))
)
"resources can only be represented by `i32` or `i64`")
2 changes: 1 addition & 1 deletion tests/cli/component-model/resources.wast
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(component
(type $x (resource (rep i64)))
)
"resources can only be represented by `i32`")
"resources with `i64` require the `cm64` feature to be enabled")

(assert_invalid
(component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
(alias core export $A "m" (core memory $m))
(core func (canon lower (func $x) (memory $m)))
)
"canonical ABI memory is not a 32-bit linear memory")
"mismatch in the shared flag for memories")
2 changes: 1 addition & 1 deletion tests/cli/validate-unknown-features.wat.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: invalid value 'unknown' for '--features <FEATURES>': unknown feature `unknown`
Valid features: mutable-global, saturating-float-to-int, sign-extension, reference-types, multi-value, bulk-memory, simd, relaxed-simd, threads, shared-everything-threads, tail-call, floats, multi-memory, exceptions, memory64, extended-const, component-model, function-references, memory-control, gc, custom-page-sizes, legacy-exceptions, gc-types, stack-switching, wide-arithmetic, cm-values, cm-nested-names, cm-async, cm-async-stackful, cm-async-builtins, cm-threading, cm-error-context, cm-fixed-length-lists, cm-gc, call-indirect-overlong, bulk-memory-opt, custom-descriptors, compact-imports, cm-map, mvp, wasm1, wasm2, wasm3, lime1, all
Valid features: mutable-global, saturating-float-to-int, sign-extension, reference-types, multi-value, bulk-memory, simd, relaxed-simd, threads, shared-everything-threads, tail-call, floats, multi-memory, exceptions, memory64, extended-const, component-model, function-references, memory-control, gc, custom-page-sizes, legacy-exceptions, gc-types, stack-switching, wide-arithmetic, cm-values, cm-nested-names, cm-async, cm-async-stackful, cm-async-builtins, cm-threading, cm-error-context, cm-fixed-length-lists, cm-gc, call-indirect-overlong, bulk-memory-opt, custom-descriptors, compact-imports, cm-map, cm64, mvp, wasm1, wasm2, wasm3, lime1, all

For more information, try '--help'.
2 changes: 1 addition & 1 deletion tests/snapshots/cli/component-model/memory64.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"line": 46,
"filename": "memory64.4.wasm",
"module_type": "binary",
"text": "canonical ABI memory is not a 32-bit linear memory"
"text": "64-bit memories require the `cm64` feature to be enabled"
}
]
}
11 changes: 11 additions & 0 deletions tests/snapshots/cli/component-model/memory64/memory64.wast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"source_filename": "tests/cli/component-model/memory64/memory64.wast",
"commands": [
{
"type": "module",
"line": 3,
"filename": "memory64.0.wasm",
"module_type": "binary"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(component
(type (;0;) (func (param "x" string)))
(import "x" (func $x (;0;) (type 0)))
(core module $A (;0;)
(memory (;0;) i64 1)
(export "m" (memory 0))
)
(core instance $A (;0;) (instantiate $A))
(alias core export $A "m" (core memory $m (;0;)))
(core func (;0;) (canon lower (func $x) (memory $m)))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"source_filename": "tests/cli/component-model/memory64/resources.wast",
"commands": [
{
"type": "module",
"line": 3,
"filename": "resources.0.wasm",
"module_type": "binary"
},
{
"type": "module",
"line": 7,
"filename": "resources.1.wasm",
"module_type": "binary"
},
{
"type": "module",
"line": 15,
"filename": "resources.2.wasm",
"module_type": "binary"
},
{
"type": "module",
"line": 24,
"filename": "resources.3.wasm",
"module_type": "binary"
},
{
"type": "assert_invalid",
"line": 46,
"filename": "resources.4.wasm",
"module_type": "binary",
"text": "wrong signature for a destructor"
},
{
"type": "assert_invalid",
"line": 57,
"filename": "resources.5.wasm",
"module_type": "binary",
"text": "wrong signature for a destructor"
},
{
"type": "assert_invalid",
"line": 68,
"filename": "resources.6.wasm",
"module_type": "binary",
"text": "resources can only be represented by `i32` or `i64`"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(component
(type $x (;0;) (resource (rep i64)))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(component
(type $x (;0;) (resource (rep i64)))
(core func (;0;) (canon resource.new $x))
(core func (;1;) (canon resource.rep $x))
(core func (;2;) (canon resource.drop $x))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(component
(core module $m (;0;)
(type (;0;) (func (param i64)))
(export "dtor" (func 0))
(func (;0;) (type 0) (param i64))
)
(core instance $m (;0;) (instantiate $m))
(alias core export $m "dtor" (core func (;0;)))
(type $x (;0;) (resource (rep i64) (dtor (func 0))))
(core func (;1;) (canon resource.new $x))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(component
(type $x (;0;) (resource (rep i64)))
(core func $f1 (;0;) (canon resource.new $x))
(core func $f2 (;1;) (canon resource.rep $x))
(core func $f3 (;2;) (canon resource.drop $x))
(core module $m (;0;)
(type (;0;) (func (param i64) (result i32)))
(type (;1;) (func (param i32) (result i64)))
(type (;2;) (func (param i32)))
(import "" "f1" (func (;0;) (type 0)))
(import "" "f2" (func (;1;) (type 1)))
(import "" "f3" (func (;2;) (type 2)))
)
(core instance (;0;)
(export "f1" (func $f1))
(export "f2" (func $f2))
(export "f3" (func $f3))
)
(core instance (;1;) (instantiate $m
(with "" (instance 0))
)
)
)
2 changes: 1 addition & 1 deletion tests/snapshots/cli/component-model/resources.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"line": 52,
"filename": "resources.5.wasm",
"module_type": "binary",
"text": "resources can only be represented by `i32`"
"text": "resources with `i64` require the `cm64` feature to be enabled"
},
{
"type": "assert_invalid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"line": 25,
"filename": "not-accepted.2.wasm",
"module_type": "binary",
"text": "canonical ABI memory is not a 32-bit linear memory"
"text": "mismatch in the shared flag for memories"
}
]
}
Loading