@@ -867,7 +867,6 @@ static bool hasDependentTypeWitness(
867
867
static bool isDependentConformance (
868
868
IRGenModule &IGM,
869
869
const RootProtocolConformance *rootConformance,
870
- bool considerResilience,
871
870
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > &visited){
872
871
// Self-conformances are never dependent.
873
872
auto conformance = dyn_cast<NormalProtocolConformance>(rootConformance);
@@ -880,7 +879,7 @@ static bool isDependentConformance(
880
879
return false ;
881
880
882
881
// If the conformance is resilient, this is always true.
883
- if (considerResilience && IGM.isResilientConformance (conformance))
882
+ if (IGM.isResilientConformance (conformance))
884
883
return true ;
885
884
886
885
// Check whether any of the conformances are dependent.
@@ -899,7 +898,6 @@ static bool isDependentConformance(
899
898
isDependentConformance (IGM,
900
899
assocConformance.getConcrete ()
901
900
->getRootConformance (),
902
- considerResilience,
903
901
visited))
904
902
return true ;
905
903
}
@@ -916,11 +914,9 @@ static bool isDependentConformance(
916
914
// / Is there anything about the given conformance that requires witness
917
915
// / tables to be dependently-generated?
918
916
bool IRGenModule::isDependentConformance (
919
- const RootProtocolConformance *conformance,
920
- bool considerResilience) {
917
+ const RootProtocolConformance *conformance) {
921
918
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > visited;
922
- return ::isDependentConformance (*this , conformance, considerResilience,
923
- visited);
919
+ return ::isDependentConformance (*this , conformance, visited);
924
920
}
925
921
926
922
static bool isSynthesizedNonUnique (const RootProtocolConformance *conformance) {
@@ -1140,7 +1136,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1140
1136
// offsets, with conditional conformances closest to 0.
1141
1137
unsigned NextPrivateDataIndex = 0 ;
1142
1138
bool ResilientConformance;
1143
- bool RequiresSpecialization = false ;
1144
1139
1145
1140
const ProtocolInfo &PI;
1146
1141
@@ -1162,21 +1157,14 @@ class AccessorConformanceInfo : public ConformanceInfo {
1162
1157
PI(IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
1163
1158
(ResilientConformance
1164
1159
? ProtocolInfoKind::RequirementSignature
1165
- : ProtocolInfoKind::Full))) {
1166
- // If the conformance is resilient, we require runtime instantiation.
1167
- if (ResilientConformance)
1168
- RequiresSpecialization = true ;
1169
- }
1160
+ : ProtocolInfoKind::Full))) {}
1170
1161
1171
1162
// / The number of entries in the witness table.
1172
1163
unsigned getTableSize () const { return TableSize; }
1173
1164
1174
1165
// / The number of private entries in the witness table.
1175
1166
unsigned getTablePrivateSize () const { return NextPrivateDataIndex; }
1176
1167
1177
- // / Whether this witness table must be specialized at runtime.
1178
- bool requiresSpecialization () const { return RequiresSpecialization; }
1179
-
1180
1168
// / The top-level entry point.
1181
1169
void build ();
1182
1170
@@ -1226,7 +1214,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1226
1214
}
1227
1215
1228
1216
// Otherwise, we'll need to derive it at instantiation time.
1229
- RequiresSpecialization = true ;
1230
1217
SpecializedBaseConformances.push_back ({Table.size (), &conf});
1231
1218
Table.addNullPointer (IGM.Int8PtrTy );
1232
1219
}
@@ -1293,8 +1280,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1293
1280
auto associate =
1294
1281
Conformance.getTypeWitness (requirement.getAssociation (), nullptr )
1295
1282
->getCanonicalType ();
1296
- if (associate->hasTypeParameter ())
1297
- RequiresSpecialization = true ;
1298
1283
llvm::Constant *witness =
1299
1284
IGM.getAssociatedTypeWitness (associate, /* inProtocolContext=*/ false );
1300
1285
Table.addBitCast (witness, IGM.Int8PtrTy );
@@ -1319,9 +1304,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1319
1304
requirement.getAssociation (),
1320
1305
requirement.getAssociatedRequirement ());
1321
1306
1322
- if (requirement.getAssociation ()->hasTypeParameter ())
1323
- RequiresSpecialization = true ;
1324
-
1325
1307
#ifndef NDEBUG
1326
1308
assert (entry.getKind () == SILWitnessTable::AssociatedTypeProtocol
1327
1309
&& " sil witness table does not match protocol" );
@@ -1372,7 +1354,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
1372
1354
1373
1355
// / Allocate another word of private data storage in the conformance table.
1374
1356
unsigned getNextPrivateDataIndex () {
1375
- RequiresSpecialization = true ;
1376
1357
return NextPrivateDataIndex++;
1377
1358
}
1378
1359
@@ -1911,7 +1892,7 @@ namespace {
1911
1892
// WitnessTablePrivateSizeInWordsAndRequiresInstantiation
1912
1893
B.addInt (IGM.Int16Ty ,
1913
1894
(Description.witnessTablePrivateSize << 1 ) |
1914
- Description.hasDependentAssociatedTypeWitnesses );
1895
+ Description.requiresSpecialization );
1915
1896
// Instantiation function
1916
1897
B.addRelativeAddressOrNull (Description.instantiationFn );
1917
1898
// Private data
@@ -2065,13 +2046,12 @@ IRGenModule::getConformanceInfo(const ProtocolDecl *protocol,
2065
2046
2066
2047
const ConformanceInfo *info;
2067
2048
// If the conformance is dependent in any way, we need to unique it.
2068
- // TODO: maybe this should apply whenever it's out of the module?
2069
- // TODO: actually enable this
2049
+ //
2070
2050
// FIXME: Both implementations of ConformanceInfo are trivially-destructible,
2071
2051
// so in theory we could allocate them on a BumpPtrAllocator. But there's not
2072
2052
// a good one for us to use. (The ASTContext's outlives the IRGenModule in
2073
2053
// batch mode.)
2074
- if (isDependentConformance (rootConformance, /* considerResilience= */ true ) ||
2054
+ if (isDependentConformance (rootConformance) ||
2075
2055
// Foreign types need to go through the accessor to unique the witness
2076
2056
// table.
2077
2057
isSynthesizedNonUnique (rootConformance)) {
@@ -2143,13 +2123,13 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
2143
2123
// Produce the initializer value.
2144
2124
auto initializer = wtableContents.finishAndCreateFuture ();
2145
2125
2126
+ bool isDependent = isDependentConformance (conf);
2127
+
2146
2128
llvm::GlobalVariable *global = nullptr ;
2147
2129
unsigned tableSize;
2148
2130
if (!isResilientConformance (conf)) {
2149
- bool isDependent =
2150
- isDependentConformance (conf, /* considerResilience=*/ false );
2151
2131
global = cast<llvm::GlobalVariable>(
2152
- isDependent
2132
+ ( isDependent && conf-> getDeclContext ()-> isGenericContext ())
2153
2133
? getAddrOfWitnessTablePattern (cast<NormalProtocolConformance>(conf),
2154
2134
initializer)
2155
2135
: getAddrOfWitnessTable (conf, initializer));
@@ -2165,10 +2145,7 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
2165
2145
// descriptor.
2166
2146
ConformanceDescription description (conf, wt, global, tableSize,
2167
2147
wtableBuilder.getTablePrivateSize (),
2168
- wtableBuilder.requiresSpecialization (),
2169
- isDependentConformance (
2170
- conf,
2171
- /* considerResilience=*/ false ));
2148
+ isDependent);
2172
2149
2173
2150
// Build the instantiation function, we if need one.
2174
2151
description.instantiationFn = wtableBuilder.buildInstantiationFunction ();
0 commit comments