@@ -127,7 +127,7 @@ std::string ASTMangler::mangleInitializerEntity(const VarDecl *var,
127127
128128std::string ASTMangler::mangleNominalType (const NominalTypeDecl *decl) {
129129 beginMangling ();
130- appendNominalType (decl);
130+ appendAnyGenericType (decl);
131131 return finalize ();
132132}
133133
@@ -322,7 +322,7 @@ std::string ASTMangler::mangleObjCRuntimeName(const NominalTypeDecl *Nominal) {
322322 }
323323 // For all other cases, we can use the new mangling.
324324 beginMangling ();
325- appendNominalType (Nominal);
325+ appendAnyGenericType (Nominal);
326326 return finalize ();
327327}
328328
@@ -342,9 +342,9 @@ std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
342342 appendConstructorEntity (Ctor, /* isAllocating=*/ false );
343343 } else if (auto Dtor = dyn_cast<DestructorDecl>(Decl)) {
344344 appendDestructorEntity (Dtor, /* isDeallocating=*/ false );
345- } else if (auto NTD = dyn_cast<NominalTypeDecl >(Decl)) {
346- appendNominalType (NTD );
347- } else if (isa<TypeAliasDecl>(Decl) || isa< AssociatedTypeDecl>(Decl)) {
345+ } else if (auto GTD = dyn_cast<GenericTypeDecl >(Decl)) {
346+ appendAnyGenericType (GTD );
347+ } else if (isa<AssociatedTypeDecl>(Decl)) {
348348 appendContextOf (Decl);
349349 appendDeclName (Decl);
350350 } else {
@@ -510,7 +510,7 @@ static const char *getMetatypeRepresentationOp(MetatypeRepresentation Rep) {
510510 llvm_unreachable (" Unhandled MetatypeRepresentation in switch." );
511511}
512512
513- static bool isStdlibType (const NominalTypeDecl *decl) {
513+ static bool isStdlibType (const TypeDecl *decl) {
514514 DeclContext *dc = decl->getDeclContext ();
515515 return dc->isModuleScopeContext () && dc->getParentModule ()->isStdlibModule ();
516516}
@@ -580,9 +580,7 @@ void ASTMangler::appendType(Type type) {
580580
581581 // For the DWARF output we want to mangle the type alias + context,
582582 // unless the type alias references a builtin type.
583- appendContextOf (decl);
584- appendDeclName (decl);
585- return appendOperator (" a" );
583+ return appendAnyGenericType (decl);
586584 }
587585
588586 case TypeKind::Paren:
@@ -693,15 +691,15 @@ void ASTMangler::appendType(Type type) {
693691 appendType (GenArgs[0 ]);
694692 appendOperator (" Sg" );
695693 } else {
696- appendNominalType (NDecl);
694+ appendAnyGenericType (NDecl);
697695 bool isFirstArgList = true ;
698696 appendBoundGenericArgs (type, isFirstArgList);
699697 appendOperator (" G" );
700698 }
701699 addSubstitution (type.getPointer ());
702700 return ;
703701 }
704- appendNominalType (tybase->getAnyNominal ());
702+ appendAnyGenericType (tybase->getAnyNominal ());
705703 return ;
706704
707705 case TypeKind::SILFunction:
@@ -1143,10 +1141,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
11431141 }
11441142
11451143 case DeclContextKind::GenericTypeDecl:
1146- if (auto nomctx = dyn_cast<NominalTypeDecl>(ctx))
1147- appendNominalType (nomctx);
1148- else
1149- appendContext (ctx->getParent ());
1144+ appendAnyGenericType (cast<GenericTypeDecl>(ctx));
11501145 return ;
11511146
11521147 case DeclContextKind::ExtensionDecl: {
@@ -1173,15 +1168,15 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
11731168 auto sig = ExtD->getGenericSignature ();
11741169 // If the extension is constrained, mangle the generic signature that
11751170 // constrains it.
1176- appendNominalType (decl);
1171+ appendAnyGenericType (decl);
11771172 appendModule (ExtD->getParentModule ());
11781173 if (sig && ExtD->isConstrainedExtension ()) {
11791174 Mod = ExtD->getModuleContext ();
11801175 appendGenericSignature (sig);
11811176 }
11821177 return appendOperator (" E" );
11831178 }
1184- return appendNominalType (decl);
1179+ return appendAnyGenericType (decl);
11851180 }
11861181
11871182 case DeclContextKind::AbstractClosureExpr:
@@ -1258,42 +1253,50 @@ void ASTMangler::appendProtocolName(const ProtocolDecl *protocol) {
12581253 appendDeclName (protocol);
12591254}
12601255
1261- void ASTMangler::appendNominalType (const NominalTypeDecl *decl) {
1256+ void ASTMangler::appendAnyGenericType (const GenericTypeDecl *decl) {
12621257 // Check for certain standard types.
12631258 if (tryAppendStandardSubstitution (decl))
12641259 return ;
12651260
12661261 // For generic types, this uses the unbound type.
1267- TypeBase *key = decl->getDeclaredType ().getPointer ();
1262+ Type key;
1263+ if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
1264+ if (alias->isGeneric ())
1265+ key = alias->getUnboundGenericType ();
1266+ else
1267+ key = alias->getDeclaredInterfaceType ();
1268+ } else {
1269+ key = cast<NominalTypeDecl>(decl)->getDeclaredType ();
1270+ }
12681271
12691272 // Try to mangle the entire name as a substitution.
1270- if (tryMangleSubstitution (key))
1273+ if (tryMangleSubstitution (key. getPointer () ))
12711274 return ;
12721275
12731276 appendContextOf (decl);
12741277 appendDeclName (decl);
12751278
12761279 switch (decl->getKind ()) {
1277- # define NOMINAL_TYPE_DECL ( id, parent )
1278- # define DECL ( id, parent ) \
1279- case DeclKind::id:
1280- # include " swift/AST/DeclNodes.def "
1281- llvm_unreachable ( " not a nominal type " );
1282-
1283- case DeclKind::Protocol:
1284- appendOperator (" P" );
1285- break ;
1286- case DeclKind::Class:
1287- appendOperator (" C" );
1288- break ;
1289- case DeclKind::Enum:
1290- appendOperator (" O" );
1291- break ;
1292- case DeclKind::Struct:
1293- appendOperator (" V" );
1294- break ;
1280+ default :
1281+ llvm_unreachable ( " not a nominal type " );
1282+
1283+ case DeclKind::TypeAlias:
1284+ appendOperator ( " a " );
1285+ break ;
1286+ case DeclKind::Protocol:
1287+ appendOperator (" P" );
1288+ break ;
1289+ case DeclKind::Class:
1290+ appendOperator (" C" );
1291+ break ;
1292+ case DeclKind::Enum:
1293+ appendOperator (" O" );
1294+ break ;
1295+ case DeclKind::Struct:
1296+ appendOperator (" V" );
1297+ break ;
12951298 }
1296- addSubstitution (key);
1299+ addSubstitution (key. getPointer () );
12971300}
12981301
12991302void ASTMangler::appendFunctionType (AnyFunctionType *fn,
@@ -1522,7 +1525,7 @@ void ASTMangler::appendAssociatedTypeName(DependentMemberType *dmt) {
15221525 appendIdentifier (assocTy->getName ().str ());
15231526 if (!OptimizeProtocolNames || !CurGenericSignature || !Mod
15241527 || CurGenericSignature->getConformsTo (dmt->getBase (), *Mod).size () > 1 ) {
1525- appendNominalType (assocTy->getProtocol ());
1528+ appendAnyGenericType (assocTy->getProtocol ());
15261529 }
15271530}
15281531
@@ -1708,7 +1711,7 @@ void ASTMangler::appendDeclType(const ValueDecl *decl, bool isFunctionMangling)
17081711 }
17091712}
17101713
1711- bool ASTMangler::tryAppendStandardSubstitution (const NominalTypeDecl *decl) {
1714+ bool ASTMangler::tryAppendStandardSubstitution (const GenericTypeDecl *decl) {
17121715 // Bail out if our parent isn't the swift standard library.
17131716 if (!isStdlibType (decl))
17141717 return false ;
0 commit comments