Skip to content

[NFC] Sema: get rid of redundant DeclContext parameter to checkConfor… #31899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,10 @@ class IterableDeclContext {
const Decl *getDecl() const;

/// Return 'this' as a \c GenericContext.
const GenericContext *getAsGenericContext() const;
GenericContext *getAsGenericContext();
const GenericContext *getAsGenericContext() const {
return const_cast<IterableDeclContext *>(this)->getAsGenericContext();
}

/// Get the DeclID this Decl was deserialized from.
serialization::DeclID getDeclID() const {
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ IterableDeclContext::getDecl() const {
llvm_unreachable("Unhandled IterableDeclContextKind in switch.");
}

const GenericContext *IterableDeclContext::getAsGenericContext() const {
GenericContext *IterableDeclContext::getAsGenericContext() {
switch (getIterableContextKind()) {
case IterableDeclContextKind::NominalTypeDecl:
return cast<NominalTypeDecl>(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
return nullptr;

// Forcibly derive conformance to CodingKey.
TypeChecker::checkConformancesInContext(enumDecl, enumDecl);
TypeChecker::checkConformancesInContext(enumDecl);

// Add to the type.
target->addMember(enumDecl);
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

TypeChecker::checkDeclCircularity(ED);

TypeChecker::checkConformancesInContext(ED, ED);
TypeChecker::checkConformancesInContext(ED);
}

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

TypeChecker::checkDeclCircularity(SD);

TypeChecker::checkConformancesInContext(SD, SD);
TypeChecker::checkConformancesInContext(SD);
}

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

TypeChecker::checkDeclCircularity(CD);

TypeChecker::checkConformancesInContext(CD, CD);
TypeChecker::checkConformancesInContext(CD);

maybeDiagnoseClassWithoutInitializers(CD);
}
Expand Down Expand Up @@ -2362,7 +2362,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

TypeChecker::checkPatternBindingCaptures(ED);

TypeChecker::checkConformancesInContext(ED, ED);
TypeChecker::checkConformancesInContext(ED);

TypeChecker::checkDeclAttributes(ED);
checkAccessControl(ED);
Expand Down
22 changes: 8 additions & 14 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5034,25 +5034,19 @@ LookupAllConformancesInContextRequest::evaluate(
return IDC->getLocalConformances(ConformanceLookupKind::All);
}

void TypeChecker::checkConformancesInContext(DeclContext *dc,
IterableDeclContext *idc) {
void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
auto *const dc = idc->getAsGenericContext();

// For anything imported from Clang, lazily check conformances.
if (isa<ClangModuleUnit>(dc->getModuleScopeContext()))
return;

const auto *const nominal = dc->getSelfNominalTypeDecl();
if (!nominal)
return;

// Determine the access level of this conformance.
Decl *currentDecl = nullptr;
AccessLevel defaultAccess;
if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
const NominalTypeDecl *nominal = ext->getExtendedNominal();
if (!nominal)
return;
defaultAccess = nominal->getFormalAccess();
currentDecl = ext;
} else {
defaultAccess = cast<NominalTypeDecl>(dc)->getFormalAccess();
currentDecl = cast<NominalTypeDecl>(dc);
}
const auto defaultAccess = nominal->getFormalAccess();

// Check each of the conformances associated with this context.
auto conformances =
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ ProtocolConformanceRef conformsToProtocol(Type T, ProtocolDecl *Proto,
void checkConformance(NormalProtocolConformance *conformance);

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

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