@@ -677,6 +677,27 @@ static bool isStdlibType(const TypeDecl *decl) {
677
677
return dc->isModuleScopeContext () && dc->getParentModule ()->isStdlibModule ();
678
678
}
679
679
680
+ // / Whether to mangle the given type as generic.
681
+ static bool shouldMangleAsGeneric (Type type) {
682
+ if (!type)
683
+ return false ;
684
+
685
+ TypeBase *typePtr = type.getPointer ();
686
+ if (auto typeAlias = dyn_cast<NameAliasType>(typePtr))
687
+ return !typeAlias->getSubstitutionMap ().empty ();
688
+
689
+ if (auto bound = dyn_cast<BoundGenericType>(typePtr))
690
+ return true ;
691
+
692
+ if (auto nominal = dyn_cast<NominalType>(typePtr))
693
+ return shouldMangleAsGeneric (nominal->getParent ());
694
+
695
+ if (auto unbound = dyn_cast<UnboundGenericType>(typePtr))
696
+ return shouldMangleAsGeneric (unbound->getParent ());
697
+
698
+ return false ;
699
+ }
700
+
680
701
// / Mangle a type into the buffer.
681
702
// /
682
703
void ASTMangler::appendType (Type type) {
@@ -845,11 +866,12 @@ void ASTMangler::appendType(Type type) {
845
866
case TypeKind::BoundGenericClass:
846
867
case TypeKind::BoundGenericEnum:
847
868
case TypeKind::BoundGenericStruct: {
848
- // We can't use getAnyNominal here because this can be TypeAliasDecl only
849
- // in case of UnboundGenericType. Such mangling happens in, for instance,
850
- // SourceKit 'cursorinfo' request.
851
- auto *Decl = type->getAnyGeneric ();
852
- if (type->isSpecialized ()) {
869
+ GenericTypeDecl *Decl;
870
+ if (auto typeAlias = dyn_cast<NameAliasType>(type.getPointer ()))
871
+ Decl = typeAlias->getDecl ();
872
+ else
873
+ Decl = type->getAnyGeneric ();
874
+ if (shouldMangleAsGeneric (type)) {
853
875
// Try to mangle the entire name as a substitution.
854
876
if (tryMangleSubstitution (tybase))
855
877
return ;
@@ -869,7 +891,7 @@ void ASTMangler::appendType(Type type) {
869
891
addSubstitution (type.getPointer ());
870
892
return ;
871
893
}
872
- appendAnyGenericType (Decl );
894
+ appendAnyGenericType (type-> getAnyGeneric () );
873
895
return ;
874
896
}
875
897
@@ -1155,14 +1177,23 @@ static bool containsRetroactiveConformance(
1155
1177
}
1156
1178
1157
1179
void ASTMangler::appendRetroactiveConformances (Type type) {
1158
- auto nominal = type->getAnyNominal ();
1159
- if (!nominal) return ;
1180
+ // Dig out the substitution map to use.
1181
+ SubstitutionMap subMap;
1182
+ ModuleDecl *module ;
1183
+ if (auto typeAlias = dyn_cast<NameAliasType>(type.getPointer ())) {
1184
+ module = Mod ? Mod : typeAlias->getDecl ()->getModuleContext ();
1185
+ subMap = typeAlias->getSubstitutionMap ();
1186
+ } else {
1187
+ if (type->hasUnboundGenericType ())
1188
+ return ;
1160
1189
1161
- auto genericSig = nominal->getGenericSignatureOfContext ();
1162
- if (!genericSig) return ;
1190
+ auto nominal = type->getAnyNominal ();
1191
+ if (!nominal) return ;
1192
+
1193
+ module = Mod ? Mod : nominal->getModuleContext ();
1194
+ subMap = type->getContextSubstitutionMap (module , nominal);
1195
+ }
1163
1196
1164
- auto module = Mod ? Mod : nominal->getModuleContext ();
1165
- auto subMap = type->getContextSubstitutionMap (module , nominal);
1166
1197
if (subMap.empty ()) return ;
1167
1198
1168
1199
unsigned numProtocolRequirements = 0 ;
0 commit comments