@@ -18,8 +18,6 @@ use wasmtime_environ::component::{
1818#[ cfg( feature = "component-model-async" ) ]
1919use crate :: component:: concurrent:: { self , PreparedCall } ;
2020#[ cfg( feature = "component-model-async" ) ]
21- use crate :: runtime:: vm:: component:: ComponentInstance ;
22- #[ cfg( feature = "component-model-async" ) ]
2321use core:: any:: Any ;
2422#[ cfg( feature = "component-model-async" ) ]
2523use core:: future:: { self , Future } ;
@@ -786,7 +784,7 @@ impl Func {
786784 unsafe fn lower_args_fn < T > (
787785 func : Func ,
788786 store : StoreContextMut < T > ,
789- instance : & mut ComponentInstance ,
787+ instance : Instance ,
790788 params_in : * mut u8 ,
791789 params_out : & mut [ MaybeUninit < ValRaw > ] ,
792790 ) -> Result < ( ) > {
@@ -835,7 +833,7 @@ impl Func {
835833 fn lift_results_sync_fn < T > (
836834 func : Func ,
837835 store : StoreContextMut < T > ,
838- instance : & mut ComponentInstance ,
836+ instance : Instance ,
839837 results : & [ ValRaw ] ,
840838 ) -> Result < Box < dyn Any + Send + Sync > > {
841839 lift_results ( store, instance, results, func, Self :: lift_results_sync)
@@ -856,7 +854,7 @@ impl Func {
856854 fn lift_results_async_fn < T > (
857855 func : Func ,
858856 store : StoreContextMut < T > ,
859- instance : & mut ComponentInstance ,
857+ instance : Instance ,
860858 results : & [ ValRaw ] ,
861859 ) -> Result < Box < dyn Any + Send + Sync > > {
862860 lift_results ( store, instance, results, func, Self :: lift_results_async)
@@ -935,7 +933,7 @@ fn lower_params<
935933 + Sync ,
936934> (
937935 mut store : StoreContextMut < T > ,
938- instance : & mut ComponentInstance ,
936+ instance : Instance ,
939937 lowered : & mut [ MaybeUninit < ValRaw > ] ,
940938 me : Func ,
941939 params : & Params ,
@@ -950,34 +948,33 @@ fn lower_params<
950948 ..
951949 } = store. 0 [ me. 0 ] ;
952950
953- let types = instance. component_types ( ) . clone ( ) ;
954- let mut flags = instance. instance_flags ( component_instance) ;
955-
956- store. with_attached_instance ( instance, |mut store, instance| {
957- if unsafe { !flags. may_enter ( ) } {
958- bail ! ( crate :: Trap :: CannotEnterComponent ) ;
959- }
951+ let reference = instance. instance ( store. 0 ) ;
952+ let types = reference. component_types ( ) . clone ( ) ;
953+ let mut flags = reference. instance_flags ( component_instance) ;
960954
961- unsafe { flags. set_may_leave ( false ) } ;
962- let mut cx = LowerContext :: new ( store. as_context_mut ( ) , & options, & types, instance) ;
963- let result = lower (
964- & mut cx,
965- params,
966- InterfaceType :: Tuple ( types[ ty] . params ) ,
967- unsafe { slice_to_storage_mut ( lowered) } ,
968- ) ;
969- unsafe { flags. set_may_leave ( true ) } ;
970- result?;
955+ if unsafe { !flags. may_enter ( ) } {
956+ bail ! ( crate :: Trap :: CannotEnterComponent ) ;
957+ }
971958
972- if !options. async_ ( ) {
973- unsafe {
974- flags. set_may_enter ( false ) ;
975- flags. set_needs_post_return ( true ) ;
976- }
959+ unsafe { flags. set_may_leave ( false ) } ;
960+ let mut cx = LowerContext :: new ( store. as_context_mut ( ) , & options, & types, instance) ;
961+ let result = lower (
962+ & mut cx,
963+ params,
964+ InterfaceType :: Tuple ( types[ ty] . params ) ,
965+ unsafe { slice_to_storage_mut ( lowered) } ,
966+ ) ;
967+ unsafe { flags. set_may_leave ( true ) } ;
968+ result?;
969+
970+ if !options. async_ ( ) {
971+ unsafe {
972+ flags. set_may_enter ( false ) ;
973+ flags. set_needs_post_return ( true ) ;
977974 }
975+ }
978976
979- Ok ( ( ) )
980- } )
977+ Ok ( ( ) )
981978}
982979
983980/// Lift results of the specified type using the specified function.
@@ -987,19 +984,17 @@ fn lift_results<
987984 T ,
988985 F : FnOnce ( & mut LiftContext , InterfaceType , & [ ValRaw ] ) -> Result < Return > + Send + Sync ,
989986> (
990- mut store : StoreContextMut < T > ,
991- instance : & mut ComponentInstance ,
987+ store : StoreContextMut < T > ,
988+ instance : Instance ,
992989 lowered : & [ ValRaw ] ,
993990 me : Func ,
994991 lift : F ,
995992) -> Result < Box < dyn std:: any:: Any + Send + Sync > > {
996993 let FuncData { options, ty, .. } = store. 0 [ me. 0 ] ;
997- let types = instance. component_types ( ) . clone ( ) ;
998- store. with_attached_instance ( instance, |store, instance| {
999- Ok ( Box :: new ( lift (
1000- & mut LiftContext :: new ( store. 0 , & options, & types, instance) ,
1001- InterfaceType :: Tuple ( types[ ty] . results ) ,
1002- lowered,
1003- ) ?) as Box < dyn std:: any:: Any + Send + Sync > )
1004- } )
994+ let types = instance. instance ( store. 0 ) . component_types ( ) . clone ( ) ;
995+ Ok ( Box :: new ( lift (
996+ & mut LiftContext :: new ( store. 0 , & options, & types, instance) ,
997+ InterfaceType :: Tuple ( types[ ty] . results ) ,
998+ lowered,
999+ ) ?) as Box < dyn std:: any:: Any + Send + Sync > )
10051000}
0 commit comments