Skip to content

Commit 38e0f38

Browse files
authored
Merge pull request #20408 from slavapestov/remove-is-extension-context
AST: Remove DeclContext::isExtensionContext()
2 parents 019919d + 564695d commit 38e0f38

File tree

11 files changed

+19
-34
lines changed

11 files changed

+19
-34
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6795,12 +6795,6 @@ inline const GenericContext *Decl::getAsGenericContext() const {
67956795
}
67966796
}
67976797

6798-
inline bool DeclContext::isExtensionContext() const {
6799-
if (auto D = getAsDecl())
6800-
return ExtensionDecl::classof(D);
6801-
return false;
6802-
}
6803-
68046798
inline bool DeclContext::classof(const Decl *D) {
68056799
switch (D->getKind()) { //
68066800
default: return false;

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
277277
LLVM_READONLY
278278
bool isTypeContext() const;
279279

280-
/// \brief Determine whether this is an extension context.
281-
LLVM_READONLY
282-
bool isExtensionContext() const; // see swift/AST/Decl.h
283-
284280
/// If this DeclContext is a NominalType declaration or an
285281
/// extension thereof, return the NominalTypeDecl.
286282
LLVM_READONLY

lib/IDE/IDETypeChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace swift;
2828

2929
static bool shouldPrintAsFavorable(const Decl *D, const PrintOptions &Options) {
3030
if (!Options.TransformContext ||
31-
!D->getDeclContext()->isExtensionContext() ||
31+
!isa<ExtensionDecl>(D->getDeclContext()) ||
3232
!Options.TransformContext->isPrintingSynthesizedExtension())
3333
return true;
3434
auto DC = Options.TransformContext->getDeclContext();

lib/SIL/SILDeclRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ SubclassScope SILDeclRef::getSubclassScope() const {
883883
DeclContext *context = FD->getDeclContext();
884884

885885
// Methods from extensions don't go into vtables (yet).
886-
if (context->isExtensionContext())
886+
if (isa<ExtensionDecl>(context))
887887
return SubclassScope::NotApplicable;
888888

889889
// Various forms of thunks don't either.

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ SILGenModule::getOrCreateProfilerForConstructors(DeclContext *ctx,
507507
// distinct files. For extensions, just pass in the constructor, because
508508
// there are no stored property initializers to visit.
509509
Decl *decl = nullptr;
510-
if (ctx->isExtensionContext())
510+
if (isa<ExtensionDecl>(ctx))
511511
decl = cd;
512512
else
513513
decl = ctx->getSelfNominalTypeDecl();

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ static bool canUseStaticDispatch(SILGenFunction &SGF,
150150

151151
// Extension methods currently must be statically dispatched, unless they're
152152
// @objc or dynamic.
153-
if (funcDecl->getDeclContext()->isExtensionContext()
154-
&& !constant.isForeign)
153+
if (isa<ExtensionDecl>(funcDecl->getDeclContext()) && !constant.isForeign)
155154
return true;
156155

157156
// We cannot form a direct reference to a method body defined in

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,10 +1787,7 @@ void ConstraintSystem::partitionForDesignatedTypes(
17871787
auto *funcDecl = cast<FuncDecl>(decl);
17881788

17891789
auto *parentDC = funcDecl->getParent();
1790-
auto *parentDecl = parentDC->getAsDecl();
1791-
1792-
if (parentDC->isExtensionContext())
1793-
parentDecl = cast<ExtensionDecl>(parentDecl)->getExtendedNominal();
1790+
auto *parentDecl = parentDC->getSelfNominalTypeDecl();
17941791

17951792
for (auto designatedTypeIndex : indices(designatedNominalTypes)) {
17961793
auto *designatedNominal =
@@ -1800,7 +1797,7 @@ void ConstraintSystem::partitionForDesignatedTypes(
18001797
continue;
18011798

18021799
auto &constraints =
1803-
parentDC->isExtensionContext()
1800+
isa<ExtensionDecl>(parentDC)
18041801
? definedInExtensionOfDesignatedType[designatedTypeIndex]
18051802
: definedInDesignatedType[designatedTypeIndex];
18061803

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ void TypeChecker::checkDynamicReplacementAttribute(ValueDecl *D) {
20502050
auto *attr = D->getAttrs().getAttribute<DynamicReplacementAttr>();
20512051
assert(attr);
20522052

2053-
if (!D->getDeclContext()->isExtensionContext() &&
2053+
if (!isa<ExtensionDecl>(D->getDeclContext()) &&
20542054
!D->getDeclContext()->isModuleScopeContext()) {
20552055
diagnose(attr->getLocation(), diag::dynamic_replacement_not_in_extension,
20562056
D->getBaseName());

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static void validatePatternBindingEntry(TypeChecker &tc,
972972
// Validate 'static'/'class' on properties in nominal type decls.
973973
auto StaticSpelling = binding->getStaticSpelling();
974974
if (StaticSpelling != StaticSpellingKind::None &&
975-
binding->getDeclContext()->isExtensionContext()) {
975+
isa<ExtensionDecl>(binding->getDeclContext())) {
976976
if (auto *NTD = binding->getDeclContext()->getSelfNominalTypeDecl()) {
977977
if (!isa<ClassDecl>(NTD)) {
978978
if (StaticSpelling == StaticSpellingKind::KeywordClass) {
@@ -4186,7 +4186,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41864186
// Validate 'static'/'class' on functions in extensions.
41874187
auto StaticSpelling = FD->getStaticSpelling();
41884188
if (StaticSpelling != StaticSpellingKind::None &&
4189-
FD->getDeclContext()->isExtensionContext()) {
4189+
isa<ExtensionDecl>(FD->getDeclContext())) {
41904190
if (auto *NTD = FD->getDeclContext()->getSelfNominalTypeDecl()) {
41914191
if (!isa<ClassDecl>(NTD)) {
41924192
if (StaticSpelling == StaticSpellingKind::KeywordClass) {

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,12 +1510,12 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
15101510
// Non-Objective-C declarations in extensions cannot override or
15111511
// be overridden.
15121512
if (!isAccessor &&
1513-
(base->getDeclContext()->isExtensionContext() ||
1514-
override->getDeclContext()->isExtensionContext()) &&
1513+
(isa<ExtensionDecl>(base->getDeclContext()) ||
1514+
isa<ExtensionDecl>(override->getDeclContext())) &&
15151515
!base->isObjC()) {
15161516
bool baseCanBeObjC = canBeRepresentedInObjC(base);
15171517
diags.diagnose(override, diag::override_decl_extension, baseCanBeObjC,
1518-
!base->getDeclContext()->isExtensionContext());
1518+
!isa<ExtensionDecl>(base->getDeclContext()));
15191519
if (baseCanBeObjC) {
15201520
SourceLoc insertionLoc =
15211521
override->getAttributeInsertionLoc(/*forModifier=*/false);
@@ -1559,8 +1559,7 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
15591559
if (!isAccessor &&
15601560
baseDecl->hasKnownSwiftImplementation() &&
15611561
!base->isObjCDynamic() &&
1562-
override->getDeclContext()->isExtensionContext()) {
1563-
// For compatibility, only generate a warning in Swift 3
1562+
isa<ExtensionDecl>(override->getDeclContext())) {
15641563
diags.diagnose(override, diag::override_class_declaration_in_extension);
15651564
diags.diagnose(base, diag::overridden_here);
15661565
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,10 +2466,10 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
24662466
Type AdopterTy, SourceLoc TypeLoc, raw_ostream &OS) {
24672467
if (isa<ConstructorDecl>(Requirement)) {
24682468
if (auto CD = Adopter->getSelfClassDecl()) {
2469-
if (!CD->isFinal() && Adopter->isExtensionContext()) {
2470-
// In this case, user should mark class as 'final' or define
2471-
// 'required' initializer directly in the class definition.
2472-
return false;
2469+
if (!CD->isFinal() && isa<ExtensionDecl>(Adopter)) {
2470+
// In this case, user should mark class as 'final' or define
2471+
// 'required' initializer directly in the class definition.
2472+
return false;
24732473
}
24742474
}
24752475
}
@@ -2508,7 +2508,7 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
25082508
if (auto CD = Adopter->getSelfClassDecl()) {
25092509
if (!CD->isFinal()) {
25102510
Printer << "required ";
2511-
} else if (Adopter->isExtensionContext()) {
2511+
} else if (isa<ExtensionDecl>(Adopter)) {
25122512
Printer << "convenience ";
25132513
}
25142514
}
@@ -2530,7 +2530,7 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
25302530
};
25312531
Options.setBaseType(AdopterTy);
25322532
Options.CurrentModule = Adopter->getParentModule();
2533-
if (!Adopter->isExtensionContext()) {
2533+
if (!isa<ExtensionDecl>(Adopter)) {
25342534
// Create a variable declaration instead of a computed property in
25352535
// nominal types
25362536
Options.PrintPropertyAccessors = false;

0 commit comments

Comments
 (0)