Skip to content

Commit 217dac2

Browse files
committed
[IRGen] Strip marker protocols when forming generic metadata requests
Without this might might end up with a single element protocol compositions which are invalid. (cherry picked from commit 552749e)
1 parent a632ee7 commit 217dac2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,16 @@ namespace {
19891989

19901990
MetadataResponse visitExistentialType(CanExistentialType type,
19911991
DynamicMetadataRequest request) {
1992+
if (auto *PCT =
1993+
type->getConstraintType()->getAs<ProtocolCompositionType>()) {
1994+
auto constraintTy = PCT->withoutMarkerProtocols();
1995+
if (constraintTy->getClassOrBoundGenericClass()) {
1996+
auto response = IGF.emitTypeMetadataRef(
1997+
constraintTy->getCanonicalType(), request);
1998+
return setLocal(type, response);
1999+
}
2000+
}
2001+
19922002
if (auto metadata = tryGetLocal(type, request))
19932003
return metadata;
19942004

test/Interpreter/protocol_composition_with_markers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,27 @@ do {
2727
print(v1 == v2)
2828
// CHECK: true
2929
}
30+
31+
@_marker
32+
protocol Marker {
33+
}
34+
35+
do {
36+
print(G<any (C & Sendable)>.self)
37+
// CHECK: G<C>
38+
39+
class D<T> {
40+
}
41+
42+
print((D<Int> & Sendable).self)
43+
// CHECK: D<Int>
44+
45+
print((D<C & Marker> & Sendable).self)
46+
// CHECK: D<C>
47+
48+
print((any Marker & Sendable).self)
49+
// CHECK: Any
50+
51+
print((AnyObject & Sendable & Marker).self)
52+
// CHECK: AnyObject
53+
}

0 commit comments

Comments
 (0)