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
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ io-lifetimes = { version = "2.0.3", default-features = false }
io-extras = "0.18.4"
rustix = "1.0.8"
# wit-bindgen:
wit-bindgen = { version = "0.49.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.49.0", default-features = false }
wit-bindgen = { version = "0.50.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.50.0", default-features = false }

# wasm-tools family:
wasmparser = { version = "0.243.0", default-features = false, features = ['simd'] }
Expand Down
15 changes: 14 additions & 1 deletion crates/test-programs/src/async_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ pub unsafe extern "C" fn task_cancel() {
unreachable!()
}

#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "$root")]
unsafe extern "C" {
#[link_name = "[thread-yield]"]
pub fn thread_yield() -> u32;
}
#[cfg(not(target_arch = "wasm32"))]
pub unsafe fn thread_yield() -> u32 {
unreachable!()
}

pub const STATUS_STARTING: u32 = 0;
pub const STATUS_STARTED: u32 = 1;
pub const STATUS_RETURNED: u32 = 2;
Expand All @@ -142,8 +153,10 @@ pub const EVENT_CANCELLED: u32 = 6;
pub const CALLBACK_CODE_EXIT: u32 = 0;
pub const CALLBACK_CODE_YIELD: u32 = 1;
pub const CALLBACK_CODE_WAIT: u32 = 2;
pub const CALLBACK_CODE_POLL: u32 = 3;

pub const BLOCKED: u32 = 0xffff_ffff;
pub const DROPPED: u32 = 1;
pub const COMPLETED: u32 = 0;

pub const SUSPEND_RESULT_NOT_CANCELLED: u32 = 0;
pub const SUSPEND_RESULT_CANCELLED: u32 = 1;
45 changes: 25 additions & 20 deletions crates/test-programs/src/bin/async_poll_stackless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ mod bindings {
use {
bindings::local::local::ready,
test_programs::async_::{
CALLBACK_CODE_EXIT, CALLBACK_CODE_POLL, EVENT_NONE, EVENT_SUBTASK, STATUS_RETURNED,
CALLBACK_CODE_EXIT, CALLBACK_CODE_YIELD, EVENT_NONE, EVENT_SUBTASK, STATUS_RETURNED,
context_get, context_set, subtask_drop, waitable_join, waitable_set_drop, waitable_set_new,
waitable_set_poll,
},
};

Expand Down Expand Up @@ -59,7 +60,7 @@ unsafe extern "C" fn export_run() -> u32 {
}

#[unsafe(export_name = "[callback][async-lift]local:local/run#run")]
unsafe extern "C" fn callback_run(event0: u32, event1: u32, event2: u32) -> u32 {
unsafe extern "C" fn callback_run(event0: u32, _: u32, _: u32) -> u32 {
let state = &mut *(usize::try_from(context_get()).unwrap() as *mut State);
match state {
State::S0 => {
Expand All @@ -71,13 +72,14 @@ unsafe extern "C" fn callback_run(event0: u32, event1: u32, event2: u32) -> u32

*state = State::S1 { set };

CALLBACK_CODE_POLL | (set << 4)
CALLBACK_CODE_YIELD
}

State::S1 { set } => {
&mut State::S1 { set } => {
let (event0, _, _) = waitable_set_poll(set);

assert_eq!(event0, EVENT_NONE);

let set = *set;
let result = async_when_ready();
let status = result & 0xf;
let call = result >> 4;
Expand All @@ -86,52 +88,55 @@ unsafe extern "C" fn callback_run(event0: u32, event1: u32, event2: u32) -> u32

*state = State::S2 { set, call };

CALLBACK_CODE_POLL | (set << 4)
CALLBACK_CODE_YIELD
}

State::S2 { set, call } => {
&mut State::S2 { set, call } => {
let (event0, _, _) = waitable_set_poll(set);

assert_eq!(event0, EVENT_NONE);

let set = *set;
let call = *call;
ready::set_ready(true);

*state = State::S3 { set, call };

CALLBACK_CODE_POLL | (set << 4)
CALLBACK_CODE_YIELD
}

State::S3 { set, call } => {
let set = *set;
&mut State::S3 { set, call } => {
let (event0, event1, event2) = waitable_set_poll(set);

if event0 != EVENT_NONE {
assert_eq!(event0, EVENT_SUBTASK);
assert_eq!(event1, *call);
assert_eq!(event1, call);
assert_eq!(event2, STATUS_RETURNED);

subtask_drop(*call);
subtask_drop(call);

*state = State::S4 { set };
}

CALLBACK_CODE_POLL | (set << 4)
CALLBACK_CODE_YIELD
}

State::S4 { set } => {
&mut State::S4 { set } => {
let (event0, _, _) = waitable_set_poll(set);

assert_eq!(event0, EVENT_NONE);

let set = *set;
assert_eq!(async_when_ready(), STATUS_RETURNED);

*state = State::S5 { set };

CALLBACK_CODE_POLL | (set << 4)
CALLBACK_CODE_YIELD
}

State::S5 { set } => {
&mut State::S5 { set } => {
let (event0, _, _) = waitable_set_poll(set);

assert_eq!(event0, EVENT_NONE);

waitable_set_drop(*set);
waitable_set_drop(set);

drop(Box::from_raw(state));

Expand Down
6 changes: 4 additions & 2 deletions crates/test-programs/src/bin/async_poll_synchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod bindings {
use {
bindings::{exports::local::local::run::Guest, local::local::ready},
test_programs::async_::{
EVENT_NONE, EVENT_SUBTASK, STATUS_RETURNED, subtask_drop, waitable_join, waitable_set_drop,
waitable_set_new, waitable_set_poll,
EVENT_NONE, EVENT_SUBTASK, STATUS_RETURNED, SUSPEND_RESULT_NOT_CANCELLED, subtask_drop,
thread_yield, waitable_join, waitable_set_drop, waitable_set_new, waitable_set_poll,
},
};

Expand Down Expand Up @@ -55,6 +55,8 @@ impl Guest for Component {

ready::set_ready(true);

assert_eq!(thread_yield(), SUSPEND_RESULT_NOT_CANCELLED);

let (event, task, code) = waitable_set_poll(set);
assert_eq!(event, EVENT_SUBTASK);
assert_eq!(call, task);
Expand Down
2 changes: 0 additions & 2 deletions crates/test-util/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,6 @@ impl WastTest {
"component-model/test/values/trap-in-post-return.wast",
"component-model/test/wasmtime/resources.wast",
"component-model/test/wasm-tools/naming.wast",
// FIXME(#12129)
"component-model/test/async/trap-if-block-and-sync.wast",
// TODO: Remove this once
// https://github.com/bytecodealliance/wasm-tools/pull/2406 is
// merged and released, and Wasmtime has been updated to use it:
Expand Down
Loading