Skip to content

Commit 68843db

Browse files
Merge pull request #70162 from cachemeifyoucan/eng/PR-swift-caching-frontend-replay-batch-mode
2 parents 1574e85 + 1325dd6 commit 68843db

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

lib/Frontend/CachingUtils.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,36 @@ bool replayCachedCompilerOutputs(
215215
Outputs.try_emplace(ID, File);
216216
});
217217

218+
// If this input doesn't produce any outputs, don't try to look up cache.
219+
// This can be a standalone emitModule action that only one input produces
220+
// output.
221+
if (Outputs.empty())
222+
return;
223+
218224
// Add cached diagnostic entry for lookup. Output path doesn't matter here.
219225
Outputs.try_emplace(file_types::ID::TY_CachedDiagnostics,
220226
"<cached-diagnostics>");
221227

222228
return replayOutputsForInputFile(InputPath, Outputs);
223229
};
224230

225-
llvm::for_each(InputsAndOutputs.getAllInputs(), replayOutputFromInput);
231+
// If there are primary inputs, look up only the primary input files.
232+
// Otherwise, prepare to do cache lookup for all inputs.
233+
if (InputsAndOutputs.hasPrimaryInputs())
234+
InputsAndOutputs.forEachPrimaryInput([&](const InputFile &File) {
235+
replayOutputFromInput(File);
236+
return false;
237+
});
238+
else
239+
llvm::for_each(InputsAndOutputs.getAllInputs(), replayOutputFromInput);
240+
241+
// If there is not diagnostic output, this is a job that produces no output
242+
// and only diagnostics, like `typecheck-module-from-interface`, look up
243+
// diagnostics from first file.
244+
if (!DiagnosticsOutput)
245+
replayOutputsForInputFile(
246+
InputsAndOutputs.getFirstOutputProducingInput().getFileName(),
247+
{{file_types::ID::TY_CachedDiagnostics, "<cached-diagnostics>"}});
226248

227249
if (!CanReplayAllOutput)
228250
return false;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
/// Test compile multiple inputs with batch mode.
5+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift %t/foo.swift -emit-module -o %t/Test.swiftmodule \
6+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-MISS %s
7+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job -primary-file %t/test.swift %t/foo.swift -c -o %t/test.o \
8+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-MISS %s
9+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift -primary-file %t/foo.swift -c -o %t/foo.o \
10+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-MISS %s
11+
12+
/// Expect cache hit second time
13+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift %t/foo.swift -emit-module -o %t/Test.swiftmodule \
14+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-HIT %s
15+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job -primary-file %t/test.swift %t/foo.swift -c -o %t/test.o \
16+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-HIT %s
17+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %t/test.swift -primary-file %t/foo.swift -c -o %t/foo.o \
18+
// RUN: -module-name Test -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck --check-prefix=CACHE-HIT %s
19+
20+
//--- test.swift
21+
func testFunc() {}
22+
23+
//--- foo.swift
24+
func foo() {}
25+
26+
// CACHE-MISS: remark: cache miss for input
27+
// CACHE-MISS-NOT: remark: replay output file
28+
// CACHE-HIT: remark: replay output file
29+
// CACHE-HIT-NOT: remark: cache miss for input

test/CAS/cas-explicit-module-map.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110

111111
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -disable-implicit-swift-modules -module-cache-path %t.module-cache -explicit-swift-module-map-file @%t/map.casid -Rmodule-loading -Xcc -Rmodule-import %s -cache-compile-job -cas-path %t/cas -allow-unstable-cache-key-for-testing 2>&1 | %FileCheck %s
112112

113-
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Foo.swiftinterface -disable-implicit-swift-modules -module-cache-path %t.module-cache -explicit-swift-module-map-file @%t/map.casid %s -cache-compile-job -cas-path %t/cas -allow-unstable-cache-key-for-testing -swift-version 5 -enable-library-evolution
113+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Foo.swiftinterface -disable-implicit-swift-modules -module-cache-path %t.module-cache -explicit-swift-module-map-file @%t/map.casid %s -cache-compile-job -cas-path %t/cas -allow-unstable-cache-key-for-testing -swift-version 5 -enable-library-evolution -o %t/Foo.swiftmodule
114114
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
115115
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Foo.swiftinterface -disable-implicit-swift-modules \
116116
// RUN: -module-cache-path %t.module-cache -explicit-swift-module-map-file @%t/map.casid %s -cache-compile-job \

0 commit comments

Comments
 (0)