Skip to content

Commit 0b3a1fc

Browse files
[Caching] Support index while building when caching on
Model indexing output as an optional output from the swift compiler as the build system has no knowledge about them and they can be regenerated by indexer. Make sure the indexing store output is produced when cache hit so the compilation is done for the module. If cache hit, no indexing data is produced since no compilation is done. rdar://123331335
1 parent 544ae88 commit 0b3a1fc

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ def index_file_path : Separate<["-"], "index-file-path">,
14501450
MetaVarName<"<path>">;
14511451

14521452
def index_store_path : Separate<["-"], "index-store-path">,
1453-
Flags<[FrontendOption, ArgumentIsPath]>, MetaVarName<"<path>">,
1453+
Flags<[FrontendOption, ArgumentIsPath, CacheInvariant]>, MetaVarName<"<path>">,
14541454
HelpText<"Store indexing data to <path>">;
14551455

14561456
def index_unit_output_path : Separate<["-"], "index-unit-output-path">,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11111111
CI->getFrontendOpts().IncludeTimestamps = false;
11121112
CI->getCASOpts() = ctx.CASOpts.CASOpts;
11131113
}
1114+
1115+
// Forward the index store path. That information is not passed to scanner
1116+
// and it is cached invariant so we don't want to re-scan if that changed.
1117+
CI->getFrontendOpts().IndexStorePath = ctx.ClangImporterOpts.IndexStorePath;
11141118
} else {
11151119
// Otherwise, create cc1 arguments from driver args.
11161120
auto driverArgs = getClangDriverArguments(ctx, ignoreClangTarget);
@@ -3984,6 +3988,9 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
39843988
FEOpts.IncludeTimestamps = false;
39853989
FEOpts.ModuleMapFiles.clear();
39863990

3991+
// IndexStorePath is forwarded from swift.
3992+
FEOpts.IndexStorePath.clear();
3993+
39873994
// PreprocessorOptions.
39883995
// Cannot clear macros as the main module clang importer doesn't have clang
39893996
// include tree created and it has to be created from command-line. However,

test/CAS/index-store.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module %t/A.swift -I %t -module-name A \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
6+
// RUN: -enable-library-evolution -swift-version 5 \
7+
// RUN: -emit-module-interface-path %t/A.swiftinterface \
8+
// RUN: -o %t/A.swiftmodule
9+
10+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -O -module-cache-path %t/clang-module-cache \
11+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
12+
// RUN: %t/test.swift -I %t -o %t/deps.json -cache-compile-job -cas-path %t/cas
13+
14+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
15+
// RUN: %swift_frontend_plain @%t/B.cmd
16+
17+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
18+
// RUN: %swift_frontend_plain @%t/A.cmd
19+
20+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
21+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
22+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
23+
24+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift -O -emit-module -o %t/Test.swiftmodule \
25+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
26+
// RUN: -disable-implicit-swift-modules -explicit-swift-module-map-file @%t/map.casid \
27+
// RUN: -module-name Test -cas-path %t/cas @%t/MyApp.cmd -index-system-modules -index-store-path %t/db 2>&1 | %FileCheck --check-prefix=CACHE-MISS %s
28+
// RUN: ls %t/db
29+
30+
/// Cache hit with a different index-store-path. Note cache hit will skip replay index data.
31+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift -O -emit-module -o %t/Test.swiftmodule \
32+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
33+
// RUN: -disable-implicit-swift-modules -explicit-swift-module-map-file @%t/map.casid \
34+
// RUN: -module-name Test -cas-path %t/cas @%t/MyApp.cmd -index-system-modules -index-store-path %t/db2 2>&1 | %FileCheck --check-prefix=CACHE-HIT %s
35+
// RUN: not ls %t/db2
36+
37+
// CACHE-MISS: remark: cache miss for input
38+
// CACHE-HIT: remark: replay output file
39+
40+
//--- test.swift
41+
import A
42+
import B
43+
func test() {}
44+
45+
//--- A.swift
46+
func a() {}
47+
48+
//--- module.modulemap
49+
module B {
50+
header "B.h"
51+
export *
52+
}
53+
54+
//--- B.h
55+
void b(void);

0 commit comments

Comments
 (0)