@@ -708,7 +708,7 @@ void ASTMangler::appendType(Type type) {
708708
709709 case TypeKind::GenericFunction: {
710710 auto genFunc = cast<GenericFunctionType>(tybase);
711- appendFunctionType (genFunc);
711+ appendFunctionType (genFunc, /* forceSingleParam */ false );
712712 appendGenericSignature (genFunc->getGenericSignature ());
713713 appendOperator (" u" );
714714 return ;
@@ -751,7 +751,7 @@ void ASTMangler::appendType(Type type) {
751751 }
752752
753753 case TypeKind::Function:
754- appendFunctionType (cast<FunctionType>(tybase));
754+ appendFunctionType (cast<FunctionType>(tybase), /* forceSingleParam */ false );
755755 return ;
756756
757757 case TypeKind::SILBox: {
@@ -1243,11 +1243,12 @@ void ASTMangler::appendNominalType(const NominalTypeDecl *decl) {
12431243 addSubstitution (key);
12441244}
12451245
1246- void ASTMangler::appendFunctionType (AnyFunctionType *fn) {
1246+ void ASTMangler::appendFunctionType (AnyFunctionType *fn,
1247+ bool forceSingleParam) {
12471248 assert ((DWARFMangling || fn->isCanonical ()) &&
12481249 " expecting canonical types when not mangling for the debugger" );
12491250
1250- appendFunctionSignature (fn);
1251+ appendFunctionSignature (fn, forceSingleParam );
12511252
12521253 // Note that we do not currently use thin representations in the AST
12531254 // for the types of function decls. This may need to change at some
@@ -1274,20 +1275,34 @@ void ASTMangler::appendFunctionType(AnyFunctionType *fn) {
12741275 }
12751276}
12761277
1277- void ASTMangler::appendFunctionSignature (AnyFunctionType *fn) {
1278- appendParams (fn->getResult ());
1279- appendParams (fn->getInput ());
1278+ void ASTMangler::appendFunctionSignature (AnyFunctionType *fn,
1279+ bool forceSingleParam) {
1280+ appendParams (fn->getResult (), /* forceSingleParam*/ false );
1281+ appendParams (fn->getInput (), forceSingleParam);
12801282 if (fn->throws ())
12811283 appendOperator (" K" );
12821284}
12831285
1284- void ASTMangler::appendParams (Type ParamsTy) {
1285- TupleType *Tuple = ParamsTy->getAs <TupleType>();
1286- if (Tuple && Tuple->getNumElements () == 0 ) {
1287- appendOperator (" y" );
1288- } else {
1289- appendType (ParamsTy);
1286+ void ASTMangler::appendParams (Type ParamsTy, bool forceSingleParam) {
1287+ if (TupleType *Tuple = ParamsTy->getAs <TupleType>()) {
1288+ if (Tuple->getNumElements () == 0 ) {
1289+ if (forceSingleParam) {
1290+ // A tuple containing a single empty tuple.
1291+ appendOperator (" t" );
1292+ appendListSeparator ();
1293+ appendOperator (" t" );
1294+ }
1295+ appendOperator (" y" );
1296+ return ;
1297+ }
1298+ if (forceSingleParam && Tuple->getNumElements () > 1 ) {
1299+ appendType (ParamsTy);
1300+ appendListSeparator ();
1301+ appendOperator (" t" );
1302+ return ;
1303+ }
12901304 }
1305+ appendType (ParamsTy);
12911306}
12921307
12931308void ASTMangler::appendTypeList (Type listTy) {
@@ -1599,7 +1614,7 @@ CanType ASTMangler::getDeclTypeForMangling(
15991614 return type->getCanonicalType ();
16001615}
16011616
1602- void ASTMangler::appendDeclType (const ValueDecl *decl) {
1617+ void ASTMangler::appendDeclType (const ValueDecl *decl, bool isFunctionMangling ) {
16031618 ArrayRef<GenericTypeParamType *> genericParams;
16041619 unsigned initialParamDepth;
16051620 ArrayRef<Requirement> requirements;
@@ -1608,13 +1623,32 @@ void ASTMangler::appendDeclType(const ValueDecl *decl) {
16081623 auto type = getDeclTypeForMangling (decl,
16091624 genericParams, initialParamDepth,
16101625 requirements, requirementsBuf);
1611- appendType (type);
1626+
1627+ if (AnyFunctionType *FuncTy = type->getAs <AnyFunctionType>()) {
1628+ bool forceSingleParam = false ;
1629+ if (const auto *FDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
1630+ unsigned PListIdx = isMethodDecl (decl) ? 1 : 0 ;
1631+ if (PListIdx < FDecl->getNumParameterLists ()) {
1632+ const ParameterList *Params = FDecl->getParameterList (PListIdx);
1633+ forceSingleParam = (Params->size () == 1 );
1634+ }
1635+ }
1636+ if (isFunctionMangling) {
1637+ appendFunctionSignature (FuncTy, forceSingleParam);
1638+ } else {
1639+ appendFunctionType (FuncTy, forceSingleParam);
1640+ }
1641+ } else {
1642+ appendType (type);
1643+ }
16121644
16131645 // Mangle the generic signature, if any.
16141646 if (!genericParams.empty () || !requirements.empty ()) {
16151647 appendGenericSignatureParts (genericParams, initialParamDepth,
16161648 requirements);
1617- appendOperator (" u" );
1649+ // The 'F' function mangling doesn't need a 'u' for its generic signature.
1650+ if (!isFunctionMangling)
1651+ appendOperator (" u" );
16181652 }
16191653}
16201654
@@ -1728,28 +1762,7 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
17281762
17291763 appendContextOf (decl);
17301764 appendDeclName (decl);
1731-
1732- ArrayRef<GenericTypeParamType *> genericParams;
1733- unsigned initialParamDepth = 0 ;
1734- ArrayRef<Requirement> requirements;
1735- SmallVector<Requirement, 4 > requirementsBuf;
1736- Mod = decl->getModuleContext ();
1737- auto type = getDeclTypeForMangling (decl,
1738- genericParams, initialParamDepth,
1739- requirements, requirementsBuf);
1740-
1741- if (AnyFunctionType *FuncTy = type->getAs <AnyFunctionType>()) {
1742- appendFunctionSignature (FuncTy);
1743- } else {
1744- // In case SourceKit comes up with an invalid (Error) function type.
1745- appendType (type);
1746- }
1747-
1748- // Mangle the generic signature, if any.
1749- if (!genericParams.empty () || !requirements.empty ()) {
1750- appendGenericSignatureParts (genericParams, initialParamDepth,
1751- requirements);
1752- }
1765+ appendDeclType (decl, /* isFunctionMangling*/ true );
17531766 appendOperator (" F" );
17541767 if (decl->isStatic ())
17551768 appendOperator (" Z" );
0 commit comments