Skip to content

Commit fb3c268

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 9f73681 commit fb3c268

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
@@ -1454,7 +1454,7 @@ def index_file_path : Separate<["-"], "index-file-path">,
14541454
MetaVarName<"<path>">;
14551455

14561456
def index_store_path : Separate<["-"], "index-store-path">,
1457-
Flags<[FrontendOption, ArgumentIsPath]>, MetaVarName<"<path>">,
1457+
Flags<[FrontendOption, ArgumentIsPath, CacheInvariant]>, MetaVarName<"<path>">,
14581458
HelpText<"Store indexing data to <path>">;
14591459

14601460
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
@@ -1110,6 +1110,10 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11101110
// the knowledge about clang command-line options.
11111111
if (ctx.CASOpts.EnableCaching)
11121112
CI->getCASOpts() = ctx.CASOpts.CASOpts;
1113+
1114+
// Forward the index store path. That information is not passed to scanner
1115+
// and it is cached invariant so we don't want to re-scan if that changed.
1116+
CI->getFrontendOpts().IndexStorePath = ctx.ClangImporterOpts.IndexStorePath;
11131117
} else {
11141118
// Otherwise, create cc1 arguments from driver args.
11151119
auto driverArgs = getClangDriverArguments(ctx, ignoreClangTarget);
@@ -3979,6 +3983,9 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
39793983
FEOpts.IncludeTimestamps = false;
39803984
FEOpts.ModuleMapFiles.clear();
39813985

3986+
// IndexStorePath is forwarded from swift.
3987+
FEOpts.IndexStorePath.clear();
3988+
39823989
// PreprocessorOptions.
39833990
// Cannot clear macros as the main module clang importer doesn't have clang
39843991
// 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)