Skip to content

Commit abfbbbe

Browse files
Merge pull request #32213 from aschwaighofer/note_use_of_type_metadata_in_conditional_reqts
IRGen: Note use of types in conditional requirements of protocol conformances
2 parents cdc38da + 05ed0dd commit abfbbbe

7 files changed

+63
-45
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,10 @@ llvm::Constant *IRGenModule::emitSwiftProtocols() {
33033303
}
33043304

33053305
void IRGenModule::addProtocolConformance(ConformanceDescription &&record) {
3306-
// Add this protocol conformance.
3306+
3307+
emitProtocolConformance(record);
3308+
3309+
// Add this conformance to the conformance list.
33073310
ProtocolConformances.push_back(std::move(record));
33083311
}
33093312

@@ -3312,10 +3315,6 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
33123315
if (ProtocolConformances.empty())
33133316
return nullptr;
33143317

3315-
// Emit the conformances.
3316-
for (const auto &record : ProtocolConformances)
3317-
emitProtocolConformance(record);
3318-
33193318
// Define the global variable for the conformance list.
33203319
ConstantInitBuilder builder(*this);
33213320
auto descriptorArray = builder.beginArray(RelativeAddressTy);

test/IRGen/associated_type_witness.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ struct Pair<T, U> : P, Q {}
9393
// GLOBAL-SAME: @"symbolic{{.*}}23associated_type_witness4PairV{{.*}}"
9494
// GLOBAL-SAME: ]
9595

96+
// Protocol conformance descriptor for Computed : Assocked.
97+
// GLOBAL-LABEL: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAMc" = hidden constant
98+
// GLOBAL-SAME: i16 4,
99+
// GLOBAL-SAME: i16 1,
100+
101+
// No instantiator function
102+
// GLOBAL-SAME: i32 0,
103+
// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint ([16 x i8*]* [[PRIVATE:@.*]] to i64), i64 ptrtoint
104+
// GLOBAL-SAME: }
105+
96106
struct Computed<T, U> : Assocked {
97107
typealias Assoc = Pair<T, U>
98108
}
@@ -117,6 +127,14 @@ protocol DerivedFromSimpleAssoc : HasSimpleAssoc {}
117127
// GLOBAL-SAME: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc"
118128
// GLOBAL-SAME: i8* null
119129

130+
// Protocol conformance descriptor for GenericComputed : DerivedFromSimpleAssoc.
131+
// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc" = hidden constant
132+
// GLOBAL-SAME: i16 2,
133+
// GLOBAL-SAME: i16 1,
134+
135+
// Relative reference to instantiator function
136+
// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint (void (i8**, %swift.type*, i8**)* @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI" to i64),
137+
120138
// Relative reference to private data
121139
struct GenericComputed<T: P> : DerivedFromSimpleAssoc {
122140
typealias Assoc = PBox<T>
@@ -155,29 +173,13 @@ extension ValidatorType {
155173

156174
// MARK: Failing example
157175
extension Validator where T == String {
158-
// GLOBAL: @"symbolic _____ySS__G 23associated_type_witness9ValidatorVAASSRszlE1VV7FailureV"
159176
struct V: ValidatorType {
160177
typealias Data = T // or String
161178

162179
struct Failure {}
163180
}
164181
}
165182

183+
// GLOBAL-LABEL: @"symbolic _____ySS__G 23associated_type_witness9ValidatorVAASSRszlE1VV7FailureV"
166184

167-
// Protocol conformance descriptor for Computed : Assocked.
168-
// GLOBAL-LABEL: @"$s23associated_type_witness8ComputedVyxq_GAA8AssockedAAMc" = hidden constant
169-
// GLOBAL-SAME: i16 4,
170-
// GLOBAL-SAME: i16 1,
171185

172-
// No instantiator function
173-
// GLOBAL-SAME: i32 0,
174-
// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint ([16 x i8*]* [[PRIVATE:@.*]] to i64), i64 ptrtoint
175-
// GLOBAL-SAME: }
176-
177-
// Protocol conformance descriptor for GenericComputed : DerivedFromSimpleAssoc.
178-
// GLOBAL-LABEL: @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAMc" = hidden constant
179-
// GLOBAL-SAME: i16 2,
180-
// GLOBAL-SAME: i16 1,
181-
182-
// Relative reference to instantiator function
183-
// GLOBAL-SAME: i32 trunc (i64 sub (i64 ptrtoint (void (i8**, %swift.type*, i8**)* @"$s23associated_type_witness15GenericComputedVyxGAA22DerivedFromSimpleAssocAAWI" to i64),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -O -emit-ir %s
2+
// RUN: %target-swift-frontend -O -primary-file %s -emit-ir
3+
4+
// Make sure that we don't crash in IRGen because the only reference to the type
5+
// E is in the protocol conformance descriptor describing the conditional
6+
// conformace.
7+
8+
private enum E {}
9+
10+
private protocol P { associatedtype AT }
11+
12+
private struct S<A, B> {}
13+
14+
extension S: P where A == E { typealias AT = B }
15+
16+
print(S<E, Bool>.AT.self)

test/IRGen/lazy_metadata_no_reflection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ public func forceMetadata() {
3434
takeMetadata(HasPropertyType.self)
3535
}
3636

37-
// CHECK-LABEL: @"$s4test1SVMn" = hidden constant
3837
// CHECK-LABEL: @"$s4test1SVSQAAMc" = hidden constant
38+
// CHECK-LABEL: @"$s4test1SVMn" = hidden constant

test/IRGen/protocol_conformance_records.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ public struct Concrete : AssociateConformance {
108108
// -- no flags are set, and no generic witness table follows
109109
// CHECK-SAME: i32 0 }
110110

111-
// CHECK-LABEL: @"\01l_protocols"
112-
// CHECK-SAME: @"$s28protocol_conformance_records8RuncibleMp"
113-
// CHECK-SAME: @"$s28protocol_conformance_records5SpoonMp"
114-
115111
public protocol Spoon { }
116112

117113
// Conditional conformances
@@ -167,6 +163,10 @@ extension Dependent : Associate {
167163
public typealias X = (T, T)
168164
}
169165

166+
// CHECK-LABEL: @"\01l_protocols"
167+
// CHECK-SAME: @"$s28protocol_conformance_records8RuncibleMp"
168+
// CHECK-SAME: @"$s28protocol_conformance_records5SpoonMp"
169+
170170
// CHECK-LABEL: @"\01l_protocol_conformances" = private constant
171171
// CHECK-SAME: @"$s28protocol_conformance_records15NativeValueTypeVAA8RuncibleAAMc"
172172
// CHECK-SAME: @"$s28protocol_conformance_records15NativeClassTypeCAA8RuncibleAAMc"

test/IRGen/protocol_resilience.sil

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ import SwiftShims
1111

1212
import resilient_protocol
1313

14+
// Protocol conformance descriptor for ResilientConformingType : OtherResilientProtocol
15+
16+
// CHECK: @"$s19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAMc" =
17+
18+
// CHECK-SAME: i32 131072,
19+
20+
// -- number of witness table entries
21+
// CHECK-SAME: i16 0,
22+
23+
// -- size of private area + 'requires instantiation' bit
24+
// CHECK-SAME: i16 1,
25+
26+
// -- instantiator function
27+
// CHECK-SAME: i32 0
28+
29+
// CHECK-SAME: }
30+
31+
1432

1533
// Protocol descriptor for ResilientProtocol
1634
// CHECK: [[RESILIENT_PROTOCOL_NAME:@.*]] = private constant [18 x i8] c"ResilientProtocol\00
@@ -88,23 +106,6 @@ protocol InternalProtocol {
88106
// CHECK-NOT: @"$s19protocol_resilience26ConformsWithResilientAssocVAA03HaseF0AAWp" = {{(protected )?}}internal
89107

90108

91-
// Protocol conformance descriptor for ResilientConformingType : OtherResilientProtocol
92-
93-
// CHECK: @"$s19protocol_resilience23ResilientConformingTypeV010resilient_A005OtherC8ProtocolAAMc" =
94-
95-
// CHECK-SAME: i32 131072,
96-
97-
// -- number of witness table entries
98-
// CHECK-SAME: i16 0,
99-
100-
// -- size of private area + 'requires instantiation' bit
101-
// CHECK-SAME: i16 1,
102-
103-
// -- instantiator function
104-
// CHECK-SAME: i32 0
105-
106-
// CHECK-SAME: }
107-
108109
// ConformsWithRequirements protocol conformance descriptor
109110

110111
// CHECK: "$s19protocol_resilience24ConformsWithRequirementsV010resilient_A008ProtocoldE0AAMc" = hidden constant {

test/IRGen/reflection_metadata.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
// STRIP_REFLECTION_NAMES_DAG: section "{{[^"]*swift5_assocty|.sw5asty\$B}}
88
// STRIP_REFLECTION_NAMES-DAG: section "{{[^"]*swift5_capture|.sw5cptr\$B}}
99
// STRIP_REFLECTION_NAMES-DAG: section "{{[^"]*swift5_typeref|.sw5tyrf\$B}}
10+
// STRIP_REFLECTION_NAMES-DAG: private constant [6 x i8] c"Inner\00", section "{{[^"]*swift5_reflstr|.sw5rfst\$B}}
1011
// STRIP_REFLECTION_NAMES-NOT: section "{{[^"]*swift5_reflstr|.sw5rfst\$B}}
1112
// STRIP_REFLECTION_NAMES-NOT: section "{{[^"]*swift5_builtin|.sw5bltn\$B}}
12-
1313
// STRIP_REFLECTION_NAMES-DAG: @"$s19reflection_metadata10MyProtocol_pMF" = internal constant {{.*}}section "{{[^"]*swift5_fieldmd|.sw5flmd\$B}}
1414

1515
// STRIP_REFLECTION_METADATA-NOT: section "{{[^"]*swift5_reflect|.sw5rfst\$B}}

0 commit comments

Comments
 (0)