@@ -3008,9 +3008,10 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
3008
3008
backtrackToPosition (BeginParserPosition);
3009
3009
SourceLoc BeginLoc = Tok.getLoc ();
3010
3010
3011
- State->delayDecl (PersistentParserState::DelayedDeclKind::Decl, Flags.toRaw (),
3012
- CurDeclContext, {BeginLoc, EndLoc},
3013
- BeginParserPosition.PreviousLoc );
3011
+ State->setCodeCompletionDelayedDeclState (
3012
+ PersistentParserState::CodeCompletionDelayedDeclKind::Decl,
3013
+ Flags.toRaw (), CurDeclContext, {BeginLoc, EndLoc},
3014
+ BeginParserPosition.PreviousLoc );
3014
3015
3015
3016
while (SourceMgr.isBeforeInBuffer (Tok.getLoc (), CurrentLoc))
3016
3017
consumeToken ();
@@ -3045,21 +3046,6 @@ void Parser::setLocalDiscriminatorToParamList(ParameterList *PL) {
3045
3046
}
3046
3047
}
3047
3048
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
-
3063
3049
// / Parse a single syntactic declaration and return a list of decl
3064
3050
// / ASTs. This can return multiple results for var decls that bind to multiple
3065
3051
// / values, structs that define a struct decl and a constructor, etc.
@@ -3429,26 +3415,23 @@ Parser::parseDecl(ParseDeclOptions Flags,
3429
3415
consumeToken (tok::code_complete);
3430
3416
}
3431
3417
3432
- if (AttrStatus.hasCodeCompletion ()) {
3433
- if (CodeCompletion) {
3418
+ if (AttrStatus.hasCodeCompletion () || DeclResult.hasCodeCompletion ()) {
3419
+ if (isCodeCompletionFirstPass () &&
3420
+ !CurDeclContext->isModuleScopeContext () &&
3421
+ !isa<TopLevelCodeDecl>(CurDeclContext) &&
3422
+ !isa<AbstractClosureExpr>(CurDeclContext)) {
3423
+ // Only consume non-toplevel decls.
3424
+ consumeDecl (BeginParserPosition, Flags, /* IsTopLevel=*/ false );
3425
+
3426
+ return makeParserError ();
3427
+ }
3428
+ if (AttrStatus.hasCodeCompletion () && CodeCompletion) {
3434
3429
Optional<DeclKind> DK;
3435
3430
if (DeclResult.isNonNull ())
3436
3431
DK = DeclResult.get ()->getKind ();
3437
3432
CodeCompletion->setAttrTargetDeclKind (DK);
3438
- } else {
3439
- delayParseFromBeginningToHere (BeginParserPosition, Flags);
3440
- return makeParserError ();
3441
3433
}
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 ();
3434
+ DeclResult.setHasCodeCompletion ();
3452
3435
}
3453
3436
3454
3437
if (auto SF = CurDeclContext->getParentSourceFile ()) {
@@ -3593,48 +3576,6 @@ std::vector<Decl *> Parser::parseDeclListDelayed(IterableDeclContext *IDC) {
3593
3576
return parseDeclList (LBLoc, RBLoc, Id, Options, IDC, hadError);
3594
3577
}
3595
3578
3596
- void Parser::parseDeclDelayed () {
3597
- auto DelayedState = State->takeDelayedDeclState ();
3598
- assert (DelayedState.get () && " should have delayed state" );
3599
-
3600
- auto BeginParserPosition = getParserPosition (DelayedState->BodyPos );
3601
- auto EndLexerState = L->getStateForEndOfTokenLoc (DelayedState->BodyEnd );
3602
-
3603
- // ParserPositionRAII needs a primed parser to restore to.
3604
- if (Tok.is (tok::NUM_TOKENS))
3605
- consumeTokenWithoutFeedingReceiver ();
3606
-
3607
- // Ensure that we restore the parser state at exit.
3608
- ParserPositionRAII PPR (*this );
3609
-
3610
- // Create a lexer that cannot go past the end state.
3611
- Lexer LocalLex (*L, BeginParserPosition.LS , EndLexerState);
3612
-
3613
- // Temporarily swap out the parser's current lexer with our new one.
3614
- llvm::SaveAndRestore<Lexer *> T (L, &LocalLex);
3615
-
3616
- // Rewind to the beginning of the decl.
3617
- restoreParserPosition (BeginParserPosition);
3618
-
3619
- // Re-enter the lexical scope.
3620
- Scope S (this , DelayedState->takeScope ());
3621
- ContextChange CC (*this , DelayedState->ParentContext );
3622
-
3623
- parseDecl (ParseDeclOptions (DelayedState->Flags ),
3624
- /* IsAtStartOfLineOrPreviousHadSemi=*/ true ,
3625
- [&](Decl *D) {
3626
- if (auto *parent = DelayedState->ParentContext ) {
3627
- if (auto *NTD = dyn_cast<NominalTypeDecl>(parent)) {
3628
- NTD->addMember (D);
3629
- } else if (auto *ED = dyn_cast<ExtensionDecl>(parent)) {
3630
- ED->addMember (D);
3631
- } else if (auto *SF = dyn_cast<SourceFile>(parent)) {
3632
- SF->Decls .push_back (D);
3633
- }
3634
- }
3635
- });
3636
- }
3637
-
3638
3579
// / Parse an 'import' declaration, doing no token skipping on error.
3639
3580
// /
3640
3581
// / \verbatim
@@ -5658,9 +5599,9 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
5658
5599
5659
5600
if (isCodeCompletionFirstPass ()) {
5660
5601
if (SourceMgr.rangeContainsCodeCompletionLoc (BodyRange)) {
5661
- State->delayDecl (PersistentParserState::DelayedDeclKind::FunctionBody,
5662
- PD_Default, AFD, BodyRange ,
5663
- BeginParserPosition.PreviousLoc );
5602
+ State->setCodeCompletionDelayedDeclState (
5603
+ PersistentParserState::CodeCompletionDelayedDeclKind::FunctionBody ,
5604
+ PD_Default, AFD, BodyRange, BeginParserPosition.PreviousLoc );
5664
5605
} else {
5665
5606
AFD->setBodySkipped (BodyRange);
5666
5607
}
@@ -5975,20 +5916,6 @@ BraceStmt *Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {
5975
5916
return parseBraceItemList (diag::func_decl_without_brace).getPtrOrNull ();
5976
5917
}
5977
5918
5978
- // / Parse a delayed function body from the 'PersistentParserState'.
5979
- void Parser::parseAbstractFunctionBodyDelayed () {
5980
- auto DelayedState = State->takeDelayedDeclState ();
5981
- assert (DelayedState.get () && " should have delayed state" );
5982
- auto CD = DelayedState->ParentContext ->getAsDecl ();
5983
- auto AFD = cast<AbstractFunctionDecl>(CD);
5984
-
5985
- // Eagarly parse local decls or nested function bodies inside the body.
5986
- llvm::SaveAndRestore<bool > DisableDelayedBody (DelayBodyParsing, false );
5987
-
5988
- auto body = parseAbstractFunctionBodyDelayed (AFD);
5989
- AFD->setBodyParsed (body);
5990
- }
5991
-
5992
5919
// / Parse a 'enum' declaration, returning true (and doing no token
5993
5920
// / skipping) on error.
5994
5921
// /
0 commit comments