Skip to content

Commit d1a4361

Browse files
committed
[Conformance lookup table] Drop unnecessary LazyResolver parameters.
There is no point in threading LazyResolver parameters through this data structure; we can recover the resolver in the one place it is needed.
1 parent 5fbd756 commit d1a4361

File tree

3 files changed

+32
-60
lines changed

3 files changed

+32
-60
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ void *ConformanceLookupTable::operator new(size_t Bytes,
126126
return C.Allocate(Bytes, Alignment);
127127
}
128128

129-
ConformanceLookupTable::ConformanceLookupTable(ASTContext &ctx,
130-
LazyResolver *resolver) {
129+
ConformanceLookupTable::ConformanceLookupTable(ASTContext &ctx) {
131130
// Register a cleanup with the ASTContext to call the conformance
132131
// table destructor.
133132
ctx.addCleanup([this]() {
@@ -146,7 +145,6 @@ namespace {
146145
template<typename NominalFunc, typename ExtensionFunc>
147146
void ConformanceLookupTable::forEachInStage(ConformanceStage stage,
148147
NominalTypeDecl *nominal,
149-
LazyResolver *resolver,
150148
NominalFunc nominalFunc,
151149
ExtensionFunc extensionFunc) {
152150
assert(static_cast<unsigned>(stage) < NumConformanceStages &&
@@ -212,8 +210,7 @@ void ConformanceLookupTable::forEachInStage(ConformanceStage stage,
212210

213211
void ConformanceLookupTable::inheritConformances(ClassDecl *classDecl,
214212
ClassDecl *superclassDecl,
215-
ExtensionDecl *superclassExt,
216-
LazyResolver *resolver) {
213+
ExtensionDecl *superclassExt) {
217214
// Local function to return the location of the superclass. This
218215
// takes a little digging, so compute on first use and cache it.
219216
SourceLoc superclassLoc;
@@ -267,13 +264,12 @@ void ConformanceLookupTable::inheritConformances(ClassDecl *classDecl,
267264
}
268265

269266
void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
270-
ConformanceStage stage,
271-
LazyResolver *resolver) {
267+
ConformanceStage stage) {
272268
switch (stage) {
273269
case ConformanceStage::RecordedExplicit:
274270
// Record all of the explicit conformances.
275271
forEachInStage(
276-
stage, nominal, resolver,
272+
stage, nominal,
277273
[&](NominalTypeDecl *nominal) {
278274
addInheritedProtocols(nominal,
279275
ConformanceSource::forExplicit(nominal));
@@ -289,7 +285,7 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
289285
break;
290286

291287
case ConformanceStage::Inherited:
292-
updateLookupTable(nominal, ConformanceStage::RecordedExplicit, resolver);
288+
updateLookupTable(nominal, ConformanceStage::RecordedExplicit);
293289

294290
// For classes, expand implied conformances of the superclass,
295291
// because an implied conformance in the superclass is considered
@@ -310,8 +306,7 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
310306
superclassDecl->prepareConformanceTable();
311307
superclassDecl->ConformanceTable->updateLookupTable(
312308
superclassDecl,
313-
ConformanceStage::Resolved,
314-
resolver);
309+
ConformanceStage::Resolved);
315310

316311
// Expand inherited conformances from all superclasses.
317312
// We may have circular inheritance in ill-formed classes, so keep an
@@ -320,15 +315,14 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
320315

321316
do {
322317
forEachInStage(
323-
stage, superclassDecl, resolver,
318+
stage, superclassDecl,
324319
[&](NominalTypeDecl *superclass) {
325-
inheritConformances(classDecl, superclassDecl, nullptr,
326-
resolver);
320+
inheritConformances(classDecl, superclassDecl, nullptr);
327321
},
328322
[&](ExtensionDecl *ext,
329323
ArrayRef<ConformanceConstructionInfo> protos) {
330324
(void)protos;
331-
inheritConformances(classDecl, superclassDecl, ext, resolver);
325+
inheritConformances(classDecl, superclassDecl, ext);
332326
});
333327
superclassDecl = superclassDecl->getSuperclassDecl();
334328
if (circularSuperclass)
@@ -343,30 +337,30 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
343337
case ConformanceStage::ExpandedImplied:
344338
// Record explicit conformances and import inherited conformances
345339
// before expanding.
346-
updateLookupTable(nominal, ConformanceStage::Inherited, resolver);
340+
updateLookupTable(nominal, ConformanceStage::Inherited);
347341

348342
// Expand inherited conformances.
349343
forEachInStage(
350-
stage, nominal, resolver,
344+
stage, nominal,
351345
[&](NominalTypeDecl *nominal) {
352-
expandImpliedConformances(nominal, nominal, resolver);
346+
expandImpliedConformances(nominal, nominal);
353347
},
354348
[&](ExtensionDecl *ext,
355349
ArrayRef<ConformanceConstructionInfo> protos) {
356350
(void)protos;
357-
expandImpliedConformances(nominal, ext, resolver);
351+
expandImpliedConformances(nominal, ext);
358352
});
359353
break;
360354

361355
case ConformanceStage::Resolved:
362356
// Expand inherited conformances so we have the complete set of
363357
// conformances.
364-
updateLookupTable(nominal, ConformanceStage::ExpandedImplied, resolver);
358+
updateLookupTable(nominal, ConformanceStage::ExpandedImplied);
365359

366360
/// Determine whether any extensions were added that might require
367361
/// us to compute conformances again.
368362
bool anyChanged = false;
369-
forEachInStage(stage, nominal, resolver,
363+
forEachInStage(stage, nominal,
370364
[&](NominalTypeDecl *nominal) { anyChanged = true; },
371365
[&](ExtensionDecl *ext,
372366
ArrayRef<ConformanceConstructionInfo>) {
@@ -481,8 +475,7 @@ void ConformanceLookupTable::addInheritedProtocols(
481475
}
482476

483477
void ConformanceLookupTable::expandImpliedConformances(NominalTypeDecl *nominal,
484-
DeclContext *dc,
485-
LazyResolver *resolver) {
478+
DeclContext *dc) {
486479
// Note: recursive type-checking implies that AllConformances
487480
// may be reallocated during this traversal, so pay the lookup cost
488481
// during each iteration.
@@ -941,16 +934,15 @@ bool ConformanceLookupTable::lookupConformance(
941934
ModuleDecl *module,
942935
NominalTypeDecl *nominal,
943936
ProtocolDecl *protocol,
944-
LazyResolver *resolver,
945937
SmallVectorImpl<ProtocolConformance *> &conformances) {
946938
// Update to record all explicit and inherited conformances.
947-
updateLookupTable(nominal, ConformanceStage::Inherited, resolver);
939+
updateLookupTable(nominal, ConformanceStage::Inherited);
948940

949941
// Look for conformances to this protocol.
950942
auto known = Conformances.find(protocol);
951943
if (known == Conformances.end()) {
952944
// If we didn't find anything, expand implied conformances.
953-
updateLookupTable(nominal, ConformanceStage::ExpandedImplied, resolver);
945+
updateLookupTable(nominal, ConformanceStage::ExpandedImplied);
954946
known = Conformances.find(protocol);
955947

956948
// We didn't find anything.
@@ -971,14 +963,13 @@ bool ConformanceLookupTable::lookupConformance(
971963
void ConformanceLookupTable::lookupConformances(
972964
NominalTypeDecl *nominal,
973965
DeclContext *dc,
974-
LazyResolver *resolver,
975966
ConformanceLookupKind lookupKind,
976967
SmallVectorImpl<ProtocolDecl *> *protocols,
977968
SmallVectorImpl<ProtocolConformance *> *conformances,
978969
SmallVectorImpl<ConformanceDiagnostic> *diagnostics) {
979970
// We need to expand all implied conformances before we can find
980971
// those conformances that pertain to this declaration context.
981-
updateLookupTable(nominal, ConformanceStage::ExpandedImplied, resolver);
972+
updateLookupTable(nominal, ConformanceStage::ExpandedImplied);
982973

983974
/// Resolve conformances for each of the protocols to which this
984975
/// declaration may provide a conformance. Only some of these will
@@ -1041,11 +1032,10 @@ void ConformanceLookupTable::lookupConformances(
10411032

10421033
void ConformanceLookupTable::getAllProtocols(
10431034
NominalTypeDecl *nominal,
1044-
LazyResolver *resolver,
10451035
SmallVectorImpl<ProtocolDecl *> &scratch) {
10461036
// We need to expand all implied conformances to find the complete
10471037
// set of protocols to which this nominal type conforms.
1048-
updateLookupTable(nominal, ConformanceStage::ExpandedImplied, resolver);
1038+
updateLookupTable(nominal, ConformanceStage::ExpandedImplied);
10491039

10501040
// Gather all of the protocols.
10511041
for (const auto &conformance : Conformances) {
@@ -1096,11 +1086,10 @@ int ConformanceLookupTable::compareProtocolConformances(
10961086

10971087
void ConformanceLookupTable::getAllConformances(
10981088
NominalTypeDecl *nominal,
1099-
LazyResolver *resolver,
11001089
bool sorted,
11011090
SmallVectorImpl<ProtocolConformance *> &scratch) {
11021091
// We need to expand and resolve all conformances to enumerate them.
1103-
updateLookupTable(nominal, ConformanceStage::Resolved, resolver);
1092+
updateLookupTable(nominal, ConformanceStage::Resolved);
11041093

11051094
// Gather all of the protocols.
11061095
for (const auto &conformance : AllConformances) {
@@ -1131,24 +1120,23 @@ ArrayRef<ValueDecl *>
11311120
ConformanceLookupTable::getSatisfiedProtocolRequirementsForMember(
11321121
const ValueDecl *member,
11331122
NominalTypeDecl *nominal,
1134-
LazyResolver *resolver,
11351123
bool sorted) {
11361124
auto It = ConformingDeclMap.find(member);
11371125
if (It != ConformingDeclMap.end())
11381126
return It->second;
11391127

11401128
SmallVector<ProtocolConformance *, 4> result;
1141-
getAllConformances(nominal, resolver, sorted, result);
1129+
getAllConformances(nominal, sorted, result);
11421130

11431131
auto &reqs = ConformingDeclMap[member];
11441132
if (isa<TypeDecl>(member)) {
11451133
for (auto *conf : result) {
11461134
if (conf->isInvalid())
11471135
continue;
11481136

1149-
conf->forEachTypeWitness(resolver, [&](const AssociatedTypeDecl *assoc,
1150-
Type type,
1151-
TypeDecl *typeDecl) -> bool {
1137+
conf->forEachTypeWitness(nullptr, [&](const AssociatedTypeDecl *assoc,
1138+
Type type,
1139+
TypeDecl *typeDecl) -> bool {
11521140
if (typeDecl == member)
11531141
reqs.push_back(const_cast<AssociatedTypeDecl*>(assoc));
11541142
return false;
@@ -1160,8 +1148,8 @@ ConformanceLookupTable::getSatisfiedProtocolRequirementsForMember(
11601148
continue;
11611149

11621150
auto normal = conf->getRootNormalConformance();
1163-
normal->forEachValueWitness(resolver, [&](ValueDecl *req,
1164-
Witness witness) {
1151+
normal->forEachValueWitness(nullptr,
1152+
[&](ValueDecl *req, Witness witness) {
11651153
if (witness.getDecl() == member)
11661154
reqs.push_back(req);
11671155
});

lib/AST/ConformanceLookupTable.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ class ConformanceLookupTable {
333333
ConformanceSource source);
334334

335335
/// Expand the implied conformances for the given DeclContext.
336-
void expandImpliedConformances(NominalTypeDecl *nominal, DeclContext *dc,
337-
LazyResolver *resolver);
336+
void expandImpliedConformances(NominalTypeDecl *nominal, DeclContext *dc);
338337

339338
/// A three-way ordering
340339
enum class Ordering {
@@ -384,7 +383,6 @@ class ConformanceLookupTable {
384383
template<typename NominalFunc, typename ExtensionFunc>
385384
void forEachInStage(ConformanceStage stage,
386385
NominalTypeDecl *nominal,
387-
LazyResolver *resolver,
388386
NominalFunc nominalFunc,
389387
ExtensionFunc extensionFunc);
390388

@@ -402,12 +400,10 @@ class ConformanceLookupTable {
402400
/// on the superclass declaration itself will be inherited.
403401
void inheritConformances(ClassDecl *classDecl,
404402
ClassDecl *superclassDecl,
405-
ExtensionDecl *superclassExt,
406-
LazyResolver *resolver);
403+
ExtensionDecl *superclassExt);
407404

408405
/// Update a lookup table with conformances from newly-added extensions.
409-
void updateLookupTable(NominalTypeDecl *nominal, ConformanceStage stage,
410-
LazyResolver *resolver);
406+
void updateLookupTable(NominalTypeDecl *nominal, ConformanceStage stage);
411407

412408
/// Load all of the protocol conformances for the given (serialized)
413409
/// declaration context.
@@ -416,7 +412,7 @@ class ConformanceLookupTable {
416412

417413
public:
418414
/// Create a new conformance lookup table.
419-
ConformanceLookupTable(ASTContext &ctx, LazyResolver *resolver);
415+
ConformanceLookupTable(ASTContext &ctx);
420416

421417
/// Destroy the conformance table.
422418
void destroy();
@@ -438,13 +434,11 @@ class ConformanceLookupTable {
438434
bool lookupConformance(ModuleDecl *module,
439435
NominalTypeDecl *nominal,
440436
ProtocolDecl *protocol,
441-
LazyResolver *resolver,
442437
SmallVectorImpl<ProtocolConformance *> &conformances);
443438

444439
/// Look for all of the conformances within the given declaration context.
445440
void lookupConformances(NominalTypeDecl *nominal,
446441
DeclContext *dc,
447-
LazyResolver *resolver,
448442
ConformanceLookupKind lookupKind,
449443
SmallVectorImpl<ProtocolDecl *> *protocols,
450444
SmallVectorImpl<ProtocolConformance *> *conformances,
@@ -453,13 +447,11 @@ class ConformanceLookupTable {
453447
/// Retrieve the complete set of protocols to which this nominal
454448
/// type conforms.
455449
void getAllProtocols(NominalTypeDecl *nominal,
456-
LazyResolver *resolver,
457450
SmallVectorImpl<ProtocolDecl *> &scratch);
458451

459452
/// Retrieve the complete set of protocol conformances for this
460453
/// nominal type.
461454
void getAllConformances(NominalTypeDecl *nominal,
462-
LazyResolver *resolver,
463455
bool sorted,
464456
SmallVectorImpl<ProtocolConformance *> &scratch);
465457

@@ -474,7 +466,6 @@ class ConformanceLookupTable {
474466
ArrayRef<ValueDecl *>
475467
getSatisfiedProtocolRequirementsForMember(const ValueDecl *member,
476468
NominalTypeDecl *nominal,
477-
LazyResolver *resolver,
478469
bool sorted);
479470

480471
// Only allow allocation of conformance lookup tables using the

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,7 @@ void NominalTypeDecl::prepareConformanceTable() const {
11371137

11381138
auto mutableThis = const_cast<NominalTypeDecl *>(this);
11391139
ASTContext &ctx = getASTContext();
1140-
auto resolver = ctx.getLazyResolver();
1141-
ConformanceTable = new (ctx) ConformanceLookupTable(ctx, resolver);
1140+
ConformanceTable = new (ctx) ConformanceLookupTable(ctx);
11421141
++NumConformanceLookupTables;
11431142

11441143
// If this type declaration was not parsed from source code or introduced
@@ -1190,15 +1189,13 @@ bool NominalTypeDecl::lookupConformance(
11901189
module,
11911190
const_cast<NominalTypeDecl *>(this),
11921191
protocol,
1193-
getASTContext().getLazyResolver(),
11941192
conformances);
11951193
}
11961194

11971195
SmallVector<ProtocolDecl *, 2> NominalTypeDecl::getAllProtocols() const {
11981196
prepareConformanceTable();
11991197
SmallVector<ProtocolDecl *, 2> result;
12001198
ConformanceTable->getAllProtocols(const_cast<NominalTypeDecl *>(this),
1201-
getASTContext().getLazyResolver(),
12021199
result);
12031200
return result;
12041201
}
@@ -1209,7 +1206,6 @@ SmallVector<ProtocolConformance *, 2> NominalTypeDecl::getAllConformances(
12091206
prepareConformanceTable();
12101207
SmallVector<ProtocolConformance *, 2> result;
12111208
ConformanceTable->getAllConformances(const_cast<NominalTypeDecl *>(this),
1212-
getASTContext().getLazyResolver(),
12131209
sorted,
12141210
result);
12151211
return result;
@@ -1237,7 +1233,6 @@ NominalTypeDecl::getSatisfiedProtocolRequirementsForMember(
12371233
prepareConformanceTable();
12381234
return ConformanceTable->getSatisfiedProtocolRequirementsForMember(member,
12391235
const_cast<NominalTypeDecl *>(this),
1240-
getASTContext().getLazyResolver(),
12411236
sorted);
12421237
}
12431238

@@ -1259,7 +1254,6 @@ DeclContext::getLocalProtocols(
12591254
nominal->ConformanceTable->lookupConformances(
12601255
nominal,
12611256
const_cast<DeclContext *>(this),
1262-
getASTContext().getLazyResolver(),
12631257
lookupKind,
12641258
&result,
12651259
nullptr,
@@ -1295,7 +1289,6 @@ DeclContext::getLocalConformances(
12951289
nominal->ConformanceTable->lookupConformances(
12961290
nominal,
12971291
const_cast<DeclContext *>(this),
1298-
nominal->getASTContext().getLazyResolver(),
12991292
lookupKind,
13001293
nullptr,
13011294
&result,

0 commit comments

Comments
 (0)