Skip to content

Commit e61671d

Browse files
authored
Merge pull request #74130 from xedin/rdar-128667580
[IRGen] Strip marker protocols in a few more places
2 parents f02d300 + 5d243bd commit e61671d

File tree

7 files changed

+76
-8
lines changed

7 files changed

+76
-8
lines changed

lib/IRGen/IRGenMangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ IRGenMangler::mangleTypeForFlatUniqueTypeRef(CanGenericSignature sig,
186186
// mangled name.
187187
configureForSymbolicMangling();
188188

189+
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(
190+
AllowMarkerProtocols, false);
191+
189192
// We don't make the substitution adjustments above because they're
190193
// target-specific and so would break the goal of getting a unique
191194
// string.

lib/IRGen/IRGenMangler.h

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

708708
std::string mangleTypeSymbol(Type type, const char *Op) {
709-
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(AllowMarkerProtocols,
710-
false);
711-
712709
beginMangling();
713710
appendType(type, nullptr);
714711
appendOperator(Op);

lib/IRGen/MetadataRequest.cpp

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

19801980
MetadataResponse visitExistentialType(CanExistentialType type,
19811981
DynamicMetadataRequest request) {
1982+
if (auto *PCT =
1983+
type->getConstraintType()->getAs<ProtocolCompositionType>()) {
1984+
auto constraintTy = PCT->withoutMarkerProtocols();
1985+
if (constraintTy->getClassOrBoundGenericClass()) {
1986+
auto response = IGF.emitTypeMetadataRef(
1987+
constraintTy->getCanonicalType(), request);
1988+
return setLocal(type, response);
1989+
}
1990+
}
1991+
19821992
if (auto metadata = tryGetLocal(type, request))
19831993
return metadata;
19841994

test/IRGen/marker_protocol.swift

Lines changed: 3 additions & 3 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_yptMD" =
17+
// CHECK-LABEL: @"$sSS_15marker_protocol1P_ptMD" =
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_yptMD")
50+
// CHECK: call ptr @__swift_instantiateConcreteTypeFromMangledName({{.*}} @"$sSS_15marker_protocol1P_ptMD")
5151
public func markerInDictionary() -> Any {
5252
let dict: [String: P] = ["answer" : 42]
5353
return dict
@@ -92,7 +92,7 @@ let v1 = (any C & P).self
9292
let v2 = C.self
9393

9494
// CHECK-LABEL: define hidden swiftcc void @"$s15marker_protocol23testProtocolCompositionyyF"()
95-
// CHECK: [[V1:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s15marker_protocol1CCMD")
95+
// CHECK: [[V1:%.*]] = call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$s15marker_protocol1P_AA1CCXcMD")
9696
// CHECK: [[V2:%.*]] = load ptr, ptr @"$s15marker_protocol2v2AA1CCmvp"
9797
func testProtocolComposition() {
9898
print(v1 == v2)

test/IRGen/marker_protocol_backdeploy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ protocol R { }
2020
// Suppress marker protocols when forming existentials at runtime
2121
public func takeAnyType<T>(_: T.Type) { }
2222

23-
// CHECK-LABEL: define {{.*}}@"$s26marker_protocol_backdeploy1Q_AA1RpMa"
24-
// CHECK: $s26marker_protocol_backdeploy1Q_AA1RpML
23+
// CHECK-LABEL: define {{.*}}@"$ss8Sendable_26marker_protocol_backdeploy1QAB1RpMa"
24+
// CHECK: ss8Sendable_26marker_protocol_backdeploy1QAB1RpML
2525
// CHECK-NOT: Sendable
2626
// CHECK: s26marker_protocol_backdeploy1QMp
2727
// CHECK-NOT: Sendable

test/Interpreter/protocol_composition_with_markers.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,34 @@ 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+
54+
func generic<T>(_: T.Type) {
55+
print((D<T> & Sendable).self)
56+
}
57+
58+
generic(Int.self)
59+
// CHECK: D<Int>
60+
}

test/Interpreter/rdar128667580.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-clang %t/Impl.m -c -o %t/Test.o
5+
// RUN: %target-build-swift %t/main.swift -import-objc-header %t/Test.h %t/Test.o -Xfrontend -disable-concrete-type-metadata-mangled-name-accessors -o %t/main
6+
// RUN: %target-codesign %t/main
7+
// RUN: %target-run %t/main | %FileCheck %s
8+
9+
// REQUIRES: executable_test
10+
// REQUIRES: objc_interop
11+
// REQUIRES: concurrency
12+
13+
//--- Test.h
14+
#import "Foundation/Foundation.h"
15+
16+
@interface Test : NSObject { }
17+
@end
18+
19+
//--- Impl.m
20+
#import "Test.h"
21+
22+
@implementation Test
23+
@end
24+
25+
//--- main.swift
26+
print((any Test & Sendable).self)
27+
// CHECK: Test

0 commit comments

Comments
 (0)