Skip to content

Commit e34a998

Browse files
committed
[IRGen] Use specialized mangled name for class constants.
Previously, various class constants for prespecialized generic metadata such as _INSTANCE_METHODS_ and _DATA_ were mangled using the objc type name of the class. As a result, names differed from one another by a number appended at the end of the string. That resulted in symbols which were difficult to work with. Here, that issue is resolved by appending the mangled name of the type metadata to the prefix. rdar://problem/72053639
1 parent af8cf15 commit e34a998

File tree

21 files changed

+57
-21
lines changed

21 files changed

+57
-21
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,15 @@ namespace {
20762076
/// Get the name of the class or protocol to mangle into the ObjC symbol
20772077
/// name.
20782078
StringRef getEntityName(llvm::SmallVectorImpl<char> &buffer) const {
2079+
if (auto prespecialization = getSpecializedGenericType()) {
2080+
buffer.clear();
2081+
llvm::raw_svector_ostream os(buffer);
2082+
os << LinkEntity::forTypeMetadata(*prespecialization,
2083+
TypeMetadataAddress::FullMetadata)
2084+
.mangleAsString();
2085+
return os.str();
2086+
}
2087+
20792088
if (auto theClass = getClass()) {
20802089
return theClass->getObjCRuntimeName(buffer);
20812090
}

test/IRGen/prespecialized-metadata/class-fileprivate-2argument-1_distinct_use-1st_argument_generic_class-2nd_argument_distinct_generic_class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
// CHECK-apple-SAME: }*,
7070
// CHECK-apple-SAME: i8*,
7171
// CHECK-apple-SAME: i8*
72-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Z_]+]]5Value to [[INT]]
72+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA9Argument1ACLLCySiGAA9Argument2ACLLCySSGGMf" to [[INT]]
7373
// CHECK-apple-SAME: ),
7474
// CHECK-apple-SAME: [[INT]] 2
7575
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-2argument-1_distinct_use-1st_argument_generic_class-2nd_argument_same_generic_class_different_value.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
// CHECK-apple-SAME: }*,
6868
// CHECK-apple-SAME: i8*,
6969
// CHECK-apple-SAME: i8*
70-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Z_]+]]5Value to [[INT]]
70+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA9Argument1ACLLCySiGAFySSGGMf" to [[INT]]
7171
// CHECK-apple-SAME: ),
7272
// CHECK-apple-SAME: [[INT]] 2
7373
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-2argument-1_distinct_use-1st_argument_generic_class-2nd_argument_same_generic_class_same_value.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
// CHECK-apple-SAME: }*,
6868
// CHECK-apple-SAME: i8*,
6969
// CHECK-apple-SAME: i8*
70-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Z_]+]]5Value to [[INT]]
70+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA9Argument1ACLLCySiGAGGMf" to [[INT]]
7171
// CHECK-apple-SAME: ),
7272
// CHECK-apple-SAME: [[INT]] 2
7373
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1arg-2ancs-1distinct_use-1st_anc_gen-1arg-1st_arg_con_int-2nd_anc_gen-1st-arg_con_double.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
// CHECK-apple-SAME: }*,
127127
// CHECK-apple-SAME: i8*,
128128
// CHECK-apple-SAME: i8*
129-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Za-z_]+]]5Value to [[INT]]
129+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CySSGMf" to [[INT]]
130130
// CHECK-apple-SAME: ),
131131
// CHECK-apple-SAME: [[INT]] 2
132132
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1arg-2ancs-1distinct_use-1st_anc_gen-1arg-1st_arg_con_int-2nd_anc_gen-1st-arg_subclass_arg.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
// CHECK-apple-SAME: }*,
119119
// CHECK-apple-SAME: i8*,
120120
// CHECK-apple-SAME: i8*
121-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Za-z_]+]]5Value to [[INT]]
121+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CySSGMf" to [[INT]]
122122
// CHECK-apple-SAME: ),
123123
// CHECK-apple-SAME: [[INT]] 2
124124
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1arg-2ancs-1distinct_use-1st_anc_gen-1arg-1st_arg_subclass_arg-2nd_anc_gen-1st-arg_con_int.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
// CHECK-apple-SAME: }*,
123123
// CHECK-apple-SAME: i8*,
124124
// CHECK-apple-SAME: i8*
125-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
125+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCySSGMf" to [[INT]]
126126
// CHECK-apple-SAME: ),
127127
// CHECK-apple-SAME: [[INT]] 2
128128
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1arg-2ancs-1distinct_use-1st_anc_gen-1arg-1st_arg_subcls_arg-2nd_anc_gen-1st-arg_subcls_arg.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
// CHECK-apple-SAME: }*,
115115
// CHECK-apple-SAME: i8*,
116116
// CHECK-apple-SAME: i8*
117-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
117+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCySiGMf" to [[INT]]
118118
// CHECK-apple-SAME: ),
119119
// CHECK-apple-SAME: [[INT]] 2
120120
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1ancestor-1distinct_use-1st_ancestor_generic-1argument-1st_argument_constant_int.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
// CHECK-apple-SAME: }*,
113113
// CHECK-apple-SAME: i8*,
114114
// CHECK-apple-SAME: i8*
115-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP33_4D007063F2EFC1988130B7D42A21EE4C5Value to [[INT]]
115+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CySSGMf" to [[INT]]
116116
// CHECK-apple-SAME: ),
117117
// CHECK-apple-SAME: [[INT]] 2
118118
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1ancestor-1distinct_use-1st_ancestor_generic-1argument-1st_argument_subclass_argument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// : }*,
5757
// : i8*,
5858
// : i8*
59-
// : }* @_DATA__TtC4mainP33_496329636AC05466637A72F247DC6ABC9Ancestor1 to i64
59+
// : }* @"_DATA_$s4main9Ancestor1[[UNIQUE_ID_1]]CySiGMf to i64
6060
// : ),
6161
// : i64 2
6262
// : ),
@@ -184,7 +184,7 @@
184184
// CHECK-apple-SAME: }*,
185185
// CHECK-apple-SAME: i8*,
186186
// CHECK-apple-SAME: i8*
187-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP33_496329636AC05466637A72F247DC6ABC5Value to [[INT]]
187+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CySiGMf" to [[INT]]
188188
// CHECK-apple-SAME: ),
189189
// CHECK-apple-SAME: [[INT]] 2
190190
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1ancestor-1distinct_use-1st_ancestor_generic-1argument-1st_argument_superclass.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
// CHECK-apple-SAME: }*,
109109
// CHECK-apple-SAME: i8*,
110110
// CHECK-apple-SAME: i8*
111-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
111+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA9Ancestor1ACLLCySSGGMf" to [[INT]]
112112
// CHECK-apple-SAME: ),
113113
// CHECK-apple-SAME: [[INT]] 2
114114
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1ancestor-1distinct_use-1st_ancestor_nongeneric-external-nonresilient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import TestModule
8181
// CHECK-apple-SAME: }*,
8282
// CHECK-apple-SAME: i8*,
8383
// CHECK-apple-SAME: i8*
84-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
84+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCySiGMf" to [[INT]]
8585
// CHECK-apple-SAME: ),
8686
// CHECK-apple-SAME: [[INT]] 2
8787
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1ancestor-1distinct_use-1st_ancestor_nongeneric-fileprivate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
// CHECK-apple-SAME: }*,
161161
// CHECK-apple-SAME: i8*,
162162
// CHECK-apple-SAME: i8*
163-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
163+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCySiGMf" to [[INT]]
164164
// CHECK-apple-SAME: ),
165165
// CHECK-apple-SAME: [[INT]] 2
166166
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use-1st_argument_generic_class-1argument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
// : }*,
5454
// : i8*,
5555
// : i8*
56-
// : }* @_DATA__TtC4mainP33_7FA9B79F85D716E7DB33358C0057E87D9Argument1 to i64
56+
// : }* @"_DATA_$s4main9Argument1[[UNIQUE_ID_1]]CySiGMf" to i64
5757
// : ),
5858
// : i64 2
5959
// : ),
@@ -148,7 +148,7 @@
148148
// CHECK-apple-SAME: }*,
149149
// CHECK-apple-SAME: i8*,
150150
// CHECK-apple-SAME: i8*
151-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP33_7FA9B79F85D716E7DB33358C0057E87D5Value to [[INT]]
151+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CyAA9Argument1ACLLCySiGGMf" to [[INT]]
152152
// CHECK-apple-SAME: ),
153153
// CHECK-apple-SAME: [[INT]] 2
154154
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// CHECK-apple-SAME: { i32, i32, [1 x { [[INT]]*, i8*, i8*, i32, i32 }] }*,
5252
// CHECK-apple-SAME: i8*,
5353
// CHECK-apple-SAME: i8*
54-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[0-9A-Z_]+]]5Value to [[INT]]
54+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CySiGMf" to [[INT]]
5555
// CHECK-apple-SAME: ),
5656
// CHECK-apple-SAME: [[INT]] 2
5757
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use_generic_class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
// CHECK-apple-SAME: }*,
7474
// CHECK-apple-SAME: i8*,
7575
// CHECK-apple-SAME: i8*
76-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
76+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA3BoxACLLCySiGGMf" to [[INT]]
7777
// CHECK-apple-SAME: ),
7878
// CHECK-apple-SAME: [[INT]] 2
7979
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use_generic_class_specialized_at_generic_class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
// CHECK-apple-SAME: }*,
7373
// CHECK-apple-SAME: i8*,
7474
// CHECK-apple-SAME: i8*
75-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
75+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCyAA3BoxACLLCyAA5InnerACLLCySiGGGMf" to [[INT]]
7676
// CHECK-apple-SAME: ),
7777
// CHECK-apple-SAME: [[INT]] 2
7878
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use_generic_enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
// CHECK-apple-SAME: }*,
7272
// CHECK-apple-SAME: i8*,
7373
// CHECK-apple-SAME: i8*
74-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[a-zA-Z0-9_]+]]5Value to [[INT]]
74+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CyAA6EitherACLLOySiGGMf" to [[INT]]
7575
// CHECK-apple-SAME: ),
7676
// CHECK-apple-SAME: [[INT]] 2
7777
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-1distinct_use_generic_struct.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
// CHECK-apple-SAME: }*,
7272
// CHECK-apple-SAME: i8*,
7373
// CHECK-apple-SAME: i8*
74-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_2:[a-zA-Z0-9_]+]]5Value to [[INT]]
74+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]CyAA4LeftACLLVySiGGMf" to [[INT]]
7575
// CHECK-apple-SAME: ),
7676
// CHECK-apple-SAME: [[INT]] 2
7777
// CHECK-apple-SAME: ),

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-2ancestor-1du-1st_ancestor_generic-fileprivate-2nd_ancestor_nongeneric.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
// CHECK-apple-SAME: }*,
120120
// CHECK-apple-SAME: i8*,
121121
// CHECK-apple-SAME: i8*
122-
// CHECK-apple-SAME: }* @_DATA__TtC4mainP[[UNIQUE_ID_1]]5Value to [[INT]]
122+
// CHECK-apple-SAME: }* @"_DATA_$s4main5Value[[UNIQUE_ID_1]]LLCySiGMf" to [[INT]]
123123
// CHECK-apple-SAME: ),
124124
// CHECK-apple-SAME: [[INT]] 2
125125
// CHECK-apple-SAME: ),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -enable-library-evolution -prespecialize-generic-metadata -target %module-target-future -emit-ir %s | %FileCheck %s -DINT=i%target-ptrsize -DALIGNMENT=%target-alignment --check-prefix=CHECK --check-prefix=CHECK-%target-vendor
2+
3+
// REQUIRES: VENDOR=apple || OS=linux-gnu
4+
// REQUIRES: objc_interop
5+
// UNSUPPORTED: CPU=i386 && OS=ios
6+
// UNSUPPORTED: CPU=armv7 && OS=ios
7+
// UNSUPPORTED: CPU=armv7s && OS=ios
8+
9+
import Foundation
10+
11+
struct S{}
12+
class Clazz<T> {
13+
@objc func foo() {}
14+
}
15+
16+
17+
@inline(never)
18+
func consume<T>(_ t: T) {
19+
withExtendedLifetime(t) { t in }
20+
}
21+
22+
func doit() {
23+
// CHECK: @"_INSTANCE_METHODS_$s4main5ClazzCyAA1SVGMf" = internal constant
24+
consume(Clazz<S>.self)
25+
}
26+
27+
doit()

0 commit comments

Comments
 (0)