Skip to content

Commit b42f442

Browse files
author
Nathan Hawes
committed
[SourceKit] Ignore .swiftsourceinfo files in SourceKit
We only show diagnostics that occur in the primary file, so getting the right source locations for symbols coming from loaded modules has no benefit and a slight performance cost.
1 parent fae3590 commit b42f442

File tree

11 files changed

+26
-48
lines changed

11 files changed

+26
-48
lines changed

test/Serialization/comments-batch-mode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %empty-directory(%t)
22
// 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
3-
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -source-filename %s -I %t | %FileCheck %s
3+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s
44

55
// RUN: %empty-directory(%t)
66
// 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
7-
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -source-filename %s -I %t | %FileCheck %s
7+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s
88

99
// CHECK: Inputs/comments-batch/File1.swift:2:13: Func/FuncFromFile1 RawComment=[/// Comment in File1\n]
1010
// CHECK: Inputs/comments-batch/File2.swift:2:13: Func/FuncFromFile2 RawComment=[/// Comment in File2\n]

test/Serialization/comments-framework.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// RUN: %empty-directory(%t/comments.framework/Modules/comments.swiftmodule/Project)
44

55
// 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
6-
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -F %t | %FileCheck %s
6+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -F %t | %FileCheck %s
77

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

1111
/// first_decl_class_1 Aaa.
1212
public class first_decl_class_1 {

test/Serialization/comments-hidden.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//
1919
// RUN: %empty-directory(%t)
2020
// 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
21-
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.testing.txt
21+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t > %t.testing.txt
2222
// RUN: %FileCheck %s -check-prefix=SOURCE-LOC < %t.testing.txt
2323

2424
/// PublicClass Documentation

test/Serialization/comments.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: llvm-bcanalyzer %t/comments.swiftmodule | %FileCheck %s -check-prefix=BCANALYZER
66
// RUN: llvm-bcanalyzer %t/comments.swiftdoc | %FileCheck %s -check-prefix=BCANALYZER
77
// RUN: llvm-bcanalyzer %t/comments.swiftsourceinfo | %FileCheck %s -check-prefix=BCANALYZER
8-
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t | %FileCheck %s -check-prefix=FIRST
8+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -enable-swiftsourceinfo -source-filename %s -I %t | %FileCheck %s -check-prefix=FIRST
99

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

test/SourceKit/CompileNotifications/arg-parsing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ARG_PARSE_0: {
44
// ARG_PARSE_0: key.notification: source.notification.compile-will-start
55
// ARG_PARSE_0: key.compileid: [[CID1:".*"]]
6-
// ARG_PARSE_0: key.compilerargs-string: "{{.*}}.swift -no-such-arg -Xfrontend -ignore-module-source-info"
6+
// ARG_PARSE_0: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
77
// ARG_PARSE_0: }
88
// ARG_PARSE_0: {
99
// ARG_PARSE_0: key.notification: source.notification.compile-did-finish
@@ -24,7 +24,7 @@
2424
// ARG_PARSE_1: {
2525
// ARG_PARSE_1: key.notification: source.notification.compile-will-start
2626
// ARG_PARSE_1: key.compileid: [[CID1:".*"]]
27-
// ARG_PARSE_1: key.compilerargs-string: "{{.*}}.swift -no-such-arg -Xfrontend -ignore-module-source-info"
27+
// ARG_PARSE_1: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
2828
// ARG_PARSE_1: }
2929
// ARG_PARSE_1: {
3030
// ARG_PARSE_1: key.notification: source.notification.compile-did-finish

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ bool SwiftASTManager::initCompilerInvocation(
535535
// We don't care about LLVMArgs
536536
FrontendOpts.LLVMArgs.clear();
537537

538+
// We only report diagnostics coming from the primary file, so getting valid
539+
// source locations for diagnostics coming from loaded modules has no effect
540+
// other than degrading performance slightly.
541+
FrontendOpts.IgnoreSwiftSourceInfo = true;
542+
538543
// Disable expensive SIL options to reduce time spent in SILGen.
539544
disableExpensiveSILOptions(Invocation.getSILOptions());
540545

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ static bool swiftCodeCompleteImpl(
172172
return false;
173173
}
174174

175-
// Disable source location resolutions from .swiftsourceinfo file because
176-
// they are somewhat heavy operations and are not needed for completions.
177-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
178-
179175
const char *Position = InputFile->getBufferStart() + CodeCompletionOffset;
180176
std::unique_ptr<llvm::WritableMemoryBuffer> NewBuffer =
181177
llvm::WritableMemoryBuffer::getNewUninitMemBuffer(

tools/SourceKit/lib/SwiftLang/SwiftConformingMethodList.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ static bool swiftConformingMethodListImpl(
6767
return false;
6868
}
6969

70-
// Disable source location resolutions from .swiftsourceinfo file because
71-
// they are somewhat heavy operations and are not needed for completions.
72-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
73-
7470
Invocation.setCodeCompletionPoint(newBuffer.get(), Offset);
7571

7672
// Create a factory for code completion callbacks that will feed the

tools/SourceKit/lib/SwiftLang/SwiftTypeContextInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ static bool swiftTypeContextInfoImpl(SwiftLangSupport &Lang,
6767
return false;
6868
}
6969

70-
// Disable source location resolutions from .swiftsourceinfo file because
71-
// they are somewhat heavy operations and are not needed for completions.
72-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
73-
7470
Invocation.setCodeCompletionPoint(newBuffer.get(), Offset);
7571

7672
// Create a factory for code completion callbacks that will feed the

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
481481
sourcekitd_object_t Req = sourcekitd_request_dictionary_create(nullptr,
482482
nullptr, 0);
483483
ActiveRequest = Opts.Request;
484-
bool ShouldIgnoreSourceInfo = true;
485484
switch (Opts.Request) {
486485
case SourceKitRequest::None:
487486
llvm::errs() << "request is not set\n";
@@ -841,7 +840,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
841840
sourcekitd_request_dictionary_set_int64(Req, KeyUsingSwiftArgs, true);
842841
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
843842
RequestEditorOpenHeaderInterface);
844-
ShouldIgnoreSourceInfo = false;
845843
}
846844

847845
sourcekitd_request_dictionary_set_string(Req, KeyName, getInterfaceGenDocumentName().c_str());
@@ -935,17 +933,6 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
935933
sourcekitd_object_t Args = sourcekitd_request_array_create(nullptr, 0);
936934
for (auto Arg : Opts.CompilerArgs)
937935
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND, Arg);
938-
if (ShouldIgnoreSourceInfo) {
939-
// Ignore .swiftsourceinfo file when testing sourcekitd.
940-
// .swiftsourceinfo for stdlib will be available when sourcekitd is tested,
941-
// which may make some stdlib-depending sourcekitd tests volatile.
942-
// We cannot append the flags when the compiler arguments are for clang
943-
// invocation.
944-
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND,
945-
"-Xfrontend");
946-
sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND,
947-
"-ignore-module-source-info");
948-
}
949936
sourcekitd_request_dictionary_set_value(Req, KeyCompilerArgs, Args);
950937
sourcekitd_request_release(Args);
951938
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,13 @@ GraphVisPath("output-request-graphviz",
696696
static llvm::cl::opt<bool>
697697
CanonicalizeType("canonicalize-type", llvm::cl::Hidden,
698698
llvm::cl::cat(Category), llvm::cl::init(false));
699+
700+
static llvm::cl::opt<bool>
701+
EnableSwiftSourceInfo("enable-swiftsourceinfo",
702+
llvm::cl::desc("Whether to consume .swiftsourceinfo files"),
703+
llvm::cl::cat(Category),
704+
llvm::cl::init(false));
705+
699706
} // namespace options
700707

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

742749
CompilerInvocation Invocation(InitInvok);
743-
744-
// Disable source location resolutions from .swiftsourceinfo file because
745-
// they are somewhat heavy operations and are not needed for completions.
746-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
747-
748750
Invocation.setCodeCompletionPoint(CleanFile.get(), Offset);
749751

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

807809
CompilerInvocation Invocation(InitInvok);
808-
809-
// Disable source location resolutions from .swiftsourceinfo file because
810-
// they are somewhat heavy operations and are not needed for completions.
811-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
812-
813810
Invocation.setCodeCompletionPoint(CleanFile.get(), Offset);
814811

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

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

882-
// Disable source location resolutions from .swiftsourceinfo file because
883-
// they are somewhat heavy operations and are not needed for completions.
884-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = true;
885-
886879
// Disable to build syntax tree because code-completion skips some portion of
887880
// source text. That breaks an invariant of syntax tree building.
888881
Invocation.getLangOptions().BuildSyntaxTree = false;
@@ -3319,6 +3312,11 @@ int main(int argc, char *argv[]) {
33193312
InitInvok.getLangOptions().EnableObjCInterop =
33203313
llvm::Triple(options::Triple).isOSDarwin();
33213314
}
3315+
3316+
// We disable source location resolutions from .swiftsourceinfo files by
3317+
// default to match SourceKit's behavior.
3318+
if (!options::EnableSwiftSourceInfo)
3319+
InitInvok.getFrontendOptions().IgnoreSwiftSourceInfo = true;
33223320
if (!options::Triple.empty())
33233321
InitInvok.setTargetTriple(options::Triple);
33243322
if (!options::SwiftVersion.empty()) {

0 commit comments

Comments
 (0)