Skip to content

Commit f0aa023

Browse files
[Caching] Fix cache build with optimization remarks are used
Temporarily disable replaying optimization remarks when cache hit. Optimization remarks file are not setup to be cached because: * the write of such files are not going through output backend * when optimization remarks files are requested, it produces files that are not intended to be produced in SupplementoryOutputs, which confuses compiler when storing and loading compilation results, and causes cache misses all the time when optimization remark file is reuqested. Disable optimization remarks for cache replay so it is currently only produced when compiler actually did the compile locally.
1 parent 9ae27d7 commit f0aa023

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ def save_optimization_record_EQ : Joined<["-"], "save-optimization-record=">,
10371037
"(default: YAML)">, MetaVarName<"<format>">;
10381038
def save_optimization_record_path :
10391039
Separate<["-"], "save-optimization-record-path">,
1040-
Flags<[FrontendOption, ArgumentIsPath]>,
1040+
Flags<[FrontendOption, ArgumentIsPath, CacheInvariant]>,
10411041
HelpText<"Specify the file name of any generated optimization record">;
10421042
def save_optimization_record_passes :
10431043
Separate<["-"], "save-optimization-record-passes">,

lib/Frontend/CASOutputBackends.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ void SwiftCASOutputBackend::Implementation::initBackend(
227227
Input.getPrimarySpecificPaths()
228228
.SupplementaryOutputs.forEachSetOutputAndType(
229229
[&](const std::string &Out, file_types::ID ID) {
230+
// FIXME: Opt Remarks are not setup correctly to be cached and
231+
// didn't go through the output backend. Do not cache them.
232+
if (ID == file_types::ID::TY_YAMLOptRecord ||
233+
ID == file_types::ID::TY_BitstreamOptRecord)
234+
return;
235+
230236
if (!file_types::isProducedFromDiagnostics(ID))
231237
OutputToInputMap.insert({Out, {Index, ID}});
232238
});

test/CAS/opt-record.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
4+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
5+
// RUN: %s -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas
6+
7+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd
8+
// RUN: %swift_frontend_plain @%t/shim.cmd
9+
10+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
11+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
12+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
13+
14+
// RUN: %target-swift-frontend -c -cache-compile-job -cas-path %t/cas -O \
15+
// RUN: -save-optimization-record -save-optimization-record-path %t/record.yaml \
16+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
17+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
18+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
19+
// RUN: @%t/MyApp.cmd %s -o %t/test.o -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-MISS
20+
21+
// RUN: %target-swift-frontend -c -cache-compile-job -cas-path %t/cas -O \
22+
// RUN: -save-optimization-record -save-optimization-record-path %t/record-1.yaml \
23+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
24+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
25+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
26+
// RUN: @%t/MyApp.cmd %s -o %t/test.o -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-HIT
27+
28+
// RUN: %FileCheck %s --check-prefix=YAML --input-file=%t/record.yaml
29+
30+
/// FIXME: Remarks are not produced when cache hit.
31+
// RUN: not %FileCheck %s --check-prefix=YAML --input-file=%t/record-1.yaml
32+
33+
// CACHE-MISS: remark: cache miss for input
34+
// CACHE-HIT: remark: replay output file '<cached-diagnostics>': key 'llvmcas://{{.*}}'
35+
// CACHE-HIT: remark: replay output file '{{.*}}{{/|\\}}test.o': key 'llvmcas://{{.*}}'
36+
// YAML: ---
37+
38+
var a: Int = 1
39+
40+
func foo() {
41+
a = 2
42+
}
43+
44+
public func bar() {
45+
foo()
46+
}

0 commit comments

Comments
 (0)