Skip to content

Commit 4df9fc1

Browse files
committed
[Parse] Remove delayed parsing for accessor decls
Now that, parsing accessor body is done by 'parseAbstractFunctionBody()' which automatically handles delayed parsing by `delayFunctionBodyParsing()`. So we no longer use delayed parsing facilities specific for accessor body.
1 parent 51b7168 commit 4df9fc1

File tree

3 files changed

+0
-116
lines changed

3 files changed

+0
-116
lines changed

include/swift/Parse/PersistentParserState.h

-29
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ class PersistentParserState {
5252
{}
5353
};
5454

55-
class AccessorBodyState {
56-
ParserPos BodyPos;
57-
SavedScope Scope;
58-
SourceLoc LBLoc;
59-
friend class Parser;
60-
61-
SavedScope takeScope() {
62-
return std::move(Scope);
63-
}
64-
65-
public:
66-
AccessorBodyState(SourceRange BodyRange, SourceLoc PreviousLoc,
67-
SavedScope &&Scope, SourceLoc LBLoc)
68-
: BodyPos{BodyRange.Start, PreviousLoc}, Scope(std::move(Scope)),
69-
LBLoc(LBLoc) {}
70-
};
71-
7255
enum class DelayedDeclKind {
7356
TopLevelCodeDecl,
7457
Decl,
@@ -109,11 +92,6 @@ class PersistentParserState {
10992
std::unique_ptr<FunctionBodyState>>;
11093
DelayedFunctionBodiesTy DelayedFunctionBodies;
11194

112-
using DelayedAccessorBodiesTy =
113-
llvm::DenseMap<AbstractFunctionDecl *,
114-
std::unique_ptr<AccessorBodyState>>;
115-
DelayedAccessorBodiesTy DelayedAccessorBodies;
116-
11795
/// \brief Parser sets this if it stopped parsing before the buffer ended.
11896
ParserPosition MarkedPos;
11997

@@ -133,13 +111,6 @@ class PersistentParserState {
133111

134112
bool hasFunctionBodyState(AbstractFunctionDecl *AFD);
135113

136-
void delayAccessorBodyParsing(AbstractFunctionDecl *AFD,
137-
SourceRange BodyRange,
138-
SourceLoc PreviousLoc,
139-
SourceLoc LBLoc);
140-
std::unique_ptr<AccessorBodyState>
141-
takeAccessorBodyState(AbstractFunctionDecl *AFD);
142-
143114
void delayDecl(DelayedDeclKind Kind, unsigned Flags,
144115
DeclContext *ParentContext,
145116
SourceRange BodyRange, SourceLoc PreviousLoc);

lib/Parse/ParseDecl.cpp

-65
Original file line numberDiff line numberDiff line change
@@ -3917,31 +3917,6 @@ static unsigned skipBracedBlock(Parser &P,
39173917
return OpenBraces;
39183918
}
39193919

3920-
void Parser::consumeGetSetBody(AbstractFunctionDecl *AFD,
3921-
SourceLoc LBLoc) {
3922-
SourceLoc SavedPreviousLoc = PreviousLoc;
3923-
3924-
SourceRange BodyRange;
3925-
BodyRange.Start = Tok.getLoc();
3926-
3927-
// Skip until the next '}' at the correct nesting level.
3928-
unsigned OpenBraces = skipUntilMatchingRBrace(*this, SyntaxContext);
3929-
3930-
if (OpenBraces != 1) {
3931-
// FIXME: implement some error recovery?
3932-
}
3933-
3934-
BodyRange.End = PreviousLoc;
3935-
3936-
if (DelayedParseCB->shouldDelayFunctionBodyParsing(
3937-
*this, AFD, AFD->getAttrs(), BodyRange)) {
3938-
State->delayAccessorBodyParsing(AFD, BodyRange, SavedPreviousLoc, LBLoc);
3939-
AFD->setBodyDelayed(BodyRange);
3940-
} else {
3941-
AFD->setBodySkipped(BodyRange);
3942-
}
3943-
}
3944-
39453920
/// Returns a descriptive name for the given accessor/addressor kind.
39463921
static StringRef getAccessorNameForDiagnostic(AccessorKind accessorKind,
39473922
AddressorKind addressorKind,
@@ -4262,46 +4237,6 @@ bool Parser::parseGetSet(ParseDeclOptions Flags,
42624237
return Invalid;
42634238
}
42644239

4265-
void Parser::parseAccessorBodyDelayed(AbstractFunctionDecl *AFD) {
4266-
assert(!AFD->getBody() && "function should not have a parsed body");
4267-
assert(AFD->getBodyKind() == AbstractFunctionDecl::BodyKind::Unparsed &&
4268-
"function body should be delayed");
4269-
4270-
auto AccessorParserState = State->takeAccessorBodyState(AFD);
4271-
assert(AccessorParserState.get() && "should have a valid state");
4272-
4273-
auto BeginParserPosition = getParserPosition(AccessorParserState->BodyPos);
4274-
auto EndLexerState = L->getStateForEndOfTokenLoc(AFD->getEndLoc());
4275-
4276-
// ParserPositionRAII needs a primed parser to restore to.
4277-
if (Tok.is(tok::NUM_TOKENS))
4278-
consumeTokenWithoutFeedingReceiver();
4279-
4280-
// Ensure that we restore the parser state at exit.
4281-
ParserPositionRAII PPR(*this);
4282-
4283-
// Create a lexer that cannot go past the end state.
4284-
Lexer LocalLex(*L, BeginParserPosition.LS, EndLexerState);
4285-
4286-
// Temporarily swap out the parser's current lexer with our new one.
4287-
llvm::SaveAndRestore<Lexer *> T(L, &LocalLex);
4288-
4289-
// Rewind to the first token of the accessor body.
4290-
restoreParserPosition(BeginParserPosition);
4291-
4292-
// Re-enter the lexical scope.
4293-
Scope S(this, AccessorParserState->takeScope());
4294-
ParseFunctionBody CC(*this, AFD);
4295-
setLocalDiscriminatorToParamList(AFD->getParameters());
4296-
4297-
SmallVector<ASTNode, 16> Entries;
4298-
parseBraceItems(Entries);
4299-
BraceStmt *Body =
4300-
BraceStmt::create(Context, AccessorParserState->LBLoc, Entries,
4301-
Tok.getLoc());
4302-
AFD->setBody(Body);
4303-
}
4304-
43054240
static void fillInAccessorTypeErrors(Parser &P, FuncDecl *accessor,
43064241
AccessorKind kind) {
43074242
if (!accessor) return;

lib/Parse/PersistentParserState.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,6 @@ bool PersistentParserState::hasFunctionBodyState(AbstractFunctionDecl *AFD) {
4545
return DelayedFunctionBodies.find(AFD) != DelayedFunctionBodies.end();
4646
}
4747

48-
void PersistentParserState::delayAccessorBodyParsing(AbstractFunctionDecl *AFD,
49-
SourceRange BodyRange,
50-
SourceLoc PreviousLoc,
51-
SourceLoc LBLoc) {
52-
std::unique_ptr<AccessorBodyState> State;
53-
State.reset(new AccessorBodyState(BodyRange, PreviousLoc,
54-
ScopeInfo.saveCurrentScope(), LBLoc));
55-
assert(DelayedAccessorBodies.find(AFD) == DelayedAccessorBodies.end() &&
56-
"Already recorded state for this body");
57-
DelayedAccessorBodies[AFD] = std::move(State);
58-
}
59-
60-
std::unique_ptr<PersistentParserState::AccessorBodyState>
61-
PersistentParserState::takeAccessorBodyState(AbstractFunctionDecl *AFD) {
62-
assert(AFD->getBodyKind() == AbstractFunctionDecl::BodyKind::Unparsed);
63-
DelayedAccessorBodiesTy::iterator I = DelayedAccessorBodies.find(AFD);
64-
assert(I != DelayedAccessorBodies.end() && "State should be saved");
65-
std::unique_ptr<AccessorBodyState> State = std::move(I->second);
66-
DelayedAccessorBodies.erase(I);
67-
return State;
68-
}
69-
7048
void PersistentParserState::delayDecl(DelayedDeclKind Kind,
7149
unsigned Flags,
7250
DeclContext *ParentContext,

0 commit comments

Comments
 (0)