Skip to content

Commit 9c97a12

Browse files
Merge pull request #72427 from cachemeifyoucan/eng/PR-122905379
[Caching] Give swiftmodule loaded from CAS a path identifier
2 parents 716a1a9 + 782a421 commit 9c97a12

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ bool ExplicitCASModuleLoader::findModule(
26032603
// that are not located on disk.
26042604
auto moduleBuf = loadCachedCompileResultFromCacheKey(
26052605
Impl.CAS, Impl.Cache, Ctx.Diags, moduleCASID,
2606-
file_types::ID::TY_SwiftModuleFile);
2606+
file_types::ID::TY_SwiftModuleFile, moduleInfo.modulePath);
26072607
if (!moduleBuf) {
26082608
// We cannot read the module content, diagnose.
26092609
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,

lib/FrontendTool/FrontendTool.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,13 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) {
410410
bool IgnoreAdjacentModules = Instance.hasASTContext() &&
411411
Instance.getASTContext().IgnoreAdjacentModules;
412412

413+
// When caching is enabled, the explicit module build dependencies are
414+
// discovered by dependency scanner and the swiftmodule is already rebuilt
415+
// ignoring candidate module. There is no need to serialized dependencies for
416+
// validation purpose.
417+
bool ShouldSerializeDeps =
418+
!Instance.getInvocation().getCASOptions().EnableCaching;
419+
413420
// If an explicit interface build was requested, bypass the creation of a new
414421
// sub-instance from the interface which will build it in a separate thread,
415422
// and isntead directly use the current \c Instance for compilation.
@@ -422,8 +429,7 @@ static bool buildModuleFromInterface(CompilerInstance &Instance) {
422429
return ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface(
423430
Instance, Invocation.getClangModuleCachePath(),
424431
FEOpts.BackupModuleInterfaceDir, PrebuiltCachePath, ABIPath, InputPath,
425-
Invocation.getOutputFilename(),
426-
/* shouldSerializeDeps */ true,
432+
Invocation.getOutputFilename(), ShouldSerializeDeps,
427433
Invocation.getSearchPathOptions().CandidateCompiledModules);
428434

429435
return ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(

test/CAS/module_trace.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-module -module-name B -o %t/B.swiftmodule -swift-version 5 \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
6+
// RUN: -emit-module-interface-path %t/ignore/B.swiftinterface -enable-library-evolution \
7+
// RUN: %t/B.swift
8+
9+
// RUN: %target-swift-frontend -emit-module -module-name A -o %t/ignore/A.swiftmodule -swift-version 5 \
10+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
11+
// RUN: -emit-module-interface-path %t/A.swiftinterface -enable-library-evolution -I %t \
12+
// RUN: %t/A.swift
13+
14+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache %t/main.swift \
15+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
16+
// RUN: -o %t/deps.json -I %t -cache-compile-job -cas-path %t/cas -swift-version 5
17+
18+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
19+
// RUN: %swift_frontend_plain @%t/A.cmd
20+
21+
// RUN: %FileCheck %s --input-file=%t/A.cmd
22+
23+
// CHECK-NOT: -candidate-module-file
24+
25+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
26+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
27+
28+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
29+
30+
// RUN: %target-swift-frontend \
31+
// RUN: -c -cache-compile-job -cas-path %t/cas \
32+
// RUN: -disable-implicit-swift-modules -o %t/test.o\
33+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
34+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
35+
// RUN: -emit-reference-dependencies-path %t/test.swiftdeps -emit-dependencies \
36+
// RUN: -primary-file %t/main.swift @%t/MyApp.cmd -emit-loaded-module-trace -emit-loaded-module-trace-path %t/test.trace.json 2>&1 \
37+
// RUN: | %FileCheck %s --check-prefix=WARNING --allow-empty
38+
39+
// WARNING-NOT: WARNING:
40+
41+
// RUN: %FileCheck %s --check-prefix=TRACE --input-file=%t/test.trace.json
42+
// TRACE-DAG: A.swiftinterface
43+
44+
// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps_with_fingerprints.py %swift-dependency-tool %t/test.swiftdeps > %t/test-processed.swiftdeps
45+
// RUN: %FileCheck %s --check-prefix=SWIFTDEPS --input-file=%t/test-processed.swiftdeps
46+
// SWIFTDEPS: A.swiftinterface
47+
// SWIFTDEPS: B.swiftmdoule
48+
49+
50+
//--- main.swift
51+
import A
52+
53+
//--- A.swift
54+
import B
55+
func test() {}
56+
57+
//--- B.swift
58+
func b() {}

0 commit comments

Comments
 (0)