Skip to content

Commit 5d243bd

Browse files
committed
[IRGen] Move marker protocol stripping from mangleTypeSymbol to mangleTypeForFlatUniqueTypeRef
The original check introduced by #71855 is too broad. For concrete metadata we call the runtime demangler so we need to strip off marker protocols when mangling that string and `mangleTypeForReflection` already does that.
1 parent 552749e commit 5d243bd

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-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);

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ do {
5050

5151
print((AnyObject & Sendable & Marker).self)
5252
// 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>
5360
}

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)