Skip to content

Commit bfe25fa

Browse files
committed
[NFC] AST: Relocate getLocalConformances to IterableDeclContext
1 parent b3af1a0 commit bfe25fa

14 files changed

+52
-52
lines changed

include/swift/AST/DeclContext.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -567,17 +567,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
567567
LLVM_READONLY
568568
ASTContext &getASTContext() const;
569569

570-
/// Retrieve the set of protocol conformances associated with this
571-
/// declaration context.
572-
///
573-
/// \param lookupKind The kind of lookup to perform.
574-
///
575-
/// FIXME: This likely makes more sense on IterableDeclContext or
576-
/// something similar.
577-
SmallVector<ProtocolConformance *, 2>
578-
getLocalConformances(ConformanceLookupKind lookupKind
579-
= ConformanceLookupKind::All) const;
580-
581570
/// Retrieves a list of separately imported overlays which are shadowing
582571
/// \p declaring. If any \p overlays are returned, qualified lookups into
583572
/// \p declaring should be performed into \p overlays instead; since they
@@ -805,6 +794,14 @@ class IterableDeclContext {
805794
getLocalProtocols(ConformanceLookupKind lookupKind
806795
= ConformanceLookupKind::All) const;
807796

797+
/// Retrieve the set of protocol conformances associated with this
798+
/// declaration context.
799+
///
800+
/// \param lookupKind The kind of lookup to perform.
801+
SmallVector<ProtocolConformance *, 2>
802+
getLocalConformances(ConformanceLookupKind lookupKind
803+
= ConformanceLookupKind::All) const;
804+
808805
/// Retrieve diagnostics discovered while expanding conformances for this
809806
/// declaration context. This operation then removes those diagnostics from
810807
/// consideration, so subsequent calls to this function with the same

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,8 @@ void simple_display(llvm::raw_ostream &out, ConformanceLookupKind kind);
22592259
/// must also be reported so it can be checked as well.
22602260
class LookupAllConformancesInContextRequest
22612261
: public SimpleRequest<LookupAllConformancesInContextRequest,
2262-
ProtocolConformanceLookupResult(const DeclContext *),
2262+
ProtocolConformanceLookupResult(
2263+
const IterableDeclContext *),
22632264
RequestFlags::Uncached |
22642265
RequestFlags::DependencySink |
22652266
RequestFlags::DependencySource> {
@@ -2271,7 +2272,7 @@ class LookupAllConformancesInContextRequest
22712272

22722273
// Evaluation.
22732274
ProtocolConformanceLookupResult
2274-
evaluate(Evaluator &evaluator, const DeclContext *DC) const;
2275+
evaluate(Evaluator &evaluator, const IterableDeclContext *IDC) const;
22752276

22762277
public:
22772278
// Incremental dependencies

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ SWIFT_REQUEST(TypeChecker, ScopedImportLookupRequest,
256256
SWIFT_REQUEST(TypeChecker, ClosureHasExplicitResultRequest,
257257
bool(ClosureExpr *), Cached, NoLocationInfo)
258258
SWIFT_REQUEST(TypeChecker, LookupAllConformancesInContextRequest,
259-
ProtocolConformanceLookupResult(const DeclContext *),
259+
ProtocolConformanceLookupResult(const IterableDeclContext *),
260260
Uncached, NoLocationInfo)
261261
SWIFT_REQUEST(TypeChecker, SimpleDidSetRequest,
262262
bool(AccessorDecl *), Cached, NoLocationInfo)

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,13 @@ IterableDeclContext::getLocalProtocols(ConformanceLookupKind lookupKind) const {
13431343
}
13441344

13451345
SmallVector<ProtocolConformance *, 2>
1346-
DeclContext::getLocalConformances(ConformanceLookupKind lookupKind) const {
1346+
IterableDeclContext::getLocalConformances(ConformanceLookupKind lookupKind)
1347+
const {
13471348
SmallVector<ProtocolConformance *, 2> result;
13481349

13491350
// Dig out the nominal type.
1350-
NominalTypeDecl *nominal = getSelfNominalTypeDecl();
1351+
const auto dc = getAsGenericContext();
1352+
const auto nominal = dc->getSelfNominalTypeDecl();
13511353
if (!nominal) {
13521354
return result;
13531355
}
@@ -1366,7 +1368,7 @@ DeclContext::getLocalConformances(ConformanceLookupKind lookupKind) const {
13661368
nominal->prepareConformanceTable();
13671369
nominal->ConformanceTable->lookupConformances(
13681370
nominal,
1369-
const_cast<DeclContext *>(this),
1371+
const_cast<GenericContext *>(dc),
13701372
lookupKind,
13711373
nullptr,
13721374
&result,

lib/AST/TypeCheckRequests.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,20 +1385,16 @@ void CheckRedeclarationRequest::writeDependencySink(
13851385
evaluator::DependencySource
13861386
LookupAllConformancesInContextRequest::readDependencySource(
13871387
const evaluator::DependencyCollector &collector) const {
1388-
auto *dc = std::get<0>(getStorage());
1389-
AccessLevel defaultAccess;
1390-
if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
1391-
const NominalTypeDecl *nominal = ext->getExtendedNominal();
1392-
if (!nominal) {
1393-
return {collector.getActiveDependencySourceOrNull(),
1394-
evaluator::DependencyScope::Cascading};
1395-
}
1396-
defaultAccess = nominal->getFormalAccess();
1397-
} else {
1398-
defaultAccess = cast<NominalTypeDecl>(dc)->getFormalAccess();
1388+
const auto *nominal = std::get<0>(getStorage())
1389+
->getAsGenericContext()
1390+
->getSelfNominalTypeDecl();
1391+
if (!nominal) {
1392+
return {collector.getActiveDependencySourceOrNull(),
1393+
evaluator::DependencyScope::Cascading};
13991394
}
1395+
14001396
return {collector.getActiveDependencySourceOrNull(),
1401-
evaluator::getScopeForAccessLevel(defaultAccess)};
1397+
evaluator::getScopeForAccessLevel(nominal->getFormalAccess())};
14021398
}
14031399

14041400
void LookupAllConformancesInContextRequest::writeDependencySink(

lib/IDE/Refactoring.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,8 @@ bool RefactoringActionConvertToTernaryExpr::performChange() {
27302730
/// these stubs should be filled.
27312731
class FillProtocolStubContext {
27322732

2733-
std::vector<ValueDecl*> getUnsatisfiedRequirements(const DeclContext *DC);
2733+
std::vector<ValueDecl*>
2734+
getUnsatisfiedRequirements(const IterableDeclContext *IDC);
27342735

27352736
/// Context in which the content should be filled; this could be either a
27362737
/// nominal type declaraion or an extension declaration.
@@ -2801,12 +2802,12 @@ getContextFromCursorInfo(ResolvedCursorInfo CursorInfo) {
28012802
}
28022803

28032804
std::vector<ValueDecl*> FillProtocolStubContext::
2804-
getUnsatisfiedRequirements(const DeclContext *DC) {
2805+
getUnsatisfiedRequirements(const IterableDeclContext *IDC) {
28052806
// The results to return.
28062807
std::vector<ValueDecl*> NonWitnessedReqs;
28072808

28082809
// For each conformance of the extended nominal.
2809-
for(ProtocolConformance *Con : DC->getLocalConformances()) {
2810+
for(ProtocolConformance *Con : IDC->getLocalConformances()) {
28102811

28112812
// Collect non-witnessed requirements.
28122813
Con->forEachNonWitnessedRequirement(

lib/IRGen/GenClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,9 @@ namespace {
11161116

11171117
/// Gather protocol records for all of the explicitly-specified Objective-C
11181118
/// protocol conformances.
1119-
void visitConformances(DeclContext *dc) {
1119+
void visitConformances(const IterableDeclContext *idc) {
11201120
llvm::SmallSetVector<ProtocolDecl *, 2> protocols;
1121-
for (auto conformance : dc->getLocalConformances(
1121+
for (auto conformance : idc->getLocalConformances(
11221122
ConformanceLookupKind::OnlyExplicit)) {
11231123
ProtocolDecl *proto = conformance->getProtocol();
11241124
getObjCProtocols(proto, protocols);

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,9 @@ IRGenModule::getConstantReferenceForProtocolDescriptor(ProtocolDecl *proto) {
913913
LinkEntity::forProtocolDescriptor(proto));
914914
}
915915

916-
void IRGenModule::addLazyConformances(DeclContext *dc) {
916+
void IRGenModule::addLazyConformances(const IterableDeclContext *idc) {
917917
for (const ProtocolConformance *conf :
918-
dc->getLocalConformances(ConformanceLookupKind::All)) {
918+
idc->getLocalConformances(ConformanceLookupKind::All)) {
919919
IRGen.addLazyWitnessTable(conf);
920920
}
921921
}

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,9 @@ private: \
15861586
void addRuntimeResolvableType(GenericTypeDecl *nominal);
15871587
void maybeEmitOpaqueTypeDecl(OpaqueTypeDecl *opaque);
15881588

1589-
/// Add all conformances of the given \c DeclContext LazyWitnessTables.
1590-
void addLazyConformances(DeclContext *dc);
1589+
/// Add all conformances of the given \c IterableDeclContext
1590+
/// LazyWitnessTables.
1591+
void addLazyConformances(const IterableDeclContext *idc);
15911592

15921593
//--- Global context emission --------------------------------------------------
15931594
public:

lib/Index/Index.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,12 @@ bool IndexSwiftASTWalker::visitImports(
777777
}
778778

779779
bool IndexSwiftASTWalker::handleWitnesses(Decl *D, SmallVectorImpl<IndexedWitness> &explicitWitnesses) {
780-
auto DC = dyn_cast<DeclContext>(D);
781-
if (!DC)
780+
const auto *const IDC = dyn_cast<IterableDeclContext>(D);
781+
if (!IDC)
782782
return true;
783783

784-
for (auto *conf : DC->getLocalConformances()) {
784+
const auto DC = IDC->getAsGenericContext();
785+
for (auto *conf : IDC->getLocalConformances()) {
785786
if (conf->isInvalid())
786787
continue;
787788

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,11 @@ getHashValueRequirement(ASTContext &C) {
10261026
}
10271027

10281028
static ProtocolConformance *
1029-
getHashableConformance(Decl *parentDecl) {
1029+
getHashableConformance(const Decl *parentDecl) {
10301030
ASTContext &C = parentDecl->getASTContext();
1031-
auto DC = cast<DeclContext>(parentDecl);
1031+
const auto IDC = cast<IterableDeclContext>(parentDecl);
10321032
auto hashableProto = C.getProtocol(KnownProtocolKind::Hashable);
1033-
for (auto conformance: DC->getLocalConformances()) {
1033+
for (auto conformance: IDC->getLocalConformances()) {
10341034
if (conformance->getProtocol() == hashableProto) {
10351035
return conformance;
10361036
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,8 +5023,8 @@ diagnoseMissingAppendInterpolationMethod(NominalTypeDecl *typeDecl) {
50235023

50245024
SmallVector<ProtocolConformance *, 2>
50255025
LookupAllConformancesInContextRequest::evaluate(
5026-
Evaluator &eval, const DeclContext *DC) const {
5027-
return DC->getLocalConformances(ConformanceLookupKind::All);
5026+
Evaluator &eval, const IterableDeclContext *IDC) const {
5027+
return IDC->getLocalConformances(ConformanceLookupKind::All);
50285028
}
50295029

50305030
void TypeChecker::checkConformancesInContext(DeclContext *dc,
@@ -5050,7 +5050,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
50505050
// Check each of the conformances associated with this context.
50515051
auto conformances =
50525052
evaluateOrDefault(dc->getASTContext().evaluator,
5053-
LookupAllConformancesInContextRequest{dc}, {});
5053+
LookupAllConformancesInContextRequest{idc}, {});
50545054

50555055
// The conformance checker bundle that checks all conformances in the context.
50565056
auto &Context = dc->getASTContext();

lib/TBDGen/TBDGen.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ void TBDGenVisitor::addBaseConformanceDescriptor(
444444
addSymbol(entity);
445445
}
446446

447-
void TBDGenVisitor::addConformances(DeclContext *DC) {
448-
for (auto conformance : DC->getLocalConformances(
447+
void TBDGenVisitor::addConformances(const IterableDeclContext *IDC) {
448+
for (auto conformance : IDC->getLocalConformances(
449449
ConformanceLookupKind::NonInherited)) {
450450
auto protocol = conformance->getProtocol();
451451
auto needsWTable =
@@ -462,8 +462,9 @@ void TBDGenVisitor::addConformances(DeclContext *DC) {
462462
// We cannot emit the witness table symbol if the protocol is imported from
463463
// another module and it's resilient, because initialization of that protocol
464464
// is necessary in this case
465-
if (!rootConformance->getProtocol()->isResilient(DC->getParentModule(),
466-
ResilienceExpansion::Maximal))
465+
if (!rootConformance->getProtocol()->isResilient(
466+
IDC->getAsGenericContext()->getParentModule(),
467+
ResilienceExpansion::Maximal))
467468
addSymbol(LinkEntity::forProtocolWitnessTable(rootConformance));
468469
addSymbol(LinkEntity::forProtocolConformanceDescriptor(rootConformance));
469470

lib/TBDGen/TBDGenVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9595

9696
void addSymbol(LinkEntity entity);
9797

98-
void addConformances(DeclContext *DC);
98+
void addConformances(const IterableDeclContext *IDC);
9999

100100
void addDispatchThunk(SILDeclRef declRef);
101101

0 commit comments

Comments
 (0)