@@ -867,7 +867,6 @@ static bool hasDependentTypeWitness(
867867static bool isDependentConformance (
868868 IRGenModule &IGM,
869869 const RootProtocolConformance *rootConformance,
870- bool considerResilience,
871870 llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > &visited){
872871 // Self-conformances are never dependent.
873872 auto conformance = dyn_cast<NormalProtocolConformance>(rootConformance);
@@ -880,7 +879,7 @@ static bool isDependentConformance(
880879 return false ;
881880
882881 // If the conformance is resilient, this is always true.
883- if (considerResilience && IGM.isResilientConformance (conformance))
882+ if (IGM.isResilientConformance (conformance))
884883 return true ;
885884
886885 // Check whether any of the conformances are dependent.
@@ -899,7 +898,6 @@ static bool isDependentConformance(
899898 isDependentConformance (IGM,
900899 assocConformance.getConcrete ()
901900 ->getRootConformance (),
902- considerResilience,
903901 visited))
904902 return true ;
905903 }
@@ -916,11 +914,9 @@ static bool isDependentConformance(
916914// / Is there anything about the given conformance that requires witness
917915// / tables to be dependently-generated?
918916bool IRGenModule::isDependentConformance (
919- const RootProtocolConformance *conformance,
920- bool considerResilience) {
917+ const RootProtocolConformance *conformance) {
921918 llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > visited;
922- return ::isDependentConformance (*this , conformance, considerResilience,
923- visited);
919+ return ::isDependentConformance (*this , conformance, visited);
924920}
925921
926922static bool isSynthesizedNonUnique (const RootProtocolConformance *conformance) {
@@ -1140,7 +1136,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
11401136 // offsets, with conditional conformances closest to 0.
11411137 unsigned NextPrivateDataIndex = 0 ;
11421138 bool ResilientConformance;
1143- bool RequiresSpecialization = false ;
11441139
11451140 const ProtocolInfo &PI;
11461141
@@ -1162,21 +1157,14 @@ class AccessorConformanceInfo : public ConformanceInfo {
11621157 PI(IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
11631158 (ResilientConformance
11641159 ? 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))) {}
11701161
11711162 // / The number of entries in the witness table.
11721163 unsigned getTableSize () const { return TableSize; }
11731164
11741165 // / The number of private entries in the witness table.
11751166 unsigned getTablePrivateSize () const { return NextPrivateDataIndex; }
11761167
1177- // / Whether this witness table must be specialized at runtime.
1178- bool requiresSpecialization () const { return RequiresSpecialization; }
1179-
11801168 // / The top-level entry point.
11811169 void build ();
11821170
@@ -1226,7 +1214,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
12261214 }
12271215
12281216 // Otherwise, we'll need to derive it at instantiation time.
1229- RequiresSpecialization = true ;
12301217 SpecializedBaseConformances.push_back ({Table.size (), &conf});
12311218 Table.addNullPointer (IGM.Int8PtrTy );
12321219 }
@@ -1293,8 +1280,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
12931280 auto associate =
12941281 Conformance.getTypeWitness (requirement.getAssociation (), nullptr )
12951282 ->getCanonicalType ();
1296- if (associate->hasTypeParameter ())
1297- RequiresSpecialization = true ;
12981283 llvm::Constant *witness =
12991284 IGM.getAssociatedTypeWitness (associate, /* inProtocolContext=*/ false );
13001285 Table.addBitCast (witness, IGM.Int8PtrTy );
@@ -1319,9 +1304,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
13191304 requirement.getAssociation (),
13201305 requirement.getAssociatedRequirement ());
13211306
1322- if (requirement.getAssociation ()->hasTypeParameter ())
1323- RequiresSpecialization = true ;
1324-
13251307#ifndef NDEBUG
13261308 assert (entry.getKind () == SILWitnessTable::AssociatedTypeProtocol
13271309 && " sil witness table does not match protocol" );
@@ -1372,7 +1354,6 @@ class AccessorConformanceInfo : public ConformanceInfo {
13721354
13731355 // / Allocate another word of private data storage in the conformance table.
13741356 unsigned getNextPrivateDataIndex () {
1375- RequiresSpecialization = true ;
13761357 return NextPrivateDataIndex++;
13771358 }
13781359
@@ -1911,7 +1892,7 @@ namespace {
19111892 // WitnessTablePrivateSizeInWordsAndRequiresInstantiation
19121893 B.addInt (IGM.Int16Ty ,
19131894 (Description.witnessTablePrivateSize << 1 ) |
1914- Description.hasDependentAssociatedTypeWitnesses );
1895+ Description.requiresSpecialization );
19151896 // Instantiation function
19161897 B.addRelativeAddressOrNull (Description.instantiationFn );
19171898 // Private data
@@ -2065,13 +2046,12 @@ IRGenModule::getConformanceInfo(const ProtocolDecl *protocol,
20652046
20662047 const ConformanceInfo *info;
20672048 // 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+ //
20702050 // FIXME: Both implementations of ConformanceInfo are trivially-destructible,
20712051 // so in theory we could allocate them on a BumpPtrAllocator. But there's not
20722052 // a good one for us to use. (The ASTContext's outlives the IRGenModule in
20732053 // batch mode.)
2074- if (isDependentConformance (rootConformance, /* considerResilience= */ true ) ||
2054+ if (isDependentConformance (rootConformance) ||
20752055 // Foreign types need to go through the accessor to unique the witness
20762056 // table.
20772057 isSynthesizedNonUnique (rootConformance)) {
@@ -2143,13 +2123,13 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
21432123 // Produce the initializer value.
21442124 auto initializer = wtableContents.finishAndCreateFuture ();
21452125
2126+ bool isDependent = isDependentConformance (conf);
2127+
21462128 llvm::GlobalVariable *global = nullptr ;
21472129 unsigned tableSize;
21482130 if (!isResilientConformance (conf)) {
2149- bool isDependent =
2150- isDependentConformance (conf, /* considerResilience=*/ false );
21512131 global = cast<llvm::GlobalVariable>(
2152- isDependent
2132+ ( isDependent && conf-> getDeclContext ()-> isGenericContext ())
21532133 ? getAddrOfWitnessTablePattern (cast<NormalProtocolConformance>(conf),
21542134 initializer)
21552135 : getAddrOfWitnessTable (conf, initializer));
@@ -2165,10 +2145,7 @@ void IRGenModule::emitSILWitnessTable(SILWitnessTable *wt) {
21652145 // descriptor.
21662146 ConformanceDescription description (conf, wt, global, tableSize,
21672147 wtableBuilder.getTablePrivateSize (),
2168- wtableBuilder.requiresSpecialization (),
2169- isDependentConformance (
2170- conf,
2171- /* considerResilience=*/ false ));
2148+ isDependent);
21722149
21732150 // Build the instantiation function, we if need one.
21742151 description.instantiationFn = wtableBuilder.buildInstantiationFunction ();
0 commit comments