Skip to content

Commit f11f8f0

Browse files
Merge pull request #31899 from AnthonyLatsis/o-checkconformancesincxt
[NFC] Sema: get rid of redundant DeclContext parameter to checkConformancesInContext
2 parents fe0bd4f + c337757 commit f11f8f0

File tree

6 files changed

+19
-22
lines changed

6 files changed

+19
-22
lines changed

include/swift/AST/DeclContext.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,10 @@ class IterableDeclContext {
813813
const Decl *getDecl() const;
814814

815815
/// Return 'this' as a \c GenericContext.
816-
const GenericContext *getAsGenericContext() const;
816+
GenericContext *getAsGenericContext();
817+
const GenericContext *getAsGenericContext() const {
818+
return const_cast<IterableDeclContext *>(this)->getAsGenericContext();
819+
}
817820

818821
/// Get the DeclID this Decl was deserialized from.
819822
serialization::DeclID getDeclID() const {

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ IterableDeclContext::getDecl() const {
773773
llvm_unreachable("Unhandled IterableDeclContextKind in switch.");
774774
}
775775

776-
const GenericContext *IterableDeclContext::getAsGenericContext() const {
776+
GenericContext *IterableDeclContext::getAsGenericContext() {
777777
switch (getIterableContextKind()) {
778778
case IterableDeclContextKind::NominalTypeDecl:
779779
return cast<NominalTypeDecl>(this);

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
372372
return nullptr;
373373

374374
// Forcibly derive conformance to CodingKey.
375-
TypeChecker::checkConformancesInContext(enumDecl, enumDecl);
375+
TypeChecker::checkConformancesInContext(enumDecl);
376376

377377
// Add to the type.
378378
target->addMember(enumDecl);

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
17591759

17601760
TypeChecker::checkDeclCircularity(ED);
17611761

1762-
TypeChecker::checkConformancesInContext(ED, ED);
1762+
TypeChecker::checkConformancesInContext(ED);
17631763
}
17641764

17651765
void visitStructDecl(StructDecl *SD) {
@@ -1789,7 +1789,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
17891789

17901790
TypeChecker::checkDeclCircularity(SD);
17911791

1792-
TypeChecker::checkConformancesInContext(SD, SD);
1792+
TypeChecker::checkConformancesInContext(SD);
17931793
}
17941794

17951795
/// Check whether the given properties can be @NSManaged in this class.
@@ -2023,7 +2023,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
20232023

20242024
TypeChecker::checkDeclCircularity(CD);
20252025

2026-
TypeChecker::checkConformancesInContext(CD, CD);
2026+
TypeChecker::checkConformancesInContext(CD);
20272027

20282028
maybeDiagnoseClassWithoutInitializers(CD);
20292029
}
@@ -2362,7 +2362,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
23622362

23632363
TypeChecker::checkPatternBindingCaptures(ED);
23642364

2365-
TypeChecker::checkConformancesInContext(ED, ED);
2365+
TypeChecker::checkConformancesInContext(ED);
23662366

23672367
TypeChecker::checkDeclAttributes(ED);
23682368
checkAccessControl(ED);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5043,25 +5043,19 @@ LookupAllConformancesInContextRequest::evaluate(
50435043
return IDC->getLocalConformances(ConformanceLookupKind::All);
50445044
}
50455045

5046-
void TypeChecker::checkConformancesInContext(DeclContext *dc,
5047-
IterableDeclContext *idc) {
5046+
void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
5047+
auto *const dc = idc->getAsGenericContext();
5048+
50485049
// For anything imported from Clang, lazily check conformances.
50495050
if (isa<ClangModuleUnit>(dc->getModuleScopeContext()))
50505051
return;
50515052

5053+
const auto *const nominal = dc->getSelfNominalTypeDecl();
5054+
if (!nominal)
5055+
return;
5056+
50525057
// Determine the access level of this conformance.
5053-
Decl *currentDecl = nullptr;
5054-
AccessLevel defaultAccess;
5055-
if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
5056-
const NominalTypeDecl *nominal = ext->getExtendedNominal();
5057-
if (!nominal)
5058-
return;
5059-
defaultAccess = nominal->getFormalAccess();
5060-
currentDecl = ext;
5061-
} else {
5062-
defaultAccess = cast<NominalTypeDecl>(dc)->getFormalAccess();
5063-
currentDecl = cast<NominalTypeDecl>(dc);
5064-
}
5058+
const auto defaultAccess = nominal->getFormalAccess();
50655059

50665060
// Check each of the conformances associated with this context.
50675061
auto conformances =

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ ProtocolConformanceRef conformsToProtocol(Type T, ProtocolDecl *Proto,
915915
void checkConformance(NormalProtocolConformance *conformance);
916916

917917
/// Check all of the conformances in the given context.
918-
void checkConformancesInContext(DeclContext *dc, IterableDeclContext *idc);
918+
void checkConformancesInContext(IterableDeclContext *idc);
919919

920920
/// Check that the type of the given property conforms to NSCopying.
921921
ProtocolConformanceRef checkConformanceToNSCopying(VarDecl *var);

0 commit comments

Comments
 (0)