Skip to content

Commit ea6ef19

Browse files
committed
[AST Mangler] Don't mangle marker protocols in retroactive conformances.
Fixes a crash in IR generation, where we would try to emit metadata referencing a marker protocol, rdar://92285294. (cherry picked from commit c5c1e28)
1 parent afb1404 commit ea6ef19

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ static bool isRetroactiveConformance(const RootProtocolConformance *root) {
16371637
return false; // self-conformances are never retroactive. nor are builtin.
16381638
}
16391639

1640+
// Don't consider marker protocols at all.
1641+
if (conformance->getProtocol()->isMarkerProtocol())
1642+
return false;
1643+
16401644
return conformance->isRetroactive();
16411645
}
16421646

@@ -1682,6 +1686,9 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,
16821686

16831687
unsigned numProtocolRequirements = 0;
16841688
for (auto conformance : subMap.getConformances()) {
1689+
if (conformance.getRequirement()->isMarkerProtocol())
1690+
continue;
1691+
16851692
SWIFT_DEFER {
16861693
++numProtocolRequirements;
16871694
};

test/IRGen/marker_protocol.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ public func markerInDictionary() -> Any {
5757
// CHECK: swiftcc void @"$s15marker_protocol7genericyyxAA1PRzlF"(%swift.opaque* noalias nocapture %0, %swift.type* %T)
5858
public func generic<T: P>(_: T) { }
5959

60+
public struct GenericType<T: Hashable & P> { }
61+
62+
// CHECK-LABEL: @"$s15marker_protocol11testGeneric1i5arrayySi_SaySiGtF"(
6063
public func testGeneric(i: Int, array: [Int]) {
6164
generic(i)
6265
generic(array)
66+
// CHECK: __swift_instantiateConcreteTypeFromMangledName{{.*}}$s15marker_protocol11GenericTypeVySaySiGGmMD
67+
print(GenericType<[Int]>.self)
6368
}
6469

6570
// Forming an existential involving a marker protocol would crash the compiler

0 commit comments

Comments
 (0)