Skip to content

Commit d5cbd3e

Browse files
committed
[Mangling] Only look for retroactive conformances in conditional reqs
Previously, the mangler searched for retroactive conformances in /any/ of a generic type's substitutions, but really we only care about the ones that affect the generic type's conformance, i.e. those that affect generic parameters. Refining this results in shorter mangled names involving instantiations of generic types. Follow-up work for rdar://problem/46735592
1 parent abc48e4 commit d5cbd3e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,16 +1137,31 @@ static bool containsRetroactiveConformance(
11371137
const ProtocolConformance *conformance,
11381138
ModuleDecl *module) {
11391139
// If the root conformance is retroactive, it's retroactive.
1140-
if (isRetroactiveConformance(conformance->getRootConformance()))
1140+
const RootProtocolConformance *rootConformance =
1141+
conformance->getRootConformance();
1142+
if (isRetroactiveConformance(rootConformance))
11411143
return true;
11421144

1143-
// If any of the substitutions used to form this conformance are retroactive,
1144-
// it's retroactive.
1145+
// If the conformance is conditional and any of the substitutions used to
1146+
// satisfy the conditions are retroactive, it's retroactive.
11451147
auto subMap = conformance->getSubstitutions(module);
1146-
for (auto conformance : subMap.getConformances()) {
1147-
if (conformance.isConcrete() &&
1148-
containsRetroactiveConformance(conformance.getConcrete(), module))
1148+
for (auto requirement : rootConformance->getConditionalRequirements()) {
1149+
if (requirement.getKind() != RequirementKind::Conformance)
1150+
continue;
1151+
ProtocolDecl *proto =
1152+
requirement.getSecondType()->castTo<ProtocolType>()->getDecl();
1153+
Optional<ProtocolConformanceRef> conformance =
1154+
subMap.lookupConformance(requirement.getFirstType()->getCanonicalType(),
1155+
proto);
1156+
if (!conformance) {
1157+
// This should only happen when mangling invalid ASTs, but that happens
1158+
// for indexing purposes.
1159+
continue;
1160+
}
1161+
if (conformance->isConcrete() &&
1162+
containsRetroactiveConformance(conformance->getConcrete(), module)) {
11491163
return true;
1164+
}
11501165
}
11511166

11521167
return false;

test/SILGen/mangling_retroactive.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct RequiresP<T: P> {}
4848
// UnconditionallyP, even though UnconditionallyP's generic param uses a
4949
// retroactive conformance to conform to Q.
5050
func rdar46735592(_: RequiresP<UnconditionallyP<Y>>) { }
51-
// CHECK: sil hidden [ossa] @$s20mangling_retroactive12rdar46735592yyAA9RequiresPVyAA16UnconditionallyPVy12RetroactiveB1YVAI0F1A1QAAHPyHCg_GAlJ1PyHCg_GF
51+
// CHECK: sil hidden [ossa] @$s20mangling_retroactive12rdar46735592yyAA9RequiresPVyAA16UnconditionallyPVy12RetroactiveB1YVAI0F1A1QAAHPyHCg_GGF
5252

5353
struct QImpl: Q {}
5454
struct ConditionallyP<T> {}

0 commit comments

Comments
 (0)