Skip to content

Commit 114f856

Browse files
committed
Reimplement IterableDeclContext::getLocalProtocls() using getLocalConformances()
The uncached, rarely-used getLocalProtocols() does not benefit from having its own distinct implementation. Reimplement it on top of getLocalConformances() to simplify things and benefit from the request-evaluator infrastructure.
1 parent 01d4440 commit 114f856

File tree

3 files changed

+7
-62
lines changed

3 files changed

+7
-62
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,7 @@ bool ConformanceLookupTable::lookupConformance(
955955
void ConformanceLookupTable::lookupConformances(
956956
NominalTypeDecl *nominal,
957957
DeclContext *dc,
958-
ConformanceLookupKind lookupKind,
959-
SmallVectorImpl<ProtocolDecl *> *protocols,
960-
SmallVectorImpl<ProtocolConformance *> *conformances,
958+
std::vector<ProtocolConformance *> *conformances,
961959
SmallVectorImpl<ConformanceDiagnostic> *diagnostics) {
962960
// We need to expand all implied conformances before we can find
963961
// those conformances that pertain to this declaration context.
@@ -980,36 +978,6 @@ void ConformanceLookupTable::lookupConformances(
980978
if (entry->isSuperseded())
981979
return true;
982980

983-
// If we are to filter out this result, do so now.
984-
switch (lookupKind) {
985-
case ConformanceLookupKind::OnlyExplicit:
986-
switch (entry->getKind()) {
987-
case ConformanceEntryKind::Explicit:
988-
case ConformanceEntryKind::Synthesized:
989-
break;
990-
case ConformanceEntryKind::Implied:
991-
case ConformanceEntryKind::Inherited:
992-
return false;
993-
}
994-
break;
995-
case ConformanceLookupKind::NonInherited:
996-
switch (entry->getKind()) {
997-
case ConformanceEntryKind::Explicit:
998-
case ConformanceEntryKind::Synthesized:
999-
case ConformanceEntryKind::Implied:
1000-
break;
1001-
case ConformanceEntryKind::Inherited:
1002-
return false;
1003-
}
1004-
break;
1005-
case ConformanceLookupKind::All:
1006-
break;
1007-
}
1008-
1009-
// Record the protocol.
1010-
if (protocols)
1011-
protocols->push_back(entry->getProtocol());
1012-
1013981
// Record the conformance.
1014982
if (conformances) {
1015983
if (auto conformance = getConformance(nominal, entry))

lib/AST/ConformanceLookupTable.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ class ConformanceLookupTable {
437437
/// Look for all of the conformances within the given declaration context.
438438
void lookupConformances(NominalTypeDecl *nominal,
439439
DeclContext *dc,
440-
ConformanceLookupKind lookupKind,
441-
SmallVectorImpl<ProtocolDecl *> *protocols,
442-
SmallVectorImpl<ProtocolConformance *> *conformances,
440+
std::vector<ProtocolConformance *> *conformances,
443441
SmallVectorImpl<ConformanceDiagnostic> *diagnostics);
444442

445443
/// Retrieve the complete set of protocols to which this nominal

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,24 +1321,8 @@ NominalTypeDecl::getSatisfiedProtocolRequirementsForMember(
13211321
SmallVector<ProtocolDecl *, 2>
13221322
IterableDeclContext::getLocalProtocols(ConformanceLookupKind lookupKind) const {
13231323
SmallVector<ProtocolDecl *, 2> result;
1324-
1325-
// Dig out the nominal type.
1326-
const auto dc = getAsGenericContext();
1327-
const auto nominal = dc->getSelfNominalTypeDecl();
1328-
if (!nominal) {
1329-
return result;
1330-
}
1331-
1332-
// Update to record all potential conformances.
1333-
nominal->prepareConformanceTable();
1334-
nominal->ConformanceTable->lookupConformances(
1335-
nominal,
1336-
const_cast<GenericContext *>(dc),
1337-
lookupKind,
1338-
&result,
1339-
nullptr,
1340-
nullptr);
1341-
1324+
for (auto conformance : getLocalConformances(lookupKind))
1325+
result.push_back(conformance->getProtocol());
13421326
return result;
13431327
}
13441328

@@ -1361,19 +1345,16 @@ LookupAllConformancesInContextRequest::evaluate(
13611345
return { };
13621346
}
13631347

1364-
// Update to record all potential conformances.
1348+
// Record all potential conformances.
13651349
nominal->prepareConformanceTable();
1366-
SmallVector<ProtocolConformance *, 4> conformances;
1350+
std::vector<ProtocolConformance *> conformances;
13671351
nominal->ConformanceTable->lookupConformances(
13681352
nominal,
13691353
const_cast<GenericContext *>(dc),
1370-
ConformanceLookupKind::All,
1371-
nullptr,
13721354
&conformances,
13731355
nullptr);
13741356

1375-
return std::vector<ProtocolConformance *>(
1376-
conformances.begin(), conformances.end());
1357+
return conformances;
13771358
}
13781359

13791360
SmallVector<ProtocolConformance *, 2>
@@ -1442,8 +1423,6 @@ IterableDeclContext::takeConformanceDiagnostics() const {
14421423
nominal->ConformanceTable->lookupConformances(
14431424
nominal,
14441425
const_cast<GenericContext *>(dc),
1445-
ConformanceLookupKind::All,
1446-
nullptr,
14471426
nullptr,
14481427
&result);
14491428

0 commit comments

Comments
 (0)