Skip to content

Commit 49fed42

Browse files
committed
NFC: Remove SILParserState from Subsystems
Since SIL parsing has been requestified, this is now redundant. Remove the type from Subsystems.h, and rename SILParserTUState to take its place.
1 parent 417e173 commit 49fed42

File tree

6 files changed

+35
-57
lines changed

6 files changed

+35
-57
lines changed

include/swift/Parse/ParseSILSupport.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace swift {
2020

2121
/// Interface between the Parse and ParseSIL libraries, to avoid circular
2222
/// dependencies.
23-
class SILParserTUStateBase {
23+
class SILParserStateBase {
2424
virtual void anchor();
2525
protected:
26-
SILParserTUStateBase() = default;
27-
virtual ~SILParserTUStateBase() = default;
26+
SILParserStateBase() = default;
27+
virtual ~SILParserStateBase() = default;
2828
public:
2929
virtual bool parseDeclSIL(Parser &P) = 0;
3030
virtual bool parseDeclSILStage(Parser &P) = 0;

include/swift/Parse/Parser.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace swift {
5050
class Lexer;
5151
class ParsedTypeSyntax;
5252
class PersistentParserState;
53-
class SILParserTUStateBase;
53+
class SILParserStateBase;
5454
class ScopeInfo;
5555
class SourceManager;
5656
class TupleType;
@@ -114,7 +114,7 @@ class Parser {
114114
DiagnosticEngine &Diags;
115115
SourceFile &SF;
116116
Lexer *L;
117-
SILParserTUStateBase *SIL; // Non-null when parsing SIL decls.
117+
SILParserStateBase *SIL; // Non-null when parsing SIL decls.
118118
PersistentParserState *State;
119119
std::unique_ptr<PersistentParserState> OwnedState;
120120
DeclContext *CurDeclContext;
@@ -396,14 +396,13 @@ class Parser {
396396

397397
public:
398398
Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
399-
SILParserTUStateBase *SIL,
400-
PersistentParserState *PersistentState,
399+
SILParserStateBase *SIL, PersistentParserState *PersistentState,
401400
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
402-
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
401+
Parser(unsigned BufferID, SourceFile &SF, SILParserStateBase *SIL,
403402
PersistentParserState *PersistentState = nullptr,
404403
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
405404
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
406-
SILParserTUStateBase *SIL = nullptr,
405+
SILParserStateBase *SIL = nullptr,
407406
PersistentParserState *PersistentState = nullptr,
408407
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
409408
~Parser();

include/swift/Subsystems.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ namespace swift {
5858
class SerializationOptions;
5959
class SILOptions;
6060
class SILModule;
61-
class SILParserTUState;
6261
class SourceFile;
6362
enum class SourceFileKind;
6463
class SourceManager;
@@ -74,17 +73,6 @@ namespace swift {
7473
class TypeConverter;
7574
}
7675

77-
/// Used to optionally maintain SIL parsing context for the parser.
78-
///
79-
/// When not parsing SIL, this has no overhead.
80-
class SILParserState {
81-
public:
82-
std::unique_ptr<SILParserTUState> Impl;
83-
84-
explicit SILParserState(SILModule *M);
85-
~SILParserState();
86-
};
87-
8876
/// @{
8977

9078
/// \returns true if the declaration should be verified. This can return

lib/Parse/ParseRequests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ BraceStmt *ParseAbstractFunctionBodyRequest::evaluate(
9696
SourceFile &sf = *afd->getDeclContext()->getParentSourceFile();
9797
SourceManager &sourceMgr = sf.getASTContext().SourceMgr;
9898
unsigned bufferID = sourceMgr.findBufferContainingLoc(afd->getLoc());
99-
Parser parser(bufferID, sf, static_cast<SILParserTUStateBase *>(nullptr),
100-
nullptr, nullptr);
99+
Parser parser(bufferID, sf, /*SIL*/ nullptr);
101100
parser.SyntaxContext->disable();
102101
auto body = parser.parseAbstractFunctionBodyDelayed(afd);
103102
afd->setBodyKind(BodyKind::Parsed);

lib/Parse/Parser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void tokenize(const LangOptions &LangOpts, const SourceManager &SM,
110110
using namespace swift;
111111
using namespace swift::syntax;
112112

113-
void SILParserTUStateBase::anchor() { }
113+
void SILParserStateBase::anchor() { }
114114

115115
void swift::performCodeCompletionSecondPass(
116116
SourceFile &SF, CodeCompletionCallbacksFactory &Factory) {
@@ -379,14 +379,14 @@ static LexerMode sourceFileKindToLexerMode(SourceFileKind kind) {
379379
llvm_unreachable("covered switch");
380380
}
381381

382-
Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
382+
Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserStateBase *SIL,
383383
PersistentParserState *PersistentState,
384384
std::shared_ptr<SyntaxParseActions> SPActions)
385385
: Parser(BufferID, SF, &SF.getASTContext().Diags, SIL, PersistentState,
386386
std::move(SPActions)) {}
387387

388388
Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
389-
SILParserTUStateBase *SIL,
389+
SILParserStateBase *SIL,
390390
PersistentParserState *PersistentState,
391391
std::shared_ptr<SyntaxParseActions> SPActions)
392392
: Parser(
@@ -521,8 +521,7 @@ class TokenRecorder: public ConsumeTokenReceiver {
521521
} // End of an anonymous namespace.
522522

523523
Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
524-
SILParserTUStateBase *SIL,
525-
PersistentParserState *PersistentState,
524+
SILParserStateBase *SIL, PersistentParserState *PersistentState,
526525
std::shared_ptr<SyntaxParseActions> SPActions)
527526
: SourceMgr(SF.getASTContext().SourceMgr),
528527
Diags(SF.getASTContext().Diags),

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ using namespace swift::syntax;
4646
// SILParserState implementation
4747
//===----------------------------------------------------------------------===//
4848

49-
namespace swift {
50-
// This has to be in the 'swift' namespace because it's forward-declared for
51-
// SILParserState.
52-
class SILParserTUState : public SILParserTUStateBase {
49+
namespace {
50+
class SILParserState : public SILParserStateBase {
5351
public:
54-
explicit SILParserTUState(SILModule &M) : M(M) {}
55-
~SILParserTUState();
52+
explicit SILParserState(SILModule &M) : M(M) {}
53+
~SILParserState();
5654

5755
SILModule &M;
5856

@@ -80,9 +78,9 @@ class SILParserTUState : public SILParserTUStateBase {
8078
bool parseSILProperty(Parser &P) override;
8179
bool parseSILScope(Parser &P) override;
8280
};
83-
} // end namespace swift
81+
} // end anonymous namespace
8482

85-
SILParserTUState::~SILParserTUState() {
83+
SILParserState::~SILParserState() {
8684
if (!ForwardRefFns.empty()) {
8785
for (auto Entry : ForwardRefFns) {
8886
if (Entry.second.Loc.isValid()) {
@@ -101,11 +99,6 @@ SILParserTUState::~SILParserTUState() {
10199
}
102100
}
103101

104-
SILParserState::SILParserState(SILModule *M)
105-
: Impl(M ? std::make_unique<SILParserTUState>(*M) : nullptr) {}
106-
107-
SILParserState::~SILParserState() = default;
108-
109102
std::unique_ptr<SILModule>
110103
ParseSILModuleRequest::evaluate(Evaluator &evaluator,
111104
SILGenDescriptor desc) const {
@@ -117,8 +110,8 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
117110

118111
auto silMod = SILModule::createEmptyModule(desc.context, desc.conv,
119112
desc.opts);
120-
SILParserState parserState(silMod.get());
121-
Parser parser(*bufferID, *SF, parserState.Impl.get());
113+
SILParserState parserState(*silMod.get());
114+
Parser parser(*bufferID, *SF, &parserState);
122115
PrettyStackTraceParser StackTrace(parser);
123116

124117
auto hadError = parser.parseTopLevelSIL();
@@ -157,11 +150,11 @@ namespace {
157150
};
158151

159152
class SILParser {
160-
friend SILParserTUState;
153+
friend SILParserState;
161154
public:
162155
Parser &P;
163156
SILModule &SILMod;
164-
SILParserTUState &TUState;
157+
SILParserState &TUState;
165158
SILFunction *F = nullptr;
166159
GenericEnvironment *ContextGenericEnv = nullptr;
167160

@@ -193,8 +186,8 @@ namespace {
193186

194187
public:
195188
SILParser(Parser &P)
196-
: P(P), SILMod(static_cast<SILParserTUState *>(P.SIL)->M),
197-
TUState(*static_cast<SILParserTUState *>(P.SIL)),
189+
: P(P), SILMod(static_cast<SILParserState *>(P.SIL)->M),
190+
TUState(*static_cast<SILParserState *>(P.SIL)),
198191
ParsedTypeCallback([](Type ty) {}) {}
199192

200193
/// diagnoseProblems - After a function is fully parse, emit any diagnostics
@@ -5638,7 +5631,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) {
56385631
/// 'sil' sil-linkage '@' identifier ':' sil-type decl-sil-body?
56395632
/// decl-sil-body:
56405633
/// '{' sil-basic-block+ '}'
5641-
bool SILParserTUState::parseDeclSIL(Parser &P) {
5634+
bool SILParserState::parseDeclSIL(Parser &P) {
56425635
// Inform the lexer that we're lexing the body of the SIL declaration. Do
56435636
// this before we consume the 'sil' token so that all later tokens are
56445637
// properly handled.
@@ -5806,7 +5799,7 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {
58065799

58075800
/// decl-sil-stage: [[only in SIL mode]]
58085801
/// 'sil_stage' ('raw' | 'canonical')
5809-
bool SILParserTUState::parseDeclSILStage(Parser &P) {
5802+
bool SILParserState::parseDeclSILStage(Parser &P) {
58105803
SourceLoc stageLoc = P.consumeToken(tok::kw_sil_stage);
58115804
if (!P.Tok.is(tok::identifier)) {
58125805
P.diagnose(P.Tok, diag::expected_sil_stage_name);
@@ -5887,7 +5880,7 @@ static Optional<VarDecl *> lookupGlobalDecl(Identifier GlobalName,
58875880

58885881
/// decl-sil-global: [[only in SIL mode]]
58895882
/// 'sil_global' sil-linkage @name : sil-type [external]
5890-
bool SILParserTUState::parseSILGlobal(Parser &P) {
5883+
bool SILParserState::parseSILGlobal(Parser &P) {
58915884
// Inform the lexer that we're lexing the body of the SIL declaration.
58925885
Lexer::SILBodyRAII Tmp(*P.L);
58935886

@@ -5944,7 +5937,7 @@ bool SILParserTUState::parseSILGlobal(Parser &P) {
59445937
/// decl-sil-property: [[only in SIL mode]]
59455938
/// 'sil_property' sil-decl-ref '(' sil-key-path-pattern-component ')'
59465939

5947-
bool SILParserTUState::parseSILProperty(Parser &P) {
5940+
bool SILParserState::parseSILProperty(Parser &P) {
59485941
Lexer::SILBodyRAII Tmp(*P.L);
59495942

59505943
auto loc = P.consumeToken(tok::kw_sil_property);
@@ -6017,7 +6010,7 @@ bool SILParserTUState::parseSILProperty(Parser &P) {
60176010
/// '{' sil-vtable-entry* '}'
60186011
/// sil-vtable-entry:
60196012
/// SILDeclRef ':' SILFunctionName
6020-
bool SILParserTUState::parseSILVTable(Parser &P) {
6013+
bool SILParserState::parseSILVTable(Parser &P) {
60216014
P.consumeToken(tok::kw_sil_vtable);
60226015
SILParser VTableState(P);
60236016

@@ -6545,7 +6538,7 @@ static bool parseSILVTableEntry(
65456538
/// associated_type_protocol (AssocName: ProtocolName):
65466539
/// protocol-conformance|dependent
65476540
/// base_protocol ProtocolName: protocol-conformance
6548-
bool SILParserTUState::parseSILWitnessTable(Parser &P) {
6541+
bool SILParserState::parseSILWitnessTable(Parser &P) {
65496542
P.consumeToken(tok::kw_sil_witness_table);
65506543
SILParser WitnessState(P);
65516544

@@ -6648,7 +6641,7 @@ bool SILParserTUState::parseSILWitnessTable(Parser &P) {
66486641
/// sil-default-witness-entry:
66496642
/// sil-witness-entry
66506643
/// 'no_default'
6651-
bool SILParserTUState::parseSILDefaultWitnessTable(Parser &P) {
6644+
bool SILParserState::parseSILDefaultWitnessTable(Parser &P) {
66526645
P.consumeToken(tok::kw_sil_default_witness_table);
66536646
SILParser WitnessState(P);
66546647

@@ -6715,7 +6708,7 @@ bool SILParserTUState::parseSILDefaultWitnessTable(Parser &P) {
67156708
///
67166709
/// index-subset ::=
67176710
/// [0-9]+ (' ' [0-9]+)*
6718-
bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
6711+
bool SILParserState::parseSILDifferentiabilityWitness(Parser &P) {
67196712
auto loc = P.consumeToken(tok::kw_sil_differentiability_witness);
67206713
auto silLoc = RegularLocation(loc);
67216714
SILParser State(P);
@@ -6865,7 +6858,7 @@ llvm::Optional<llvm::coverage::Counter> SILParser::parseSILCoverageExpr(
68656858
/// StartLine ':' StartCol '->' EndLine ':' EndCol
68666859
/// sil-coverage-expr:
68676860
/// ...
6868-
bool SILParserTUState::parseSILCoverageMap(Parser &P) {
6861+
bool SILParserState::parseSILCoverageMap(Parser &P) {
68696862
P.consumeToken(tok::kw_sil_coverage_map);
68706863
SILParser State(P);
68716864

@@ -6956,7 +6949,7 @@ bool SILParserTUState::parseSILCoverageMap(Parser &P) {
69566949
/// scope-parent ::= sil-function-name ':' sil-type
69576950
/// scope-parent ::= sil-scope-ref
69586951
/// debug-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+
6959-
bool SILParserTUState::parseSILScope(Parser &P) {
6952+
bool SILParserState::parseSILScope(Parser &P) {
69606953
P.consumeToken(tok::kw_sil_scope);
69616954
SILParser ScopeState(P);
69626955

0 commit comments

Comments
 (0)