Skip to content

Commit b7c6055

Browse files
committed
[IRGen] Strip marker protocols from type symbol's mangling
1 parent b728546 commit b7c6055

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/IRGen/IRGenMangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ class IRGenMangler : public Mangle::ASTMangler {
697697
llvm::function_ref<void ()> body);
698698

699699
std::string mangleTypeSymbol(Type type, const char *Op) {
700+
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(AllowMarkerProtocols,
701+
false);
702+
700703
beginMangling();
701704
appendType(type, nullptr);
702705
appendOperator(Op);

test/IRGen/marker_protocol.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension Int: P { }
1414
extension Array: P where Element: P { }
1515

1616
// No mention of the marker protocol for runtime type instantiation.
17-
// CHECK-LABEL: @"$sSS_15marker_protocol1P_ptMD" =
17+
// CHECK-LABEL: @"$sSS_yptMD" =
1818
// CHECK-SAME: @"symbolic SS_ypt"
1919

2020
// CHECK-LABEL: @"$s15marker_protocol1QMp" = {{(dllexport |protected )?}}constant
@@ -47,7 +47,7 @@ struct HasMarkers {
4747

4848
// Note: no mention of marker protocols when forming a dictionary.
4949
// CHECK-LABEL: define{{.*}}@"$s15marker_protocol0A12InDictionaryypyF"
50-
// CHECK: call ptr @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSS_15marker_protocol1P_ptMD")
50+
// CHECK: call ptr @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSS_yptMD")
5151
public func markerInDictionary() -> Any {
5252
let dict: [String: P] = ["answer" : 42]
5353
return dict
@@ -85,3 +85,15 @@ protocol P2 {
8585

8686
// CHECK: define{{.*}}$s15marker_protocol3fooyy3FooQz_xtAA1PRzAA2P2RzlF
8787
func foo<T: P & P2>(_: T.Foo, _: T) { }
88+
89+
class C {}
90+
91+
let v1 = (any C & P).self
92+
let v2 = C.self
93+
94+
// CHECK-LABEL: define hidden swiftcc void @"$s15marker_protocol23testProtocolCompositionyyF"()
95+
// CHECK: [[V1:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s15marker_protocol1CCMD")
96+
// CHECK: [[V2:%.*]] = load ptr, ptr @"$s15marker_protocol2v2AA1CCmvp"
97+
func testProtocolComposition() {
98+
print(v1 == v2)
99+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-run-simple-swift | %FileCheck %s
2+
// REQUIRES: executable_test
3+
4+
protocol P {
5+
init()
6+
func f()
7+
}
8+
class C: P {
9+
required init() {}
10+
func f() { print("C.f") }
11+
}
12+
struct G<T: P> {
13+
func f() { T().f() }
14+
}
15+
16+
G<any (C & Sendable)>().f()
17+
// CHECK: C.f
18+
19+
do {
20+
let v1 = (any C & Sendable).self
21+
let v2 = C.self
22+
23+
print(v1)
24+
// CHECK: C
25+
print(v2)
26+
// CHECK: C
27+
print(v1 == v2)
28+
// CHECK: true
29+
}

0 commit comments

Comments
 (0)