From c80da8d059be2a58116285f4c0107ed7d4d2fb85 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 2 Apr 2025 02:52:17 +0900 Subject: [PATCH 1/5] feat(wasmparser): emojigate error-context separately from async Signed-off-by: Victor Adossi --- crates/wasmparser/src/features.rs | 6 ++++++ crates/wasmparser/src/validator/component.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/wasmparser/src/features.rs b/crates/wasmparser/src/features.rs index f46f2e89c8..fbe88a38f9 100644 --- a/crates/wasmparser/src/features.rs +++ b/crates/wasmparser/src/features.rs @@ -248,6 +248,12 @@ define_wasm_features! { /// Corresponds to the 🚝 character in /// . pub cm_async_builtins: CM_ASYNC_BUILTINS(1 << 29) = false; + /// Gates some intrinsics being marked with `error-context` in the component + /// model async proposal. + /// + /// Corresponds to the 📝 character in + /// . + pub cm_error_context: CM_ERROR_CONTEXT(1 << 30) = false; } } diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs index 01e67ac58f..b3b633959e 100644 --- a/crates/wasmparser/src/validator/component.rs +++ b/crates/wasmparser/src/validator/component.rs @@ -1736,10 +1736,10 @@ impl ComponentState { offset: usize, features: &WasmFeatures, ) -> Result<()> { - if !features.cm_async() { + if !features.cm_error_context() { bail!( offset, - "`error-context.new` requires the component model async feature" + "`error-context.new` requires the component model error-context feature" ) } @@ -1760,10 +1760,10 @@ impl ComponentState { offset: usize, features: &WasmFeatures, ) -> Result<()> { - if !features.cm_async() { + if !features.cm_error_context() { bail!( offset, - "`error-context.debug-message` requires the component model async feature" + "`error-context.debug-message` requires the component model error-context feature" ) } @@ -1783,10 +1783,10 @@ impl ComponentState { offset: usize, features: &WasmFeatures, ) -> Result<()> { - if !features.cm_async() { + if !features.cm_error_context() { bail!( offset, - "`error-context.drop` requires the component model async feature" + "`error-context.drop` requires the component model error-context feature" ) } From 4acffde8660b11043244daafd9a7bced43728cc5 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 2 Apr 2025 03:02:35 +0900 Subject: [PATCH 2/5] refactor(wasmparser): refactor wast tests for error-context feature Signed-off-by: Victor Adossi --- .../component-model-async/error-context.wast | 2 +- .../component-model/error-context.wast | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/cli/missing-features/component-model/error-context.wast diff --git a/tests/cli/component-model-async/error-context.wast b/tests/cli/component-model-async/error-context.wast index 377082b00d..66d6aef57d 100644 --- a/tests/cli/component-model-async/error-context.wast +++ b/tests/cli/component-model-async/error-context.wast @@ -1,4 +1,4 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async +;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-error-context ;; error-context.new (component diff --git a/tests/cli/missing-features/component-model/error-context.wast b/tests/cli/missing-features/component-model/error-context.wast new file mode 100644 index 0000000000..057e8ab9cd --- /dev/null +++ b/tests/cli/missing-features/component-model/error-context.wast @@ -0,0 +1,50 @@ +;; RUN: wast --assert default --snapshot tests/snapshots % -f=-cm-error-context + +;; error-context.new +(assert_invalid + (component + (core module $libc (memory (export "memory") 1)) + (core instance $libc (instantiate $libc)) + (core module $m + (import "" "error-context.new" (func $error-context-new (param i32 i32) (result i32))) + ) + (core func $error-context-new (canon error-context.new (memory $libc "memory"))) + (core instance $i (instantiate $m (with "" (instance (export "error-context.new" (func $error-context-new)))))) + ) + "`error-context.new` requires the component model error-context feature" +) + +;; error-context.debug-message +(assert_invalid + (component + (core module $libc + (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) + (memory (export "memory") 1) + ) + (core instance $libc (instantiate $libc)) + (core module $m + (import "" "error-context.debug-message" (func $error-context-debug-message (param i32 i32))) + ) + (core func $error-context-debug-message (canon error-context.debug-message (memory $libc "memory") (realloc (func $libc "realloc")))) + (core instance $i (instantiate $m (with "" (instance (export "error-context.debug-message" (func $error-context-debug-message)))))) + ) + "`error-context.debug-message` requires the component model error-context feature" +) + +;; error-context.drop +(assert_invalid + (component + (core module $m + (import "" "error-context.drop" (func $error-context-drop (param i32))) + ) + (core func $error-context-drop (canon error-context.drop)) + (core instance $i (instantiate $m (with "" (instance (export "error-context.drop" (func $error-context-drop)))))) + ) + "`error-context.drop` requires the component model error-context feature" +) + +;; various types +(assert_invalid + (component (type error-context)) + "requires the component model error-context feature" +) From 63aceb83fb0bfeef4e4c37c97228077cd47ed7b3 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 2 Apr 2025 03:03:48 +0900 Subject: [PATCH 3/5] chore(wasmparser): update unknown features test Signed-off-by: Victor Adossi --- tests/cli/validate-unknown-features.wat.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/validate-unknown-features.wat.stderr b/tests/cli/validate-unknown-features.wat.stderr index afd424198b..1c6e4539c4 100644 --- a/tests/cli/validate-unknown-features.wat.stderr +++ b/tests/cli/validate-unknown-features.wat.stderr @@ -1,4 +1,4 @@ error: invalid value 'unknown' for '--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, mvp, wasm1, wasm2, wasm3, 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-error-context, mvp, wasm1, wasm2, wasm3, all For more information, try '--help'. From f665dedb1c9e9b3bf0adccdca6e007d70b4e81c1 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 2 Apr 2025 03:08:03 +0900 Subject: [PATCH 4/5] refactor(tests): move error-context wast tests Signed-off-by: Victor Adossi --- .../error-context.wast.json | 0 .../error-context.wast/0.print | 0 .../error-context.wast/2.print | 0 .../error-context.wast/4.print | 0 .../error-context.wast/6.print | 0 .../error-context.wast/7.print | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast.json (100%) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast/0.print (100%) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast/2.print (100%) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast/4.print (100%) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast/6.print (100%) rename tests/snapshots/cli/{component-model-async => component-model-error-context}/error-context.wast/7.print (100%) diff --git a/tests/snapshots/cli/component-model-async/error-context.wast.json b/tests/snapshots/cli/component-model-error-context/error-context.wast.json similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast.json rename to tests/snapshots/cli/component-model-error-context/error-context.wast.json diff --git a/tests/snapshots/cli/component-model-async/error-context.wast/0.print b/tests/snapshots/cli/component-model-error-context/error-context.wast/0.print similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast/0.print rename to tests/snapshots/cli/component-model-error-context/error-context.wast/0.print diff --git a/tests/snapshots/cli/component-model-async/error-context.wast/2.print b/tests/snapshots/cli/component-model-error-context/error-context.wast/2.print similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast/2.print rename to tests/snapshots/cli/component-model-error-context/error-context.wast/2.print diff --git a/tests/snapshots/cli/component-model-async/error-context.wast/4.print b/tests/snapshots/cli/component-model-error-context/error-context.wast/4.print similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast/4.print rename to tests/snapshots/cli/component-model-error-context/error-context.wast/4.print diff --git a/tests/snapshots/cli/component-model-async/error-context.wast/6.print b/tests/snapshots/cli/component-model-error-context/error-context.wast/6.print similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast/6.print rename to tests/snapshots/cli/component-model-error-context/error-context.wast/6.print diff --git a/tests/snapshots/cli/component-model-async/error-context.wast/7.print b/tests/snapshots/cli/component-model-error-context/error-context.wast/7.print similarity index 100% rename from tests/snapshots/cli/component-model-async/error-context.wast/7.print rename to tests/snapshots/cli/component-model-error-context/error-context.wast/7.print From a4a6fd33aeff64250a0c5255a8dc1a1aead2bba6 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 2 Apr 2025 03:17:11 +0900 Subject: [PATCH 5/5] chore(tests): update tests to use cm-error-context feature Signed-off-by: Victor Adossi --- crates/wasmparser/src/validator/component.rs | 4 +- .../component-model-async/task-builtins.wast | 2 +- .../error-context.wast | 0 ...my-async-export-future-with-named-type.wit | 2 +- tests/cli/dummy-async-export-using-export.wit | 2 +- tests/cli/dummy-async-future-with-flags.wit | 2 +- .../cli/dummy-async-resource-with-stream.wit | 2 +- tests/cli/dummy-async-resource.wit | 2 +- .../component-model/async.wast | 47 ------------------ .../error-context.wast.json | 2 +- .../component-model/async.wast.json | 48 ++++--------------- .../component-model/error-context.wast.json | 33 +++++++++++++ 12 files changed, 52 insertions(+), 94 deletions(-) rename tests/cli/{component-model-async => component-model-error-context}/error-context.wast (100%) create mode 100644 tests/snapshots/cli/missing-features/component-model/error-context.wast.json diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs index b3b633959e..3a4671b788 100644 --- a/crates/wasmparser/src/validator/component.rs +++ b/crates/wasmparser/src/validator/component.rs @@ -3566,10 +3566,10 @@ impl ComponentState { ) -> Result { match ty { crate::ComponentDefinedType::Primitive(ty) => { - if ty == crate::PrimitiveValType::ErrorContext && !features.cm_async() { + if ty == crate::PrimitiveValType::ErrorContext && !features.cm_error_context() { bail!( offset, - "`error-context` requires the component model async feature" + "`error-context` requires the component model error-context feature" ) } Ok(ComponentDefinedType::Primitive(ty)) diff --git a/tests/cli/component-model-async/task-builtins.wast b/tests/cli/component-model-async/task-builtins.wast index 2a06072ff7..9c13d42994 100644 --- a/tests/cli/component-model-async/task-builtins.wast +++ b/tests/cli/component-model-async/task-builtins.wast @@ -1,4 +1,4 @@ -;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-async-builtins,cm-async-stackful +;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-async-builtins,cm-async-stackful,cm-error-context ;; backpressure.set (component diff --git a/tests/cli/component-model-async/error-context.wast b/tests/cli/component-model-error-context/error-context.wast similarity index 100% rename from tests/cli/component-model-async/error-context.wast rename to tests/cli/component-model-error-context/error-context.wast diff --git a/tests/cli/dummy-async-export-future-with-named-type.wit b/tests/cli/dummy-async-export-future-with-named-type.wit index bd668335d4..d58f05177d 100644 --- a/tests/cli/dummy-async-export-future-with-named-type.wit +++ b/tests/cli/dummy-async-export-future-with-named-type.wit @@ -1,6 +1,6 @@ // RUN: component embed % --dummy-names legacy --async-callback | \ // component new | \ -// validate -f cm-async +// validate -f cm-async,cm-error-context package a:b; diff --git a/tests/cli/dummy-async-export-using-export.wit b/tests/cli/dummy-async-export-using-export.wit index 2ca7a07355..0a6540b706 100644 --- a/tests/cli/dummy-async-export-using-export.wit +++ b/tests/cli/dummy-async-export-using-export.wit @@ -1,6 +1,6 @@ // RUN: component embed % --dummy-names legacy --async-callback | \ // component new | \ -// validate -f cm-async +// validate -f cm-async,cm-error-context package a:b; diff --git a/tests/cli/dummy-async-future-with-flags.wit b/tests/cli/dummy-async-future-with-flags.wit index 918d8cfa32..0d86559711 100644 --- a/tests/cli/dummy-async-future-with-flags.wit +++ b/tests/cli/dummy-async-future-with-flags.wit @@ -1,6 +1,6 @@ // RUN: component embed % --dummy-names legacy --async-callback | \ // component new | \ -// validate -f cm-async +// validate -f cm-async,cm-error-context package y:name; diff --git a/tests/cli/dummy-async-resource-with-stream.wit b/tests/cli/dummy-async-resource-with-stream.wit index a8358525d6..667e53bc9f 100644 --- a/tests/cli/dummy-async-resource-with-stream.wit +++ b/tests/cli/dummy-async-resource-with-stream.wit @@ -1,6 +1,6 @@ // RUN: component embed % --dummy-names legacy --async-callback | \ // component new | \ -// validate -f cm-async +// validate -f cm-async,cm-error-context package a:b; diff --git a/tests/cli/dummy-async-resource.wit b/tests/cli/dummy-async-resource.wit index 4f64ca1686..d6522363cf 100644 --- a/tests/cli/dummy-async-resource.wit +++ b/tests/cli/dummy-async-resource.wit @@ -1,6 +1,6 @@ // RUN: component embed % --dummy-names legacy --async-callback | \ // component new | \ -// validate -f cm-async +// validate -f cm-async,cm-error-context package a:b; diff --git a/tests/cli/missing-features/component-model/async.wast b/tests/cli/missing-features/component-model/async.wast index 7410dec1e9..56d37cb235 100644 --- a/tests/cli/missing-features/component-model/async.wast +++ b/tests/cli/missing-features/component-model/async.wast @@ -314,49 +314,6 @@ "requires the component model async feature" ) -;; error-context.new -(assert_invalid - (component - (core module $libc (memory (export "memory") 1)) - (core instance $libc (instantiate $libc)) - (core module $m - (import "" "error-context.new" (func $error-context-new (param i32 i32) (result i32))) - ) - (core func $error-context-new (canon error-context.new (memory $libc "memory"))) - (core instance $i (instantiate $m (with "" (instance (export "error-context.new" (func $error-context-new)))))) - ) - "`error-context.new` requires the component model async feature" -) - -;; error-context.debug-message -(assert_invalid - (component - (core module $libc - (func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable) - (memory (export "memory") 1) - ) - (core instance $libc (instantiate $libc)) - (core module $m - (import "" "error-context.debug-message" (func $error-context-debug-message (param i32 i32))) - ) - (core func $error-context-debug-message (canon error-context.debug-message (memory $libc "memory") (realloc (func $libc "realloc")))) - (core instance $i (instantiate $m (with "" (instance (export "error-context.debug-message" (func $error-context-debug-message)))))) - ) - "`error-context.debug-message` requires the component model async feature" -) - -;; error-context.drop -(assert_invalid - (component - (core module $m - (import "" "error-context.drop" (func $error-context-drop (param i32))) - ) - (core func $error-context-drop (canon error-context.drop)) - (core instance $i (instantiate $m (with "" (instance (export "error-context.drop" (func $error-context-drop)))))) - ) - "`error-context.drop` requires the component model async feature" -) - ;; various types (assert_invalid (component (type (future))) @@ -366,10 +323,6 @@ (component (type (stream))) "requires the component model async feature" ) -(assert_invalid - (component (type error-context)) - "requires the component model async feature" -) (assert_invalid (component (type $t (resource (rep i32))) diff --git a/tests/snapshots/cli/component-model-error-context/error-context.wast.json b/tests/snapshots/cli/component-model-error-context/error-context.wast.json index 32a6761587..a8e25ae50b 100644 --- a/tests/snapshots/cli/component-model-error-context/error-context.wast.json +++ b/tests/snapshots/cli/component-model-error-context/error-context.wast.json @@ -1,5 +1,5 @@ { - "source_filename": "tests/cli/component-model-async/error-context.wast", + "source_filename": "tests/cli/component-model-error-context/error-context.wast", "commands": [ { "type": "module", diff --git a/tests/snapshots/cli/missing-features/component-model/async.wast.json b/tests/snapshots/cli/missing-features/component-model/async.wast.json index 43d36cc909..b8b79571c6 100644 --- a/tests/snapshots/cli/missing-features/component-model/async.wast.json +++ b/tests/snapshots/cli/missing-features/component-model/async.wast.json @@ -181,68 +181,40 @@ "line": 319, "filename": "async.25.wasm", "module_type": "binary", - "text": "`error-context.new` requires the component model async feature" - }, - { - "type": "assert_invalid", - "line": 333, - "filename": "async.26.wasm", - "module_type": "binary", - "text": "`error-context.debug-message` requires the component model async feature" - }, - { - "type": "assert_invalid", - "line": 350, - "filename": "async.27.wasm", - "module_type": "binary", - "text": "`error-context.drop` requires the component model async feature" - }, - { - "type": "assert_invalid", - "line": 362, - "filename": "async.28.wasm", - "module_type": "binary", - "text": "requires the component model async feature" - }, - { - "type": "assert_invalid", - "line": 366, - "filename": "async.29.wasm", - "module_type": "binary", "text": "requires the component model async feature" }, { "type": "assert_invalid", - "line": 370, - "filename": "async.30.wasm", + "line": 323, + "filename": "async.26.wasm", "module_type": "binary", "text": "requires the component model async feature" }, { "type": "assert_invalid", - "line": 374, - "filename": "async.31.wasm", + "line": 327, + "filename": "async.27.wasm", "module_type": "binary", "text": "requires the component model async builtins feature" }, { "type": "assert_invalid", - "line": 382, - "filename": "async.32.wasm", + "line": 335, + "filename": "async.28.wasm", "module_type": "binary", "text": "require the component model async feature" }, { "type": "assert_invalid", - "line": 387, - "filename": "async.33.wasm", + "line": 340, + "filename": "async.29.wasm", "module_type": "binary", "text": "require the component model async feature" }, { "type": "assert_invalid", - "line": 392, - "filename": "async.34.wasm", + "line": 345, + "filename": "async.30.wasm", "module_type": "binary", "text": "require the component model async feature" } diff --git a/tests/snapshots/cli/missing-features/component-model/error-context.wast.json b/tests/snapshots/cli/missing-features/component-model/error-context.wast.json new file mode 100644 index 0000000000..fa7b63465f --- /dev/null +++ b/tests/snapshots/cli/missing-features/component-model/error-context.wast.json @@ -0,0 +1,33 @@ +{ + "source_filename": "tests/cli/missing-features/component-model/error-context.wast", + "commands": [ + { + "type": "assert_invalid", + "line": 5, + "filename": "error-context.0.wasm", + "module_type": "binary", + "text": "`error-context.new` requires the component model error-context feature" + }, + { + "type": "assert_invalid", + "line": 19, + "filename": "error-context.1.wasm", + "module_type": "binary", + "text": "`error-context.debug-message` requires the component model error-context feature" + }, + { + "type": "assert_invalid", + "line": 36, + "filename": "error-context.2.wasm", + "module_type": "binary", + "text": "`error-context.drop` requires the component model error-context feature" + }, + { + "type": "assert_invalid", + "line": 48, + "filename": "error-context.3.wasm", + "module_type": "binary", + "text": "requires the component model error-context feature" + } + ] +} \ No newline at end of file