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
39 changes: 6 additions & 33 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,7 @@ impl ComponentState {
CanonicalFunction::TaskCancel => self.task_cancel(types, offset),
CanonicalFunction::ContextGet(i) => self.context_get(i, types, offset),
CanonicalFunction::ContextSet(i) => self.context_set(i, types, offset),
CanonicalFunction::ThreadYield { cancellable } => {
self.thread_yield(cancellable, types, offset)
}
CanonicalFunction::ThreadYield { cancellable: _ } => self.thread_yield(types, offset),
CanonicalFunction::SubtaskDrop => self.subtask_drop(types, offset),
CanonicalFunction::SubtaskCancel { async_ } => {
self.subtask_cancel(async_, types, offset)
Expand Down Expand Up @@ -1250,13 +1248,13 @@ impl ComponentState {
CanonicalFunction::ErrorContextDrop => self.error_context_drop(types, offset),
CanonicalFunction::WaitableSetNew => self.waitable_set_new(types, offset),
CanonicalFunction::WaitableSetWait {
cancellable,
cancellable: _,
memory,
} => self.waitable_set_wait(cancellable, memory, types, offset),
} => self.waitable_set_wait(memory, types, offset),
CanonicalFunction::WaitableSetPoll {
cancellable,
cancellable: _,
memory,
} => self.waitable_set_poll(cancellable, memory, types, offset),
} => self.waitable_set_poll(memory, types, offset),
CanonicalFunction::WaitableSetDrop => self.waitable_set_drop(types, offset),
CanonicalFunction::WaitableJoin => self.waitable_join(types, offset),
CanonicalFunction::ThreadIndex => self.thread_index(types, offset),
Expand Down Expand Up @@ -1535,24 +1533,13 @@ impl ComponentState {
Ok(())
}

fn thread_yield(
&mut self,
cancellable: bool,
types: &mut TypeAlloc,
offset: usize,
) -> Result<()> {
fn thread_yield(&mut self, types: &mut TypeAlloc, offset: usize) -> Result<()> {
if !self.features.cm_async() {
bail!(
offset,
"`thread.yield` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_stackful() {
bail!(
offset,
"cancellable `thread.yield` requires the component model async stackful feature"
)
}

self.core_funcs
.push(types.intern_func_type(FuncType::new([], [ValType::I32]), offset));
Expand Down Expand Up @@ -2053,7 +2040,6 @@ impl ComponentState {

fn waitable_set_wait(
&mut self,
cancellable: bool,
memory: u32,
types: &mut TypeAlloc,
offset: usize,
Expand All @@ -2064,12 +2050,6 @@ impl ComponentState {
"`waitable-set.wait` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_stackful() {
bail!(
offset,
"cancellable `waitable-set.wait` requires the component model async stackful feature"
)
}

self.cabi_memory_at(memory, offset)?;

Expand All @@ -2080,7 +2060,6 @@ impl ComponentState {

fn waitable_set_poll(
&mut self,
cancellable: bool,
memory: u32,
types: &mut TypeAlloc,
offset: usize,
Expand All @@ -2091,12 +2070,6 @@ impl ComponentState {
"`waitable-set.poll` requires the component model async feature"
)
}
if cancellable && !self.features.cm_async_stackful() {
bail!(
offset,
"cancellable `waitable-set.poll` requires the component model async stackful feature"
)
}

self.cabi_memory_at(memory, offset)?;

Expand Down
50 changes: 22 additions & 28 deletions tests/cli/component-model/async/task-builtins.wast
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,15 @@
"type mismatch for export `waitable-set.wait` of module instantiation argument ``"
)

(assert_invalid
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
)
(core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32)))
)
"requires the component model async stackful feature")
(core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait))))))
)

;; waitable-set.poll
(component
Expand All @@ -170,17 +168,15 @@
(core func $waitable-set-poll (canon waitable-set.poll (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
)
(assert_invalid
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
)
(core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32)))
)
"requires the component model async stackful feature")
(core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll))))))
)

;; waitable-set.poll; incorrect type
(assert_invalid
Expand Down Expand Up @@ -298,15 +294,13 @@
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
)

(assert_invalid
(component
(core module $m
(import "" "thread.yield" (func $thread.yield (result i32)))
)
(core func $thread.yield (canon thread.yield cancellable))
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
(component
(core module $m
(import "" "thread.yield" (func $thread.yield (result i32)))
)
"requires the component model async stackful feature")
(core func $thread.yield (canon thread.yield cancellable))
(core instance $i (instantiate $m (with "" (instance (export "thread.yield" (func $thread.yield))))))
)

;; thread.yield; incorrect type
(assert_invalid
Expand Down
30 changes: 12 additions & 18 deletions tests/cli/missing-features/component-model/async-stackful.wast
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
"requires the component model async stackful feature")

;; waitable-set.wait cancellable
(assert_invalid
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core func (canon waitable-set.wait cancellable (memory $libc "memory")))
)
"requires the component model async stackful feature")
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core func (canon waitable-set.wait cancellable (memory $libc "memory")))
)

(component
(core module $libc (memory (export "memory") 1))
Expand All @@ -28,13 +26,11 @@
)

;; waitable-set.poll cancellable
(assert_invalid
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core func (canon waitable-set.poll cancellable (memory $libc "memory")))
)
"requires the component model async stackful feature")
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core func (canon waitable-set.poll cancellable (memory $libc "memory")))
)

(component
(core module $libc (memory (export "memory") 1))
Expand All @@ -43,8 +39,6 @@
)

;; thread.yield
(assert_invalid
(component (core func (canon thread.yield cancellable)))
"requires the component model async stackful feature")
(component (core func (canon thread.yield cancellable)))

(component (core func (canon thread.yield)))
(component (core func (canon thread.yield)))
Loading