Skip to content

[SourceKit] Remove option to regions reused as part of incremental parsing #18848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tools/SourceKit/include/SourceKit/Core/LangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ class EditorConsumer {
}
virtual SyntaxTreeTransferMode syntaxTreeTransferMode() = 0;

virtual bool syntaxReuseInfoEnabled() = 0;
virtual void
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) = 0;

virtual void finished() {}
};

Expand Down
47 changes: 13 additions & 34 deletions tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,44 +2265,23 @@ void SwiftLangSupport::editorReplaceText(StringRef Name,
EditorDoc->readSyntaxInfo(Consumer);

// Log reuse information
if (SyntaxCache.hasValue()) {
// Avoid computing the reused ranges if the consumer doesn't care about
// them
if (Consumer.syntaxReuseInfoEnabled()) {
auto &SyntaxTree = EditorDoc->getSyntaxTree();
auto ReuseRegions = SyntaxCache->getReusedRegions(*SyntaxTree);

// Abstract away from SyntaxReuseRegions to std::pair<unsigned, unsigned>
// so that SourceKit doesn't have to import swiftParse
std::vector<SourceFileRange> ReuseRegionOffsets;
ReuseRegionOffsets.reserve(ReuseRegions.size());
for (auto ReuseRegion : ReuseRegions) {
auto Start = ReuseRegion.Start.getOffset();
auto End = ReuseRegion.End.getOffset();
ReuseRegionOffsets.push_back({Start, End});
}
Consumer.handleSyntaxReuseRegions(ReuseRegionOffsets);
}
if (LogReuseRegions) {
auto &SyntaxTree = EditorDoc->getSyntaxTree();
auto ReuseRegions = SyntaxCache->getReusedRegions(*SyntaxTree);
LOG_SECTION("SyntaxCache", InfoHighPrio) {
Log->getOS() << "Reused ";

bool FirstIteration = true;
for (auto ReuseRegion : ReuseRegions) {
if (!FirstIteration) {
Log->getOS() << ", ";
} else {
FirstIteration = false;
}
if (SyntaxCache.hasValue() && LogReuseRegions) {
auto &SyntaxTree = EditorDoc->getSyntaxTree();
auto ReuseRegions = SyntaxCache->getReusedRegions(*SyntaxTree);
LOG_SECTION("SyntaxCache", InfoHighPrio) {
Log->getOS() << "Reused ";

Log->getOS() << ReuseRegion.Start << " - " << ReuseRegion.End;
bool FirstIteration = true;
for (auto ReuseRegion : ReuseRegions) {
if (!FirstIteration) {
Log->getOS() << ", ";
} else {
FirstIteration = false;
}

Log->getOS() << ReuseRegion.Start << " - " << ReuseRegion.End;
}
}
} else {
Consumer.handleSyntaxReuseRegions({});
}

if (Consumer.syntaxTreeEnabled()) {
Expand Down
27 changes: 0 additions & 27 deletions tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ struct SKEditorConsumerOptions {
SyntaxTreeSerializationFormat SyntaxSerializationFormat =
SyntaxTreeSerializationFormat::JSON;
bool SyntacticOnly = false;
bool EnableSyntaxReuseInfo = false;
};

} // anonymous namespace
Expand Down Expand Up @@ -471,9 +470,6 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
auto SerializationFormatUID = Req.getUID(KeySyntaxTreeSerializationFormat);
int64_t SyntacticOnly = false;
Req.getInt64(KeySyntacticOnly, SyntacticOnly, /*isOptional=*/true);
int64_t EnableSyntaxReuseInfo = false;
Req.getInt64(KeyEnableSyntaxReuseRegions, EnableSyntaxReuseInfo,
/*isOptional=*/true);

SKEditorConsumerOptions Opts;
Opts.EnableSyntaxMap = EnableSyntaxMap;
Expand All @@ -486,7 +482,6 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
return Rec(createErrorRequestFailed("Invalid serialization format"));
Opts.SyntaxSerializationFormat = SyntaxSerializationFormat.getValue();
Opts.SyntacticOnly = SyntacticOnly;
Opts.EnableSyntaxReuseInfo = EnableSyntaxReuseInfo;
return Rec(editorOpen(*Name, InputBuf.get(), Opts, Args));
}
if (ReqUID == RequestEditorClose) {
Expand Down Expand Up @@ -519,9 +514,6 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
Req.getInt64(KeyEnableDiagnostics, EnableDiagnostics, /*isOptional=*/true);
int64_t SyntacticOnly = false;
Req.getInt64(KeySyntacticOnly, SyntacticOnly, /*isOptional=*/true);
int64_t EnableSyntaxReuseInfo = false;
Req.getInt64(KeyEnableSyntaxReuseRegions, EnableSyntaxReuseInfo,
/*isOptional=*/true);
auto TransferModeUID = Req.getUID(KeySyntaxTreeTransferMode);
auto SerializationFormatUID = Req.getUID(KeySyntaxTreeSerializationFormat);

Expand All @@ -535,9 +527,7 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
if (!SyntaxSerializationFormat)
return Rec(createErrorRequestFailed("Invalid serialization format"));
Opts.SyntaxSerializationFormat = SyntaxSerializationFormat.getValue();
Opts.EnableSyntaxReuseInfo = EnableSyntaxReuseInfo;
Opts.SyntacticOnly = SyntacticOnly;
Opts.EnableSyntaxReuseInfo = EnableSyntaxReuseInfo;

return Rec(editorReplaceText(*Name, InputBuf.get(), Offset, Length, Opts));
}
Expand Down Expand Up @@ -2120,10 +2110,6 @@ class SKEditorConsumer : public EditorConsumer {
void handleSyntaxTree(const swift::syntax::SourceFileSyntax &SyntaxTree,
std::unordered_set<unsigned> &ReusedNodeIds) override;

bool syntaxReuseInfoEnabled() override { return Opts.EnableSyntaxReuseInfo; }
void
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) override;

SyntaxTreeTransferMode syntaxTreeTransferMode() override {
return Opts.SyntaxTransferMode;
}
Expand Down Expand Up @@ -2537,19 +2523,6 @@ void SKEditorConsumer::handleSyntaxTree(
}
}

void SKEditorConsumer::handleSyntaxReuseRegions(
std::vector<SourceFileRange> ReuseRegions) {
if (Opts.EnableSyntaxReuseInfo) {
auto Array = Dict.setArray(KeySyntaxReuseRegions);

for (auto Region : ReuseRegions) {
auto SubDict = Array.appendDictionary();
SubDict.set(KeyOffset, Region.Start);
SubDict.set(KeyLength, Region.End - Region.Start);
}
}
}

static sourcekitd_response_t
editorFindUSR(StringRef DocumentName, StringRef USR) {
ResponseBuilder RespBuilder;
Expand Down
6 changes: 0 additions & 6 deletions unittests/SourceKit/SwiftLang/CursorInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ class NullEditorConsumer : public EditorConsumer {
return SyntaxTreeTransferMode::Off;
}

bool syntaxReuseInfoEnabled() override { return false; }

void
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) override {
}

public:
bool needsSema = false;
};
Expand Down
5 changes: 0 additions & 5 deletions unittests/SourceKit/SwiftLang/EditingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ class DiagConsumer : public EditorConsumer {
return SyntaxTreeTransferMode::Off;
}

bool syntaxReuseInfoEnabled() override { return false; }

void
handleSyntaxReuseRegions(std::vector<SourceFileRange> ReuseRegions) override {
}
};

struct DocUpdateMutexState {
Expand Down
2 changes: 0 additions & 2 deletions utils/gyb_sourcekit_support/UIDs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def __init__(self, internal_name, external_name):
KEY('Length', 'key.length'),
KEY('SourceFile', 'key.sourcefile'),
KEY('SerializedSyntaxTree', 'key.serialized_syntax_tree'),
KEY('SyntaxReuseRegions', 'key.syntaxreuseregions'),
KEY('SourceText', 'key.sourcetext'),
KEY('EnableSyntaxReuseRegions', 'key.enablesyntaxreuseregions'),
KEY('EnableSyntaxMap', 'key.enablesyntaxmap'),
KEY('SyntaxTreeTransferMode', 'key.syntaxtreetransfermode'),
KEY('SyntaxTreeSerializationFormat',
Expand Down