Skip to content

[SourceKit] Ignore .swiftsourceinfo files in SourceKit #28374

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

Closed
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: 2 additions & 2 deletions test/Serialization/comments-batch-mode.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-batch-mode -emit-module -emit-module-doc -emit-module-path %t/Foo.swiftmodule %S/Inputs/comments-batch/File1.swift %S/Inputs/comments-batch/File2.swift %S/Inputs/comments-batch/File3.swift %S/Inputs/comments-batch/File4.swift %S/Inputs/comments-batch/File5.swift -module-name Foo -emit-module-source-info-path %t/Foo.swiftsourceinfo -emit-module-doc-path %t/Foo.swiftdoc
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -source-filename %s -I %t | %FileCheck %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -wmo -emit-module -emit-module-doc -emit-module-path %t/Foo.swiftmodule %S/Inputs/comments-batch/File1.swift %S/Inputs/comments-batch/File2.swift %S/Inputs/comments-batch/File3.swift %S/Inputs/comments-batch/File4.swift %S/Inputs/comments-batch/File5.swift -module-name Foo -emit-module-source-info-path %t/Foo.swiftsourceinfo -emit-module-doc-path %t/Foo.swiftdoc
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -source-filename %s -I %t | %FileCheck %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s

// CHECK: Inputs/comments-batch/File1.swift:2:13: Func/FuncFromFile1 RawComment=[/// Comment in File1\n]
// CHECK: Inputs/comments-batch/File2.swift:2:13: Func/FuncFromFile2 RawComment=[/// Comment in File2\n]
Expand Down
4 changes: 2 additions & 2 deletions test/Serialization/comments-framework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// RUN: %empty-directory(%t/comments.framework/Modules/comments.swiftmodule/Project)

// RUN: %target-swift-frontend -module-name comments -emit-module -emit-module-path %t/comments.framework/Modules/comments.swiftmodule/%target-swiftmodule-name -emit-module-doc-path %t/comments.framework/Modules/comments.swiftmodule/%target-swiftdoc-name -emit-module-source-info-path %t/comments.framework/Modules/comments.swiftmodule/Project/%target-swiftsourceinfo-name %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -F %t | %FileCheck %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -F %t | %FileCheck %s

// RUN: cp -r %t/comments.framework/Modules/comments.swiftmodule %t/comments.swiftmodule
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t | %FileCheck %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s

/// first_decl_class_1 Aaa.
public class first_decl_class_1 {
Expand Down
2 changes: 1 addition & 1 deletion test/Serialization/comments-hidden.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-testing -module-name comments -emit-module -emit-module-path %t/comments.swiftmodule -emit-module-doc -emit-module-doc-path %t/comments.swiftdoc -emit-module-source-info-path %t/comments.swiftsourceinfo %s
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.testing.txt
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t > %t.testing.txt
// RUN: %FileCheck %s -check-prefix=SOURCE-LOC < %t.testing.txt

/// PublicClass Documentation
Expand Down
4 changes: 2 additions & 2 deletions test/Serialization/comments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// RUN: llvm-bcanalyzer %t/comments.swiftmodule | %FileCheck %s -check-prefix=BCANALYZER
// RUN: llvm-bcanalyzer %t/comments.swiftdoc | %FileCheck %s -check-prefix=BCANALYZER
// RUN: llvm-bcanalyzer %t/comments.swiftsourceinfo | %FileCheck %s -check-prefix=BCANALYZER
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t | %FileCheck %s -check-prefix=FIRST
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s -check-prefix=FIRST

// Test the case when we have a multiple files in a module.
//
Expand All @@ -16,7 +16,7 @@
// RUN: llvm-bcanalyzer %t/comments.swiftmodule | %FileCheck %s -check-prefix=BCANALYZER
// RUN: llvm-bcanalyzer %t/comments.swiftdoc | %FileCheck %s -check-prefix=BCANALYZER
// RUN: llvm-bcanalyzer %t/comments.swiftsourceinfo | %FileCheck %s -check-prefix=BCANALYZER
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.printed.txt
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t > %t.printed.txt
// RUN: %FileCheck %s -check-prefix=FIRST < %t.printed.txt
// RUN: %FileCheck %s -check-prefix=SECOND < %t.printed.txt

Expand Down
4 changes: 2 additions & 2 deletions test/SourceKit/CompileNotifications/arg-parsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ARG_PARSE_0: {
// ARG_PARSE_0: key.notification: source.notification.compile-will-start
// ARG_PARSE_0: key.compileid: [[CID1:".*"]]
// ARG_PARSE_0: key.compilerargs-string: "{{.*}}.swift -no-such-arg -Xfrontend -ignore-module-source-info"
// ARG_PARSE_0: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
// ARG_PARSE_0: }
// ARG_PARSE_0: {
// ARG_PARSE_0: key.notification: source.notification.compile-did-finish
Expand All @@ -24,7 +24,7 @@
// ARG_PARSE_1: {
// ARG_PARSE_1: key.notification: source.notification.compile-will-start
// ARG_PARSE_1: key.compileid: [[CID1:".*"]]
// ARG_PARSE_1: key.compilerargs-string: "{{.*}}.swift -no-such-arg -Xfrontend -ignore-module-source-info"
// ARG_PARSE_1: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
// ARG_PARSE_1: }
// ARG_PARSE_1: {
// ARG_PARSE_1: key.notification: source.notification.compile-did-finish
Expand Down
5 changes: 5 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ bool SwiftASTManager::initCompilerInvocation(
// We don't care about LLVMArgs
FrontendOpts.LLVMArgs.clear();

// We only report diagnostics coming from the primary file, so getting valid
// source locations for diagnostics coming from loaded modules has no effect
// other than degrading performance slightly.
FrontendOpts.IgnoreSwiftSourceInfo = true;

// Disable expensive SIL options to reduce time spent in SILGen.
disableExpensiveSILOptions(Invocation.getSILOptions());

Expand Down
4 changes: 0 additions & 4 deletions tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ static bool swiftCodeCompleteImpl(
return false;
}

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

const char *Position = InputFile->getBufferStart() + CodeCompletionOffset;
std::unique_ptr<llvm::WritableMemoryBuffer> NewBuffer =
llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
Expand Down
4 changes: 0 additions & 4 deletions tools/SourceKit/lib/SwiftLang/SwiftConformingMethodList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ static bool swiftConformingMethodListImpl(
return false;
}

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

Invocation.setCodeCompletionPoint(newBuffer.get(), Offset);

// Create a factory for code completion callbacks that will feed the
Expand Down
4 changes: 0 additions & 4 deletions tools/SourceKit/lib/SwiftLang/SwiftTypeContextInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ static bool swiftTypeContextInfoImpl(SwiftLangSupport &Lang,
return false;
}

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

Invocation.setCodeCompletionPoint(newBuffer.get(), Offset);

// Create a factory for code completion callbacks that will feed the
Expand Down
13 changes: 0 additions & 13 deletions tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
sourcekitd_object_t Req = sourcekitd_request_dictionary_create(nullptr,
nullptr, 0);
ActiveRequest = Opts.Request;
bool ShouldIgnoreSourceInfo = true;
switch (Opts.Request) {
case SourceKitRequest::None:
llvm::errs() << "request is not set\n";
Expand Down Expand Up @@ -841,7 +840,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
sourcekitd_request_dictionary_set_int64(Req, KeyUsingSwiftArgs, true);
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
RequestEditorOpenHeaderInterface);
ShouldIgnoreSourceInfo = false;
}

sourcekitd_request_dictionary_set_string(Req, KeyName, getInterfaceGenDocumentName().c_str());
Expand Down Expand Up @@ -935,17 +933,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
sourcekitd_object_t Args = sourcekitd_request_array_create(nullptr, 0);
for (auto Arg : Opts.CompilerArgs)
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND, Arg);
if (ShouldIgnoreSourceInfo) {
// Ignore .swiftsourceinfo file when testing sourcekitd.
// .swiftsourceinfo for stdlib will be available when sourcekitd is tested,
// which may make some stdlib-depending sourcekitd tests volatile.
// We cannot append the flags when the compiler arguments are for clang
// invocation.
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND,
"-Xfrontend");
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND,
"-ignore-module-source-info");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!
Because of this, sourcekitd-test was not compatible to older versions of SourceKit (because they don't understand -ignore-module-source-info frontend option).

sourcekitd_request_dictionary_set_value(Req, KeyCompilerArgs, Args);
sourcekitd_request_release(Args);
}
Expand Down
26 changes: 12 additions & 14 deletions tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ GraphVisPath("output-request-graphviz",
static llvm::cl::opt<bool>
CanonicalizeType("canonicalize-type", llvm::cl::Hidden,
llvm::cl::cat(Category), llvm::cl::init(false));

static llvm::cl::opt<bool>
EnableSwiftSourceInfo("enable-swiftsourceinfo",
llvm::cl::desc("Whether to consume .swiftsourceinfo files"),
llvm::cl::cat(Category),
llvm::cl::init(false));

} // namespace options

static std::unique_ptr<llvm::MemoryBuffer>
Expand Down Expand Up @@ -740,11 +747,6 @@ static int doTypeContextInfo(const CompilerInvocation &InitInvok,
<< " at offset " << Offset << "\n";

CompilerInvocation Invocation(InitInvok);

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

Invocation.setCodeCompletionPoint(CleanFile.get(), Offset);

// Create a CodeCompletionConsumer.
Expand Down Expand Up @@ -805,11 +807,6 @@ doConformingMethodList(const CompilerInvocation &InitInvok,
<< " at offset " << Offset << "\n";

CompilerInvocation Invocation(InitInvok);

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

Invocation.setCodeCompletionPoint(CleanFile.get(), Offset);

SmallVector<const char *, 4> typeNames;
Expand Down Expand Up @@ -879,10 +876,6 @@ static int doCodeCompletion(const CompilerInvocation &InitInvok,

Invocation.setCodeCompletionPoint(CleanFile.get(), CodeCompletionOffset);

// Disable source location resolutions from .swiftsourceinfo file because
// they are somewhat heavy operations and are not needed for completions.
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;

// Disable to build syntax tree because code-completion skips some portion of
// source text. That breaks an invariant of syntax tree building.
Invocation.getLangOptions().BuildSyntaxTree = false;
Expand Down Expand Up @@ -3319,6 +3312,11 @@ int main(int argc, char *argv[]) {
InitInvok.getLangOptions().EnableObjCInterop =
llvm::Triple(options::Triple).isOSDarwin();
}

// We disable source location resolutions from .swiftsourceinfo files by
// default to match SourceKit's behavior.
if (!options::EnableSwiftSourceInfo)
InitInvok.getFrontendOptions().IgnoreSwiftSourceInfo = true;
if (!options::Triple.empty())
InitInvok.setTargetTriple(options::Triple);
if (!options::SwiftVersion.empty()) {
Expand Down