Skip to content

Commit 0128989

Browse files
authored
Merge pull request #41950 from DougGregor/existential-marker-protocol-metadata-5.6
Ensure that we don't emit references to marker protocols in existential type metadata.
2 parents 4b7e5e5 + 026a7a0 commit 0128989

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// Temporarily disable on arm (rdar://89910199)
13+
// UNSUPPORTED: CPU=arm64, CPU=arm64e
14+
15+
@_marker public protocol P { }
16+
public protocol Q: P { }
17+
protocol R { }
18+
19+
20+
// Suppress marker protocols when forming existentials at runtime
21+
public func takeAnyType<T>(_: T.Type) { }
22+
23+
// CHECK-LABEL: define {{.*}}@"$ss8Sendable_26marker_protocol_backdeploy1QAB1RpMa"
24+
// CHECK: ss8Sendable_26marker_protocol_backdeploy1QAB1RpML
25+
// CHECK-NOT: Sendable
26+
// CHECK: s26marker_protocol_backdeploy1QMp
27+
// CHECK-NOT: Sendable
28+
// CHECK: s26marker_protocol_backdeploy1RMp
29+
// CHECK-NOT: SENDABLE
30+
// CHECK: swift_getExistentialTypeMetadata
31+
public func passExistentialType() {
32+
typealias Fn = (Sendable & P & Q & R) async -> Void
33+
takeAnyType(Fn.self)
34+
}

0 commit comments

Comments
 (0)