Skip to content

Commit 2007dfa

Browse files
authored
Merge pull request swiftlang#72671 from cachemeifyoucan/eng/PR-swift-caching-6.0
[6.0] Swift Caching Updates
2 parents f67b21a + 376d137 commit 2007dfa

12 files changed

+88
-23
lines changed

include/swift/Option/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ def windows_sdk_root : Separate<["-"], "windows-sdk-root">,
246246
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
247247
HelpText<"Windows SDK Root">, MetaVarName<"<root>">;
248248
def windows_sdk_version : Separate<["-"], "windows-sdk-version">,
249-
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
249+
Flags<[FrontendOption, SwiftAPIExtractOption,
250250
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
251251
HelpText<"Windows SDK Version">, MetaVarName<"<version>">;
252252
def visualc_tools_root : Separate<["-"], "visualc-tools-root">,
253253
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
254254
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
255255
HelpText<"VisualC++ Tools Root">, MetaVarName<"<root>">;
256256
def visualc_tools_version : Separate<["-"], "visualc-tools-version">,
257-
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
257+
Flags<[FrontendOption, SwiftAPIExtractOption,
258258
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
259259
HelpText<"VisualC++ ToolSet Version">, MetaVarName<"<version>">;
260260

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,6 @@ static void writeJSON(llvm::raw_ostream &out,
823823
if (!moduleInterfacePath.empty()) {
824824
writeJSONSingleField(out, "moduleInterfacePath", moduleInterfacePath, 5,
825825
/*trailingComma=*/true);
826-
writeJSONSingleField(out, "contextHash", swiftTextualDeps->context_hash,
827-
5,
828-
/*trailingComma=*/true);
829826
out.indent(5 * 2);
830827
out << "\"compiledModuleCandidates\": [\n";
831828
for (int i = 0,
@@ -856,6 +853,9 @@ static void writeJSON(llvm::raw_ostream &out,
856853
}
857854
out.indent(5 * 2);
858855
out << "],\n";
856+
writeJSONSingleField(out, "contextHash", swiftTextualDeps->context_hash,
857+
5,
858+
/*trailingComma=*/true);
859859
bool hasBridgingHeaderPath =
860860
swiftTextualDeps->bridging_header_path.data &&
861861
get_C_string(swiftTextualDeps->bridging_header_path)[0] != '\0';
@@ -1251,9 +1251,7 @@ generateFullDependencyGraph(const CompilerInstance &instance,
12511251
bridgedOverlayDependencyNames);
12521252

12531253
details->swift_textual_details = {
1254-
moduleInterfacePath,
1255-
create_empty_set(),
1256-
bridgingHeaderPath,
1254+
moduleInterfacePath, create_empty_set(), bridgingHeaderPath,
12571255
create_set(
12581256
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles),
12591257
create_set(swiftSourceDeps->textualModuleDetails
@@ -1262,7 +1260,9 @@ generateFullDependencyGraph(const CompilerInstance &instance,
12621260
create_set(swiftSourceDeps->textualModuleDetails.buildCommandLine),
12631261
create_set(swiftSourceDeps->bridgingHeaderBuildCommandLine),
12641262
create_set(swiftSourceDeps->textualModuleDetails.extraPCMArgs),
1265-
/*contextHash*/ create_null(),
1263+
/*contextHash*/
1264+
create_clone(
1265+
instance.getInvocation().getModuleScanningHash().c_str()),
12661266
/*isFramework*/ false,
12671267
/*CASFS*/
12681268
create_clone(swiftSourceDeps->textualModuleDetails

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,17 +1873,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18731873
if (LoaderOpts.requestedAction ==
18741874
FrontendOptions::ActionType::ScanDependencies) {
18751875
// For a dependency scanning action, interface build command generation must
1876-
// inherit
1877-
// `-Xcc` flags used for configuration of the building instance's
1876+
// inherit `-Xcc` flags used for configuration of the building instance's
18781877
// `ClangImporter`. However, we can ignore Clang search path flags because
18791878
// explicit Swift module build tasks will not rely on them and they may be
18801879
// source-target-context-specific and hinder module sharing across
18811880
// compilation source targets.
1882-
// Clang module dependecies of this Swift dependency will be distinguished by
1883-
// their context hash for different variants, so would still cause a difference
1884-
// in the Swift compile commands, when different.
1885-
inheritedParentContextClangArgs =
1886-
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
1881+
// If using DirectCC1Scan, the command-line reduction is handled inside
1882+
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
1883+
// anything here as the ExtraArgs from the invocation are clang driver
1884+
// options, not cc1 options.
1885+
// Clang module dependecies of this Swift dependency will be distinguished
1886+
// by their context hash for different variants, so would still cause a
1887+
// difference in the Swift compile commands, when different.
1888+
if (!clangImporterOpts.ClangImporterDirectCC1Scan)
1889+
inheritedParentContextClangArgs =
1890+
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
18871891
genericSubInvocation.getFrontendOptions()
18881892
.DependencyScanningSubInvocation = true;
18891893
} else if (LoaderOpts.strictImplicitModuleContext ||
@@ -2610,7 +2614,7 @@ bool ExplicitCASModuleLoader::findModule(
26102614
// that are not located on disk.
26112615
auto moduleBuf = loadCachedCompileResultFromCacheKey(
26122616
Impl.CAS, Impl.Cache, Ctx.Diags, moduleCASID,
2613-
file_types::ID::TY_SwiftModuleFile);
2617+
file_types::ID::TY_SwiftModuleFile, moduleInfo.modulePath);
26142618
if (!moduleBuf) {
26152619
// We cannot read the module content, diagnose.
26162620
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,

test/CAS/module_deps.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ import SubE
133133
// CHECK: ],
134134
// CHECK-NEXT: "details": {
135135

136-
// CHECK: "contextHash": "{{.*}}",
137136
// CHECK: "commandLine": [
138137
// CHECK: "-compile-module-from-interface"
139138
// CHECK: "-target"
@@ -144,6 +143,7 @@ import SubE
144143
// CHECK: "-swift-version"
145144
// CHECK: "5"
146145
// CHECK: ],
146+
// CHECK: "contextHash": "{{.*}}",
147147
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
148148
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
149149
// CHECK_NO_CLANG_TARGET-NEXT: "-target",

test/CAS/module_deps_include_tree.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ import SubE
127127
// CHECK: ],
128128
// CHECK-NEXT: "details": {
129129

130-
// CHECK: "contextHash": "{{.*}}",
131130
// CHECK: "commandLine": [
132131
// CHECK: "-compile-module-from-interface"
133132
// CHECK: "-target"
@@ -138,6 +137,7 @@ import SubE
138137
// CHECK: "-swift-version"
139138
// CHECK: "5"
140139
// CHECK: ],
140+
// CHECK: "contextHash": "{{.*}}",
141141
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
142142
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
143143
// CHECK_NO_CLANG_TARGET-NEXT: "-target",

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() {}

test/CAS/plugin_cas.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ import SubE
115115
// CHECK: ],
116116
// CHECK-NEXT: "details": {
117117

118-
// CHECK: "contextHash": "{{.*}}",
119118
// CHECK: "commandLine": [
120119
// CHECK: "-compile-module-from-interface"
121120
// CHECK: "-target"
@@ -124,6 +123,7 @@ import SubE
124123
// CHECK: "-swift-version"
125124
// CHECK: "5"
126125
// CHECK: ],
126+
// CHECK: "contextHash": "{{.*}}",
127127
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
128128
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
129129
// CHECK_NO_CLANG_TARGET-NEXT: "-target",

test/ModuleInterface/clang-session-transitive.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import TestModule
3333
// CHECK-NEXT: "details": {
3434
// CHECK-NEXT: "swift": {
3535
// CHECK-NEXT: "moduleInterfacePath":
36-
// CHECK-NEXT: "contextHash":
3736
// CHECK-NEXT: "compiledModuleCandidates": [
3837
// CHECK-NEXT: TestModule.swiftmodule
3938
// CHECK-NEXT: ],

test/ModuleInterface/extension-transitive-availability.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func foo() {
3434
// CHECK-NEXT: "details": {
3535
// CHECK-NEXT: "swift": {
3636
// CHECK-NEXT: "moduleInterfacePath":
37-
// CHECK-NEXT: "contextHash":
3837
// CHECK-NEXT: "compiledModuleCandidates": [
3938
// CHECK-NEXT: ],
4039
// CHECK-NEXT: "commandLine": [

test/ScanDependencies/direct_cc1_scan.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps2.json -I %t \
1717
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
18+
// RUN: -g -file-compilation-dir %t -Xcc -ferror-limit=1 \
1819
// RUN: %t/test.swift -module-name Test -swift-version 5 -experimental-clang-importer-direct-cc1-scan
1920
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps2.json A | %FileCheck %s --check-prefix CHECK-DIRECT-CC1-SCAN
2021
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps2.json Test | %FileCheck %s --check-prefix CHECK-DIRECT-CC1-SCAN
2122

2223
// CHECK-NO-DIRECT-CC1-NOT: -direct-clang-cc1-module-build
2324
// CHECK-DIRECT-CC1-SCAN: -direct-clang-cc1-module-build
25+
// CHECK-DIRECT-CC1-SCAN-NOT: -ffile-compilation-dir
26+
// CHECK-DIRECT-CC1-SCAN-NOT: -ferror-limit=1
2427

2528
//--- A.swift
2629
func a() {}

0 commit comments

Comments
 (0)