@@ -82,6 +82,11 @@ fn provenance_test_config() -> Config {
8282 config. memory_reservation ( 1 << 20 ) ;
8383 config. memory_guard_size ( 0 ) ;
8484 config. signals_based_traps ( false ) ;
85+ config. async_support ( true ) ;
86+ config. wasm_component_model_async ( true ) ;
87+ config. wasm_component_model_async_stackful ( true ) ;
88+ config. wasm_component_model_async_builtins ( true ) ;
89+ config. wasm_component_model_error_context ( true ) ;
8590 config
8691}
8792
@@ -109,9 +114,9 @@ fn provenance_test_config() -> Config {
109114/// and instructions. The goal is to kind of do a dry run of interesting
110115/// shapes/sizes of what you can do with core wasm and ensure MIRI gives us a
111116/// clean bill of health.
112- #[ test]
117+ #[ tokio :: test]
113118#[ cfg_attr( miri, ignore) ]
114- fn pulley_provenance_test ( ) -> Result < ( ) > {
119+ async fn pulley_provenance_test ( ) -> Result < ( ) > {
115120 let config = provenance_test_config ( ) ;
116121 let engine = Engine :: new ( & config) ?;
117122 let module = if cfg ! ( miri) {
@@ -132,7 +137,8 @@ fn pulley_provenance_test() -> Result<()> {
132137 results[ 2 ] = Val :: I32 ( 3 ) ;
133138 Ok ( ( ) )
134139 } ) ;
135- let instance = Instance :: new ( & mut store, & module, & [ host_wrap. into ( ) , host_new. into ( ) ] ) ?;
140+ let instance =
141+ Instance :: new_async ( & mut store, & module, & [ host_wrap. into ( ) , host_new. into ( ) ] ) . await ?;
136142
137143 for func in [
138144 "call-wasm" ,
@@ -145,53 +151,59 @@ fn pulley_provenance_test() -> Result<()> {
145151 let func = instance
146152 . get_typed_func :: < ( ) , ( i32 , i32 , i32 ) > ( & mut store, func)
147153 . unwrap ( ) ;
148- let results = func. call ( & mut store, ( ) ) ?;
154+ let results = func. call_async ( & mut store, ( ) ) . await ?;
149155 assert_eq ! ( results, ( 1 , 2 , 3 ) ) ;
150156 }
151157
152158 let funcref = instance. get_func ( & mut store, "call-wasm" ) . unwrap ( ) ;
153159 for func in [ "call_ref-wasm" , "return_call_ref-wasm" ] {
154160 println ! ( "testing func {func:?}" ) ;
155161 let func = instance. get_typed_func :: < Func , ( i32 , i32 , i32 ) > ( & mut store, func) ?;
156- let results = func. call ( & mut store, funcref) ?;
162+ let results = func. call_async ( & mut store, funcref) . await ?;
157163 assert_eq ! ( results, ( 1 , 2 , 3 ) ) ;
158164 }
159165
160166 let trap = instance
161167 . get_typed_func :: < ( ) , ( ) > ( & mut store, "unreachable" ) ?
162- . call ( & mut store, ( ) )
168+ . call_async ( & mut store, ( ) )
169+ . await
163170 . unwrap_err ( )
164171 . downcast :: < Trap > ( ) ?;
165172 assert_eq ! ( trap, Trap :: UnreachableCodeReached ) ;
166173
167174 let trap = instance
168175 . get_typed_func :: < ( ) , i32 > ( & mut store, "divide-by-zero" ) ?
169- . call ( & mut store, ( ) )
176+ . call_async ( & mut store, ( ) )
177+ . await
170178 . unwrap_err ( )
171179 . downcast :: < Trap > ( ) ?;
172180 assert_eq ! ( trap, Trap :: IntegerDivisionByZero ) ;
173181
174182 instance
175183 . get_typed_func :: < ( ) , ( ) > ( & mut store, "memory-intrinsics" ) ?
176- . call ( & mut store, ( ) ) ?;
184+ . call_async ( & mut store, ( ) )
185+ . await ?;
177186 instance
178187 . get_typed_func :: < ( ) , ( ) > ( & mut store, "table-intrinsics" ) ?
179- . call ( & mut store, ( ) ) ?;
180-
181- let funcref = Func :: wrap ( & mut store, move |mut caller : Caller < ' _ , ( ) > | {
182- let func = instance. get_typed_func :: < ( ) , ( i32 , i32 , i32 ) > ( & mut caller, "call-wasm" ) ?;
183- func. call ( & mut caller, ( ) )
188+ . call_async ( & mut store, ( ) )
189+ . await ?;
190+
191+ let funcref = Func :: wrap_async ( & mut store, move |mut caller : Caller < ' _ , ( ) > , ( ) | {
192+ Box :: new ( async move {
193+ let func = instance. get_typed_func :: < ( ) , ( i32 , i32 , i32 ) > ( & mut caller, "call-wasm" ) ?;
194+ func. call_async ( & mut caller, ( ) ) . await
195+ } )
184196 } ) ;
185197 let func = instance. get_typed_func :: < Func , ( i32 , i32 , i32 ) > ( & mut store, "call_ref-wasm" ) ?;
186- let results = func. call ( & mut store, funcref) ?;
198+ let results = func. call_async ( & mut store, funcref) . await ?;
187199 assert_eq ! ( results, ( 1 , 2 , 3 ) ) ;
188200
189201 Ok ( ( ) )
190202}
191203
192- #[ test]
204+ #[ tokio :: test]
193205#[ cfg_attr( miri, ignore) ]
194- fn pulley_provenance_test_components ( ) -> Result < ( ) > {
206+ async fn pulley_provenance_test_components ( ) -> Result < ( ) > {
195207 let config = provenance_test_config ( ) ;
196208 let engine = Engine :: new ( & config) ?;
197209 let component = if cfg ! ( miri) {
@@ -240,7 +252,7 @@ fn pulley_provenance_test_components() -> Result<()> {
240252 linker
241253 . root ( )
242254 . func_wrap ( "host-list" , |_, ( value, ) : ( Vec < String > , ) | Ok ( ( value, ) ) ) ?;
243- let instance = linker. instantiate ( & mut store, & component) ?;
255+ let instance = linker. instantiate_async ( & mut store, & component) . await ?;
244256
245257 let guest_u32 = instance. get_typed_func :: < ( u32 , ) , ( u32 , ) > ( & mut store, "guest-u32" ) ?;
246258 let guest_enum = instance. get_typed_func :: < ( E , ) , ( E , ) > ( & mut store, "guest-enum" ) ?;
@@ -255,45 +267,50 @@ fn pulley_provenance_test_components() -> Result<()> {
255267 let guest_list =
256268 instance. get_typed_func :: < ( & [ & str ] , ) , ( Vec < String > , ) > ( & mut store, "guest-list" ) ?;
257269
258- let ( result, ) = guest_u32. call ( & mut store, ( 42 , ) ) ?;
270+ let ( result, ) = guest_u32. call_async ( & mut store, ( 42 , ) ) . await ?;
259271 assert_eq ! ( result, 42 ) ;
260- guest_u32. post_return ( & mut store) ?;
272+ guest_u32. post_return_async ( & mut store) . await ?;
261273
262- let ( result, ) = guest_enum. call ( & mut store, ( E :: B , ) ) ?;
274+ let ( result, ) = guest_enum. call_async ( & mut store, ( E :: B , ) ) . await ?;
263275 assert_eq ! ( result, E :: B ) ;
264- guest_enum. post_return ( & mut store) ?;
276+ guest_enum. post_return_async ( & mut store) . await ?;
265277
266- let ( result, ) = guest_option. call ( & mut store, ( None , ) ) ?;
278+ let ( result, ) = guest_option. call_async ( & mut store, ( None , ) ) . await ?;
267279 assert_eq ! ( result, None ) ;
268- guest_option. post_return ( & mut store) ?;
269- let ( result, ) = guest_option. call ( & mut store, ( Some ( 200 ) , ) ) ?;
280+ guest_option. post_return_async ( & mut store) . await ?;
281+ let ( result, ) = guest_option. call_async ( & mut store, ( Some ( 200 ) , ) ) . await ?;
270282 assert_eq ! ( result, Some ( 200 ) ) ;
271- guest_option. post_return ( & mut store) ?;
283+ guest_option. post_return_async ( & mut store) . await ?;
272284
273- let ( result, ) = guest_result. call ( & mut store, ( Ok ( 10 ) , ) ) ?;
285+ let ( result, ) = guest_result. call_async ( & mut store, ( Ok ( 10 ) , ) ) . await ?;
274286 assert_eq ! ( result, Ok ( 10 ) ) ;
275- guest_result. post_return ( & mut store) ?;
276- let ( result, ) = guest_result. call ( & mut store, ( Err ( i64:: MIN ) , ) ) ?;
287+ guest_result. post_return_async ( & mut store) . await ?;
288+ let ( result, ) = guest_result
289+ . call_async ( & mut store, ( Err ( i64:: MIN ) , ) )
290+ . await ?;
277291 assert_eq ! ( result, Err ( i64 :: MIN ) ) ;
278- guest_result. post_return ( & mut store) ?;
292+ guest_result. post_return_async ( & mut store) . await ?;
279293
280- let ( result, ) = guest_string. call ( & mut store, ( "" , ) ) ?;
294+ let ( result, ) = guest_string. call_async ( & mut store, ( "" , ) ) . await ?;
281295 assert_eq ! ( result, "" ) ;
282- guest_string. post_return ( & mut store) ?;
283- let ( result, ) = guest_string. call ( & mut store, ( "hello" , ) ) ?;
296+ guest_string. post_return_async ( & mut store) . await ?;
297+ let ( result, ) = guest_string. call_async ( & mut store, ( "hello" , ) ) . await ?;
284298 assert_eq ! ( result, "hello" ) ;
285- guest_string. post_return ( & mut store) ?;
299+ guest_string. post_return_async ( & mut store) . await ?;
286300
287- let ( result, ) = guest_list. call ( & mut store, ( & [ ] , ) ) ?;
301+ let ( result, ) = guest_list. call_async ( & mut store, ( & [ ] , ) ) . await ?;
288302 assert ! ( result. is_empty( ) ) ;
289- guest_list. post_return ( & mut store) ?;
290- let ( result, ) = guest_list. call ( & mut store, ( & [ "a" , "" , "b" , "c" ] , ) ) ?;
303+ guest_list. post_return_async ( & mut store) . await ?;
304+ let ( result, ) = guest_list
305+ . call_async ( & mut store, ( & [ "a" , "" , "b" , "c" ] , ) )
306+ . await ?;
291307 assert_eq ! ( result, [ "a" , "" , "b" , "c" ] ) ;
292- guest_list. post_return ( & mut store) ?;
308+ guest_list. post_return_async ( & mut store) . await ?;
293309
294310 instance
295311 . get_typed_func :: < ( ) , ( ) > ( & mut store, "resource-intrinsics" ) ?
296- . call ( & mut store, ( ) ) ?;
312+ . call_async ( & mut store, ( ) )
313+ . await ?;
297314 }
298315 {
299316 use wasmtime:: component:: Val ;
@@ -323,7 +340,7 @@ fn pulley_provenance_test_components() -> Result<()> {
323340 results[ 0 ] = args[ 0 ] . clone ( ) ;
324341 Ok ( ( ) )
325342 } ) ?;
326- let instance = linker. instantiate ( & mut store, & component) ?;
343+ let instance = linker. instantiate_async ( & mut store, & component) . await ?;
327344
328345 let guest_u32 = instance. get_func ( & mut store, "guest-u32" ) . unwrap ( ) ;
329346 let guest_enum = instance. get_func ( & mut store, "guest-enum" ) . unwrap ( ) ;
@@ -333,53 +350,71 @@ fn pulley_provenance_test_components() -> Result<()> {
333350 let guest_list = instance. get_func ( & mut store, "guest-list" ) . unwrap ( ) ;
334351
335352 let mut results = [ Val :: U32 ( 0 ) ] ;
336- guest_u32. call ( & mut store, & [ Val :: U32 ( 42 ) ] , & mut results) ?;
353+ guest_u32
354+ . call_async ( & mut store, & [ Val :: U32 ( 42 ) ] , & mut results)
355+ . await ?;
337356 assert_eq ! ( results[ 0 ] , Val :: U32 ( 42 ) ) ;
338- guest_u32. post_return ( & mut store) ?;
357+ guest_u32. post_return_async ( & mut store) . await ?;
339358
340- guest_enum. call ( & mut store, & [ Val :: Enum ( "B" . into ( ) ) ] , & mut results) ?;
359+ guest_enum
360+ . call_async ( & mut store, & [ Val :: Enum ( "B" . into ( ) ) ] , & mut results)
361+ . await ?;
341362 assert_eq ! ( results[ 0 ] , Val :: Enum ( "B" . into( ) ) ) ;
342- guest_enum. post_return ( & mut store) ?;
363+ guest_enum. post_return_async ( & mut store) . await ?;
343364
344- guest_option. call ( & mut store, & [ Val :: Option ( None ) ] , & mut results) ?;
365+ guest_option
366+ . call_async ( & mut store, & [ Val :: Option ( None ) ] , & mut results)
367+ . await ?;
345368 assert_eq ! ( results[ 0 ] , Val :: Option ( None ) ) ;
346- guest_option. post_return ( & mut store) ?;
347- guest_option. call (
348- & mut store,
349- & [ Val :: Option ( Some ( Box :: new ( Val :: U8 ( 201 ) ) ) ) ] ,
350- & mut results,
351- ) ?;
369+ guest_option. post_return_async ( & mut store) . await ?;
370+ guest_option
371+ . call_async (
372+ & mut store,
373+ & [ Val :: Option ( Some ( Box :: new ( Val :: U8 ( 201 ) ) ) ) ] ,
374+ & mut results,
375+ )
376+ . await ?;
352377 assert_eq ! ( results[ 0 ] , Val :: Option ( Some ( Box :: new( Val :: U8 ( 201 ) ) ) ) ) ;
353- guest_option. post_return ( & mut store) ?;
354-
355- guest_result. call (
356- & mut store,
357- & [ Val :: Result ( Ok ( Some ( Box :: new ( Val :: U16 ( 20 ) ) ) ) ) ] ,
358- & mut results,
359- ) ?;
378+ guest_option. post_return_async ( & mut store) . await ?;
379+
380+ guest_result
381+ . call_async (
382+ & mut store,
383+ & [ Val :: Result ( Ok ( Some ( Box :: new ( Val :: U16 ( 20 ) ) ) ) ) ] ,
384+ & mut results,
385+ )
386+ . await ?;
360387 assert_eq ! ( results[ 0 ] , Val :: Result ( Ok ( Some ( Box :: new( Val :: U16 ( 20 ) ) ) ) ) ) ;
361- guest_result. post_return ( & mut store) ?;
362- guest_result. call (
363- & mut store,
364- & [ Val :: Result ( Err ( Some ( Box :: new ( Val :: S64 ( i64:: MAX ) ) ) ) ) ] ,
365- & mut results,
366- ) ?;
388+ guest_result. post_return_async ( & mut store) . await ?;
389+ guest_result
390+ . call_async (
391+ & mut store,
392+ & [ Val :: Result ( Err ( Some ( Box :: new ( Val :: S64 ( i64:: MAX ) ) ) ) ) ] ,
393+ & mut results,
394+ )
395+ . await ?;
367396 assert_eq ! (
368397 results[ 0 ] ,
369398 Val :: Result ( Err ( Some ( Box :: new( Val :: S64 ( i64 :: MAX ) ) ) ) )
370399 ) ;
371- guest_result. post_return ( & mut store) ?;
400+ guest_result. post_return_async ( & mut store) . await ?;
372401
373- guest_string. call ( & mut store, & [ Val :: String ( "B" . into ( ) ) ] , & mut results) ?;
402+ guest_string
403+ . call_async ( & mut store, & [ Val :: String ( "B" . into ( ) ) ] , & mut results)
404+ . await ?;
374405 assert_eq ! ( results[ 0 ] , Val :: String ( "B" . into( ) ) ) ;
375- guest_string. post_return ( & mut store) ?;
376- guest_string. call ( & mut store, & [ Val :: String ( "" . into ( ) ) ] , & mut results) ?;
406+ guest_string. post_return_async ( & mut store) . await ?;
407+ guest_string
408+ . call_async ( & mut store, & [ Val :: String ( "" . into ( ) ) ] , & mut results)
409+ . await ?;
377410 assert_eq ! ( results[ 0 ] , Val :: String ( "" . into( ) ) ) ;
378- guest_string. post_return ( & mut store) ?;
411+ guest_string. post_return_async ( & mut store) . await ?;
379412
380- guest_list. call ( & mut store, & [ Val :: List ( Vec :: new ( ) ) ] , & mut results) ?;
413+ guest_list
414+ . call_async ( & mut store, & [ Val :: List ( Vec :: new ( ) ) ] , & mut results)
415+ . await ?;
381416 assert_eq ! ( results[ 0 ] , Val :: List ( Vec :: new( ) ) ) ;
382- guest_list. post_return ( & mut store) ?;
417+ guest_list. post_return_async ( & mut store) . await ?;
383418 }
384419
385420 Ok ( ( ) )
@@ -432,12 +467,7 @@ async fn sleep(duration: std::time::Duration) {
432467#[ tokio:: test]
433468#[ cfg_attr( miri, ignore) ]
434469async fn pulley_provenance_test_async_components ( ) -> Result < ( ) > {
435- let mut config = provenance_test_config ( ) ;
436- config. async_support ( true ) ;
437- config. wasm_component_model_async ( true ) ;
438- config. wasm_component_model_async_stackful ( true ) ;
439- config. wasm_component_model_async_builtins ( true ) ;
440- config. wasm_component_model_error_context ( true ) ;
470+ let config = provenance_test_config ( ) ;
441471 let engine = Engine :: new ( & config) ?;
442472 let component = if cfg ! ( miri) {
443473 unsafe {
0 commit comments