Skip to content

Commit fd97268

Browse files
authored
Merge pull request #70983 from hamishknight/another-cleanup
[AST] Remove SerializedLocalDeclContext
2 parents ba32759 + 3f4b45b commit fd97268

File tree

21 files changed

+95
-126
lines changed

21 files changed

+95
-126
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,16 +2494,13 @@ class TopLevelCodeDecl : public DeclContext, public Decl {
24942494
/// SerializedTopLevelCodeDeclContext - This represents what was originally a
24952495
/// TopLevelCodeDecl during serialization. It is preserved only to maintain the
24962496
/// correct AST structure and remangling after deserialization.
2497-
class SerializedTopLevelCodeDeclContext : public SerializedLocalDeclContext {
2497+
class SerializedTopLevelCodeDeclContext : public DeclContext {
24982498
public:
24992499
SerializedTopLevelCodeDeclContext(DeclContext *Parent)
2500-
: SerializedLocalDeclContext(LocalDeclContextKind::TopLevelCodeDecl,
2501-
Parent) {}
2500+
: DeclContext(DeclContextKind::SerializedTopLevelCodeDecl, Parent) {}
2501+
25022502
static bool classof(const DeclContext *DC) {
2503-
if (auto LDC = dyn_cast<SerializedLocalDeclContext>(DC))
2504-
return LDC->getLocalDeclContextKind() ==
2505-
LocalDeclContextKind::TopLevelCodeDecl;
2506-
return false;
2503+
return DC->getContextKind() == DeclContextKind::SerializedTopLevelCodeDecl;
25072504
}
25082505
};
25092506

include/swift/AST/DeclContext.h

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ enum class DeclContextKind : unsigned {
9797
SubscriptDecl,
9898
EnumElementDecl,
9999
AbstractFunctionDecl,
100-
SerializedLocal,
100+
SerializedAbstractClosure,
101+
SerializedTopLevelCodeDecl,
101102
MacroDecl,
102103
Last_LocalDeclContextKind = MacroDecl,
103104
Package,
@@ -108,14 +109,6 @@ enum class DeclContextKind : unsigned {
108109
Last_DeclContextKind = ExtensionDecl
109110
};
110111

111-
/// Kinds of DeclContexts after deserialization.
112-
///
113-
/// \see SerializedLocalDeclContext.
114-
enum class LocalDeclContextKind : uint8_t {
115-
AbstractClosure,
116-
TopLevelCodeDecl
117-
};
118-
119112
/// Describes the kind of a particular conformance.
120113
///
121114
/// The following code involves conformances of the three different kinds:
@@ -251,10 +244,11 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
251244
FileUnit,
252245
Package,
253246
Initializer,
254-
SerializedLocal,
247+
SerializedAbstractClosure,
248+
SerializedTopLevelCodeDecl,
255249
// If you add a new AST hierarchies, then update the static_assert() below.
256250
};
257-
static_assert(unsigned(ASTHierarchy::SerializedLocal) <
251+
static_assert(unsigned(ASTHierarchy::SerializedTopLevelCodeDecl) <
258252
(1 << DeclContextAlignInBits),
259253
"ASTHierarchy exceeds bits available");
260254

@@ -283,8 +277,10 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
283277
return ASTHierarchy::Expr;
284278
case DeclContextKind::Initializer:
285279
return ASTHierarchy::Initializer;
286-
case DeclContextKind::SerializedLocal:
287-
return ASTHierarchy::SerializedLocal;
280+
case DeclContextKind::SerializedAbstractClosure:
281+
return ASTHierarchy::SerializedAbstractClosure;
282+
case DeclContextKind::SerializedTopLevelCodeDecl:
283+
return ASTHierarchy::SerializedTopLevelCodeDecl;
288284
case DeclContextKind::FileUnit:
289285
return ASTHierarchy::FileUnit;
290286
case DeclContextKind::Package:
@@ -706,31 +702,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
706702
static bool classof(const Decl *D);
707703
};
708704

709-
/// SerializedLocalDeclContext - the base class for DeclContexts that were
710-
/// serialized to preserve AST structure and accurate mangling after
711-
/// deserialization.
712-
class SerializedLocalDeclContext : public DeclContext {
713-
private:
714-
unsigned LocalKind : 3;
715-
716-
protected:
717-
unsigned SpareBits : 29;
718-
719-
public:
720-
SerializedLocalDeclContext(LocalDeclContextKind LocalKind,
721-
DeclContext *Parent)
722-
: DeclContext(DeclContextKind::SerializedLocal, Parent),
723-
LocalKind(static_cast<unsigned>(LocalKind)) {}
724-
725-
LocalDeclContextKind getLocalDeclContextKind() const {
726-
return static_cast<LocalDeclContextKind>(LocalKind);
727-
}
728-
729-
static bool classof(const DeclContext *DC) {
730-
return DC->getContextKind() == DeclContextKind::SerializedLocal;
731-
}
732-
};
733-
734705
/// An iterator that walks through a list of declarations stored
735706
/// within some iterable declaration context.
736707
class DeclIterator {

include/swift/AST/Expr.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,16 +3947,15 @@ class AbstractClosureExpr : public DeclContext, public Expr {
39473947
/// SerializedAbstractClosureExpr - This represents what was originally an
39483948
/// AbstractClosureExpr during serialization. It is preserved only to maintain
39493949
/// the correct AST structure and remangling after deserialization.
3950-
class SerializedAbstractClosureExpr : public SerializedLocalDeclContext {
3950+
class SerializedAbstractClosureExpr : public DeclContext {
39513951
const Type Ty;
39523952
llvm::PointerIntPair<Type, 1> TypeAndImplicit;
39533953
const unsigned Discriminator;
39543954

39553955
public:
39563956
SerializedAbstractClosureExpr(Type Ty, bool Implicit, unsigned Discriminator,
39573957
DeclContext *Parent)
3958-
: SerializedLocalDeclContext(LocalDeclContextKind::AbstractClosure,
3959-
Parent),
3958+
: DeclContext(DeclContextKind::SerializedAbstractClosure, Parent),
39603959
TypeAndImplicit(llvm::PointerIntPair<Type, 1>(Ty, Implicit)),
39613960
Discriminator(Discriminator) {}
39623961

@@ -3973,10 +3972,7 @@ class SerializedAbstractClosureExpr : public SerializedLocalDeclContext {
39733972
}
39743973

39753974
static bool classof(const DeclContext *DC) {
3976-
if (auto LDC = dyn_cast<SerializedLocalDeclContext>(DC))
3977-
return LDC->getLocalDeclContextKind() ==
3978-
LocalDeclContextKind::AbstractClosure;
3979-
return false;
3975+
return DC->getContextKind() == DeclContextKind::SerializedAbstractClosure;
39803976
}
39813977
};
39823978

lib/AST/ASTDumper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,8 +1732,8 @@ void swift::printContext(raw_ostream &os, DeclContext *dc) {
17321732
os << "(file)";
17331733
break;
17341734

1735-
case DeclContextKind::SerializedLocal:
1736-
os << "local context";
1735+
case DeclContextKind::SerializedAbstractClosure:
1736+
os << "serialized abstract closure";
17371737
break;
17381738

17391739
case DeclContextKind::AbstractClosureExpr: {
@@ -1782,6 +1782,7 @@ void swift::printContext(raw_ostream &os, DeclContext *dc) {
17821782
break;
17831783

17841784
case DeclContextKind::TopLevelCodeDecl:
1785+
case DeclContextKind::SerializedTopLevelCodeDecl:
17851786
os << "top-level code";
17861787
break;
17871788

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,17 +2317,6 @@ void ASTMangler::appendContext(const DeclContext *ctx, StringRef useModuleName)
23172317
appendContext(ctx->getParent(), useModuleName);
23182318
return;
23192319

2320-
case DeclContextKind::SerializedLocal: {
2321-
auto local = cast<SerializedLocalDeclContext>(ctx);
2322-
switch (local->getLocalDeclContextKind()) {
2323-
case LocalDeclContextKind::AbstractClosure:
2324-
appendClosureEntity(cast<SerializedAbstractClosureExpr>(local));
2325-
return;
2326-
case LocalDeclContextKind::TopLevelCodeDecl:
2327-
return appendContext(local->getParent(), useModuleName);
2328-
}
2329-
}
2330-
23312320
case DeclContextKind::GenericTypeDecl:
23322321
appendAnyGenericType(cast<GenericTypeDecl>(ctx));
23332322
return;
@@ -2368,6 +2357,9 @@ void ASTMangler::appendContext(const DeclContext *ctx, StringRef useModuleName)
23682357
case DeclContextKind::AbstractClosureExpr:
23692358
return appendClosureEntity(cast<AbstractClosureExpr>(ctx));
23702359

2360+
case DeclContextKind::SerializedAbstractClosure:
2361+
return appendClosureEntity(cast<SerializedAbstractClosureExpr>(ctx));
2362+
23712363
case DeclContextKind::AbstractFunctionDecl: {
23722364
auto fn = cast<AbstractFunctionDecl>(ctx);
23732365

@@ -2428,6 +2420,7 @@ void ASTMangler::appendContext(const DeclContext *ctx, StringRef useModuleName)
24282420
llvm_unreachable("bad initializer kind");
24292421

24302422
case DeclContextKind::TopLevelCodeDecl:
2423+
case DeclContextKind::SerializedTopLevelCodeDecl:
24312424
// Mangle the containing module context.
24322425
return appendContext(ctx->getParent(), useModuleName);
24332426

lib/AST/AccessRequests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ AccessLevelRequest::evaluate(Evaluator &evaluator, ValueDecl *D) const {
110110

111111
switch (DC->getContextKind()) {
112112
case DeclContextKind::TopLevelCodeDecl:
113+
case DeclContextKind::SerializedTopLevelCodeDecl:
113114
// Variables declared in a top-level 'guard' statement can be accessed in
114115
// later top-level code.
115116
return AccessLevel::FilePrivate;
116117
case DeclContextKind::AbstractClosureExpr:
118+
case DeclContextKind::SerializedAbstractClosure:
117119
if (isa<ParamDecl>(D)) {
118120
// Closure parameters may need to be accessible to the enclosing
119121
// context, for single-expression closures.
120122
return AccessLevel::FilePrivate;
121123
} else {
122124
return AccessLevel::Private;
123125
}
124-
case DeclContextKind::SerializedLocal:
125126
case DeclContextKind::Initializer:
126127
case DeclContextKind::AbstractFunctionDecl:
127128
case DeclContextKind::SubscriptDecl:

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11769,7 +11769,8 @@ MacroDiscriminatorContext::getInnermostMacroContext(DeclContext *dc) {
1176911769

1177011770
case DeclContextKind::EnumElementDecl:
1177111771
case DeclContextKind::AbstractFunctionDecl:
11772-
case DeclContextKind::SerializedLocal:
11772+
case DeclContextKind::SerializedAbstractClosure:
11773+
case DeclContextKind::SerializedTopLevelCodeDecl:
1177311774
case DeclContextKind::Package:
1177411775
case DeclContextKind::Module:
1177511776
case DeclContextKind::FileUnit:

lib/AST/DeclContext.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ SourceFile *DeclContext::getParentSourceFile() const {
342342
case DeclContextKind::FileUnit:
343343
case DeclContextKind::Module:
344344
case DeclContextKind::Package:
345-
case DeclContextKind::SerializedLocal:
345+
case DeclContextKind::SerializedAbstractClosure:
346+
case DeclContextKind::SerializedTopLevelCodeDecl:
346347
break;
347348
}
348349
}
@@ -613,7 +614,8 @@ bool DeclContext::walkContext(ASTWalker &Walker) {
613614
return cast<EnumElementDecl>(this)->walk(Walker);
614615
case DeclContextKind::MacroDecl:
615616
return cast<MacroDecl>(this)->walk(Walker);
616-
case DeclContextKind::SerializedLocal:
617+
case DeclContextKind::SerializedAbstractClosure:
618+
case DeclContextKind::SerializedTopLevelCodeDecl:
617619
llvm_unreachable("walk is unimplemented for deserialized contexts");
618620
case DeclContextKind::Initializer:
619621
// Is there any point in trying to walk the expression?
@@ -689,10 +691,12 @@ unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
689691
case DeclContextKind::Package: Kind = "Package"; break;
690692
case DeclContextKind::Module: Kind = "Module"; break;
691693
case DeclContextKind::FileUnit: Kind = "FileUnit"; break;
692-
case DeclContextKind::SerializedLocal: Kind = "Serialized Local"; break;
693694
case DeclContextKind::AbstractClosureExpr:
694695
Kind = "AbstractClosureExpr";
695696
break;
697+
case DeclContextKind::SerializedAbstractClosure:
698+
Kind = "SerializedAbstractClosure";
699+
break;
696700
case DeclContextKind::GenericTypeDecl:
697701
switch (cast<GenericTypeDecl>(this)->getKind()) {
698702
#define DECL(ID, PARENT) \
@@ -702,6 +706,9 @@ unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
702706
break;
703707
case DeclContextKind::ExtensionDecl: Kind = "ExtensionDecl"; break;
704708
case DeclContextKind::TopLevelCodeDecl: Kind = "TopLevelCodeDecl"; break;
709+
case DeclContextKind::SerializedTopLevelCodeDecl:
710+
Kind = "SerializedTopLevelCodeDecl";
711+
break;
705712
case DeclContextKind::Initializer: Kind = "Initializer"; break;
706713
case DeclContextKind::AbstractFunctionDecl:
707714
Kind = "AbstractFunctionDecl";
@@ -741,16 +748,29 @@ unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
741748
OS << " line=" << getLineNumber(cast<AbstractClosureExpr>(this));
742749
OS << " : " << cast<AbstractClosureExpr>(this)->getType();
743750
break;
751+
752+
case DeclContextKind::SerializedAbstractClosure: {
753+
OS << " : " << cast<SerializedAbstractClosureExpr>(this)->getType();
754+
break;
755+
}
756+
744757
case DeclContextKind::GenericTypeDecl:
745758
OS << " name=" << cast<GenericTypeDecl>(this)->getName();
746759
break;
760+
747761
case DeclContextKind::ExtensionDecl:
748762
OS << " line=" << getLineNumber(cast<ExtensionDecl>(this));
749763
OS << " base=" << cast<ExtensionDecl>(this)->getExtendedType();
750764
break;
765+
751766
case DeclContextKind::TopLevelCodeDecl:
752767
OS << " line=" << getLineNumber(cast<TopLevelCodeDecl>(this));
753768
break;
769+
770+
case DeclContextKind::SerializedTopLevelCodeDecl:
771+
// Already printed the kind, nothing else to do.
772+
break;
773+
754774
case DeclContextKind::AbstractFunctionDecl: {
755775
auto *AFD = cast<AbstractFunctionDecl>(this);
756776
OS << " name=" << AFD->getName();
@@ -815,20 +835,6 @@ unsigned DeclContext::printContext(raw_ostream &OS, const unsigned indent,
815835
}
816836
}
817837
break;
818-
819-
case DeclContextKind::SerializedLocal: {
820-
auto local = cast<SerializedLocalDeclContext>(this);
821-
switch (local->getLocalDeclContextKind()) {
822-
case LocalDeclContextKind::AbstractClosure: {
823-
auto serializedClosure = cast<SerializedAbstractClosureExpr>(local);
824-
OS << " closure : " << serializedClosure->getType();
825-
break;
826-
}
827-
case LocalDeclContextKind::TopLevelCodeDecl:
828-
OS << " TopLevelCode";
829-
break;
830-
}
831-
}
832838
}
833839

834840
if (auto decl = getAsDecl())
@@ -1308,8 +1314,10 @@ DeclContextKind DeclContext::getContextKind() const {
13081314
return DeclContextKind::AbstractClosureExpr;
13091315
case ASTHierarchy::Initializer:
13101316
return DeclContextKind::Initializer;
1311-
case ASTHierarchy::SerializedLocal:
1312-
return DeclContextKind::SerializedLocal;
1317+
case ASTHierarchy::SerializedAbstractClosure:
1318+
return DeclContextKind::SerializedAbstractClosure;
1319+
case ASTHierarchy::SerializedTopLevelCodeDecl:
1320+
return DeclContextKind::SerializedTopLevelCodeDecl;
13131321
case ASTHierarchy::FileUnit:
13141322
return DeclContextKind::FileUnit;
13151323
case ASTHierarchy::Package:
@@ -1362,7 +1370,8 @@ bool DeclContext::isAsyncContext() const {
13621370
case DeclContextKind::Initializer:
13631371
case DeclContextKind::EnumElementDecl:
13641372
case DeclContextKind::ExtensionDecl:
1365-
case DeclContextKind::SerializedLocal:
1373+
case DeclContextKind::SerializedAbstractClosure:
1374+
case DeclContextKind::SerializedTopLevelCodeDecl:
13661375
case DeclContextKind::Package:
13671376
case DeclContextKind::Module:
13681377
case DeclContextKind::GenericTypeDecl:
@@ -1414,7 +1423,8 @@ SourceLoc swift::extractNearestSourceLoc(const DeclContext *dc) {
14141423
return SourceLoc();
14151424

14161425
case DeclContextKind::Initializer:
1417-
case DeclContextKind::SerializedLocal:
1426+
case DeclContextKind::SerializedAbstractClosure:
1427+
case DeclContextKind::SerializedTopLevelCodeDecl:
14181428
return extractNearestSourceLoc(dc->getParent());
14191429
}
14201430
llvm_unreachable("Unhandled DeclContextKindIn switch");

lib/AST/DiagnosticEngine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
12471247

12481248
case DeclContextKind::FileUnit:
12491249
case DeclContextKind::TopLevelCodeDecl:
1250+
case DeclContextKind::SerializedTopLevelCodeDecl:
12501251
break;
12511252

12521253
case DeclContextKind::ExtensionDecl:
@@ -1257,9 +1258,9 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
12571258
ppDecl = cast<GenericTypeDecl>(dc);
12581259
break;
12591260

1260-
case DeclContextKind::SerializedLocal:
12611261
case DeclContextKind::Initializer:
12621262
case DeclContextKind::AbstractClosureExpr:
1263+
case DeclContextKind::SerializedAbstractClosure:
12631264
case DeclContextKind::AbstractFunctionDecl:
12641265
case DeclContextKind::SubscriptDecl:
12651266
case DeclContextKind::EnumElementDecl:

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,13 @@ IRGenModule::getAddrOfContextDescriptorForParent(DeclContext *parent,
886886
bool fromAnonymousContext) {
887887
switch (parent->getContextKind()) {
888888
case DeclContextKind::AbstractClosureExpr:
889+
case DeclContextKind::SerializedAbstractClosure:
889890
case DeclContextKind::AbstractFunctionDecl:
890891
case DeclContextKind::SubscriptDecl:
891892
case DeclContextKind::EnumElementDecl:
892893
case DeclContextKind::TopLevelCodeDecl:
894+
case DeclContextKind::SerializedTopLevelCodeDecl:
893895
case DeclContextKind::Initializer:
894-
case DeclContextKind::SerializedLocal:
895896
return {getAddrOfAnonymousContextDescriptor(
896897
fromAnonymousContext ? parent : ofChild),
897898
ConstantReference::Direct};

0 commit comments

Comments
 (0)