[SourceKit] Add a global-configuration request to control SourceKit's behavior around .swiftsourceinfo files

SwiftSourceInfo files provide source location information for decls coming from
loaded modules. For most IDE use cases it either has an undesirable impact on
performance with no benefit (code completion), results in stale locations being
used instead of more up-to-date indexer locations (cursor info), or has no
observable effect (live diagnostics, which are filtered to just those with a
location in the primary file).

For non-IDE clients of SourceKit though, cursor info providing declaration
locations for symbols from other modules is useful, so add a global
configuration option (and a new request to set it) to control whether
.swiftsourceinfo files are loaded or not based on use case (they are loaded by
default).
This commit is contained in:
Nathan Hawes
2019-11-19 17:48:19 -08:00
parent 12bda79e23
commit b9d5672ca1
23 changed files with 226 additions and 55 deletions

View File

@@ -371,11 +371,13 @@ struct CacheKeyHashInfo<ASTKey> {
struct SwiftASTManager::Implementation {
explicit Implementation(
std::shared_ptr<SwiftEditorDocumentFileMap> EditorDocs,
std::shared_ptr<GlobalConfig> Config,
std::shared_ptr<SwiftStatistics> Stats, StringRef RuntimeResourcePath)
: EditorDocs(EditorDocs), Stats(Stats),
: EditorDocs(EditorDocs), Config(Config), Stats(Stats),
RuntimeResourcePath(RuntimeResourcePath) {}
std::shared_ptr<SwiftEditorDocumentFileMap> EditorDocs;
std::shared_ptr<GlobalConfig> Config;
std::shared_ptr<SwiftStatistics> Stats;
std::string RuntimeResourcePath;
SourceManager SourceMgr;
@@ -401,8 +403,10 @@ struct SwiftASTManager::Implementation {
SwiftASTManager::SwiftASTManager(
std::shared_ptr<SwiftEditorDocumentFileMap> EditorDocs,
std::shared_ptr<GlobalConfig> Config,
std::shared_ptr<SwiftStatistics> Stats, StringRef RuntimeResourcePath)
: Impl(*new Implementation(EditorDocs, Stats, RuntimeResourcePath)) {}
: Impl(*new Implementation(EditorDocs, Config, Stats,
RuntimeResourcePath)) {}
SwiftASTManager::~SwiftASTManager() {
delete &Impl;
@@ -535,6 +539,15 @@ bool SwiftASTManager::initCompilerInvocation(
// We don't care about LLVMArgs
FrontendOpts.LLVMArgs.clear();
// SwiftSourceInfo files provide source location information for decls coming
// from loaded modules. For most IDE use cases it either has an undesirable
// impact on performance with no benefit (code completion), results in stale
// locations being used instead of more up-to-date indexer locations (cursor
// info), or has no observable effect (diagnostics, which are filtered to just
// those with a location in the primary file, and everything else).
if (Impl.Config->shouldOptimizeForIDE())
FrontendOpts.IgnoreSwiftSourceInfo = true;
// Disable expensive SIL options to reduce time spent in SILGen.
disableExpensiveSILOptions(Invocation.getSILOptions());