Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
53 changes: 37 additions & 16 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 !component.features.cm64() {
if rep != ValType::I32 {
bail!(offset, "resources can only be represented by `i32`");
}
} else {
if rep != ValType::I32 && rep != ValType::I64 {
bail!(
offset,
"resources can only be represented by `i32` or `i64`"
);
}
}
Comment thread
alexcrichton marked this conversation as resolved.

// If specified validate that the destructor is both a valid
Expand Down Expand Up @@ -4351,23 +4360,35 @@ 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,
)
let valid_memory_type = MemoryType {
initial: 0,
maximum: None,
memory64: ty.memory64,
shared: false,
page_size_log2: None,
};
let mut msg = "";
if !ty.memory64 {
SubtypeCx::memory_type(ty, &valid_memory_type, offset)
} else {
if !self.features.cm64() {
bail!(
offset,
"64-bit memories require the component model 64-bit feature"
);
} else {
msg = "or 64-bit ";
SubtypeCx::memory_type(ty, &valid_memory_type, offset)
}
}
.map_err(|mut e| {
e.add_context("canonical ABI memory is not a 32-bit linear memory".into());
e.add_context(format!(
"canonical ABI memory is not a 32-bit {msg}linear memory"
));
e
Comment thread
michael-weigelt marked this conversation as resolved.
Outdated
})
}
Expand Down
4 changes: 1 addition & 3 deletions tests/cli/component-model/memory64.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; RUN: wast --assert default --snapshot tests/snapshots %
;; RUN: wast --assert default --snapshot tests/snapshots -f cm64 %

(assert_invalid
(component
Expand Down Expand Up @@ -42,7 +42,6 @@
(core instance (instantiate $B (with "" (instance (export "" (table $m))))))
)

(assert_invalid
(component
(import "x" (func $x (param "x" string)))
(core module $A
Expand All @@ -51,4 +50,3 @@
(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.
65 changes: 65 additions & 0 deletions tests/cli/component-model/memory64/resources.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
;; 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")
2 changes: 1 addition & 1 deletion tests/cli/component-model/resources.wast
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

(assert_invalid
(component
(type $x (resource (rep i64)))
(type $x (resource (rep v128)))
Comment thread
michael-weigelt marked this conversation as resolved.
Outdated
)
"resources can only be represented by `i32`")

Expand Down
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'.
7 changes: 3 additions & 4 deletions tests/snapshots/cli/component-model/memory64.wast.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
"module_type": "binary"
},
{
"type": "assert_invalid",
"line": 46,
"type": "module",
"line": 45,
"filename": "memory64.4.wasm",
"module_type": "binary",
"text": "canonical ABI memory is not a 32-bit linear memory"
"module_type": "binary"
}
]
}
11 changes: 11 additions & 0 deletions tests/snapshots/cli/component-model/memory64.wast/4.print
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,43 @@
{
"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"
}
]
}
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))
)
)
)
Loading