Skip to content

Commit a785fa6

Browse files
author
Nathan Hawes
committed
[Frontend][Index] Add frontend option to skip indexing the stdlib (for test performance)
Several tests related to indexing system modules were taking a considerable amount of time (100+ seconds in the worst case) indexing the standard library. This adds a frontend option to skip it and updates those tests to pass it.
1 parent 8b03b05 commit a785fa6

9 files changed

+52
-15
lines changed

Diff for: include/swift/Frontend/FrontendOptions.h

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class FrontendOptions {
8282
/// Emit index data for imported serialized swift system modules.
8383
bool IndexSystemModules = false;
8484

85+
/// If indexing system modules, don't index the stdlib.
86+
bool IndexIgnoreStdlib = false;
87+
8588
/// The module for which we should verify all of the generic signatures.
8689
std::string VerifyGenericSignaturesInModule;
8790

Diff for: include/swift/Index/IndexRecord.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ namespace index {
3636
/// \param indexSystemModules If true, emit index data for imported serialized
3737
/// swift system modules.
3838
///
39+
/// \param skipStdlib If indexing system modules, don't index the standard
40+
/// library.
41+
///
3942
/// \param isDebugCompilation true for non-optimized compiler invocation.
4043
///
4144
/// \param targetTriple The target for this compilation.
4245
///
4346
/// \param dependencyTracker The set of dependencies seen while building.
4447
bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
4548
StringRef indexStorePath, bool indexSystemModules,
46-
bool isDebugCompilation, StringRef targetTriple,
49+
bool skipStdlib, bool isDebugCompilation,
50+
StringRef targetTriple,
4751
const DependencyTracker &dependencyTracker);
4852

4953
/// Index the given module and store the results to \p indexStorePath.
@@ -64,15 +68,18 @@ bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
6468
/// \param indexSystemModules If true, emit index data for imported serialized
6569
/// swift system modules.
6670
///
71+
/// \param skipStdlib If indexing system modules, don't index the standard
72+
/// library.
73+
///
6774
/// \param isDebugCompilation true for non-optimized compiler invocation.
6875
///
6976
/// \param targetTriple The target for this compilation.
7077
///
7178
/// \param dependencyTracker The set of dependencies seen while building.
7279
bool indexAndRecord(ModuleDecl *module, ArrayRef<std::string> indexUnitTokens,
7380
StringRef moduleUnitToken, StringRef indexStorePath,
74-
bool indexSystemModules, bool isDebugCompilation,
75-
StringRef targetTriple,
81+
bool indexSystemModules, bool skipStdlib,
82+
bool isDebugCompilation, StringRef targetTriple,
7683
const DependencyTracker &dependencyTracker);
7784
// FIXME: indexUnitTokens could be StringRef, but that creates an impedance
7885
// mismatch in the caller.

Diff for: include/swift/Option/FrontendOptions.td

+4
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ def external_pass_pipeline_filename : Separate<["-"], "external-pass-pipeline-fi
604604
def index_system_modules : Flag<["-"], "index-system-modules">,
605605
HelpText<"Emit index data for imported serialized swift system modules">;
606606

607+
def index_ignore_stdlib :
608+
Flag<["-"], "index-ignore-stdlib">,
609+
HelpText<"Avoid emitting index data for the standard library.">;
610+
607611
def dump_interface_hash : Flag<["-"], "dump-interface-hash">,
608612
HelpText<"Parse input file(s) and dump interface token hash(es)">,
609613
ModeOpt;

Diff for: lib/Frontend/ArgsToFrontendOptionsConverter.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ bool ArgsToFrontendOptionsConverter::convert(
6767
Opts.BridgingHeaderDirForPrint = A->getValue();
6868
}
6969
Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules);
70+
Opts.IndexIgnoreStdlib |= Args.hasArg(OPT_index_ignore_stdlib);
7071

7172
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
7273
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);

Diff for: lib/FrontendTool/FrontendTool.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,8 @@ static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
17291729
PrimarySourceFile->getFilename());
17301730
if (index::indexAndRecord(PrimarySourceFile, PSPs.OutputFilename,
17311731
opts.IndexStorePath, opts.IndexSystemModules,
1732-
isDebugCompilation, Invocation.getTargetTriple(),
1732+
opts.IndexIgnoreStdlib, isDebugCompilation,
1733+
Invocation.getTargetTriple(),
17331734
*Instance.getDependencyTracker())) {
17341735
return true;
17351736
}
@@ -1741,7 +1742,7 @@ static bool emitIndexDataIfNeeded(SourceFile *PrimarySourceFile,
17411742

17421743
if (index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
17431744
moduleToken, opts.IndexStorePath,
1744-
opts.IndexSystemModules,
1745+
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
17451746
isDebugCompilation, Invocation.getTargetTriple(),
17461747
*Instance.getDependencyTracker())) {
17471748
return true;

Diff for: lib/Index/IndexRecord.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ static bool
389389
emitDataForSwiftSerializedModule(ModuleDecl *module,
390390
StringRef indexStorePath,
391391
bool indexSystemModules,
392+
bool skipStdlib,
392393
StringRef targetTriple,
393394
const clang::CompilerInstance &clangCI,
394395
DiagnosticEngine &diags,
@@ -398,6 +399,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
398399
static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
399400
StringRef indexStorePath,
400401
bool indexSystemModules,
402+
bool skipStdlib,
401403
StringRef targetTriple,
402404
const clang::CompilerInstance &clangCI,
403405
DiagnosticEngine &diags,
@@ -441,9 +443,10 @@ static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
441443
// We don't officially support binary swift modules, so normally
442444
// the index data for user modules would get generated while
443445
// building them.
444-
if (mod->isSystemModule() && indexSystemModules) {
446+
if (mod->isSystemModule() && indexSystemModules &&
447+
(!skipStdlib || !mod->isStdlibModule())) {
445448
emitDataForSwiftSerializedModule(mod, indexStorePath,
446-
indexSystemModules,
449+
indexSystemModules, skipStdlib,
447450
targetTriple, clangCI, diags,
448451
unitWriter, initialFile);
449452
withoutUnitName = false;
@@ -470,6 +473,7 @@ static bool
470473
emitDataForSwiftSerializedModule(ModuleDecl *module,
471474
StringRef indexStorePath,
472475
bool indexSystemModules,
476+
bool skipStdlib,
473477
StringRef targetTriple,
474478
const clang::CompilerInstance &clangCI,
475479
DiagnosticEngine &diags,
@@ -590,7 +594,7 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
590594
SmallVector<ModuleDecl::ImportedModule, 8> imports;
591595
module->getImportedModules(imports, importFilter);
592596
StringScratchSpace moduleNameScratch;
593-
addModuleDependencies(imports, indexStorePath, indexSystemModules,
597+
addModuleDependencies(imports, indexStorePath, indexSystemModules, skipStdlib,
594598
targetTriple, clangCI, diags, unitWriter,
595599
moduleNameScratch, initialFile);
596600

@@ -605,7 +609,8 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
605609
static bool
606610
recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
607611
StringRef indexStorePath, bool indexSystemModules,
608-
bool isDebugCompilation, StringRef targetTriple,
612+
bool skipStdlib, bool isDebugCompilation,
613+
StringRef targetTriple,
609614
ArrayRef<const clang::FileEntry *> fileDependencies,
610615
const clang::CompilerInstance &clangCI,
611616
DiagnosticEngine &diags) {
@@ -628,11 +633,11 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
628633
importFilter |= ModuleDecl::ImportFilterKind::Public;
629634
importFilter |= ModuleDecl::ImportFilterKind::Private;
630635
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
631-
// FIXME: ImportFilterKind::ShadowedBySeparateOverlay?
636+
632637
SmallVector<ModuleDecl::ImportedModule, 8> imports;
633638
primarySourceFile->getImportedModules(imports, importFilter);
634639
StringScratchSpace moduleNameScratch;
635-
addModuleDependencies(imports, indexStorePath, indexSystemModules,
640+
addModuleDependencies(imports, indexStorePath, indexSystemModules, skipStdlib,
636641
targetTriple, clangCI, diags, unitWriter,
637642
moduleNameScratch, primarySourceFile);
638643

@@ -685,6 +690,7 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
685690
StringRef indexUnitToken,
686691
StringRef indexStorePath,
687692
bool indexSystemModules,
693+
bool skipStdlib,
688694
bool isDebugCompilation,
689695
StringRef targetTriple,
690696
const DependencyTracker &dependencyTracker) {
@@ -712,7 +718,7 @@ bool index::indexAndRecord(SourceFile *primarySourceFile,
712718
#endif
713719

714720
return recordSourceFileUnit(primarySourceFile, indexUnitToken,
715-
indexStorePath, indexSystemModules,
721+
indexStorePath, indexSystemModules, skipStdlib,
716722
isDebugCompilation, targetTriple,
717723
fileDependencies.getArrayRef(),
718724
clangCI, diags);
@@ -723,6 +729,7 @@ bool index::indexAndRecord(ModuleDecl *module,
723729
StringRef moduleUnitToken,
724730
StringRef indexStorePath,
725731
bool indexSystemModules,
732+
bool skipStdlib,
726733
bool isDebugCompilation,
727734
StringRef targetTriple,
728735
const DependencyTracker &dependencyTracker) {
@@ -758,7 +765,7 @@ bool index::indexAndRecord(ModuleDecl *module,
758765
return true;
759766
}
760767
if (recordSourceFileUnit(SF, indexUnitTokens[unitIndex],
761-
indexStorePath, indexSystemModules,
768+
indexStorePath, indexSystemModules, skipStdlib,
762769
isDebugCompilation, targetTriple,
763770
fileDependencies.getArrayRef(),
764771
clangCI, diags))

Diff for: test/Index/Store/cross-import-overlay.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: cp -r %S/../Inputs/CrossImport %t/CrossImport
33
// RUN: %{python} %S/../../CrossImport/Inputs/rewrite-module-triples.py %t/CrossImport %module-target-triple
44

5-
// RUN: %target-swift-frontend -c -index-store-path %t/idx -index-system-modules -enable-cross-import-overlays %s -Fsystem %t/CrossImport -o %t/file1.o -module-name cross_import_overlay
5+
// RUN: %target-swift-frontend -c -index-store-path %t/idx -index-system-modules -index-ignore-stdlib -enable-cross-import-overlays %s -Fsystem %t/CrossImport -o %t/file1.o -module-name cross_import_overlay
66
// RUN: c-index-test core -print-unit %t/idx > %t/units
77
// RUN: %FileCheck %s --input-file %t/units --check-prefix=UNIT
88
// RUN: %FileCheck %s --input-file %t/units --check-prefix=UNIT-NEGATIVE
@@ -16,6 +16,8 @@ fromB()
1616
from_ABAdditions()
1717
from__ABAdditionsCAdditions()
1818

19+
// Check the overlay modules' names match the names of their underlying modules.
20+
//
1921
// UNIT: module-name: cross_import_overlay
2022
// UNIT: main-path: {{.*}}/cross-import-overlay.swift
2123
// UNIT: DEPEND START
@@ -59,6 +61,14 @@ from__ABAdditionsCAdditions()
5961
// UNIT: Record | system | A | {{.*}}/A.swiftmodule/{{.*}}
6062
// UNIT: DEPEND END
6163

64+
// Make sure we aren't leaking the underscored overlay names anywhere
65+
//
6266
// UNIT-NEGATIVE-NOT: Unit | {{.*}} | _ABAdditions |
67+
// UNIT-NEGATIVE-NOT: Record | {{.*}} | _ABAdditions |
6368
// UNIT-NEGATIVE-NOT: Unit | {{.*}} | __ABAdditionsCAdditions |
69+
// UNIT-NEGATIVE-NOT: Record | {{.*}} | __ABAdditionsCAdditions |
70+
71+
// Make sure we don't regress test performance by indexing the stdlib.
72+
//
73+
// UNIT-NEGATIVE-NOT: Record | system | Swift |
6474

Diff for: test/Index/Store/driver-index-with-auxiliary-outputs.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// make sure the frontend job doesn't try to emit the auxiliary outputs based
55
// on the non-indexed files. (This is how Xcode currently constructs -index-file
66
// invocations: take a normal build command and add extra arguments to it.)
7-
// RUN: %target-build-swift -index-file -index-file-path %S/Inputs/SwiftModuleA.swift %S/Inputs/SwiftModuleA.swift %s -index-store-path %t/idx -module-name driver_index -emit-objc-header-path %t/out.h -emit-module-interface-path %t/out.swiftinterface
7+
// RUN: %target-build-swift -index-file -index-file-path %S/Inputs/SwiftModuleA.swift %S/Inputs/SwiftModuleA.swift %s -index-store-path %t/idx -Xfrontend -index-ignore-stdlib -module-name driver_index -emit-objc-header-path %t/out.h -emit-module-interface-path %t/out.swiftinterface
88

99
// RUN: test ! -f %t/out.h
1010
// RUN: test ! -f %t/out.swiftinterface

Diff for: test/Index/index_swift_only_systemmodule.swift

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ print(someFunc())
3434
// RUN: %target-swift-frontend \
3535
// RUN: -typecheck \
3636
// RUN: -index-system-modules \
37+
// RUN: -index-ignore-stdlib \
3738
// RUN: -index-store-path %t/idx \
3839
// RUN: -sdk %t/SDK \
3940
// RUN: -Fsystem %t/SDK/Frameworks \
@@ -66,6 +67,7 @@ print(someFunc())
6667
// RUN: %target-swift-frontend \
6768
// RUN: -typecheck \
6869
// RUN: -index-system-modules \
70+
// RUN: -index-ignore-stdlib \
6971
// RUN: -index-store-path %t/idx \
7072
// RUN: -sdk %t/SDK \
7173
// RUN: -Fsystem %t/SDK/Frameworks \
@@ -95,6 +97,7 @@ print(someFunc())
9597
// RUN: %target-swift-frontend \
9698
// RUN: -typecheck \
9799
// RUN: -index-system-modules \
100+
// RUN: -index-ignore-stdlib \
98101
// RUN: -index-store-path %t/idx \
99102
// RUN: -sdk %t/SDK \
100103
// RUN: -Fsystem %t/SDK/Frameworks \
@@ -123,6 +126,7 @@ print(someFunc())
123126
// RUN: %target-swift-frontend \
124127
// RUN: -typecheck \
125128
// RUN: -index-system-modules \
129+
// RUN: -index-ignore-stdlib \
126130
// RUN: -index-store-path %t/idx \
127131
// RUN: -sdk %t/SDK \
128132
// RUN: -Fsystem %t/SDK/Frameworks \

0 commit comments

Comments
 (0)