Skip to content

Commit b3af1a0

Browse files
committed
[NFC] AST: Relocate takeConformanceDiagnostics & getLocalProtocols to IterableDeclContext
1 parent edcf764 commit b3af1a0

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

include/swift/AST/DeclContext.h

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

570-
/// Retrieve the set of protocols whose conformances will be
571-
/// associated with this declaration context.
572-
///
573-
/// This function differs from \c getLocalConformances() in that it
574-
/// returns protocol declarations, not protocol conformances, and
575-
/// therefore does not require the protocol conformances to be
576-
/// formed.
577-
///
578-
/// \param lookupKind The kind of lookup to perform.
579-
///
580-
/// FIXME: This likely makes more sense on IterableDeclContext or
581-
/// something similar.
582-
SmallVector<ProtocolDecl *, 2>
583-
getLocalProtocols(ConformanceLookupKind lookupKind
584-
= ConformanceLookupKind::All) const;
585-
586570
/// Retrieve the set of protocol conformances associated with this
587571
/// declaration context.
588572
///
@@ -594,14 +578,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
594578
getLocalConformances(ConformanceLookupKind lookupKind
595579
= ConformanceLookupKind::All) const;
596580

597-
/// Retrieve diagnostics discovered while expanding conformances for this
598-
/// declaration context. This operation then removes those diagnostics from
599-
/// consideration, so subsequent calls to this function with the same
600-
/// declaration context that have not had any new extensions bound
601-
/// will see an empty array.
602-
SmallVector<ConformanceDiagnostic, 4>
603-
takeConformanceDiagnostics() const;
604-
605581
/// Retrieves a list of separately imported overlays which are shadowing
606582
/// \p declaring. If any \p overlays are returned, qualified lookups into
607583
/// \p declaring should be performed into \p overlays instead; since they
@@ -816,6 +792,26 @@ class IterableDeclContext {
816792
/// valid).
817793
bool wasDeserialized() const;
818794

795+
/// Retrieve the set of protocols whose conformances will be
796+
/// associated with this declaration context.
797+
///
798+
/// This function differs from \c getLocalConformances() in that it
799+
/// returns protocol declarations, not protocol conformances, and
800+
/// therefore does not require the protocol conformances to be
801+
/// formed.
802+
///
803+
/// \param lookupKind The kind of lookup to perform.
804+
SmallVector<ProtocolDecl *, 2>
805+
getLocalProtocols(ConformanceLookupKind lookupKind
806+
= ConformanceLookupKind::All) const;
807+
808+
/// Retrieve diagnostics discovered while expanding conformances for this
809+
/// declaration context. This operation then removes those diagnostics from
810+
/// consideration, so subsequent calls to this function with the same
811+
/// declaration context that have not had any new extensions bound
812+
/// will see an empty array.
813+
SmallVector<ConformanceDiagnostic, 4> takeConformanceDiagnostics() const;
814+
819815
/// Return 'this' as a \c Decl.
820816
const Decl *getDecl() const;
821817

lib/AST/ProtocolConformance.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,11 +1319,12 @@ NominalTypeDecl::getSatisfiedProtocolRequirementsForMember(
13191319
}
13201320

13211321
SmallVector<ProtocolDecl *, 2>
1322-
DeclContext::getLocalProtocols(ConformanceLookupKind lookupKind) const {
1322+
IterableDeclContext::getLocalProtocols(ConformanceLookupKind lookupKind) const {
13231323
SmallVector<ProtocolDecl *, 2> result;
13241324

13251325
// Dig out the nominal type.
1326-
NominalTypeDecl *nominal = getSelfNominalTypeDecl();
1326+
const auto dc = getAsGenericContext();
1327+
const auto nominal = dc->getSelfNominalTypeDecl();
13271328
if (!nominal) {
13281329
return result;
13291330
}
@@ -1332,7 +1333,7 @@ DeclContext::getLocalProtocols(ConformanceLookupKind lookupKind) const {
13321333
nominal->prepareConformanceTable();
13331334
nominal->ConformanceTable->lookupConformances(
13341335
nominal,
1335-
const_cast<DeclContext *>(this),
1336+
const_cast<GenericContext *>(dc),
13361337
lookupKind,
13371338
&result,
13381339
nullptr,
@@ -1375,25 +1376,27 @@ DeclContext::getLocalConformances(ConformanceLookupKind lookupKind) const {
13751376
}
13761377

13771378
SmallVector<ConformanceDiagnostic, 4>
1378-
DeclContext::takeConformanceDiagnostics() const {
1379+
IterableDeclContext::takeConformanceDiagnostics() const {
13791380
SmallVector<ConformanceDiagnostic, 4> result;
13801381

13811382
// Dig out the nominal type.
1382-
NominalTypeDecl *nominal = getSelfNominalTypeDecl();
1383+
const auto dc = getAsGenericContext();
1384+
const auto nominal = dc->getSelfNominalTypeDecl();
1385+
13831386
if (!nominal) {
1384-
return { };
1387+
return result;
13851388
}
13861389

13871390
// Protocols are not subject to the checks for supersession.
13881391
if (isa<ProtocolDecl>(nominal)) {
1389-
return { };
1392+
return result;
13901393
}
13911394

13921395
// Update to record all potential conformances.
13931396
nominal->prepareConformanceTable();
13941397
nominal->ConformanceTable->lookupConformances(
13951398
nominal,
1396-
const_cast<DeclContext *>(this),
1399+
const_cast<GenericContext *>(dc),
13971400
ConformanceLookupKind::All,
13981401
nullptr,
13991402
nullptr,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5103,7 +5103,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
51035103
groupChecker.getUnsatisfiedRequirements().end());
51045104

51055105
// Diagnose any conflicts attributed to this declaration context.
5106-
for (const auto &diag : dc->takeConformanceDiagnostics()) {
5106+
for (const auto &diag : idc->takeConformanceDiagnostics()) {
51075107
// Figure out the declaration of the existing conformance.
51085108
Decl *existingDecl = dyn_cast<NominalTypeDecl>(diag.ExistingDC);
51095109
if (!existingDecl)

0 commit comments

Comments
 (0)