Skip to content

Commit 4e50237

Browse files
committed
[Parse/CodeCompletion] Cleanup code completion facilities in Parse
- delayParseFromBeginningToHere is useless. Use delayDecl() instead - Inline PersistentParserState::delayTopLevel() - Cleanup completion handling in parseDecl()
1 parent 253d6ac commit 4e50237

File tree

5 files changed

+15
-44
lines changed

5 files changed

+15
-44
lines changed

include/swift/Parse/Parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,6 @@ class Parser {
895895
/// Options that control the parsing of declarations.
896896
using ParseDeclOptions = OptionSet<ParseDeclFlags>;
897897

898-
void delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
899-
ParseDeclOptions Flags);
900898
void consumeDecl(ParserPosition BeginParserPosition, ParseDeclOptions Flags,
901899
bool IsTopLevel);
902900

include/swift/Parse/PersistentParserState.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ class PersistentParserState {
9595

9696
void delayDeclList(IterableDeclContext *D);
9797

98-
void delayTopLevel(TopLevelCodeDecl *TLCD, SourceRange BodyRange,
99-
SourceLoc PreviousLoc);
100-
10198
bool hasDelayedDecl() {
10299
return CodeCompletionDelayedDeclState.get() != nullptr;
103100
}

lib/Parse/ParseDecl.cpp

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,21 +3045,6 @@ void Parser::setLocalDiscriminatorToParamList(ParameterList *PL) {
30453045
}
30463046
}
30473047

3048-
void Parser::delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
3049-
ParseDeclOptions Flags) {
3050-
auto CurLoc = Tok.getLoc();
3051-
backtrackToPosition(BeginParserPosition);
3052-
SourceLoc BeginLoc = Tok.getLoc();
3053-
SourceLoc EndLoc = CurLoc;
3054-
State->delayDecl(PersistentParserState::DelayedDeclKind::Decl,
3055-
Flags.toRaw(),
3056-
CurDeclContext, {BeginLoc, EndLoc},
3057-
BeginParserPosition.PreviousLoc);
3058-
3059-
while (Tok.isNot(tok::eof))
3060-
consumeToken();
3061-
}
3062-
30633048
/// Parse a single syntactic declaration and return a list of decl
30643049
/// ASTs. This can return multiple results for var decls that bind to multiple
30653050
/// values, structs that define a struct decl and a constructor, etc.
@@ -3429,26 +3414,23 @@ Parser::parseDecl(ParseDeclOptions Flags,
34293414
consumeToken(tok::code_complete);
34303415
}
34313416

3432-
if (AttrStatus.hasCodeCompletion()) {
3433-
if (CodeCompletion) {
3417+
if (AttrStatus.hasCodeCompletion() || DeclResult.hasCodeCompletion()) {
3418+
if (isCodeCompletionFirstPass() &&
3419+
!CurDeclContext->isModuleScopeContext() &&
3420+
!isa<TopLevelCodeDecl>(CurDeclContext) &&
3421+
!isa<AbstractClosureExpr>(CurDeclContext)) {
3422+
// Only consume non-toplevel decls.
3423+
consumeDecl(BeginParserPosition, Flags, /*IsTopLevel=*/false);
3424+
3425+
return makeParserError();
3426+
}
3427+
if (AttrStatus.hasCodeCompletion() && CodeCompletion) {
34343428
Optional<DeclKind> DK;
34353429
if (DeclResult.isNonNull())
34363430
DK = DeclResult.get()->getKind();
34373431
CodeCompletion->setAttrTargetDeclKind(DK);
3438-
} else {
3439-
delayParseFromBeginningToHere(BeginParserPosition, Flags);
3440-
return makeParserError();
34413432
}
3442-
}
3443-
3444-
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass() &&
3445-
!CurDeclContext->isModuleScopeContext() &&
3446-
!isa<TopLevelCodeDecl>(CurDeclContext) &&
3447-
!isa<AbstractClosureExpr>(CurDeclContext)) {
3448-
// Only consume non-toplevel decls.
3449-
consumeDecl(BeginParserPosition, Flags, /*IsTopLevel=*/false);
3450-
3451-
return makeParserError();
3433+
DeclResult.setHasCodeCompletion();
34523434
}
34533435

34543436
if (auto SF = CurDeclContext->getParentSourceFile()) {

lib/Parse/ParseStmt.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ void Parser::consumeTopLevelDecl(ParserPosition BeginParserPosition,
256256
SourceLoc EndLoc = PreviousLoc;
257257
backtrackToPosition(BeginParserPosition);
258258
SourceLoc BeginLoc = Tok.getLoc();
259-
State->delayTopLevel(TLCD, {BeginLoc, EndLoc},
260-
BeginParserPosition.PreviousLoc);
259+
State->delayDecl(PersistentParserState::DelayedDeclKind::TopLevelCodeDecl,
260+
PD_Default, TLCD, {BeginLoc, EndLoc},
261+
BeginParserPosition.PreviousLoc);
261262

262263
// Skip the rest of the file to prevent the parser from constructing the AST
263264
// for it. Forward references are not allowed at the top level.

lib/Parse/PersistentParserState.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,3 @@ void PersistentParserState::parseAllDelayedDeclLists() {
4545
for (auto IDC : DelayedDeclLists)
4646
IDC->loadAllMembers();
4747
}
48-
49-
void PersistentParserState::delayTopLevel(TopLevelCodeDecl *TLCD,
50-
SourceRange BodyRange,
51-
SourceLoc PreviousLoc) {
52-
delayDecl(DelayedDeclKind::TopLevelCodeDecl, 0U, TLCD, BodyRange,
53-
PreviousLoc);
54-
}

0 commit comments

Comments
 (0)