A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Migrate some component async tests from Rust to `*.wast` (#13290)
Alex Crichton46665ea29ebf
diff --git a/tests/all/component_model/async.rs b/tests/all/component_model/async.rsindex 58edc578c7..2a91f1be20 100644--- a/tests/all/component_model/async.rs+++ b/tests/all/component_model/async.rs@@ -311,360 +311,6 @@ async fn drop_resource_async() -> Result<()> {Ok(())}-/// Test task deletion in three situations, for every combination of lift/lower/(guest/host):-/// 1. An explicit thread calls task.return-/// 2. An explicit thread suspends indefinitely-/// 3. An explicit thread yield loops indefinitely-#[tokio::test]-#[cfg_attr(miri, ignore)]-async fn task_deletion() -> Result<()> {- let mut config = Config::new();- config.wasm_component_model_async(true);- config.wasm_component_model_threading(true);- config.wasm_component_model_async_stackful(true);- config.wasm_component_model_more_async_builtins(true);- let engine = Engine::new(&config)?;- let component = Component::new(- &engine,- r#"(component- (component $C- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- ;; Defines the table for the thread start functions- (core module $libc- (table (export "__indirect_function_table") 3 funcref))- (core module $CM- (import "" "mem" (memory 1))- (import "" "task.return" (func $task-return (param i32)))- (import "" "task.cancel" (func $task-cancel))- (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))- (import "" "thread.suspend" (func $thread-suspend (result i32)))- (import "" "thread.suspend-cancellable" (func $thread-suspend-cancellable (result i32)))- (import "" "thread.yield-to-suspended" (func $thread-yield-to-suspended (param i32) (result i32)))- (import "" "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable (param i32) (result i32)))- (import "" "thread.suspend-to" (func $thread-suspend-to (param i32) (result i32)))- (import "" "thread.suspend-to-cancellable" (func $thread-suspend-to-cancellable (param i32) (result i32)))- (import "" "thread.yield" (func $thread-yield (result i32)))- (import "" "thread.yield-cancellable" (func $thread-yield-cancellable (result i32)))- (import "" "thread.index" (func $thread-index (result i32)))- (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "libc" "__indirect_function_table" (table $indirect-function-table 3 funcref))-- ;; Indices into the function table for the thread start functions- (global $call-return-ftbl-idx i32 (i32.const 0))- (global $suspend-ftbl-idx i32 (i32.const 1))- (global $yield-loop-ftbl-idx i32 (i32.const 2))-- (func $call-return (param i32)- (call $task-return (local.get 0)))-- (func $suspend (param i32)- (drop (call $thread-suspend)))-- (func $yield-loop (param i32)- (loop $top- (drop (call $thread-yield))- (br $top)))-- (func (export "explicit-thread-calls-return-stackful")- (call $thread-unsuspend- (call $thread-new-indirect (global.get $call-return-ftbl-idx) (i32.const 42))))-- (func (export "explicit-thread-calls-return-stackless") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (global.get $call-return-ftbl-idx) (i32.const 42)))- (i32.const 0 (; EXIT ;)))-- (func (export "cb") (param i32 i32 i32) (result i32)- (unreachable))-- (func (export "explicit-thread-suspends-sync") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))- (i32.const 42))-- (func (export "explicit-thread-suspends-stackful")- (call $thread-unsuspend- (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))- (call $task-return (i32.const 42)))-- (func (export "explicit-thread-suspends-stackless") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))- (call $task-return (i32.const 42))- (i32.const 0))-- (func (export "explicit-thread-yield-loops-sync") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (global.get $yield-loop-ftbl-idx) (i32.const 42)))- (i32.const 42))-- (func (export "explicit-thread-yield-loops-stackful")- (call $thread-unsuspend- (call $thread-new-indirect (global.get $yield-loop-ftbl-idx) (i32.const 42)))- (call $task-return (i32.const 42)))-- (func (export "explicit-thread-yield-loops-stackless") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))- (call $task-return (i32.const 42))- (i32.const 0 (; EXIT ;)))-- ;; Initialize the function table that will be used by thread.new-indirect- (elem (table $indirect-function-table) (i32.const 0 (; call-return-ftbl-idx ;)) func $call-return)- (elem (table $indirect-function-table) (i32.const 1 (; suspend-ftbl-idx ;)) func $suspend)- (elem (table $indirect-function-table) (i32.const 2 (; yield-loop-ftbl-idx ;)) func $yield-loop)- )-- ;; Instantiate the libc module to get the table- (core instance $libc (instantiate $libc))- ;; Get access to `thread.new-indirect` that uses the table from libc- (core type $start-func-ty (func (param i32)))- (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))-- (core func $task-return (canon task.return (result u32)))- (core func $task-cancel (canon task.cancel))- (core func $thread-new-indirect- (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))- (core func $thread-yield (canon thread.yield))- (core func $thread-yield-cancellable (canon thread.yield cancellable))- (core func $thread-index (canon thread.index))- (core func $thread-yield-to-suspended (canon thread.yield-to-suspended))- (core func $thread-yield-to-suspended-cancellable (canon thread.yield-to-suspended cancellable))- (core func $thread-unsuspend (canon thread.unsuspend))- (core func $thread-suspend-to (canon thread.suspend-to))- (core func $thread-suspend-to-cancellable (canon thread.suspend-to cancellable))- (core func $thread-suspend (canon thread.suspend))- (core func $thread-suspend-cancellable (canon thread.suspend cancellable))- (core func $waitable-set.new (canon waitable-set.new))- (core func $waitable.join (canon waitable.join))- (core func $waitable-set.wait (canon waitable-set.wait (memory $memory "mem")))-- ;; Instantiate the main module- (core instance $cm (- instantiate $CM- (with "" (instance- (export "mem" (memory $memory "mem"))- (export "task.return" (func $task-return))- (export "task.cancel" (func $task-cancel))- (export "thread.new-indirect" (func $thread-new-indirect))- (export "thread.index" (func $thread-index))- (export "thread.yield-to-suspended" (func $thread-yield-to-suspended))- (export "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable))- (export "thread.yield" (func $thread-yield))- (export "thread.yield-cancellable" (func $thread-yield-cancellable))- (export "thread.suspend-to" (func $thread-suspend-to))- (export "thread.suspend-to-cancellable" (func $thread-suspend-to-cancellable))- (export "thread.suspend" (func $thread-suspend))- (export "thread.suspend-cancellable" (func $thread-suspend-cancellable))- (export "thread.unsuspend" (func $thread-unsuspend))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "waitable-set.new" (func $waitable-set.new))))- (with "libc" (instance $libc))))-- (func (export "explicit-thread-calls-return-stackful") async (result u32)- (canon lift (core func $cm "explicit-thread-calls-return-stackful") async))- (func (export "explicit-thread-calls-return-stackless") async (result u32)- (canon lift (core func $cm "explicit-thread-calls-return-stackless") async (callback (func $cm "cb"))))- (func (export "explicit-thread-suspends-sync") async (result u32)- (canon lift (core func $cm "explicit-thread-suspends-sync")))- (func (export "explicit-thread-suspends-stackful") async (result u32)- (canon lift (core func $cm "explicit-thread-suspends-stackful") async))- (func (export "explicit-thread-suspends-stackless") async (result u32)- (canon lift (core func $cm "explicit-thread-suspends-stackless") async (callback (func $cm "cb"))))- (func (export "explicit-thread-yield-loops-sync") async (result u32)- (canon lift (core func $cm "explicit-thread-yield-loops-sync")))- (func (export "explicit-thread-yield-loops-stackful") async (result u32)- (canon lift (core func $cm "explicit-thread-yield-loops-stackful") async))- (func (export "explicit-thread-yield-loops-stackless") async (result u32)- (canon lift (core func $cm "explicit-thread-yield-loops-stackless") async (callback (func $cm "cb"))))- )-- (component $D- (import "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful async (result u32)))- (import "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless async (result u32)))- (import "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync async (result u32)))- (import "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful async (result u32)))- (import "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless async (result u32)))- (import "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync async (result u32)))- (import "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful async (result u32)))- (import "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless async (result u32)))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $DM- (import "" "mem" (memory 1))- (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32)))- ;; sync lowered- (import "" "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful (result i32)))- (import "" "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless (result i32)))- (import "" "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync (result i32)))- (import "" "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful (result i32)))- (import "" "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless (result i32)))- (import "" "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync (result i32)))- (import "" "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful (result i32)))- (import "" "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless (result i32)))- ;; async lowered- (import "" "explicit-thread-calls-return-stackful-async" (func $explicit-thread-calls-return-stackful-async (param i32) (result i32)))- (import "" "explicit-thread-calls-return-stackless-async" (func $explicit-thread-calls-return-stackless-async (param i32) (result i32)))- (import "" "explicit-thread-suspends-sync-async" (func $explicit-thread-suspends-sync-async (param i32) (result i32)))- (import "" "explicit-thread-suspends-stackful-async" (func $explicit-thread-suspends-stackful-async (param i32) (result i32)))- (import "" "explicit-thread-suspends-stackless-async" (func $explicit-thread-suspends-stackless-async (param i32) (result i32)))- (import "" "explicit-thread-yield-loops-sync-async" (func $explicit-thread-yield-loops-sync-async (param i32) (result i32)))- (import "" "explicit-thread-yield-loops-stackful-async" (func $explicit-thread-yield-loops-stackful-async (param i32) (result i32)))- (import "" "explicit-thread-yield-loops-stackless-async" (func $explicit-thread-yield-loops-stackless-async (param i32) (result i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "thread.yield" (func $thread-yield (result i32)))-- (func $check (param i32)- (if (i32.ne (local.get 0) (i32.const 42))- (then unreachable))- )-- (func $check-async (param i32)- (local $retp i32) (local $ws i32) (local $ws-retp i32)- (local.set $retp (i32.const 8))- (local.set $ws-retp (i32.const 16))- (local.set $ws (call $waitable-set.new))-- (if (i32.eq (i32.and (local.get 0) (i32.const 0xF)) (i32.const 2 (; RETURNED ;)))- (then (call $check (i32.load (local.get $retp))))- (else- (call $waitable.join (i32.shr_u (local.get 0) (i32.const 4)) (local.get $ws))- (drop (call $waitable-set.wait (local.get $ws) (local.get $ws-retp)))- (call $check (i32.load (local.get $retp)))))- )-- (func $run (export "run") (result i32)- (local $retp i32)- (local.set $retp (i32.const 8))- (call $check (call $explicit-thread-calls-return-stackless))- (call $check (call $explicit-thread-calls-return-stackful))- (call $check (call $explicit-thread-suspends-sync))- (call $check (call $explicit-thread-suspends-stackful))- (call $check (call $explicit-thread-suspends-stackless))- (call $check (call $explicit-thread-yield-loops-sync))- (call $check (call $explicit-thread-yield-loops-stackful))- (call $check (call $explicit-thread-yield-loops-stackless))-- (call $check-async (call $explicit-thread-calls-return-stackless-async (local.get $retp)))- (call $check-async (call $explicit-thread-calls-return-stackful-async (local.get $retp)))- (call $check-async (call $explicit-thread-suspends-sync-async (local.get $retp)))- (call $check-async (call $explicit-thread-suspends-stackful-async (local.get $retp)))- (call $check-async (call $explicit-thread-suspends-stackless-async (local.get $retp)))- (call $check-async (call $explicit-thread-yield-loops-sync-async (local.get $retp)))- (call $check-async (call $explicit-thread-yield-loops-stackful-async (local.get $retp)))- (call $check-async (call $explicit-thread-yield-loops-stackless-async (local.get $retp)))-- (i32.const 42)- )- )-- (core func $waitable-set.new (canon waitable-set.new))- (core func $waitable-set.wait (canon waitable-set.wait (memory $memory "mem")))- (core func $waitable.join (canon waitable.join))- (core func $subtask.cancel (canon subtask.cancel async))- (core func $thread.yield (canon thread.yield))- ;; sync lowered- (canon lower (func $explicit-thread-calls-return-stackful) (memory $memory "mem") (core func $explicit-thread-calls-return-stackful'))- (canon lower (func $explicit-thread-calls-return-stackless) (memory $memory "mem") (core func $explicit-thread-calls-return-stackless'))- (canon lower (func $explicit-thread-suspends-sync) (memory $memory "mem") (core func $explicit-thread-suspends-sync'))- (canon lower (func $explicit-thread-suspends-stackful) (memory $memory "mem") (core func $explicit-thread-suspends-stackful'))- (canon lower (func $explicit-thread-suspends-stackless) (memory $memory "mem") (core func $explicit-thread-suspends-stackless'))- (canon lower (func $explicit-thread-yield-loops-sync) (memory $memory "mem") (core func $explicit-thread-yield-loops-sync'))- (canon lower (func $explicit-thread-yield-loops-stackful) (memory $memory "mem") (core func $explicit-thread-yield-loops-stackful'))- (canon lower (func $explicit-thread-yield-loops-stackless) (memory $memory "mem") (core func $explicit-thread-yield-loops-stackless'))- ;; async lowered- (canon lower (func $explicit-thread-calls-return-stackful) async (memory $memory "mem") (core func $explicit-thread-calls-return-stackful-async'))- (canon lower (func $explicit-thread-calls-return-stackless) async (memory $memory "mem") (core func $explicit-thread-calls-return-stackless-async'))- (canon lower (func $explicit-thread-suspends-sync) async (memory $memory "mem") (core func $explicit-thread-suspends-sync-async'))- (canon lower (func $explicit-thread-suspends-stackful) async (memory $memory "mem") (core func $explicit-thread-suspends-stackful-async'))- (canon lower (func $explicit-thread-suspends-stackless) async (memory $memory "mem") (core func $explicit-thread-suspends-stackless-async'))- (canon lower (func $explicit-thread-yield-loops-sync) async (memory $memory "mem") (core func $explicit-thread-yield-loops-sync-async'))- (canon lower (func $explicit-thread-yield-loops-stackful) async (memory $memory "mem") (core func $explicit-thread-yield-loops-stackful-async'))- (canon lower (func $explicit-thread-yield-loops-stackless) async (memory $memory "mem") (core func $explicit-thread-yield-loops-stackless-async'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful'))- (export "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless'))- (export "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync'))- (export "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful'))- (export "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless'))- (export "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync'))- (export "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful'))- (export "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless'))- (export "explicit-thread-calls-return-stackful-async" (func $explicit-thread-calls-return-stackful-async'))- (export "explicit-thread-calls-return-stackless-async" (func $explicit-thread-calls-return-stackless-async'))- (export "explicit-thread-suspends-sync-async" (func $explicit-thread-suspends-sync-async'))- (export "explicit-thread-suspends-stackful-async" (func $explicit-thread-suspends-stackful-async'))- (export "explicit-thread-suspends-stackless-async" (func $explicit-thread-suspends-stackless-async'))- (export "explicit-thread-yield-loops-sync-async" (func $explicit-thread-yield-loops-sync-async'))- (export "explicit-thread-yield-loops-stackful-async" (func $explicit-thread-yield-loops-stackful-async'))- (export "explicit-thread-yield-loops-stackless-async" (func $explicit-thread-yield-loops-stackless-async'))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "subtask.cancel" (func $subtask.cancel))- (export "thread.yield" (func $thread.yield))- ))))- (func (export "run") async (result u32) (canon lift (core func $dm "run")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D- (with "explicit-thread-calls-return-stackful" (func $c "explicit-thread-calls-return-stackful"))- (with "explicit-thread-calls-return-stackless" (func $c "explicit-thread-calls-return-stackless"))- (with "explicit-thread-suspends-sync" (func $c "explicit-thread-suspends-sync"))- (with "explicit-thread-suspends-stackful" (func $c "explicit-thread-suspends-stackful"))- (with "explicit-thread-suspends-stackless" (func $c "explicit-thread-suspends-stackless"))- (with "explicit-thread-yield-loops-sync" (func $c "explicit-thread-yield-loops-sync"))- (with "explicit-thread-yield-loops-stackful" (func $c "explicit-thread-yield-loops-stackful"))- (with "explicit-thread-yield-loops-stackless" (func $c "explicit-thread-yield-loops-stackless"))- ))- (func (export "run") (alias export $d "run"))- (func (export "explicit-thread-calls-return-stackful") (alias export $c "explicit-thread-calls-return-stackful"))- (func (export "explicit-thread-calls-return-stackless") (alias export $c "explicit-thread-calls-return-stackless"))- (func (export "explicit-thread-suspends-sync") (alias export $c "explicit-thread-suspends-sync"))- (func (export "explicit-thread-suspends-stackful") (alias export $c "explicit-thread-suspends-stackful"))- (func (export "explicit-thread-suspends-stackless") (alias export $c "explicit-thread-suspends-stackless"))- (func (export "explicit-thread-yield-loops-sync") (alias export $c "explicit-thread-yield-loops-sync"))- (func (export "explicit-thread-yield-loops-stackful") (alias export $c "explicit-thread-yield-loops-stackful"))- (func (export "explicit-thread-yield-loops-stackless") (alias export $c "explicit-thread-yield-loops-stackless"))-)- "#,- )?- .serialize()?;-- let component = unsafe { Component::deserialize(&engine, &component)? };- let mut store = Store::new(&engine, ());- let instance = Linker::new(&engine)- .instantiate_async(&mut store, &component)- .await?;- let funcs = vec![- "run",- "explicit-thread-calls-return-stackful",- "explicit-thread-calls-return-stackless",- "explicit-thread-suspends-sync",- "explicit-thread-suspends-stackful",- "explicit-thread-suspends-stackless",- "explicit-thread-yield-loops-sync",- "explicit-thread-yield-loops-stackful",- "explicit-thread-yield-loops-stackless",- ];- for func in funcs {- let func = instance.get_typed_func::<(), (u32,)>(&mut store, func)?;- assert_eq!(func.call_async(&mut store, ()).await?, (42,));- }-- Ok(())-}-#[tokio::test]#[cfg_attr(miri, ignore)]async fn cancel_host_future() -> Result<()> {@@ -1324,60 +970,3 @@ async fn bytes_stream_producer() -> Result<()> {Ok(())}--#[tokio::test]-#[cfg_attr(miri, ignore)]-async fn drop_deadlocked_typed_future() -> Result<()> {- let mut config = Config::new();- config.wasm_component_model_async(true);-- let engine = Engine::new(&config)?;- let component = Component::new(- &engine,- r#"- (component- (core func $backpressure_inc (canon backpressure.inc))-- (core module $m- (import "" "backpressure.inc" (func $backpressure_inc))- (func (export "set-backpressure") (call $backpressure_inc))- (func (export "target") (result i32) unreachable)- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- )-- (core instance $i (instantiate $m- (with "" (instance (export "backpressure.inc" (func $backpressure_inc))))- ))-- (func (export "set-backpressure")- (canon lift (core func $i "set-backpressure")))-- (func (export "target")- (canon lift (core func $i "target") async (callback (func $i "callback"))))- )- "#,- )?;- let mut store = Store::new(&engine, ());- let linker = Linker::<()>::new(&engine);- let instance = linker.instantiate_async(&mut store, &component).await?;-- // Force the instance to deadlock the next call by turning on backpressure- // meaning it can't enter the instance.- instance- .get_typed_func::<(), ()>(&mut store, "set-backpressure")?- .call_async(&mut store, ())- .await?;-- // This call should fail due to deadlock since no progress is possible. When- // the future is dropped that shouldn't cause anything to go awry...- let result = instance- .get_typed_func::<(), ()>(&mut store, "target")?- .call_async(&mut store, ())- .await;-- assert!(result.is_err(), "expected an error, got Ok");- let trap = result.unwrap_err().downcast::<Trap>()?;- assert_eq!(trap, Trap::AsyncDeadlock);-- Ok(())-}diff --git a/tests/all/component_model/func.rs b/tests/all/component_model/func.rsindex e9dcfc3a58..59c6c11195 100644--- a/tests/all/component_model/func.rs+++ b/tests/all/component_model/func.rs@@ -809,342 +809,6 @@ fn strings() -> Result<()> {Ok(())}-#[tokio::test]-async fn async_reentrance() -> Result<()> {- _ = env_logger::try_init();-- let component = r#"- (component- (core module $shim- (import "" "task.return" (func $task-return (param i32)))- (table (export "funcs") 1 1 funcref)- (func (export "export") (param i32) (result i32)- (call_indirect (i32.const 0) (local.get 0))- )- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- )- (core func $task-return (canon task.return (result u32)))- (core instance $shim (instantiate $shim- (with "" (instance (export "task.return" (func $task-return))))- ))- (func $shim-export (param "p1" u32) (result u32)- (canon lift (core func $shim "export") async (callback (func $shim "callback")))- )-- (component $inner- (import "import" (func $import (param "p1" u32) (result u32)))- (core module $libc (memory (export "memory") 1))- (core instance $libc (instantiate $libc))- (core func $import (canon lower (func $import) async (memory $libc "memory")))-- (core module $m- (import "libc" "memory" (memory 1))- (import "" "import" (func $import (param i32 i32) (result i32)))- (import "" "task.return" (func $task-return (param i32)))- (func (export "export") (param i32) (result i32)- (i32.store offset=0 (i32.const 1200) (local.get 0))- (call $import (i32.const 1200) (i32.const 1204))- drop- (call $task-return (i32.load offset=0 (i32.const 1204)))- i32.const 0- )- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- )- (core type $task-return-type (func (param i32)))- (core func $task-return (canon task.return (result u32)))- (core instance $i (instantiate $m- (with "" (instance- (export "task.return" (func $task-return))- (export "import" (func $import))- ))- (with "libc" (instance $libc))- ))- (func (export "export") (param "p1" u32) (result u32)- (canon lift (core func $i "export") async (callback (func $i "callback")))- )- )- (instance $inner (instantiate $inner (with "import" (func $shim-export))))-- (core module $libc (memory (export "memory") 1))- (core instance $libc (instantiate $libc))- (core func $inner-export (canon lower (func $inner "export") async (memory $libc "memory")))-- (core module $donut- (import "" "funcs" (table 1 1 funcref))- (import "libc" "memory" (memory 1))- (import "" "import" (func $import (param i32 i32) (result i32)))- (import "" "task.return" (func $task-return (param i32)))- (func $host-export (export "export") (param i32) (result i32)- (i32.store offset=0 (i32.const 1200) (local.get 0))- (call $import (i32.const 1200) (i32.const 1204))- drop- (call $task-return (i32.load offset=0 (i32.const 1204)))- i32.const 0- )- (func $guest-export (export "guest-export") (param i32) (result i32) unreachable)- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- (func $start- (table.set (i32.const 0) (ref.func $guest-export))- )- (start $start)- )-- (core instance $donut (instantiate $donut- (with "" (instance- (export "task.return" (func $task-return))- (export "import" (func $inner-export))- (export "funcs" (table $shim "funcs"))- ))- (with "libc" (instance $libc))- ))- (func (export "export") (param "p1" u32) (result u32)- (canon lift (core func $donut "export") async (callback (func $donut "callback")))- )- )"#;-- let mut config = Config::new();- config.wasm_component_model_async(true);- config.wasm_component_model_async_stackful(true);- config.wasm_component_model_threading(true);- let engine = &Engine::new(&config)?;- let component = Component::new(&engine, component)?;- let mut store = Store::new(&engine, ());-- let instance = Linker::new(&engine)- .instantiate_async(&mut store, &component)- .await?;- let func = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "export")?;- let message = "cannot enter component instance";- match store- .run_concurrent(async move |accessor| {- wasmtime::error::Ok(func.call_concurrent(accessor, (42,)).await?.0)- })- .await- {- Ok(_) => panic!(),- Err(e) => assert!(- format!("{e:?}").contains(message),- "expected `{message}`; got `{e:?}`"- ),- }-- Ok(())-}--#[tokio::test]-async fn missing_task_return_call_stackless() -> Result<()> {- task_return_trap(- r#"(component- (core module $m- (import "" "task.return" (func $task-return))- (func (export "foo") (result i32)- i32.const 0- )- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- )- (core func $task-return (canon task.return))- (core instance $i (instantiate $m- (with "" (instance (export "task.return" (func $task-return))))- ))- (func (export "foo") (canon lift (core func $i "foo") async (callback (func $i "callback"))))- )"#,- "wasm trap: async-lifted export failed to produce a result",- )- .await-}--#[tokio::test]-async fn missing_task_return_call_stackless_explicit_thread() -> Result<()> {- task_return_trap(- r#"(component- (core module $libc- (table (export "__indirect_function_table") 1 funcref))- (core module $m- (import "" "task.return" (func $task-return))- (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))- (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))- (import "libc" "__indirect_function_table" (table $indirect-function-table 1 funcref))- (func $thread-start (param i32) (; empty ;))- (elem (table $indirect-function-table) (i32.const 0) func $thread-start)- (func (export "foo") (result i32)- (call $thread-unsuspend- (call $thread-new-indirect (i32.const 0) (i32.const 0)))- i32.const 0- )- (func (export "callback") (param i32 i32 i32) (result i32) unreachable)- )- (core instance $libc (instantiate $libc))- (core type $start-func-ty (func (param i32)))- (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))- (core func $thread-new-indirect- (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))- (core func $thread-unsuspend (canon thread.unsuspend))- (core func $task-return (canon task.return))- (core instance $i (instantiate $m- (with "" (instance- (export "thread.new-indirect" (func $thread-new-indirect))- (export "thread.unsuspend" (func $thread-unsuspend))- (export "task.return" (func $task-return))- ))- (with "libc" (instance $libc))- ))- (func (export "foo") (canon lift (core func $i "foo") async (callback (func $i "callback"))))- )"#,- "wasm trap: async-lifted export failed to produce a result",- )- .await-}--#[tokio::test]-async fn missing_task_return_call_stackful_explicit_thread() -> Result<()> {- task_return_trap(- r#"(component- (core module $libc- (table (export "__indirect_function_table") 1 funcref))- (core module $m- (import "" "task.return" (func $task-return))- (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))- (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))- (import "libc" "__indirect_function_table" (table $indirect-function-table 1 funcref))- (func $thread-start (param i32) (; empty ;))- (elem (table $indirect-function-table) (i32.const 0) func $thread-start)- (func (export "foo")- (call $thread-unsuspend- (call $thread-new-indirect (i32.const 0) (i32.const 0)))- )- )- (core instance $libc (instantiate $libc))- (core type $start-func-ty (func (param i32)))- (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))- (core func $thread-new-indirect- (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))- (core func $thread-unsuspend (canon thread.unsuspend))- (core func $task-return (canon task.return))- (core instance $i (instantiate $m- (with "" (instance- (export "thread.new-indirect" (func $thread-new-indirect))- (export "thread.unsuspend" (func $thread-unsuspend))- (export "task.return" (func $task-return))- ))- (with "libc" (instance $libc))- ))- (func (export "foo") (canon lift (core func $i "foo") async))- )"#,- "wasm trap: async-lifted export failed to produce a result",- )- .await-}--#[tokio::test]-async fn missing_task_return_call_stackful() -> Result<()> {- task_return_trap(- r#"(component- (core module $m- (import "" "task.return" (func $task-return))- (func (export "foo"))- )- (core func $task-return (canon task.return))- (core instance $i (instantiate $m- (with "" (instance (export "task.return" (func $task-return))))- ))- (func (export "foo") (canon lift (core func $i "foo") async))- )"#,- "wasm trap: async-lifted export failed to produce a result",- )- .await-}--#[tokio::test]-async fn task_return_type_mismatch() -> Result<()> {- task_return_trap(- r#"(component- (core module $m- (import "" "task.return" (func $task-return (param i32)))- (func (export "foo") (call $task-return (i32.const 42)))- )- (core func $task-return (canon task.return (result u32)))- (core instance $i (instantiate $m- (with "" (instance (export "task.return" (func $task-return))))- ))- (func (export "foo") (canon lift (core func $i "foo") async))- )"#,- "invalid `task.return` signature and/or options for current task",- )- .await-}--#[tokio::test]-async fn task_return_memory_mismatch() -> Result<()> {- task_return_trap(- r#"(component- (core module $libc (memory (export "memory") 1))- (core instance $libc (instantiate $libc))- (core module $m- (import "" "task.return" (func $task-return))- (func (export "foo") (call $task-return))- )- (core func $task-return (canon task.return (memory $libc "memory")))- (core instance $i (instantiate $m- (with "" (instance (export "task.return" (func $task-return))))- ))- (func (export "foo") (canon lift (core func $i "foo") async))- )"#,- "invalid `task.return` signature and/or options for current task",- )- .await-}--#[tokio::test]-async fn task_return_string_encoding_mismatch() -> Result<()> {- task_return_trap(- r#"(component- (core module $m- (import "" "task.return" (func $task-return))- (func (export "foo") (call $task-return))- )- (core func $task-return (canon task.return string-encoding=utf16))- (core instance $i (instantiate $m- (with "" (instance (export "task.return" (func $task-return))))- ))- (func (export "foo") (canon lift (core func $i "foo") async))- )"#,- "invalid `task.return` signature and/or options for current task",- )- .await-}--async fn task_return_trap(component: &str, substring: &str) -> Result<()> {- let mut config = Config::new();- config.wasm_component_model_async(true);- config.wasm_component_model_async_stackful(true);- config.wasm_component_model_threading(true);- let engine = &Engine::new(&config)?;- let component = Component::new(&engine, component)?;- let mut store = Store::new(&engine, ());-- let instance = Linker::new(&engine)- .instantiate_async(&mut store, &component)- .await?;-- let func = instance.get_typed_func::<(), ()>(&mut store, "foo")?;- match store- .run_concurrent(async move |accessor| {- wasmtime::error::Ok(func.call_concurrent(accessor, ()).await?)- })- .await- {- Ok(_) => panic!(),- Err(e) => {- assert!(- format!("{e:?}").contains(substring),- "could not find `{substring}` in `{e:?}`"- )- }- }-- Ok(())-}-#[tokio::test]async fn many_parameters() -> Result<()> {test_many_parameters(false, false).awaitdiff --git a/tests/all/component_model/nested.rs b/tests/all/component_model/nested.rsindex 2a6cddd9af..67f24f1a67 100644--- a/tests/all/component_model/nested.rs+++ b/tests/all/component_model/nested.rs@@ -3,7 +3,7 @@use super::REALLOC_AND_FREE;use wasmtime::Result;use wasmtime::component::*;-use wasmtime::{Module, Store, StoreContextMut};+use wasmtime::{Module, Store};#[test]fn top_level_instance_two_level() -> Result<()> {@@ -57,55 +57,6 @@ fn top_level_instance_two_level() -> Result<()> {Ok(())}-#[test]-fn nested_many_instantiations() -> Result<()> {- let component = r#"-(component- (import "count" (func $count))- (component $c1- (import "count" (func $count))- (core func $count_lower (canon lower (func $count)))- (core module $m- (import "" "" (func $count))- (start $count)- )- (core instance (instantiate $m (with "" (instance (export "" (func $count_lower))))))- (core instance (instantiate $m (with "" (instance (export "" (func $count_lower))))))- )- (component $c2- (import "count" (func $count))- (instance (instantiate $c1 (with "count" (func $count))))- (instance (instantiate $c1 (with "count" (func $count))))- )- (component $c3- (import "count" (func $count))- (instance (instantiate $c2 (with "count" (func $count))))- (instance (instantiate $c2 (with "count" (func $count))))- )- (component $c4- (import "count" (func $count))- (instance (instantiate $c3 (with "count" (func $count))))- (instance (instantiate $c3 (with "count" (func $count))))- )-- (instance (instantiate $c4 (with "count" (func $count))))-)- "#;- let engine = super::engine();- let component = Component::new(&engine, component)?;- let mut store = Store::new(&engine, 0);- let mut linker = Linker::new(&engine);- linker- .root()- .func_wrap("count", |mut store: StoreContextMut<'_, u32>, _: ()| {- *store.data_mut() += 1;- Ok(())- })?;- linker.instantiate(&mut store, &component)?;- assert_eq!(*store.data(), 16);- Ok(())-}-#[test]fn thread_options_through_inner() -> Result<()> {let component = format!(diff --git a/tests/misc_testsuite/component-model/async/drop-deadlock.wast b/tests/misc_testsuite/component-model/async/drop-deadlock.wastnew file mode 100644index 0000000000..2d7b77dde6--- /dev/null+++ b/tests/misc_testsuite/component-model/async/drop-deadlock.wast@@ -0,0 +1,25 @@+;;! component_model_async = true++(component+ (core func $backpressure_inc (canon backpressure.inc))++ (core module $m+ (import "" "backpressure.inc" (func $backpressure_inc))+ (func (export "set-backpressure") (call $backpressure_inc))+ (func (export "target") (result i32) unreachable)+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ )++ (core instance $i (instantiate $m+ (with "" (instance (export "backpressure.inc" (func $backpressure_inc))))+ ))++ (func (export "set-backpressure")+ (canon lift (core func $i "set-backpressure")))++ (func (export "target")+ (canon lift (core func $i "target") async (callback (func $i "callback"))))+)++(assert_return (invoke "set-backpressure"))+(assert_trap (invoke "target") "cannot make further progress")diff --git a/tests/misc_testsuite/component-model/async/reentrance.wast b/tests/misc_testsuite/component-model/async/reentrance.wastnew file mode 100644index 0000000000..65707f1329--- /dev/null+++ b/tests/misc_testsuite/component-model/async/reentrance.wast@@ -0,0 +1,92 @@+;;! component_model_async = true+;;! reference_types = true++(component+ (core module $shim+ (import "" "task.return" (func $task-return (param i32)))+ (table (export "funcs") 1 1 funcref)+ (func (export "export") (param i32) (result i32)+ (call_indirect (i32.const 0) (local.get 0))+ )+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ )+ (core func $task-return (canon task.return (result u32)))+ (core instance $shim (instantiate $shim+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func $shim-export (param "p1" u32) (result u32)+ (canon lift (core func $shim "export") async (callback (func $shim "callback")))+ )++ (component $inner+ (import "import" (func $import (param "p1" u32) (result u32)))+ (core module $libc (memory (export "memory") 1))+ (core instance $libc (instantiate $libc))+ (core func $import (canon lower (func $import) async (memory $libc "memory")))++ (core module $m+ (import "libc" "memory" (memory 1))+ (import "" "import" (func $import (param i32 i32) (result i32)))+ (import "" "task.return" (func $task-return (param i32)))+ (func (export "export") (param i32) (result i32)+ (i32.store offset=0 (i32.const 1200) (local.get 0))+ (call $import (i32.const 1200) (i32.const 1204))+ drop+ (call $task-return (i32.load offset=0 (i32.const 1204)))+ i32.const 0+ )+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ )+ (core type $task-return-type (func (param i32)))+ (core func $task-return (canon task.return (result u32)))+ (core instance $i (instantiate $m+ (with "" (instance+ (export "task.return" (func $task-return))+ (export "import" (func $import))+ ))+ (with "libc" (instance $libc))+ ))+ (func (export "export") (param "p1" u32) (result u32)+ (canon lift (core func $i "export") async (callback (func $i "callback")))+ )+ )+ (instance $inner (instantiate $inner (with "import" (func $shim-export))))++ (core module $libc (memory (export "memory") 1))+ (core instance $libc (instantiate $libc))+ (core func $inner-export (canon lower (func $inner "export") async (memory $libc "memory")))++ (core module $donut+ (import "" "funcs" (table 1 1 funcref))+ (import "libc" "memory" (memory 1))+ (import "" "import" (func $import (param i32 i32) (result i32)))+ (import "" "task.return" (func $task-return (param i32)))+ (func $host-export (export "export") (param i32) (result i32)+ (i32.store offset=0 (i32.const 1200) (local.get 0))+ (call $import (i32.const 1200) (i32.const 1204))+ drop+ (call $task-return (i32.load offset=0 (i32.const 1204)))+ i32.const 0+ )+ (func $guest-export (export "guest-export") (param i32) (result i32) unreachable)+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ (func $start+ (table.set (i32.const 0) (ref.func $guest-export))+ )+ (start $start)+ )++ (core instance $donut (instantiate $donut+ (with "" (instance+ (export "task.return" (func $task-return))+ (export "import" (func $inner-export))+ (export "funcs" (table $shim "funcs"))+ ))+ (with "libc" (instance $libc))+ ))+ (func (export "export") (param "p1" u32) (result u32)+ (canon lift (core func $donut "export") async (callback (func $donut "callback")))+ )+)++(assert_trap (invoke "export" (u32.const 42)) "cannot enter component instance")diff --git a/tests/misc_testsuite/component-model/async/task-deletion.wast b/tests/misc_testsuite/component-model/async/task-deletion.wastnew file mode 100644index 0000000000..dd8d534665--- /dev/null+++ b/tests/misc_testsuite/component-model/async/task-deletion.wast@@ -0,0 +1,331 @@+;;! component_model_async = true+;;! component_model_threading = true+;;! component_model_async_stackful = true+;;! component_model_more_async_builtins = true+;;! reference_types = true++;; Test task deletion in three situations, for every combination of lift/lower/(guest/host):+;; 1. An explicit thread calls task.return+;; 2. An explicit thread suspends indefinitely+;; 3. An explicit thread yield loops indefinitely+(component+ (component $C+ (core module $Memory (memory (export "mem") 1))+ (core instance $memory (instantiate $Memory))+ ;; Defines the table for the thread start functions+ (core module $libc+ (table (export "__indirect_function_table") 3 funcref))+ (core module $CM+ (import "" "mem" (memory 1))+ (import "" "task.return" (func $task-return (param i32)))+ (import "" "task.cancel" (func $task-cancel))+ (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))+ (import "" "thread.suspend" (func $thread-suspend (result i32)))+ (import "" "thread.suspend-cancellable" (func $thread-suspend-cancellable (result i32)))+ (import "" "thread.yield-to-suspended" (func $thread-yield-to-suspended (param i32) (result i32)))+ (import "" "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable (param i32) (result i32)))+ (import "" "thread.suspend-to" (func $thread-suspend-to (param i32) (result i32)))+ (import "" "thread.suspend-to-cancellable" (func $thread-suspend-to-cancellable (param i32) (result i32)))+ (import "" "thread.yield" (func $thread-yield (result i32)))+ (import "" "thread.yield-cancellable" (func $thread-yield-cancellable (result i32)))+ (import "" "thread.index" (func $thread-index (result i32)))+ (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))+ (import "" "waitable.join" (func $waitable.join (param i32 i32)))+ (import "" "waitable-set.new" (func $waitable-set.new (result i32)))+ (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))+ (import "libc" "__indirect_function_table" (table $indirect-function-table 3 funcref))++ ;; Indices into the function table for the thread start functions+ (global $call-return-ftbl-idx i32 (i32.const 0))+ (global $suspend-ftbl-idx i32 (i32.const 1))+ (global $yield-loop-ftbl-idx i32 (i32.const 2))++ (func $call-return (param i32)+ (call $task-return (local.get 0)))++ (func $suspend (param i32)+ (drop (call $thread-suspend)))++ (func $yield-loop (param i32)+ (loop $top+ (drop (call $thread-yield))+ (br $top)))++ (func (export "explicit-thread-calls-return-stackful")+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $call-return-ftbl-idx) (i32.const 42))))++ (func (export "explicit-thread-calls-return-stackless") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $call-return-ftbl-idx) (i32.const 42)))+ (i32.const 0 (; EXIT ;)))++ (func (export "cb") (param i32 i32 i32) (result i32)+ (unreachable))++ (func (export "explicit-thread-suspends-sync") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))+ (i32.const 42))++ (func (export "explicit-thread-suspends-stackful")+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))+ (call $task-return (i32.const 42)))++ (func (export "explicit-thread-suspends-stackless") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))+ (call $task-return (i32.const 42))+ (i32.const 0))++ (func (export "explicit-thread-yield-loops-sync") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $yield-loop-ftbl-idx) (i32.const 42)))+ (i32.const 42))++ (func (export "explicit-thread-yield-loops-stackful")+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $yield-loop-ftbl-idx) (i32.const 42)))+ (call $task-return (i32.const 42)))++ (func (export "explicit-thread-yield-loops-stackless") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (global.get $suspend-ftbl-idx) (i32.const 42)))+ (call $task-return (i32.const 42))+ (i32.const 0 (; EXIT ;)))++ ;; Initialize the function table that will be used by thread.new-indirect+ (elem (table $indirect-function-table) (i32.const 0 (; call-return-ftbl-idx ;)) func $call-return)+ (elem (table $indirect-function-table) (i32.const 1 (; suspend-ftbl-idx ;)) func $suspend)+ (elem (table $indirect-function-table) (i32.const 2 (; yield-loop-ftbl-idx ;)) func $yield-loop)+ )++ ;; Instantiate the libc module to get the table+ (core instance $libc (instantiate $libc))+ ;; Get access to `thread.new-indirect` that uses the table from libc+ (core type $start-func-ty (func (param i32)))+ (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))++ (core func $task-return (canon task.return (result u32)))+ (core func $task-cancel (canon task.cancel))+ (core func $thread-new-indirect+ (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))+ (core func $thread-yield (canon thread.yield))+ (core func $thread-yield-cancellable (canon thread.yield cancellable))+ (core func $thread-index (canon thread.index))+ (core func $thread-yield-to-suspended (canon thread.yield-to-suspended))+ (core func $thread-yield-to-suspended-cancellable (canon thread.yield-to-suspended cancellable))+ (core func $thread-unsuspend (canon thread.unsuspend))+ (core func $thread-suspend-to (canon thread.suspend-to))+ (core func $thread-suspend-to-cancellable (canon thread.suspend-to cancellable))+ (core func $thread-suspend (canon thread.suspend))+ (core func $thread-suspend-cancellable (canon thread.suspend cancellable))+ (core func $waitable-set.new (canon waitable-set.new))+ (core func $waitable.join (canon waitable.join))+ (core func $waitable-set.wait (canon waitable-set.wait (memory $memory "mem")))++ ;; Instantiate the main module+ (core instance $cm (+ instantiate $CM+ (with "" (instance+ (export "mem" (memory $memory "mem"))+ (export "task.return" (func $task-return))+ (export "task.cancel" (func $task-cancel))+ (export "thread.new-indirect" (func $thread-new-indirect))+ (export "thread.index" (func $thread-index))+ (export "thread.yield-to-suspended" (func $thread-yield-to-suspended))+ (export "thread.yield-to-suspended-cancellable" (func $thread-yield-to-suspended-cancellable))+ (export "thread.yield" (func $thread-yield))+ (export "thread.yield-cancellable" (func $thread-yield-cancellable))+ (export "thread.suspend-to" (func $thread-suspend-to))+ (export "thread.suspend-to-cancellable" (func $thread-suspend-to-cancellable))+ (export "thread.suspend" (func $thread-suspend))+ (export "thread.suspend-cancellable" (func $thread-suspend-cancellable))+ (export "thread.unsuspend" (func $thread-unsuspend))+ (export "waitable.join" (func $waitable.join))+ (export "waitable-set.wait" (func $waitable-set.wait))+ (export "waitable-set.new" (func $waitable-set.new))))+ (with "libc" (instance $libc))))++ (func (export "explicit-thread-calls-return-stackful") async (result u32)+ (canon lift (core func $cm "explicit-thread-calls-return-stackful") async))+ (func (export "explicit-thread-calls-return-stackless") async (result u32)+ (canon lift (core func $cm "explicit-thread-calls-return-stackless") async (callback (func $cm "cb"))))+ (func (export "explicit-thread-suspends-sync") async (result u32)+ (canon lift (core func $cm "explicit-thread-suspends-sync")))+ (func (export "explicit-thread-suspends-stackful") async (result u32)+ (canon lift (core func $cm "explicit-thread-suspends-stackful") async))+ (func (export "explicit-thread-suspends-stackless") async (result u32)+ (canon lift (core func $cm "explicit-thread-suspends-stackless") async (callback (func $cm "cb"))))+ (func (export "explicit-thread-yield-loops-sync") async (result u32)+ (canon lift (core func $cm "explicit-thread-yield-loops-sync")))+ (func (export "explicit-thread-yield-loops-stackful") async (result u32)+ (canon lift (core func $cm "explicit-thread-yield-loops-stackful") async))+ (func (export "explicit-thread-yield-loops-stackless") async (result u32)+ (canon lift (core func $cm "explicit-thread-yield-loops-stackless") async (callback (func $cm "cb"))))+ )++ (component $D+ (import "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful async (result u32)))+ (import "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless async (result u32)))+ (import "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync async (result u32)))+ (import "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful async (result u32)))+ (import "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless async (result u32)))+ (import "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync async (result u32)))+ (import "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful async (result u32)))+ (import "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless async (result u32)))++ (core module $Memory (memory (export "mem") 1))+ (core instance $memory (instantiate $Memory))+ (core module $DM+ (import "" "mem" (memory 1))+ (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32)))+ ;; sync lowered+ (import "" "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful (result i32)))+ (import "" "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless (result i32)))+ (import "" "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync (result i32)))+ (import "" "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful (result i32)))+ (import "" "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless (result i32)))+ (import "" "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync (result i32)))+ (import "" "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful (result i32)))+ (import "" "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless (result i32)))+ ;; async lowered+ (import "" "explicit-thread-calls-return-stackful-async" (func $explicit-thread-calls-return-stackful-async (param i32) (result i32)))+ (import "" "explicit-thread-calls-return-stackless-async" (func $explicit-thread-calls-return-stackless-async (param i32) (result i32)))+ (import "" "explicit-thread-suspends-sync-async" (func $explicit-thread-suspends-sync-async (param i32) (result i32)))+ (import "" "explicit-thread-suspends-stackful-async" (func $explicit-thread-suspends-stackful-async (param i32) (result i32)))+ (import "" "explicit-thread-suspends-stackless-async" (func $explicit-thread-suspends-stackless-async (param i32) (result i32)))+ (import "" "explicit-thread-yield-loops-sync-async" (func $explicit-thread-yield-loops-sync-async (param i32) (result i32)))+ (import "" "explicit-thread-yield-loops-stackful-async" (func $explicit-thread-yield-loops-stackful-async (param i32) (result i32)))+ (import "" "explicit-thread-yield-loops-stackless-async" (func $explicit-thread-yield-loops-stackless-async (param i32) (result i32)))+ (import "" "waitable.join" (func $waitable.join (param i32 i32)))+ (import "" "waitable-set.new" (func $waitable-set.new (result i32)))+ (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))+ (import "" "thread.yield" (func $thread-yield (result i32)))++ (func $check (param i32)+ (if (i32.ne (local.get 0) (i32.const 42))+ (then unreachable))+ )++ (func $check-async (param i32)+ (local $retp i32) (local $ws i32) (local $ws-retp i32)+ (local.set $retp (i32.const 8))+ (local.set $ws-retp (i32.const 16))+ (local.set $ws (call $waitable-set.new))++ (if (i32.eq (i32.and (local.get 0) (i32.const 0xF)) (i32.const 2 (; RETURNED ;)))+ (then (call $check (i32.load (local.get $retp))))+ (else+ (call $waitable.join (i32.shr_u (local.get 0) (i32.const 4)) (local.get $ws))+ (drop (call $waitable-set.wait (local.get $ws) (local.get $ws-retp)))+ (call $check (i32.load (local.get $retp)))))+ )++ (func $run (export "run") (result i32)+ (local $retp i32)+ (local.set $retp (i32.const 8))+ (call $check (call $explicit-thread-calls-return-stackless))+ (call $check (call $explicit-thread-calls-return-stackful))+ (call $check (call $explicit-thread-suspends-sync))+ (call $check (call $explicit-thread-suspends-stackful))+ (call $check (call $explicit-thread-suspends-stackless))+ (call $check (call $explicit-thread-yield-loops-sync))+ (call $check (call $explicit-thread-yield-loops-stackful))+ (call $check (call $explicit-thread-yield-loops-stackless))++ (call $check-async (call $explicit-thread-calls-return-stackless-async (local.get $retp)))+ (call $check-async (call $explicit-thread-calls-return-stackful-async (local.get $retp)))+ (call $check-async (call $explicit-thread-suspends-sync-async (local.get $retp)))+ (call $check-async (call $explicit-thread-suspends-stackful-async (local.get $retp)))+ (call $check-async (call $explicit-thread-suspends-stackless-async (local.get $retp)))+ (call $check-async (call $explicit-thread-yield-loops-sync-async (local.get $retp)))+ (call $check-async (call $explicit-thread-yield-loops-stackful-async (local.get $retp)))+ (call $check-async (call $explicit-thread-yield-loops-stackless-async (local.get $retp)))++ (i32.const 42)+ )+ )++ (core func $waitable-set.new (canon waitable-set.new))+ (core func $waitable-set.wait (canon waitable-set.wait (memory $memory "mem")))+ (core func $waitable.join (canon waitable.join))+ (core func $subtask.cancel (canon subtask.cancel async))+ (core func $thread.yield (canon thread.yield))+ ;; sync lowered+ (canon lower (func $explicit-thread-calls-return-stackful) (memory $memory "mem") (core func $explicit-thread-calls-return-stackful'))+ (canon lower (func $explicit-thread-calls-return-stackless) (memory $memory "mem") (core func $explicit-thread-calls-return-stackless'))+ (canon lower (func $explicit-thread-suspends-sync) (memory $memory "mem") (core func $explicit-thread-suspends-sync'))+ (canon lower (func $explicit-thread-suspends-stackful) (memory $memory "mem") (core func $explicit-thread-suspends-stackful'))+ (canon lower (func $explicit-thread-suspends-stackless) (memory $memory "mem") (core func $explicit-thread-suspends-stackless'))+ (canon lower (func $explicit-thread-yield-loops-sync) (memory $memory "mem") (core func $explicit-thread-yield-loops-sync'))+ (canon lower (func $explicit-thread-yield-loops-stackful) (memory $memory "mem") (core func $explicit-thread-yield-loops-stackful'))+ (canon lower (func $explicit-thread-yield-loops-stackless) (memory $memory "mem") (core func $explicit-thread-yield-loops-stackless'))+ ;; async lowered+ (canon lower (func $explicit-thread-calls-return-stackful) async (memory $memory "mem") (core func $explicit-thread-calls-return-stackful-async'))+ (canon lower (func $explicit-thread-calls-return-stackless) async (memory $memory "mem") (core func $explicit-thread-calls-return-stackless-async'))+ (canon lower (func $explicit-thread-suspends-sync) async (memory $memory "mem") (core func $explicit-thread-suspends-sync-async'))+ (canon lower (func $explicit-thread-suspends-stackful) async (memory $memory "mem") (core func $explicit-thread-suspends-stackful-async'))+ (canon lower (func $explicit-thread-suspends-stackless) async (memory $memory "mem") (core func $explicit-thread-suspends-stackless-async'))+ (canon lower (func $explicit-thread-yield-loops-sync) async (memory $memory "mem") (core func $explicit-thread-yield-loops-sync-async'))+ (canon lower (func $explicit-thread-yield-loops-stackful) async (memory $memory "mem") (core func $explicit-thread-yield-loops-stackful-async'))+ (canon lower (func $explicit-thread-yield-loops-stackless) async (memory $memory "mem") (core func $explicit-thread-yield-loops-stackless-async'))+ (core instance $dm (instantiate $DM (with "" (instance+ (export "mem" (memory $memory "mem"))+ (export "explicit-thread-calls-return-stackful" (func $explicit-thread-calls-return-stackful'))+ (export "explicit-thread-calls-return-stackless" (func $explicit-thread-calls-return-stackless'))+ (export "explicit-thread-suspends-sync" (func $explicit-thread-suspends-sync'))+ (export "explicit-thread-suspends-stackful" (func $explicit-thread-suspends-stackful'))+ (export "explicit-thread-suspends-stackless" (func $explicit-thread-suspends-stackless'))+ (export "explicit-thread-yield-loops-sync" (func $explicit-thread-yield-loops-sync'))+ (export "explicit-thread-yield-loops-stackful" (func $explicit-thread-yield-loops-stackful'))+ (export "explicit-thread-yield-loops-stackless" (func $explicit-thread-yield-loops-stackless'))+ (export "explicit-thread-calls-return-stackful-async" (func $explicit-thread-calls-return-stackful-async'))+ (export "explicit-thread-calls-return-stackless-async" (func $explicit-thread-calls-return-stackless-async'))+ (export "explicit-thread-suspends-sync-async" (func $explicit-thread-suspends-sync-async'))+ (export "explicit-thread-suspends-stackful-async" (func $explicit-thread-suspends-stackful-async'))+ (export "explicit-thread-suspends-stackless-async" (func $explicit-thread-suspends-stackless-async'))+ (export "explicit-thread-yield-loops-sync-async" (func $explicit-thread-yield-loops-sync-async'))+ (export "explicit-thread-yield-loops-stackful-async" (func $explicit-thread-yield-loops-stackful-async'))+ (export "explicit-thread-yield-loops-stackless-async" (func $explicit-thread-yield-loops-stackless-async'))+ (export "waitable.join" (func $waitable.join))+ (export "waitable-set.new" (func $waitable-set.new))+ (export "waitable-set.wait" (func $waitable-set.wait))+ (export "subtask.cancel" (func $subtask.cancel))+ (export "thread.yield" (func $thread.yield))+ ))))+ (func (export "run") async (result u32) (canon lift (core func $dm "run")))+ )++ (instance $c (instantiate $C))+ (instance $d (instantiate $D+ (with "explicit-thread-calls-return-stackful" (func $c "explicit-thread-calls-return-stackful"))+ (with "explicit-thread-calls-return-stackless" (func $c "explicit-thread-calls-return-stackless"))+ (with "explicit-thread-suspends-sync" (func $c "explicit-thread-suspends-sync"))+ (with "explicit-thread-suspends-stackful" (func $c "explicit-thread-suspends-stackful"))+ (with "explicit-thread-suspends-stackless" (func $c "explicit-thread-suspends-stackless"))+ (with "explicit-thread-yield-loops-sync" (func $c "explicit-thread-yield-loops-sync"))+ (with "explicit-thread-yield-loops-stackful" (func $c "explicit-thread-yield-loops-stackful"))+ (with "explicit-thread-yield-loops-stackless" (func $c "explicit-thread-yield-loops-stackless"))+ ))+ (func (export "run") (alias export $d "run"))+ (func (export "explicit-thread-calls-return-stackful") (alias export $c "explicit-thread-calls-return-stackful"))+ (func (export "explicit-thread-calls-return-stackless") (alias export $c "explicit-thread-calls-return-stackless"))+ (func (export "explicit-thread-suspends-sync") (alias export $c "explicit-thread-suspends-sync"))+ (func (export "explicit-thread-suspends-stackful") (alias export $c "explicit-thread-suspends-stackful"))+ (func (export "explicit-thread-suspends-stackless") (alias export $c "explicit-thread-suspends-stackless"))+ (func (export "explicit-thread-yield-loops-sync") (alias export $c "explicit-thread-yield-loops-sync"))+ (func (export "explicit-thread-yield-loops-stackful") (alias export $c "explicit-thread-yield-loops-stackful"))+ (func (export "explicit-thread-yield-loops-stackless") (alias export $c "explicit-thread-yield-loops-stackless"))+)++(assert_return (invoke "run") (u32.const 42))+(assert_return (invoke "explicit-thread-calls-return-stackful") (u32.const 42))+(assert_return (invoke "explicit-thread-calls-return-stackless") (u32.const 42))+(assert_return (invoke "explicit-thread-suspends-sync") (u32.const 42))+(assert_return (invoke "explicit-thread-suspends-stackful") (u32.const 42))+(assert_return (invoke "explicit-thread-suspends-stackless") (u32.const 42))+(assert_return (invoke "explicit-thread-yield-loops-sync") (u32.const 42))+(assert_return (invoke "explicit-thread-yield-loops-stackful") (u32.const 42))+(assert_return (invoke "explicit-thread-yield-loops-stackless") (u32.const 42))diff --git a/tests/misc_testsuite/component-model/async/task-return-traps.wast b/tests/misc_testsuite/component-model/async/task-return-traps.wastnew file mode 100644index 0000000000..9d483b0558--- /dev/null+++ b/tests/misc_testsuite/component-model/async/task-return-traps.wast@@ -0,0 +1,151 @@+;;! component_model_async = true+;;! component_model_async_stackful = true+;;! component_model_threading = true++(component+ (core module $m+ (import "" "task.return" (func $task-return))+ (func (export "foo") (result i32)+ i32.const 0+ )+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ )+ (core func $task-return (canon task.return))+ (core instance $i (instantiate $m+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async (callback (func $i "callback"))))+)+(assert_trap (invoke "foo") "async-lifted export failed to produce a result")++(component+ (core module $libc+ (table (export "__indirect_function_table") 1 funcref))+ (core module $m+ (import "" "task.return" (func $task-return))+ (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))+ (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))+ (import "libc" "__indirect_function_table" (table $indirect-function-table 1 funcref))+ (func $thread-start (param i32) (; empty ;))+ (elem (table $indirect-function-table) (i32.const 0) func $thread-start)+ (func (export "foo") (result i32)+ (call $thread-unsuspend+ (call $thread-new-indirect (i32.const 0) (i32.const 0)))+ i32.const 0+ )+ (func (export "callback") (param i32 i32 i32) (result i32) unreachable)+ )+ (core instance $libc (instantiate $libc))+ (core type $start-func-ty (func (param i32)))+ (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))+ (core func $thread-new-indirect+ (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))+ (core func $thread-unsuspend (canon thread.unsuspend))+ (core func $task-return (canon task.return))+ (core instance $i (instantiate $m+ (with "" (instance+ (export "thread.new-indirect" (func $thread-new-indirect))+ (export "thread.unsuspend" (func $thread-unsuspend))+ (export "task.return" (func $task-return))+ ))+ (with "libc" (instance $libc))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async (callback (func $i "callback"))))+)++(assert_trap (invoke "foo") "async-lifted export failed to produce a result")++(component+ (core module $libc+ (table (export "__indirect_function_table") 1 funcref))+ (core module $m+ (import "" "task.return" (func $task-return))+ (import "" "thread.new-indirect" (func $thread-new-indirect (param i32 i32) (result i32)))+ (import "" "thread.unsuspend" (func $thread-unsuspend (param i32)))+ (import "libc" "__indirect_function_table" (table $indirect-function-table 1 funcref))+ (func $thread-start (param i32) (; empty ;))+ (elem (table $indirect-function-table) (i32.const 0) func $thread-start)+ (func (export "foo")+ (call $thread-unsuspend+ (call $thread-new-indirect (i32.const 0) (i32.const 0)))+ )+ )+ (core instance $libc (instantiate $libc))+ (core type $start-func-ty (func (param i32)))+ (alias core export $libc "__indirect_function_table" (core table $indirect-function-table))+ (core func $thread-new-indirect+ (canon thread.new-indirect $start-func-ty (table $indirect-function-table)))+ (core func $thread-unsuspend (canon thread.unsuspend))+ (core func $task-return (canon task.return))+ (core instance $i (instantiate $m+ (with "" (instance+ (export "thread.new-indirect" (func $thread-new-indirect))+ (export "thread.unsuspend" (func $thread-unsuspend))+ (export "task.return" (func $task-return))+ ))+ (with "libc" (instance $libc))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async))+)++(assert_trap (invoke "foo") "async-lifted export failed to produce a result")++(component+ (core module $m+ (import "" "task.return" (func $task-return))+ (func (export "foo"))+ )+ (core func $task-return (canon task.return))+ (core instance $i (instantiate $m+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async))+)+(assert_trap (invoke "foo") "async-lifted export failed to produce a result")++(component+ (core module $m+ (import "" "task.return" (func $task-return (param i32)))+ (func (export "foo") (call $task-return (i32.const 42)))+ )+ (core func $task-return (canon task.return (result u32)))+ (core instance $i (instantiate $m+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async))+)++(assert_trap (invoke "foo")+ "invalid `task.return` signature and/or options for current task")++(component+ (core module $libc (memory (export "memory") 1))+ (core instance $libc (instantiate $libc))+ (core module $m+ (import "" "task.return" (func $task-return))+ (func (export "foo") (call $task-return))+ )+ (core func $task-return (canon task.return (memory $libc "memory")))+ (core instance $i (instantiate $m+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async))+)++(assert_trap (invoke "foo")+ "invalid `task.return` signature and/or options for current task")++(component+ (core module $m+ (import "" "task.return" (func $task-return))+ (func (export "foo") (call $task-return))+ )+ (core func $task-return (canon task.return string-encoding=utf16))+ (core instance $i (instantiate $m+ (with "" (instance (export "task.return" (func $task-return))))+ ))+ (func (export "foo") (canon lift (core func $i "foo") async))+)++(assert_trap (invoke "foo")+ "invalid `task.return` signature and/or options for current task")diff --git a/tests/misc_testsuite/component-model/nested-many-instantiations.wast b/tests/misc_testsuite/component-model/nested-many-instantiations.wastnew file mode 100644index 0000000000..0cd7dbefbb--- /dev/null+++ b/tests/misc_testsuite/component-model/nested-many-instantiations.wast@@ -0,0 +1,55 @@+(component+ (component $A+ (core module $m+ (global $cnt (mut i32) (i32.const 0))+ (func (export "inc")+ global.get $cnt+ i32.const 1+ i32.add+ global.set $cnt+ )++ (func (export "get") (result i32) global.get $cnt)+ )+ (core instance $i (instantiate $m))+ (func (export "inc") (canon lift (core func $i "inc")))+ (func (export "get") (result u32) (canon lift (core func $i "get")))+ )+ (component $B+ (import "inc" (func $inc))+ (component $c1+ (import "inc" (func $inc))+ (core func $inc_lower (canon lower (func $inc)))+ (core module $m+ (import "" "" (func $inc))+ (start $inc)+ )+ (core instance (instantiate $m (with "" (instance (export "" (func $inc_lower))))))+ (core instance (instantiate $m (with "" (instance (export "" (func $inc_lower))))))+ )+ (component $c2+ (import "inc" (func $inc))+ (instance (instantiate $c1 (with "inc" (func $inc))))+ (instance (instantiate $c1 (with "inc" (func $inc))))+ )+ (component $c3+ (import "inc" (func $inc))+ (instance (instantiate $c2 (with "inc" (func $inc))))+ (instance (instantiate $c2 (with "inc" (func $inc))))+ )+ (component $c4+ (import "inc" (func $inc))+ (instance (instantiate $c3 (with "inc" (func $inc))))+ (instance (instantiate $c3 (with "inc" (func $inc))))+ )++ (instance (instantiate $c4 (with "inc" (func $inc))))+ )++ (instance $a (instantiate $A))+ (instance $b (instantiate $B (with "inc" (func $a "inc"))))+ (export "get" (func $a "get"))++)++(assert_return (invoke "get") (u32.const 16))