sourcekitd: build Swift syntax tree more lazily than collecting parsed tokens. (#14578)

Before this patch, we have one flag (KeepSyntaxInfo) to turn on two syntax
functionalities of parser: (1) collecting parsed tokens for coloring and
(2) building syntax trees. Since sourcekitd is the only consumer of either of these
functionalities, sourcekitd by default always enables such flag.
However, empirical results show (2) is both heavier and less-frequently
needed than (1). Therefore, separating the flag to two flags makes more
sense, where CollectParsedToken controls (1) and BuildSyntaxTree
controls (2).

CollectingParsedToken is always enabled by sourcekitd because
formatting and syntax-coloring need it; however BuildSyntaxTree should
be explicitly switched on by sourcekitd clients.

resolves: rdar://problem/37483076
This commit is contained in:
Xi Ge
2018-02-13 16:27:12 -08:00
committed by GitHub
parent cfca329fc3
commit 37f352fe41
16 changed files with 64 additions and 37 deletions

View File

@@ -442,7 +442,7 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
Invocation.setSerializedDiagnosticsPath(StringRef());
Invocation.getLangOptions().AttachCommentsToDecls = true;
Invocation.getLangOptions().DiagnosticsEditorMode = true;
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
Invocation.getLangOptions().CollectParsedToken = true;
auto &FrontendOpts = Invocation.getFrontendOptions();
if (FrontendOpts.PlaygroundTransform) {
// The playground instrumenter changes the AST in ways that disrupt the
@@ -817,7 +817,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
InvokRef->Impl.Opts.applyToSubstitutingInputs(
Invocation, convertFileContentsToInputs(Contents));
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true;
Invocation.getLangOptions().CollectParsedToken = true;
if (CompIns.setup(Invocation)) {
// FIXME: Report the diagnostic.