@@ -891,21 +891,34 @@ impl TypeData for ComponentFuncType {
891891 }
892892}
893893
894+ #[ derive( Copy , Clone , Debug ) ]
895+ pub ( crate ) enum Abi {
896+ LowerSync ,
897+ LowerAsync ,
898+ LiftSync ,
899+ LiftAsync ,
900+ LiftAsyncStackful ,
901+ }
902+
894903impl ComponentFuncType {
895904 /// Lowers the component function type to core parameter and result types for the
896905 /// canonical ABI.
897- pub ( crate ) fn lower ( & self , types : & TypeList , is_lower : bool , async_ : bool ) -> LoweringInfo {
906+ pub ( crate ) fn lower ( & self , types : & TypeList , abi : Abi ) -> LoweringInfo {
898907 let mut info = LoweringInfo :: default ( ) ;
899908
900- if async_ && is_lower {
901- for _ in 0 ..2 {
902- info. params . push ( ValType :: I32 ) ;
909+ let is_lower = match abi {
910+ Abi :: LowerAsync => {
911+ for _ in 0 ..2 {
912+ info. params . push ( ValType :: I32 ) ;
913+ }
914+ info. results . push ( ValType :: I32 ) ;
915+ info. requires_memory = true ;
916+ info. requires_realloc = self . results . iter ( ) . any ( |( _, ty) | ty. contains_ptr ( types) ) ;
917+ return info;
903918 }
904- info. results . push ( ValType :: I32 ) ;
905- info. requires_memory = true ;
906- info. requires_realloc = self . results . iter ( ) . any ( |( _, ty) | ty. contains_ptr ( types) ) ;
907- return info;
908- }
919+ Abi :: LowerSync => true ,
920+ Abi :: LiftSync | Abi :: LiftAsync | Abi :: LiftAsyncStackful => false ,
921+ } ;
909922
910923 for ( _, ty) in self . params . iter ( ) {
911924 // Check to see if `ty` has a pointer somewhere in it, needed for
@@ -940,32 +953,37 @@ impl ComponentFuncType {
940953 }
941954 }
942955
943- if async_ {
944- info . results . push ( ValType :: I32 ) ;
945- } else {
946- for ( _, ty) in self . results . iter ( ) {
947- // Results of lowered functions that contains pointers must be
948- // allocated by the callee meaning that realloc is required.
949- // Results of lifted function are allocated by the guest which
950- // means that no realloc option is necessary.
951- if is_lower && !info. requires_realloc {
952- info. requires_realloc = ty. contains_ptr ( types) ;
953- }
956+ match abi {
957+ Abi :: LowerAsync => unreachable ! ( ) ,
958+ Abi :: LowerSync | Abi :: LiftSync => {
959+ for ( _, ty) in self . results . iter ( ) {
960+ // Results of lowered functions that contains pointers must be
961+ // allocated by the callee meaning that realloc is required.
962+ // Results of lifted function are allocated by the guest which
963+ // means that no realloc option is necessary.
964+ if is_lower && !info. requires_realloc {
965+ info. requires_realloc = ty. contains_ptr ( types) ;
966+ }
954967
955- if !ty. push_wasm_types ( types, & mut info. results ) {
956- // Too many results to return directly, either a retptr parameter will be used (import)
957- // or a single pointer will be returned (export)
958- info. results . clear ( ) ;
959- if is_lower {
960- info. params . max = MAX_LOWERED_TYPES ;
961- assert ! ( info. params. push( ValType :: I32 ) ) ;
962- } else {
963- assert ! ( info. results. push( ValType :: I32 ) ) ;
968+ if !ty. push_wasm_types ( types, & mut info. results ) {
969+ // Too many results to return directly, either a retptr parameter will be used (import)
970+ // or a single pointer will be returned (export)
971+ info. results . clear ( ) ;
972+ if is_lower {
973+ info. params . max = MAX_LOWERED_TYPES ;
974+ assert ! ( info. params. push( ValType :: I32 ) ) ;
975+ } else {
976+ assert ! ( info. results. push( ValType :: I32 ) ) ;
977+ }
978+ info. requires_memory = true ;
979+ break ;
964980 }
965- info. requires_memory = true ;
966- break ;
967981 }
968982 }
983+ Abi :: LiftAsync => {
984+ info. results . push ( ValType :: I32 ) ;
985+ }
986+ Abi :: LiftAsyncStackful => { }
969987 }
970988
971989 // Memory is always required when realloc is required
0 commit comments