Skip to content

Commit accd108

Browse files
authored
Merge pull request #79857 from rintaro/retire-pound-diagnostics-decl
[Parse/AST] Remove PoundDiagnosticDecl
2 parents b57f8a9 + 5eac58e commit accd108

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+119
-305
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ final public class TopLevelCodeDecl: Decl {}
110110

111111
final public class ImportDecl: Decl {}
112112

113-
final public class PoundDiagnosticDecl: Decl {}
114-
115113
final public class PrecedenceGroupDecl: Decl {}
116114

117115
final public class MissingDecl: Decl {}

SwiftCompilerSources/Sources/AST/Registration.swift

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public func registerAST() {
3636
registerDecl(ExtensionDecl.self)
3737
registerDecl(TopLevelCodeDecl.self)
3838
registerDecl(ImportDecl.self)
39-
registerDecl(PoundDiagnosticDecl.self)
4039
registerDecl(PrecedenceGroupDecl.self)
4140
registerDecl(MissingDecl.self)
4241
registerDecl(MissingMemberDecl.self)

include/swift/AST/Decl.h

-55
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ enum class DescriptiveDeclKind : uint8_t {
156156
Extension,
157157
EnumCase,
158158
TopLevelCode,
159-
PoundDiagnostic,
160159
PatternBinding,
161160
Var,
162161
Param,
@@ -839,14 +838,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
839838
HasLazyConformances : 1
840839
);
841840

842-
SWIFT_INLINE_BITFIELD(PoundDiagnosticDecl, Decl, 1+1,
843-
/// `true` if the diagnostic is an error, `false` if it's a warning.
844-
IsError : 1,
845-
846-
/// Whether this diagnostic has already been emitted.
847-
HasBeenEmitted : 1
848-
);
849-
850841
SWIFT_INLINE_BITFIELD(MissingMemberDecl, Decl, 1+2,
851842
NumberOfFieldOffsetVectorEntries : 1,
852843
NumberOfVTableEntries : 2
@@ -2799,52 +2790,6 @@ class SerializedTopLevelCodeDeclContext : public DeclContext {
27992790
}
28002791
};
28012792

2802-
class StringLiteralExpr;
2803-
2804-
class PoundDiagnosticDecl : public Decl {
2805-
SourceLoc StartLoc;
2806-
SourceLoc EndLoc;
2807-
StringLiteralExpr *Message;
2808-
SourceLoc getLocFromSource() const { return StartLoc; }
2809-
friend class Decl;
2810-
public:
2811-
PoundDiagnosticDecl(DeclContext *Parent, bool IsError, SourceLoc StartLoc,
2812-
SourceLoc EndLoc, StringLiteralExpr *Message)
2813-
: Decl(DeclKind::PoundDiagnostic, Parent), StartLoc(StartLoc),
2814-
EndLoc(EndLoc), Message(Message) {
2815-
Bits.PoundDiagnosticDecl.IsError = IsError;
2816-
Bits.PoundDiagnosticDecl.HasBeenEmitted = false;
2817-
}
2818-
2819-
DiagnosticKind getKind() const {
2820-
return isError() ? DiagnosticKind::Error : DiagnosticKind::Warning;
2821-
}
2822-
2823-
StringLiteralExpr *getMessage() const { return Message; }
2824-
2825-
bool isError() const {
2826-
return Bits.PoundDiagnosticDecl.IsError;
2827-
}
2828-
2829-
bool hasBeenEmitted() const {
2830-
return Bits.PoundDiagnosticDecl.HasBeenEmitted;
2831-
}
2832-
2833-
void markEmitted() {
2834-
Bits.PoundDiagnosticDecl.HasBeenEmitted = true;
2835-
}
2836-
2837-
SourceLoc getEndLoc() const { return EndLoc; };
2838-
2839-
SourceRange getSourceRange() const {
2840-
return SourceRange(StartLoc, EndLoc);
2841-
}
2842-
2843-
static bool classof(const Decl *D) {
2844-
return D->getKind() == DeclKind::PoundDiagnostic;
2845-
}
2846-
};
2847-
28482793
class OpaqueTypeDecl;
28492794

28502795
/// ValueDecl - All named decls that are values in the language. These can

include/swift/AST/DeclExportabilityVisitor.h

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class DeclExportabilityVisitor
171171
bool visit##KIND##Decl(const KIND##Decl *D) { return true; }
172172
UNINTERESTING(TopLevelCode);
173173
UNINTERESTING(Import);
174-
UNINTERESTING(PoundDiagnostic);
175174
UNINTERESTING(PrecedenceGroup);
176175
UNINTERESTING(EnumCase);
177176
UNINTERESTING(Operator);

include/swift/AST/DeclNodes.def

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ ABSTRACT_DECL(Value, Decl)
185185
ITERABLE_GENERIC_DECL(Extension, Decl)
186186
CONTEXT_DECL(TopLevelCode, Decl)
187187
DECL(Import, Decl)
188-
DECL(PoundDiagnostic, Decl)
189188
DECL(PrecedenceGroup, Decl)
190189
DECL(Missing, Decl)
191190
DECL(MissingMember, Decl)

include/swift/AST/DiagnosticsCommon.def

+7
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,12 @@ ERROR(bridged_error, none, "%0", (StringRef))
274274
ERROR(bridged_fatal_error, Fatal, "%0", (StringRef))
275275
REMARK(bridged_remark, none, "%0", (StringRef))
276276

277+
//------------------------------------------------------------------------------
278+
// MARK: #warning and #error
279+
//------------------------------------------------------------------------------
280+
281+
WARNING(pound_warning, none, "%0", (StringRef))
282+
ERROR(pound_error, none, "%0", (StringRef))
283+
277284
#define UNDEFINE_DIAGNOSTIC_MACROS
278285
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

-3
Original file line numberDiff line numberDiff line change
@@ -1708,9 +1708,6 @@ ERROR(invalid_autoclosure_pointer_conversion,none,
17081708
ERROR(missing_initializer_def,PointsToFirstBadToken,
17091709
"initializer requires a body", ())
17101710

1711-
WARNING(pound_warning, none, "%0", (StringRef))
1712-
ERROR(pound_error, none, "%0", (StringRef))
1713-
17141711
// Attributes
17151712

17161713
ERROR(operator_not_func,none,

include/swift/AST/Stmt.h

+9-29
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ class CaseStmt final
14081408

14091409
/// Switch statement.
14101410
class SwitchStmt final : public LabeledStmt,
1411-
private llvm::TrailingObjects<SwitchStmt, ASTNode> {
1411+
private llvm::TrailingObjects<SwitchStmt, CaseStmt *> {
14121412
friend TrailingObjects;
14131413

14141414
SourceLoc SwitchLoc, LBraceLoc, RBraceLoc;
@@ -1431,16 +1431,13 @@ class SwitchStmt final : public LabeledStmt,
14311431
public:
14321432
/// Allocate a new SwitchStmt in the given ASTContext.
14331433
static SwitchStmt *create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc,
1434-
Expr *SubjectExpr,
1435-
SourceLoc LBraceLoc,
1436-
ArrayRef<ASTNode> Cases,
1437-
SourceLoc RBraceLoc,
1438-
SourceLoc EndLoc,
1439-
ASTContext &C);
1434+
Expr *SubjectExpr, SourceLoc LBraceLoc,
1435+
ArrayRef<CaseStmt *> Cases, SourceLoc RBraceLoc,
1436+
SourceLoc EndLoc, ASTContext &C);
14401437

14411438
static SwitchStmt *createImplicit(LabeledStmtInfo LabelInfo,
1442-
Expr *SubjectExpr, ArrayRef<ASTNode> Cases,
1443-
ASTContext &C) {
1439+
Expr *SubjectExpr,
1440+
ArrayRef<CaseStmt *> Cases, ASTContext &C) {
14441441
return SwitchStmt::create(LabelInfo, /*SwitchLoc=*/SourceLoc(), SubjectExpr,
14451442
/*LBraceLoc=*/SourceLoc(), Cases,
14461443
/*RBraceLoc=*/SourceLoc(), /*EndLoc=*/SourceLoc(),
@@ -1463,27 +1460,10 @@ class SwitchStmt final : public LabeledStmt,
14631460
Expr *getSubjectExpr() const { return SubjectExpr; }
14641461
void setSubjectExpr(Expr *e) { SubjectExpr = e; }
14651462

1466-
ArrayRef<ASTNode> getRawCases() const {
1467-
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
1468-
}
1469-
1470-
private:
1471-
struct AsCaseStmtWithSkippingNonCaseStmts {
1472-
AsCaseStmtWithSkippingNonCaseStmts() {}
1473-
std::optional<CaseStmt *> operator()(const ASTNode &N) const {
1474-
if (auto *CS = llvm::dyn_cast_or_null<CaseStmt>(N.dyn_cast<Stmt*>()))
1475-
return CS;
1476-
return std::nullopt;
1477-
}
1478-
};
1479-
1480-
public:
1481-
using AsCaseStmtRange = OptionalTransformRange<ArrayRef<ASTNode>,
1482-
AsCaseStmtWithSkippingNonCaseStmts>;
1483-
14841463
/// Get the list of case clauses.
1485-
AsCaseStmtRange getCases() const {
1486-
return AsCaseStmtRange(getRawCases(), AsCaseStmtWithSkippingNonCaseStmts());
1464+
ArrayRef<CaseStmt *> getCases() const {
1465+
return {getTrailingObjects<CaseStmt *>(),
1466+
static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
14871467
}
14881468

14891469
/// Retrieve the complete set of branches for this switch statement.

include/swift/AST/TypeMemberVisitor.h

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ class TypeMemberVisitor : public DeclVisitor<ImplClass, RetTy> {
4242
BAD_MEMBER(PrecedenceGroup)
4343
BAD_MEMBER(Macro)
4444

45-
// These decls are disregarded.
46-
RetTy visitPoundDiagnosticDecl(PoundDiagnosticDecl *D) {
47-
return RetTy();
48-
}
49-
5045
RetTy visitMacroExpansionDecl(MacroExpansionDecl *D) {
5146
// Expansion already visited as auxiliary decls.
5247
return RetTy();

include/swift/Parse/Parser.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ class Parser {
984984
DeclAttributes &attributes, bool ifConfigsAreDeclAttrs);
985985

986986
/// Parse a #error or #warning diagnostic.
987-
ParserResult<PoundDiagnosticDecl> parseDeclPoundDiagnostic();
987+
ParserStatus parseDeclPoundDiagnostic();
988988

989989
/// Parse a #line/#sourceLocation directive.
990990
/// 'isLine = true' indicates parsing #line instead of #sourcelocation
@@ -1969,7 +1969,8 @@ class Parser {
19691969
ParserResult<CaseStmt> parseStmtCatch();
19701970
ParserResult<Stmt> parseStmtForEach(LabeledStmtInfo LabelInfo);
19711971
ParserResult<Stmt> parseStmtSwitch(LabeledStmtInfo LabelInfo);
1972-
ParserStatus parseStmtCases(SmallVectorImpl<ASTNode> &cases, bool IsActive);
1972+
ParserStatus parseStmtCases(SmallVectorImpl<CaseStmt *> &cases,
1973+
bool IsActive);
19731974
ParserResult<CaseStmt> parseStmtCase(bool IsActive);
19741975
ParserResult<Stmt> parseStmtPoundAssert();
19751976

include/swift/SIL/SILWitnessVisitor.h

-4
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
172172
// We only care about the contained VarDecls.
173173
}
174174

175-
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *pdd) {
176-
// We don't care about diagnostics at this stage.
177-
}
178-
179175
private:
180176
void addAutoDiffDerivativeMethodsIfRequired(AbstractFunctionDecl *AFD,
181177
SILDeclRef::Kind kind) {

lib/APIDigester/ModuleAnalyzerNodes.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1935,8 +1935,6 @@ SwiftDeclCollector::addMembersToRoot(SDKNode *Root, IterableDeclContext *Context
19351935
// All containing variables should have been handled.
19361936
} else if (isa<EnumCaseDecl>(Member)) {
19371937
// All containing variables should have been handled.
1938-
} else if (isa<PoundDiagnosticDecl>(Member)) {
1939-
// All containing members should have been handled.
19401938
} else if (isa<DestructorDecl>(Member)) {
19411939
// deinit has no impact.
19421940
} else if (isa<MissingMemberDecl>(Member)) {

lib/AST/ASTDumper.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -2691,13 +2691,6 @@ namespace {
26912691
printFoot();
26922692
}
26932693

2694-
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD, Label label) {
2695-
printCommon(PDD, "pound_diagnostic_decl", label);
2696-
printField(PDD->isError() ? "error" : "warning", Label::always("kind"));
2697-
printRec(PDD->getMessage(), Label::optional("message"));
2698-
printFoot();
2699-
}
2700-
27012694
void visitPrecedenceGroupDecl(PrecedenceGroupDecl *PGD, Label label) {
27022695
printCommon(PGD, "precedence_group_decl", label);
27032696
printName(PGD->getName(), Label::optional("name"));
@@ -3130,12 +3123,9 @@ class PrintStmt : public StmtVisitor<PrintStmt, void, Label>,
31303123
void visitSwitchStmt(SwitchStmt *S, Label label) {
31313124
printCommon(S, "switch_stmt", label);
31323125
printRec(S->getSubjectExpr(), Label::optional("subject_expr"));
3133-
printList(S->getRawCases(), [&](ASTNode N, Label label) {
3134-
if (N.is<Stmt*>())
3135-
printRec(N.get<Stmt*>(), label);
3136-
else
3137-
printRec(N.get<Decl*>(), label);
3138-
}, Label::optional("cases"));
3126+
printList(
3127+
S->getCases(), [&](CaseStmt *CS, Label label) { printRec(CS, label); },
3128+
Label::optional("cases"));
31393129
printFoot();
31403130
}
31413131
void visitCaseStmt(CaseStmt *S, Label label) {

lib/AST/ASTMangler.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -5289,7 +5289,6 @@ ASTMangler::BaseEntitySignature::BaseEntitySignature(const Decl *decl)
52895289
case DeclKind::Extension:
52905290
case DeclKind::TopLevelCode:
52915291
case DeclKind::Import:
5292-
case DeclKind::PoundDiagnostic:
52935292
case DeclKind::PrecedenceGroup:
52945293
case DeclKind::Missing:
52955294
case DeclKind::MissingMember:

lib/AST/ASTPrinter.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -3522,17 +3522,6 @@ void PrintAST::visitTopLevelCodeDecl(TopLevelCodeDecl *decl) {
35223522
printASTNodes(decl->getBody()->getElements(), /*NeedIndent=*/false);
35233523
}
35243524

3525-
void PrintAST::visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
3526-
/// TODO: Should we even print #error/#warning?
3527-
if (PDD->isError()) {
3528-
Printer << tok::pound_error;
3529-
} else {
3530-
Printer << tok::pound_warning;
3531-
}
3532-
3533-
Printer << "(\"" << PDD->getMessage()->getValue() << "\")";
3534-
}
3535-
35363525
void PrintAST::visitOpaqueTypeDecl(OpaqueTypeDecl *decl) {
35373526
// TODO: If we introduce explicit opaque type decls, print them.
35383527
assert(decl->getName().empty());
@@ -5668,9 +5657,8 @@ void PrintAST::visitSwitchStmt(SwitchStmt *stmt) {
56685657
visit(stmt->getSubjectExpr());
56695658
Printer << " {";
56705659
Printer.printNewline();
5671-
for (auto N : stmt->getRawCases()) {
5672-
if (N.is<Stmt*>())
5673-
visit(cast<CaseStmt>(N.get<Stmt*>()));
5660+
for (auto *CS : stmt->getCases()) {
5661+
visit(CS);
56745662
Printer.printNewline();
56755663
}
56765664
indent();

lib/AST/ASTScopeCreation.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ class NodeAdder
364364
VISIT_AND_IGNORE(AssociatedTypeDecl)
365365
VISIT_AND_IGNORE(ModuleDecl)
366366
VISIT_AND_IGNORE(ParamDecl)
367-
VISIT_AND_IGNORE(PoundDiagnosticDecl)
368367
VISIT_AND_IGNORE(MissingDecl)
369368
VISIT_AND_IGNORE(MissingMemberDecl)
370369

lib/AST/ASTWalker.cpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
244244
return true;
245245
}
246246

247-
bool visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
248-
// By default, ignore #error/#warning.
249-
return false;
250-
}
251-
252247
bool visitOperatorDecl(OperatorDecl *OD) {
253248
return false;
254249
}
@@ -2068,19 +2063,12 @@ Stmt *Traversal::visitSwitchStmt(SwitchStmt *S) {
20682063
else
20692064
return nullptr;
20702065

2071-
for (auto N : S->getRawCases()) {
2072-
if (Stmt *aCase = N.dyn_cast<Stmt*>()) {
2073-
assert(isa<CaseStmt>(aCase));
2074-
if (Stmt *aStmt = doIt(aCase)) {
2075-
assert(aCase == aStmt && "switch case remap not supported");
2076-
(void)aStmt;
2077-
} else
2078-
return nullptr;
2079-
} else {
2080-
assert(isa<PoundDiagnosticDecl>(N.get<Decl*>()));
2081-
if (doIt(N.get<Decl*>()))
2082-
return nullptr;
2083-
}
2066+
for (auto *aCase : S->getCases()) {
2067+
if (Stmt *aStmt = doIt(aCase)) {
2068+
assert(aCase == aStmt && "switch case remap not supported");
2069+
(void)aStmt;
2070+
} else
2071+
return nullptr;
20842072
}
20852073

20862074
return S;

lib/AST/Bridging/StmtBridging.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ BridgedSwitchStmt BridgedSwitchStmt_createParsed(
251251
BridgedSourceLoc cLBraceLoc, BridgedArrayRef cCases,
252252
BridgedSourceLoc cRBraceLoc) {
253253
auto &context = cContext.unbridged();
254-
auto cases =
255-
context.AllocateTransform<ASTNode>(cCases.unbridged<BridgedASTNode>(),
256-
[](auto &e) { return e.unbridged(); });
254+
SmallVector<CaseStmt *, 16> cases;
255+
for (auto cCase : cCases.unbridged<BridgedCaseStmt>())
256+
cases.push_back(cCase.unbridged());
257257
return SwitchStmt::create(cLabelInfo.unbridged(), cSwitchLoc.unbridged(),
258258
cSubjectExpr.unbridged(), cLBraceLoc.unbridged(),
259259
cases, cRBraceLoc.unbridged(),

0 commit comments

Comments
 (0)