mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -1753,7 +1753,7 @@ void SwiftEditorDocument::updateSemaInfo() {
|
||||
}
|
||||
|
||||
void SwiftEditorDocument::parse(ImmutableTextSnapshotRef Snapshot,
|
||||
SwiftLangSupport &Lang) {
|
||||
SwiftLangSupport &Lang, bool BuildSyntexTree) {
|
||||
llvm::sys::ScopedLock L(Impl.AccessMtx);
|
||||
|
||||
assert(Impl.SemanticInfo && "Impl.SemanticInfo must be set");
|
||||
@@ -1773,7 +1773,7 @@ void SwiftEditorDocument::parse(ImmutableTextSnapshotRef Snapshot,
|
||||
Lang.getASTManager().
|
||||
initCompilerInvocation(CompInv, Args, StringRef(), Error);
|
||||
}
|
||||
|
||||
CompInv.getLangOptions().BuildSyntaxTree = BuildSyntexTree;
|
||||
// Access to Impl.SyntaxInfo is guarded by Impl.AccessMtx
|
||||
Impl.SyntaxInfo.reset(
|
||||
new SwiftDocumentSyntaxInfo(CompInv, Snapshot, Args, Impl.FilePath));
|
||||
@@ -2095,12 +2095,12 @@ void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
|
||||
ArrayRef<const char *> Args) {
|
||||
|
||||
ImmutableTextSnapshotRef Snapshot = nullptr;
|
||||
|
||||
const bool BuildSyntaxTree = Consumer.syntaxTreeEnabled();
|
||||
auto EditorDoc = EditorDocuments.getByUnresolvedName(Name);
|
||||
if (!EditorDoc) {
|
||||
EditorDoc = new SwiftEditorDocument(Name, *this);
|
||||
Snapshot = EditorDoc->initializeText(Buf, Args);
|
||||
EditorDoc->parse(Snapshot, *this);
|
||||
EditorDoc->parse(Snapshot, *this, BuildSyntaxTree);
|
||||
if (EditorDocuments.getOrUpdate(Name, *this, EditorDoc)) {
|
||||
// Document already exists, re-initialize it. This should only happen
|
||||
// if we get OPEN request while the previous document is not closed.
|
||||
@@ -2113,7 +2113,7 @@ void SwiftLangSupport::editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
|
||||
|
||||
if (!Snapshot) {
|
||||
Snapshot = EditorDoc->initializeText(Buf, Args);
|
||||
EditorDoc->parse(Snapshot, *this);
|
||||
EditorDoc->parse(Snapshot, *this, BuildSyntaxTree);
|
||||
}
|
||||
|
||||
if (Consumer.needsSemanticInfo()) {
|
||||
@@ -2161,7 +2161,7 @@ void SwiftLangSupport::editorReplaceText(StringRef Name, llvm::MemoryBuffer *Buf
|
||||
Snapshot = EditorDoc->replaceText(Offset, Length, Buf,
|
||||
Consumer.needsSemanticInfo());
|
||||
assert(Snapshot);
|
||||
EditorDoc->parse(Snapshot, *this);
|
||||
EditorDoc->parse(Snapshot, *this, Consumer.syntaxTreeEnabled());
|
||||
EditorDoc->readSyntaxInfo(Consumer);
|
||||
} else {
|
||||
Snapshot = EditorDoc->getLatestSnapshot();
|
||||
|
||||
Reference in New Issue
Block a user