Skip to content

[5.8][SourceKit] Only verify the solver-based cursor info implementation if requested #63348

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
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
1 change: 1 addition & 0 deletions tools/SourceKit/include/SourceKit/Core/LangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ class LangSupport {
bool SymbolGraph, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
bool VerifySolverBasedCursorInfo,
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;

virtual void
Expand Down
1 change: 1 addition & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ class SwiftLangSupport : public LangSupport {
ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
bool VerifySolverBasedCursorInfo,
std::function<void(const RequestResult<CursorInfoData> &)>
Receiver) override;

Expand Down
8 changes: 2 additions & 6 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,7 @@ void SwiftLangSupport::getCursorInfo(
bool SymbolGraph, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
bool VerifySolverBasedCursorInfo,
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) {

std::string error;
Expand Down Expand Up @@ -1967,19 +1968,14 @@ void SwiftLangSupport::getCursorInfo(
// Currently, we only verify that the solver-based cursor implementation
// produces the same results as the AST-based implementation. Only enable it
// in assert builds for now.
#ifndef NDEBUG
bool EnableSolverBasedCursorInfo = true;
#else
bool EnableSolverBasedCursorInfo = false;
#endif

// If solver based completion is enabled, a string description of the cursor
// info result produced by the solver-based implementation. Once the AST-based
// result is produced, we verify that the solver-based result matches the
// AST-based result.
std::string SolverBasedResultDescription;
size_t SolverBasedResultCount = 0;
if (EnableSolverBasedCursorInfo) {
if (VerifySolverBasedCursorInfo) {
std::string InputFileError;
llvm::SmallString<64> RealInputFilePath;
fileSystem->getRealPath(InputFile, RealInputFilePath);
Expand Down
2 changes: 2 additions & 0 deletions tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
} else {
sourcekitd_request_dictionary_set_int64(Req, KeyOffset, ByteOffset);
}
sourcekitd_request_dictionary_set_int64(Req, KeyVerifySolverBasedCursorInfo,
true);
addRequestOptionsDirect(Req, Opts);
break;
case SourceKitRequest::RangeInfo: {
Expand Down
5 changes: 4 additions & 1 deletion tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,13 @@ static void handleSemanticRequest(
Req.getInt64(KeyRetrieveRefactorActions, Actionables, /*isOptional=*/true);
int64_t SymbolGraph = false;
Req.getInt64(KeyRetrieveSymbolGraph, SymbolGraph, /*isOptional=*/true);
int64_t VerifySolverBasedCursorInfo = false;
Req.getInt64(KeyVerifySolverBasedCursorInfo, VerifySolverBasedCursorInfo,
/*isOptional=*/true);
return Lang.getCursorInfo(
*SourceFile, Offset, Length, Actionables, SymbolGraph,
CancelOnSubsequentRequest, Args, std::move(vfsOptions),
CancellationToken,
CancellationToken, VerifySolverBasedCursorInfo,
[Rec](const RequestResult<CursorInfoData> &Result) {
reportCursorInfo(Result, Rec);
});
Expand Down
3 changes: 3 additions & 0 deletions unittests/SourceKit/SwiftLang/CursorInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class CursorInfoTest : public ::testing::Test {
DocName, Offset, /*Length=*/0, /*Actionables=*/false,
/*SymbolGraph=*/false, CancelOnSubsequentRequest, Args,
/*vfsOptions=*/None, CancellationToken,
/*VerifySolverBasedCursorInfo=*/true,
[&](const RequestResult<CursorInfoData> &Result) {
assert(!Result.isCancelled());
if (Result.isError()) {
Expand Down Expand Up @@ -451,6 +452,7 @@ TEST_F(CursorInfoTest, CursorInfoCancelsPreviousRequest) {
SlowDocName, SlowOffset, /*Length=*/0, /*Actionables=*/false,
/*SymbolGraph=*/false, /*CancelOnSubsequentRequest=*/true, ArgsForSlow,
/*vfsOptions=*/None, /*CancellationToken=*/nullptr,
/*VerifySolverBasedCursorInfo=*/true,
[&](const RequestResult<CursorInfoData> &Result) {
EXPECT_TRUE(Result.isCancelled());
FirstCursorInfoSema.signal();
Expand Down Expand Up @@ -494,6 +496,7 @@ TEST_F(CursorInfoTest, CursorInfoCancellation) {
SlowDocName, SlowOffset, /*Length=*/0, /*Actionables=*/false,
/*SymbolGraph=*/false, /*CancelOnSubsequentRequest=*/false, ArgsForSlow,
/*vfsOptions=*/None, /*CancellationToken=*/CancellationToken,
/*VerifySolverBasedCursorInfo=*/true,
[&](const RequestResult<CursorInfoData> &Result) {
EXPECT_TRUE(Result.isCancelled());
CursorInfoSema.signal();
Expand Down
1 change: 1 addition & 0 deletions utils/gyb_sourcekit_support/UIDs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __init__(self, internal_name, external_name):
KEY('OptimizeForIDE', 'key.optimize_for_ide'),
KEY('RequiredBystanders', 'key.required_bystanders'),
KEY('ReusingASTContext', 'key.reusingastcontext'),
KEY('VerifySolverBasedCursorInfo', 'key.verifysolverbasedcursorinfo'),
KEY('CompletionMaxASTContextReuseCount',
'key.completion_max_astcontext_reuse_count'),
KEY('CompletionCheckDependencyInterval',
Expand Down