@@ -608,7 +608,7 @@ class DeclAndTypePrinter::Implementation
608
608
}
609
609
610
610
Type getForeignResultType (AbstractFunctionDecl *AFD,
611
- FunctionType *methodTy,
611
+ AnyFunctionType *methodTy,
612
612
Optional<ForeignAsyncConvention> asyncConvention,
613
613
Optional<ForeignErrorConvention> errorConvention) {
614
614
// A foreign error convention can affect the result type as seen in
@@ -950,7 +950,7 @@ class DeclAndTypePrinter::Implementation
950
950
}
951
951
952
952
// / Print C or C++ trailing attributes for a function declaration.
953
- void printFunctionClangAttributes (FuncDecl *FD, FunctionType *funcTy) {
953
+ void printFunctionClangAttributes (FuncDecl *FD, AnyFunctionType *funcTy) {
954
954
if (funcTy->getResult ()->isUninhabited ()) {
955
955
os << " SWIFT_NORETURN" ;
956
956
} else if (!funcTy->getResult ()->isVoid () &&
@@ -1010,15 +1010,21 @@ class DeclAndTypePrinter::Implementation
1010
1010
llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1011
1011
¶ms) {
1012
1012
for (auto param : ABIparams) {
1013
- if (param.role ==
1014
- IRABIDetailsProvider::ABIAdditionalParam::ABIParameterRole::Self)
1013
+ if (param.role == IRABIDetailsProvider::ABIAdditionalParam::
1014
+ ABIParameterRole::GenericRequirementRole)
1015
+ params.push_back ({DeclAndTypeClangFunctionPrinter::AdditionalParam::
1016
+ Role::GenericRequirement,
1017
+ resultTy->getASTContext ().getOpaquePointerType (),
1018
+ /* isIndirect=*/ false , param.genericRequirement });
1019
+ else if (param.role ==
1020
+ IRABIDetailsProvider::ABIAdditionalParam::ABIParameterRole::Self)
1015
1021
params.push_back (
1016
1022
{DeclAndTypeClangFunctionPrinter::AdditionalParam::Role::Self,
1017
1023
resultTy->getASTContext ().getOpaquePointerType (),
1018
1024
/* isIndirect=*/
1019
1025
isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false });
1020
- if (param.role ==
1021
- IRABIDetailsProvider::ABIAdditionalParam:: ABIParameterRole::Error)
1026
+ else if (param.role == IRABIDetailsProvider::ABIAdditionalParam::
1027
+ ABIParameterRole::Error)
1022
1028
params.push_back (
1023
1029
{DeclAndTypeClangFunctionPrinter::AdditionalParam::Role::Error,
1024
1030
resultTy->getASTContext ().getOpaquePointerType ()});
@@ -1034,12 +1040,15 @@ class DeclAndTypePrinter::Implementation
1034
1040
FD->getForeignAsyncConvention ();
1035
1041
Optional<ForeignErrorConvention> errorConvention =
1036
1042
FD->getForeignErrorConvention ();
1037
- assert (!FD->getGenericSignature () &&
1038
- " top-level generic functions not supported here" );
1039
1043
// FIXME (Alex): Make type adjustments for C++.
1040
- auto funcTy = givenFuncType
1041
- ? *givenFuncType
1042
- : FD->getInterfaceType ()->castTo <FunctionType>();
1044
+ AnyFunctionType *funcTy;
1045
+ if (givenFuncType || FD->getInterfaceType ()->is <FunctionType>()) {
1046
+ funcTy = givenFuncType ? *givenFuncType
1047
+ : FD->getInterfaceType ()->castTo <FunctionType>();
1048
+ } else {
1049
+ funcTy = FD->getInterfaceType ()->castTo <GenericFunctionType>();
1050
+ }
1051
+
1043
1052
auto resultTy =
1044
1053
getForeignResultType (FD, funcTy, asyncConvention, errorConvention);
1045
1054
@@ -1061,7 +1070,8 @@ class DeclAndTypePrinter::Implementation
1061
1070
/* isIndirect=*/
1062
1071
isa<FuncDecl>(FD) ? cast<FuncDecl>(FD)->isMutating () : false });
1063
1072
}
1064
- if (funcTy->isThrowing () && !ABIparams.empty ())
1073
+ // FIXME: Fix the method 'self' parameter.
1074
+ if (!selfTypeDeclContext && !ABIparams.empty ())
1065
1075
convertABIAdditionalParams (FD, resultTy, ABIparams, additionalParams);
1066
1076
1067
1077
funcPrinter.printFunctionSignature (
@@ -1098,26 +1108,25 @@ class DeclAndTypePrinter::Implementation
1098
1108
FD->getForeignAsyncConvention ();
1099
1109
Optional<ForeignErrorConvention> errorConvention =
1100
1110
FD->getForeignErrorConvention ();
1101
- assert (!FD->getGenericSignature () &&
1102
- " top-level generic functions not supported here" );
1103
- auto funcTy = FD->getInterfaceType ()->castTo <FunctionType>();
1111
+ auto funcTy = FD->getInterfaceType ()->castTo <AnyFunctionType>();
1104
1112
auto resultTy =
1105
1113
getForeignResultType (FD, funcTy, asyncConvention, errorConvention);
1106
1114
1107
- os << " inline " ;
1108
1115
DeclAndTypeClangFunctionPrinter funcPrinter (os, owningPrinter.prologueOS ,
1109
1116
owningPrinter.typeMapping ,
1110
1117
owningPrinter.interopContext );
1111
1118
llvm::SmallVector<DeclAndTypeClangFunctionPrinter::AdditionalParam, 2 >
1112
1119
additionalParams;
1113
1120
auto ABIparams = owningPrinter.interopContext .getIrABIDetails ()
1114
1121
.getFunctionABIAdditionalParams (FD);
1115
- if (funcTy-> isThrowing () && !ABIparams.empty ())
1122
+ if (!ABIparams.empty ())
1116
1123
convertABIAdditionalParams (FD, resultTy, ABIparams, additionalParams);
1117
-
1124
+ DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers modifiers;
1125
+ modifiers.isInline = true ;
1118
1126
funcPrinter.printFunctionSignature (
1119
1127
FD, FD->getName ().getBaseIdentifier ().get (), resultTy,
1120
- DeclAndTypeClangFunctionPrinter::FunctionSignatureKind::CxxInlineThunk);
1128
+ DeclAndTypeClangFunctionPrinter::FunctionSignatureKind::CxxInlineThunk,
1129
+ {}, modifiers);
1121
1130
// FIXME: Support throwing exceptions for Swift errors.
1122
1131
if (!funcTy->isThrowing ())
1123
1132
os << " noexcept" ;
@@ -1126,7 +1135,7 @@ class DeclAndTypePrinter::Implementation
1126
1135
os << " {\n " ;
1127
1136
funcPrinter.printCxxThunkBody (
1128
1137
funcABI.getSymbolName (), FD->getModuleContext (), resultTy,
1129
- FD->getParameters (), additionalParams, funcTy->isThrowing ());
1138
+ FD->getParameters (), additionalParams, funcTy->isThrowing (), funcTy );
1130
1139
os << " }\n " ;
1131
1140
}
1132
1141
0 commit comments