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
4 changes: 2 additions & 2 deletions crates/wasmparser/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ define_wasm_features! {
/// Corresponds to the 🚟 character in
/// <https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md>.
pub cm_async_stackful: CM_ASYNC_STACKFUL(1 << 28) = false;
/// Gates some intrinsics being marked with `async` in the component
/// Gates some intrinsics and options on intrinsics in the component
/// model async proposal.
///
/// Corresponds to the 🚝 character in
/// <https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md>.
pub cm_async_builtins: CM_ASYNC_BUILTINS(1 << 29) = false;
pub cm_more_async_builtins: CM_MORE_ASYNC_BUILTINS(1 << 29) = false;
/// Support for threading in the component model proposal.
///
/// Corresponds to the 🧵 character in
Expand Down
68 changes: 46 additions & 22 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ impl ComponentState {
self.future_read(ty, &options, types, offset)
}
CanonicalFunction::FutureWrite { ty, options } => {
self.future_write(ty, options.into_vec(), types, offset)
self.future_write(ty, &options, types, offset)
}
CanonicalFunction::FutureCancelRead { ty, async_ } => {
self.future_cancel_read(ty, async_, types, offset)
Expand Down Expand Up @@ -1386,10 +1386,10 @@ impl ComponentState {
types: &mut TypeAlloc,
offset: usize,
) -> Result<()> {
if !self.features.cm_async_builtins() {
if !self.features.cm_more_async_builtins() {
bail!(
offset,
"`resource.drop` as `async` requires the component model async builtins feature"
"`resource.drop` as `async` requires the component model more async builtins feature"
)
}
self.resource_at(resource, types, offset)?;
Expand Down Expand Up @@ -1608,10 +1608,10 @@ impl ComponentState {
"`subtask.cancel` requires the component model async feature"
)
}
if async_ && !self.features.cm_async_builtins() {
if async_ && !self.features.cm_more_async_builtins() {
bail!(
offset,
"async `subtask.cancel` requires the component model async builtins feature"
"async `subtask.cancel` requires the component model more async builtins feature"
)
}

Expand Down Expand Up @@ -1657,8 +1657,14 @@ impl ComponentState {
bail!(offset, "`stream.read` requires a stream type")
};

let ty_id = self
.check_options(types, options, offset)?
let options = self.check_options(types, options, offset)?;
if options.concurrency.is_sync() && !self.features.cm_more_async_builtins() {
bail!(
offset,
"synchronous `stream.read` requires the component model more async builtins feature"
);
}
let ty_id = options
.require_memory_if(offset, || elem_ty.is_some())?
.require_realloc_if(offset, || elem_ty.is_some_and(|ty| ty.contains_ptr(types)))?
.check_lower(offset)?
Expand Down Expand Up @@ -1691,8 +1697,14 @@ impl ComponentState {
bail!(offset, "`stream.write` requires a stream type")
};

let ty_id = self
.check_options(types, options, offset)?
let options = self.check_options(types, options, offset)?;
if options.concurrency.is_sync() && !self.features.cm_more_async_builtins() {
bail!(
offset,
"synchronous `stream.write` requires the component model more async builtins feature"
);
}
let ty_id = options
.require_memory_if(offset, || elem_ty.is_some())?
.check_lower(offset)?
.check_core_type(
Expand All @@ -1718,10 +1730,10 @@ impl ComponentState {
"`stream.cancel-read` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_builtins() {
if cancellable && !self.features.cm_more_async_builtins() {
bail!(
offset,
"async `stream.cancel-read` requires the component model async builtins feature"
"async `stream.cancel-read` requires the component model more async builtins feature"
)
}

Expand All @@ -1748,10 +1760,10 @@ impl ComponentState {
"`stream.cancel-write` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_builtins() {
if cancellable && !self.features.cm_more_async_builtins() {
bail!(
offset,
"async `stream.cancel-write` requires the component model async builtins feature"
"async `stream.cancel-write` requires the component model more async builtins feature"
)
}

Expand Down Expand Up @@ -1848,8 +1860,14 @@ impl ComponentState {
bail!(offset, "`future.read` requires a future type")
};

let ty_id = self
.check_options(types, options, offset)?
let options = self.check_options(types, options, offset)?;
if options.concurrency.is_sync() && !self.features.cm_more_async_builtins() {
bail!(
offset,
"synchronous `future.read` requires the component model more async builtins feature"
);
}
let ty_id = options
.require_memory_if(offset, || elem_ty.is_some())?
.require_realloc_if(offset, || elem_ty.is_some_and(|ty| ty.contains_ptr(types)))?
.check_lower(offset)?
Expand All @@ -1866,7 +1884,7 @@ impl ComponentState {
fn future_write(
&mut self,
ty: u32,
options: Vec<CanonicalOption>,
options: &[CanonicalOption],
types: &mut TypeAlloc,
offset: usize,
) -> Result<()> {
Expand All @@ -1882,8 +1900,14 @@ impl ComponentState {
bail!(offset, "`future.write` requires a future type")
};

let ty_id = self
.check_options(types, &options, offset)?
let options = self.check_options(types, &options, offset)?;
if options.concurrency.is_sync() && !self.features.cm_more_async_builtins() {
bail!(
offset,
"synchronous `future.write` requires the component model more async builtins feature"
);
}
let ty_id = options
.require_memory_if(offset, || elem_ty.is_some())?
.check_core_type(
types,
Expand All @@ -1908,10 +1932,10 @@ impl ComponentState {
"`future.cancel-read` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_builtins() {
if cancellable && !self.features.cm_more_async_builtins() {
bail!(
offset,
"async `future.cancel-read` requires the component model async builtins feature"
"async `future.cancel-read` requires the component model more async builtins feature"
)
}

Expand All @@ -1938,10 +1962,10 @@ impl ComponentState {
"`future.cancel-write` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_builtins() {
if cancellable && !self.features.cm_more_async_builtins() {
bail!(
offset,
"async `future.cancel-write` requires the component model async builtins feature"
"async `future.cancel-write` requires the component model more async builtins feature"
)
}

Expand Down
8 changes: 4 additions & 4 deletions crates/wit-component/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ fn push_imported_future_and_stream_intrinsics(
wat.push_str(&format!(
r#"
(import {module:?} {new:?} (func (result i64)))
(import {module:?} {read:?} (func (param i32 i32) (result i32)))
(import {module:?} {write:?} (func (param i32 i32) (result i32)))
(import {module:?} {cancel_read:?} (func (param i32) (result i32)))
(import {module:?} {cancel_write:?} (func (param i32) (result i32)))
(import {module:?} {drop_readable:?} (func (param i32)))
Expand All @@ -218,6 +216,8 @@ fn push_imported_future_and_stream_intrinsics(
(import {module:?} {async_write:?} (func (param i32 i32) (result i32)))

;; deferred behind 🚝
;;(import {module:?} {read:?} (func (param i32 i32) (result i32)))
;;(import {module:?} {write:?} (func (param i32 i32) (result i32)))
;;(import {module:?} {async_cancel_read:?} (func (param i32) (result i32)))
;;(import {module:?} {async_cancel_write:?} (func (param i32) (result i32)))
"#
Expand Down Expand Up @@ -261,8 +261,6 @@ fn push_imported_future_and_stream_intrinsics(
wat.push_str(&format!(
r#"
(import {module:?} {new:?} (func (result i64)))
(import {module:?} {read:?} (func (param i32 i32 i32) (result i32)))
(import {module:?} {write:?} (func (param i32 i32 i32) (result i32)))
(import {module:?} {cancel_read:?} (func (param i32) (result i32)))
(import {module:?} {cancel_write:?} (func (param i32) (result i32)))
(import {module:?} {drop_readable:?} (func (param i32)))
Expand All @@ -271,6 +269,8 @@ fn push_imported_future_and_stream_intrinsics(
(import {module:?} {async_write:?} (func (param i32 i32 i32) (result i32)))

;; deferred behind 🚝
;;(import {module:?} {read:?} (func (param i32 i32 i32) (result i32)))
;;(import {module:?} {write:?} (func (param i32 i32 i32) (result i32)))
;;(import {module:?} {async_cancel_read:?} (func (param i32) (result i32)))
;;(import {module:?} {async_cancel_write:?} (func (param i32) (result i32)))
"#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ interface or world `non-existence` does not exist
--> tests/ui/parse-fail/bad-include1.wit:4:11
|
4 | include non-existence;
| ^------------
| ^------------
12 changes: 11 additions & 1 deletion tests/cli/component-model/async/async-builtins.wast
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-async-builtins
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-more-async-builtins

;; stream.cancel-read
(component
Expand Down Expand Up @@ -101,3 +101,13 @@
)
"type mismatch for export `future.cancel-write` of module instantiation argument ``"
)

;; synchronous future/stream read/write
(component
(type $f (future))
(type $s (stream))
(core func (canon future.read $f))
(core func (canon future.write $f))
(core func (canon stream.read $s))
(core func (canon stream.write $s))
)
4 changes: 2 additions & 2 deletions tests/cli/component-model/async/futures.wast
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
(core func $future-cancel-read (canon future.cancel-read $future-type async))
(core instance $i (instantiate $m (with "" (instance (export "future.cancel-read" (func $future-cancel-read))))))
)
"requires the component model async builtins feature")
"requires the component model more async builtins feature")

;; future.cancel-read; incorrect type
(assert_invalid
Expand Down Expand Up @@ -195,7 +195,7 @@
(core func $future-cancel-write (canon future.cancel-write $future-type async))
(core instance $i (instantiate $m (with "" (instance (export "future.cancel-write" (func $future-cancel-write))))))
)
"requires the component model async builtins feature"
"requires the component model more async builtins feature"
)

;; future.cancel-write; incorrect type
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/component-model/async/streams.wast
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
(core func $stream-cancel-read (canon stream.cancel-read $stream-type async))
(core instance $i (instantiate $m (with "" (instance (export "stream.cancel-read" (func $stream-cancel-read))))))
)
"requires the component model async builtins feature")
"requires the component model more async builtins feature")

;; stream.drop-readable
(component
Expand Down Expand Up @@ -187,7 +187,7 @@
(core func $stream-cancel-write (canon stream.cancel-write $stream-type async))
(core instance $i (instantiate $m (with "" (instance (export "stream.cancel-write" (func $stream-cancel-write))))))
)
"requires the component model async builtins feature")
"requires the component model more async builtins feature")

;; stream.drop-writable
(component
Expand Down
16 changes: 8 additions & 8 deletions tests/cli/component-model/async/task-builtins.wast
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@
(canon stream.drop-readable $s (core func))
(core func (canon stream.drop-writable $s))
(canon stream.drop-writable $s (core func))
(core func (canon future.read $f (memory $m)))
(canon future.read $f (memory $m) (core func))
(core func (canon future.write $f (memory $m)))
(canon future.write $f (memory $m) (core func))
(core func (canon stream.read $s (memory $m)))
(canon stream.read $s (memory $m) (core func))
(core func (canon stream.write $s (memory $m)))
(canon stream.write $s (memory $m) (core func))
(core func (canon future.read $f (memory $m) async))
(canon future.read $f (memory $m) async (core func))
(core func (canon future.write $f (memory $m) async))
(canon future.write $f (memory $m) async (core func))
(core func (canon stream.read $s (memory $m) async))
(canon stream.read $s (memory $m) async (core func))
(core func (canon stream.write $s (memory $m) async))
(canon stream.write $s (memory $m) async (core func))

(core func (canon context.get i32 0))
(canon context.get i32 0 (core func))
Expand Down
37 changes: 30 additions & 7 deletions tests/cli/missing-features/component-model/async-builtins.wast
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
;; RUN: wast % --assert default --snapshot tests/snapshots \
;; -f=cm-async,-cm-async-builtins
;; -f=cm-async,-cm-more-async-builtins

;; {future,stream}.cancel-{read,write}
(assert_invalid
(component
(type $t (future))
(core func (canon future.cancel-read $t async)))
"requires the component model async builtins feature")
"requires the component model more async builtins feature")
(assert_invalid
(component
(type $t (future))
(core func (canon future.cancel-write $t async)))
"requires the component model async builtins feature")
"requires the component model more async builtins feature")
(assert_invalid
(component
(type $t (stream))
(core func (canon stream.cancel-read $t async)))
"requires the component model async builtins feature")
"requires the component model more async builtins feature")
(assert_invalid
(component
(type $t (stream))
(core func (canon stream.cancel-write $t async)))
"requires the component model async builtins feature")
"requires the component model more async builtins feature")

(component
(type $f (future))
Expand All @@ -37,8 +37,31 @@
(component
(type $t (resource (rep i32)))
(core func (canon resource.drop $t async)))
"requires the component model async builtins feature")
"requires the component model more async builtins feature")
(component
(type $t (resource (rep i32)))
(core func (canon resource.drop $t)))


(assert_invalid
(component
(type $t (stream))
(core func (canon stream.write $t)))
"requires the component model more async builtins feature")

(assert_invalid
(component
(type $t (stream))
(core func (canon stream.read $t)))
"requires the component model more async builtins feature")

(assert_invalid
(component
(type $t (future))
(core func (canon future.write $t)))
"requires the component model more async builtins feature")

(assert_invalid
(component
(type $t (future))
(core func (canon future.read $t)))
"requires the component model more async builtins feature")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; RUN: wast % --assert default --snapshot tests/snapshots \
;; -f=cm-async,-cm-async-builtins
;; -f=cm-async,-cm-more-async-builtins

(assert_invalid
(component
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/missing-features/component-model/async.wast
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
(type $t (resource (rep i32)))
(core func $f (canon resource.drop $t async))
)
"requires the component model async builtins feature"
"requires the component model more async builtins feature"
)

;; async function types
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, cm64, 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-more-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'.
Loading
Loading