Skip to content

Commit d7f6768

Browse files
committed
Eliminate DelayedParsingCallbacks.
DelayedParsingCallbacks only had one implementation, for code completion, which is only used to determine which bodies to skip and which to delay. Inline that logic into the parser's delay logic and remove DelayedParsingCallbacks entirely.
1 parent b3e3d39 commit d7f6768

File tree

11 files changed

+24
-125
lines changed

11 files changed

+24
-125
lines changed

include/swift/Frontend/Frontend.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ class CompilerInstance {
616616

617617
private:
618618
void createREPLFile(const ImplicitImports &implicitImports);
619-
std::unique_ptr<DelayedParsingCallbacks> computeDelayedParsingCallback();
620619

621620
void addMainFileToModule(const ImplicitImports &implicitImports);
622621

@@ -625,20 +624,17 @@ class CompilerInstance {
625624
SourceFile::ASTStage_t LimitStage);
626625

627626
void parseLibraryFile(unsigned BufferID,
628-
const ImplicitImports &implicitImports,
629-
DelayedParsingCallbacks *DelayedCB);
627+
const ImplicitImports &implicitImports);
630628

631629
/// Return true if had load error
632630
bool
633-
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports,
634-
DelayedParsingCallbacks *DelayedCB);
631+
parsePartialModulesAndLibraryFiles(const ImplicitImports &implicitImports);
635632

636633
OptionSet<TypeCheckingFlags> computeTypeCheckingOptions();
637634

638635
void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);
639636

640637
void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage,
641-
DelayedParsingCallbacks *DelayedParseCB,
642638
OptionSet<TypeCheckingFlags> TypeCheckOptions);
643639

644640
void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions);

include/swift/Parse/DelayedParsingCallbacks.h

-59
This file was deleted.

include/swift/Parse/Parser.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ namespace llvm {
4646
namespace swift {
4747
class CodeCompletionCallbacks;
4848
class DefaultArgumentInitializer;
49-
class DelayedParsingCallbacks;
5049
class DiagnosticEngine;
5150
class Expr;
5251
class Lexer;
@@ -165,14 +164,8 @@ class Parser {
165164

166165
LocalContext *CurLocalContext = nullptr;
167166

168-
DelayedParsingCallbacks *DelayedParseCB = nullptr;
169-
170167
bool isDelayedParsingEnabled() const {
171-
return DelayBodyParsing || DelayedParseCB != nullptr;
172-
}
173-
174-
void setDelayedParsingCallbacks(DelayedParsingCallbacks *DelayedParseCB) {
175-
this->DelayedParseCB = DelayedParseCB;
168+
return DelayBodyParsing || SourceMgr.getCodeCompletionLoc().isValid();
176169
}
177170

178171
void setCodeCompletionCallbacks(CodeCompletionCallbacks *Callbacks) {

include/swift/Subsystems.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ namespace swift {
4343
class CodeCompletionCallbacksFactory;
4444
class Decl;
4545
class DeclContext;
46-
class DelayedParsingCallbacks;
4746
class DiagnosticConsumer;
4847
class DiagnosticEngine;
4948
class Evaluator;
@@ -114,23 +113,18 @@ namespace swift {
114113
/// \param PersistentState if non-null the same PersistentState object can
115114
/// be used to resume parsing or parse delayed function bodies.
116115
///
117-
/// \param DelayedParseCB if non-null enables delayed parsing for function
118-
/// bodies.
119-
///
120116
/// \return true if the parser found code with side effects.
121117
bool parseIntoSourceFile(SourceFile &SF, unsigned BufferID, bool *Done,
122118
SILParserState *SIL = nullptr,
123119
PersistentParserState *PersistentState = nullptr,
124-
DelayedParsingCallbacks *DelayedParseCB = nullptr,
125120
bool DelayBodyParsing = true);
126121

127122
/// Parse a single buffer into the given source file, until the full source
128123
/// contents are parsed.
129124
///
130125
/// \return true if the parser found code with side effects.
131126
bool parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
132-
PersistentParserState *PersistentState = nullptr,
133-
DelayedParsingCallbacks *DelayedParseCB = nullptr,
127+
PersistentParserState *PersistentState = nullptr,
134128
bool DelayBodyParsing = true);
135129

136130
/// Finish the parsing by going over the nodes that were delayed

lib/Basic/SourceLoc.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void SourceManager::verifyAllBuffers() const {
3535
}
3636

3737
SourceLoc SourceManager::getCodeCompletionLoc() const {
38+
if (CodeCompletionBufferID == 0U)
39+
return SourceLoc();
40+
3841
return getLocForBufferStart(CodeCompletionBufferID)
3942
.getAdvancedLoc(CodeCompletionOffset);
4043
}

lib/Frontend/Frontend.cpp

+9-24
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "swift/Basic/SourceManager.h"
2525
#include "swift/Basic/Statistic.h"
2626
#include "swift/Frontend/ParseableInterfaceModuleLoader.h"
27-
#include "swift/Parse/DelayedParsingCallbacks.h"
2827
#include "swift/Parse/Lexer.h"
2928
#include "swift/SIL/SILModule.h"
3029
#include "swift/SILOptimizer/PassManager/Passes.h"
@@ -758,14 +757,6 @@ void CompilerInstance::createREPLFile(const ImplicitImports &implicitImports) {
758757
addAdditionalInitialImportsTo(SingleInputFile, implicitImports);
759758
}
760759

761-
std::unique_ptr<DelayedParsingCallbacks>
762-
CompilerInstance::computeDelayedParsingCallback() {
763-
if (Invocation.isCodeCompletion())
764-
return llvm::make_unique<CodeCompleteDelayedCallbacks>(
765-
SourceMgr.getCodeCompletionLoc());
766-
return nullptr;
767-
}
768-
769760
void CompilerInstance::addMainFileToModule(
770761
const ImplicitImports &implicitImports) {
771762
auto *MainFile = createSourceFileForMainModule(
@@ -776,13 +767,10 @@ void CompilerInstance::addMainFileToModule(
776767
void CompilerInstance::parseAndCheckTypesUpTo(
777768
const ImplicitImports &implicitImports, SourceFile::ASTStage_t limitStage) {
778769
FrontendStatsTracer tracer(Context->Stats, "parse-and-check-types");
779-
std::unique_ptr<DelayedParsingCallbacks> DelayedCB{
780-
computeDelayedParsingCallback()};
781770

782771
PersistentState = llvm::make_unique<PersistentParserState>();
783772

784-
bool hadLoadError = parsePartialModulesAndLibraryFiles(
785-
implicitImports, DelayedCB.get());
773+
bool hadLoadError = parsePartialModulesAndLibraryFiles(implicitImports);
786774
if (Invocation.isCodeCompletion()) {
787775
// When we are doing code completion, make sure to emit at least one
788776
// diagnostic, so that ASTContext is marked as erroneous. In this case
@@ -800,7 +788,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
800788
// In addition, the main file has parsing and type-checking
801789
// interwined.
802790
if (MainBufferID != NO_SUCH_BUFFER) {
803-
parseAndTypeCheckMainFileUpTo(limitStage, DelayedCB.get(), TypeCheckOptions);
791+
parseAndTypeCheckMainFileUpTo(limitStage, TypeCheckOptions);
804792
}
805793

806794
assert(llvm::all_of(MainModule->getFiles(), [](const FileUnit *File) -> bool {
@@ -846,8 +834,7 @@ void CompilerInstance::parseAndCheckTypesUpTo(
846834
}
847835

848836
void CompilerInstance::parseLibraryFile(
849-
unsigned BufferID, const ImplicitImports &implicitImports,
850-
DelayedParsingCallbacks *DelayedCB) {
837+
unsigned BufferID, const ImplicitImports &implicitImports) {
851838
FrontendStatsTracer tracer(Context->Stats, "parse-library-file");
852839

853840
auto *NextInput = createSourceFileForMainModule(
@@ -865,7 +852,7 @@ void CompilerInstance::parseLibraryFile(
865852
// Parser may stop at some erroneous constructions like #else, #endif
866853
// or '}' in some cases, continue parsing until we are done
867854
parseIntoSourceFile(*NextInput, BufferID, &Done, nullptr,
868-
PersistentState.get(), DelayedCB,
855+
PersistentState.get(),
869856
/*DelayedBodyParsing=*/!IsPrimary);
870857
} while (!Done);
871858

@@ -893,8 +880,7 @@ OptionSet<TypeCheckingFlags> CompilerInstance::computeTypeCheckingOptions() {
893880
}
894881

895882
bool CompilerInstance::parsePartialModulesAndLibraryFiles(
896-
const ImplicitImports &implicitImports,
897-
DelayedParsingCallbacks *DelayedCB) {
883+
const ImplicitImports &implicitImports) {
898884
FrontendStatsTracer tracer(Context->Stats,
899885
"parse-partial-modules-and-library-files");
900886
bool hadLoadError = false;
@@ -910,15 +896,14 @@ bool CompilerInstance::parsePartialModulesAndLibraryFiles(
910896
// Then parse all the library files.
911897
for (auto BufferID : InputSourceCodeBufferIDs) {
912898
if (BufferID != MainBufferID) {
913-
parseLibraryFile(BufferID, implicitImports, DelayedCB);
899+
parseLibraryFile(BufferID, implicitImports);
914900
}
915901
}
916902
return hadLoadError;
917903
}
918904

919905
void CompilerInstance::parseAndTypeCheckMainFileUpTo(
920906
SourceFile::ASTStage_t LimitStage,
921-
DelayedParsingCallbacks *DelayedParseCB,
922907
OptionSet<TypeCheckingFlags> TypeCheckOptions) {
923908
FrontendStatsTracer tracer(Context->Stats,
924909
"parse-and-typecheck-main-file");
@@ -942,7 +927,7 @@ void CompilerInstance::parseAndTypeCheckMainFileUpTo(
942927
// with 'sil' definitions.
943928
parseIntoSourceFile(MainFile, MainFile.getBufferID().getValue(), &Done,
944929
TheSILModule ? &SILContext : nullptr,
945-
PersistentState.get(), DelayedParseCB,
930+
PersistentState.get(),
946931
/*DelayedBodyParsing=*/false);
947932

948933
if (mainIsPrimary && (Done || CurTUElem < MainFile.Decls.size())) {
@@ -1069,7 +1054,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10691054
BufferID);
10701055

10711056
parseIntoSourceFileFull(*NextInput, BufferID, PersistentState.get(),
1072-
nullptr, /*DelayBodyParsing=*/!IsPrimary);
1057+
/*DelayBodyParsing=*/!IsPrimary);
10731058
}
10741059

10751060
// Now parse the main file.
@@ -1079,7 +1064,7 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals,
10791064
MainFile.SyntaxParsingCache = Invocation.getMainFileSyntaxParsingCache();
10801065

10811066
parseIntoSourceFileFull(MainFile, MainFile.getBufferID().getValue(),
1082-
PersistentState.get(), nullptr,
1067+
PersistentState.get(),
10831068
/*DelayBodyParsing=*/false);
10841069
}
10851070

lib/IDE/REPLCodeCompletion.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "swift/AST/Module.h"
2121
#include "swift/Basic/LLVM.h"
2222
#include "swift/Basic/SourceManager.h"
23-
#include "swift/Parse/DelayedParsingCallbacks.h"
2423
#include "swift/Parse/Parser.h"
2524
#include "swift/IDE/CodeCompletion.h"
2625
#include "swift/Subsystems.h"
@@ -208,12 +207,9 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
208207
const unsigned OriginalDeclCount = SF.Decls.size();
209208

210209
PersistentParserState PersistentState;
211-
std::unique_ptr<DelayedParsingCallbacks> DelayedCB(
212-
new CodeCompleteDelayedCallbacks(Ctx.SourceMgr.getCodeCompletionLoc()));
213210
bool Done;
214211
do {
215-
parseIntoSourceFile(SF, *BufferID, &Done, nullptr, &PersistentState,
216-
DelayedCB.get());
212+
parseIntoSourceFile(SF, *BufferID, &Done, nullptr, &PersistentState);
217213
} while (!Done);
218214
performTypeChecking(SF, PersistentState.getTopLevelContext(), None,
219215
OriginalDeclCount);

lib/Parse/ParseDecl.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "swift/Parse/Parser.h"
1818
#include "swift/Parse/CodeCompletionCallbacks.h"
19-
#include "swift/Parse/DelayedParsingCallbacks.h"
2019
#include "swift/Parse/ParsedSyntaxRecorder.h"
2120
#include "swift/Parse/ParseSILSupport.h"
2221
#include "swift/Parse/SyntaxParsingContext.h"
@@ -5387,9 +5386,8 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
53875386

53885387
BodyRange.End = PreviousLoc;
53895388

5390-
if (!DelayedParseCB ||
5391-
DelayedParseCB->shouldDelayFunctionBodyParsing(*this, AFD, Attrs,
5392-
BodyRange)) {
5389+
if (SourceMgr.getCodeCompletionLoc().isInvalid() ||
5390+
SourceMgr.rangeContainsCodeCompletionLoc(BodyRange)) {
53935391
AFD->setBodyDelayed(BodyRange);
53945392
} else {
53955393
AFD->setBodySkipped(BodyRange);

lib/Parse/Parser.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/Basic/Timer.h"
2626
#include "swift/Parse/Lexer.h"
2727
#include "swift/Parse/CodeCompletionCallbacks.h"
28-
#include "swift/Parse/DelayedParsingCallbacks.h"
2928
#include "swift/Parse/ParsedSyntaxNodes.h"
3029
#include "swift/Parse/ParsedSyntaxRecorder.h"
3130
#include "swift/Parse/ParseSILSupport.h"
@@ -112,7 +111,6 @@ void tokenize(const LangOptions &LangOpts, const SourceManager &SM,
112111
using namespace swift;
113112
using namespace swift::syntax;
114113

115-
void DelayedParsingCallbacks::anchor() { }
116114
void SILParserTUStateBase::anchor() { }
117115

118116
namespace {

lib/ParseSIL/ParseSIL.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
115115
bool *Done,
116116
SILParserState *SIL,
117117
PersistentParserState *PersistentState,
118-
DelayedParsingCallbacks *DelayedParseCB,
119118
bool FullParse,
120119
bool DelayBodyParsing) {
121120
assert((!FullParse || (SF.canBeParsedInFull() && !SIL)) &&
@@ -147,8 +146,6 @@ static bool parseIntoSourceFileImpl(SourceFile &SF,
147146

148147
llvm::SaveAndRestore<bool> S(P.IsParsingInterfaceTokens,
149148
SF.hasInterfaceHash());
150-
if (DelayedParseCB)
151-
P.setDelayedParsingCallbacks(DelayedParseCB);
152149

153150
bool FoundSideEffects = false;
154151
do {
@@ -177,22 +174,20 @@ bool swift::parseIntoSourceFile(SourceFile &SF,
177174
bool *Done,
178175
SILParserState *SIL,
179176
PersistentParserState *PersistentState,
180-
DelayedParsingCallbacks *DelayedParseCB,
181177
bool DelayBodyParsing) {
182178
return parseIntoSourceFileImpl(SF, BufferID, Done, SIL,
183-
PersistentState, DelayedParseCB,
179+
PersistentState,
184180
/*FullParse=*/SF.shouldBuildSyntaxTree(),
185181
DelayBodyParsing);
186182
}
187183

188184
bool swift::parseIntoSourceFileFull(SourceFile &SF, unsigned BufferID,
189185
PersistentParserState *PersistentState,
190-
DelayedParsingCallbacks *DelayedParseCB,
191186
bool DelayBodyParsing) {
192187
bool Done = false;
193188
return parseIntoSourceFileImpl(SF, BufferID, &Done, /*SIL=*/nullptr,
194-
PersistentState, DelayedParseCB,
195-
/*FullParse=*/true, DelayBodyParsing);
189+
PersistentState, /*FullParse=*/true,
190+
DelayBodyParsing);
196191
}
197192

198193

lib/Sema/SourceLoader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#include "swift/Sema/SourceLoader.h"
1919
#include "swift/Subsystems.h"
20+
#include "swift/AST/ASTContext.h"
2021
#include "swift/AST/DiagnosticsSema.h"
2122
#include "swift/AST/Module.h"
22-
#include "swift/Parse/DelayedParsingCallbacks.h"
2323
#include "swift/Parse/PersistentParserState.h"
2424
#include "swift/Basic/SourceManager.h"
2525
#include "llvm/ADT/SmallString.h"
@@ -131,7 +131,7 @@ ModuleDecl *SourceLoader::loadModule(SourceLoc importLoc,
131131
importMod->addFile(*importFile);
132132

133133
bool done;
134-
parseIntoSourceFile(*importFile, bufferID, &done, nullptr, nullptr, nullptr);
134+
parseIntoSourceFile(*importFile, bufferID, &done, nullptr, nullptr);
135135
assert(done && "Parser returned early?");
136136
(void)done;
137137

0 commit comments

Comments
 (0)