Skip to content

Commit dd1d29a

Browse files
committed
Ensure that we don't emit references to marker protocols in existential type metadata.
Fixes rdar://88922030. (cherry picked from commit 93703ef)
1 parent ce25df6 commit dd1d29a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,12 @@ namespace {
16701670
}
16711671

16721672
auto layout = type.getExistentialLayout();
1673-
1674-
auto protocols = layout.getProtocols();
1673+
1674+
SmallVector<ProtocolType *, 4> protocols;
1675+
for (auto proto : layout.getProtocols()) {
1676+
if (!proto->getDecl()->isMarkerProtocol())
1677+
protocols.push_back(proto);
1678+
}
16751679

16761680
// Collect references to the protocol descriptors.
16771681
auto descriptorArrayTy
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-frontend -primary-file %s -target %target-cpu-apple-macosx10.15 -emit-ir -o - | %FileCheck %s
2+
3+
// Marker protocols should have no ABI impact at all, so this source file checks
4+
// for the absence of symbols related to marker protocols.
5+
6+
// CHECK-NOT: $s26marker_protocol_backdeploy1PP
7+
// CHECK-NOT: $s26marker_protocol_backdeploy1PMp
8+
9+
// REQUIRES: PTRSIZE=64
10+
// REQUIRES: OS=macosx
11+
12+
@_marker public protocol P { }
13+
public protocol Q: P { }
14+
protocol R { }
15+
16+
17+
// Suppress marker protocols when forming existentials at runtime
18+
public func takeAnyType<T>(_: T.Type) { }
19+
20+
// CHECK-LABEL: define {{.*}}@"$ss8Sendable_26marker_protocol_backdeploy1QAB1RpMa"
21+
// CHECK: ss8Sendable_26marker_protocol_backdeploy1QAB1RpML
22+
// CHECK-NOT: Sendable
23+
// CHECK: s26marker_protocol_backdeploy1QMp
24+
// CHECK-NOT: Sendable
25+
// CHECK: s26marker_protocol_backdeploy1RMp
26+
// CHECK-NOT: SENDABLE
27+
// CHECK: swift_getExistentialTypeMetadata
28+
public func passExistentialType() {
29+
typealias Fn = (Sendable & P & Q & R) async -> Void
30+
takeAnyType(Fn.self)
31+
}

0 commit comments

Comments
 (0)