Skip to content

Commit 3d3a2a5

Browse files
committed
Remove redundant state from PersistentParserState
Now that we parse Swift decls in one pass, we no longer need to track the parser's position across multiple parser calls.
1 parent 312f7dd commit 3d3a2a5

File tree

4 files changed

+7
-42
lines changed

4 files changed

+7
-42
lines changed

include/swift/Parse/Parser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,8 @@ class Parser {
431431
PreviousLoc);
432432
}
433433

434-
ParserPosition getParserPosition(const PersistentParserState::ParserPos &Pos){
435-
return ParserPosition(L->getStateForBeginningOfTokenLoc(Pos.Loc),
436-
Pos.PrevLoc);
434+
ParserPosition getParserPosition(SourceLoc loc, SourceLoc previousLoc) {
435+
return ParserPosition(L->getStateForBeginningOfTokenLoc(loc), previousLoc);
437436
}
438437

439438
void restoreParserPosition(ParserPosition PP, bool enableDiagnostics = false) {

include/swift/Parse/PersistentParserState.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,12 @@ class CodeCompletionDelayedDeclState {
5959
/// Parser state persistent across multiple parses.
6060
class PersistentParserState {
6161
public:
62-
struct ParserPos {
63-
SourceLoc Loc;
64-
SourceLoc PrevLoc;
65-
66-
bool isValid() const { return Loc.isValid(); }
67-
};
68-
69-
bool InPoundLineEnvironment = false;
7062
// FIXME: When condition evaluation moves to a later phase, remove this bit
7163
// and adjust the client call 'performParseOnly'.
7264
bool PerformConditionEvaluation = true;
7365
private:
7466
swift::ScopeInfo ScopeInfo;
7567

76-
/// Parser sets this if it stopped parsing before the buffer ended.
77-
ParserPosition MarkedPos;
78-
7968
std::unique_ptr<CodeCompletionDelayedDeclState> CodeCompletionDelayedDeclStat;
8069

8170
/// The local context for all top-level code.
@@ -113,19 +102,6 @@ class PersistentParserState {
113102
TopLevelContext &getTopLevelContext() {
114103
return TopLevelCode;
115104
}
116-
117-
void markParserPosition(ParserPosition Pos,
118-
bool InPoundLineEnvironment) {
119-
MarkedPos = Pos;
120-
this->InPoundLineEnvironment = InPoundLineEnvironment;
121-
}
122-
123-
/// Returns the marked parser position and resets it.
124-
ParserPosition takeParserPosition() {
125-
ParserPosition Pos = MarkedPos;
126-
MarkedPos = ParserPosition();
127-
return Pos;
128-
}
129105
};
130106

131107
} // end namespace swift

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ void Parser::parseTopLevel() {
239239
SF.ASTStage = SourceFile::Parsed;
240240
verify(SF);
241241

242-
// Next time start relexing from the beginning of the comment so that we can
243-
// attach it to the token.
244-
State->markParserPosition(getParserPosition(),
245-
InPoundLineEnvironment);
246-
247242
// Finalize the token receiver.
248243
SyntaxContext->addToken(Tok, LeadingTrivia, TrailingTrivia);
249244
TokReceiver->finalize();
@@ -4012,7 +4007,8 @@ Parser::parseDeclListDelayed(IterableDeclContext *IDC) {
40124007
return {std::vector<Decl *>(), None};
40134008
}
40144009

4015-
auto BeginParserPosition = getParserPosition({BodyRange.Start, SourceLoc()});
4010+
auto BeginParserPosition = getParserPosition(BodyRange.Start,
4011+
/*previousLoc*/ SourceLoc());
40164012
auto EndLexerState = L->getStateForEndOfTokenLoc(BodyRange.End);
40174013

40184014
// ParserPositionRAII needs a primed parser to restore to.
@@ -6426,7 +6422,8 @@ BraceStmt *Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {
64266422
"function body should be delayed");
64276423

64286424
auto bodyRange = AFD->getBodySourceRange();
6429-
auto BeginParserPosition = getParserPosition({bodyRange.Start, SourceLoc()});
6425+
auto BeginParserPosition = getParserPosition(bodyRange.Start,
6426+
/*previousLoc*/ SourceLoc());
64306427
auto EndLexerState = L->getStateForEndOfTokenLoc(AFD->getEndLoc());
64316428

64326429
// ParserPositionRAII needs a primed parser to restore to.

lib/Parse/Parser.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void Parser::performCodeCompletionSecondPassImpl(
148148
if (info.PrevOffset != ~0U)
149149
prevLoc = SourceMgr.getLocForOffset(BufferID, info.PrevOffset);
150150
// Set the parser position to the start of the delayed decl or the body.
151-
restoreParserPosition(getParserPosition({startLoc, prevLoc}));
151+
restoreParserPosition(getParserPosition(startLoc, prevLoc));
152152

153153
// Do not delay parsing in the second pass.
154154
llvm::SaveAndRestore<bool> DisableDelayedBody(DelayBodyParsing, false);
@@ -543,13 +543,6 @@ Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
543543
// Set the token to a sentinel so that we know the lexer isn't primed yet.
544544
// This cannot be tok::unknown, since that is a token the lexer could produce.
545545
Tok.setKind(tok::NUM_TOKENS);
546-
547-
auto ParserPos = State->takeParserPosition();
548-
if (ParserPos.isValid() &&
549-
L->isStateForCurrentBuffer(ParserPos.LS)) {
550-
restoreParserPosition(ParserPos);
551-
InPoundLineEnvironment = State->InPoundLineEnvironment;
552-
}
553546
}
554547

555548
Parser::~Parser() {

0 commit comments

Comments
 (0)