Skip to content

[6.0] Swift Caching Updates #72671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ def windows_sdk_root : Separate<["-"], "windows-sdk-root">,
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
HelpText<"Windows SDK Root">, MetaVarName<"<root>">;
def windows_sdk_version : Separate<["-"], "windows-sdk-version">,
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
Flags<[FrontendOption, SwiftAPIExtractOption,
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
HelpText<"Windows SDK Version">, MetaVarName<"<version>">;
def visualc_tools_root : Separate<["-"], "visualc-tools-root">,
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
HelpText<"VisualC++ Tools Root">, MetaVarName<"<root>">;
def visualc_tools_version : Separate<["-"], "visualc-tools-version">,
Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption,
Flags<[FrontendOption, SwiftAPIExtractOption,
SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,
HelpText<"VisualC++ ToolSet Version">, MetaVarName<"<version>">;

Expand Down
14 changes: 7 additions & 7 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,6 @@ static void writeJSON(llvm::raw_ostream &out,
if (!moduleInterfacePath.empty()) {
writeJSONSingleField(out, "moduleInterfacePath", moduleInterfacePath, 5,
/*trailingComma=*/true);
writeJSONSingleField(out, "contextHash", swiftTextualDeps->context_hash,
5,
/*trailingComma=*/true);
out.indent(5 * 2);
out << "\"compiledModuleCandidates\": [\n";
for (int i = 0,
Expand Down Expand Up @@ -856,6 +853,9 @@ static void writeJSON(llvm::raw_ostream &out,
}
out.indent(5 * 2);
out << "],\n";
writeJSONSingleField(out, "contextHash", swiftTextualDeps->context_hash,
5,
/*trailingComma=*/true);
bool hasBridgingHeaderPath =
swiftTextualDeps->bridging_header_path.data &&
get_C_string(swiftTextualDeps->bridging_header_path)[0] != '\0';
Expand Down Expand Up @@ -1251,9 +1251,7 @@ generateFullDependencyGraph(const CompilerInstance &instance,
bridgedOverlayDependencyNames);

details->swift_textual_details = {
moduleInterfacePath,
create_empty_set(),
bridgingHeaderPath,
moduleInterfacePath, create_empty_set(), bridgingHeaderPath,
create_set(
swiftSourceDeps->textualModuleDetails.bridgingSourceFiles),
create_set(swiftSourceDeps->textualModuleDetails
Expand All @@ -1262,7 +1260,9 @@ generateFullDependencyGraph(const CompilerInstance &instance,
create_set(swiftSourceDeps->textualModuleDetails.buildCommandLine),
create_set(swiftSourceDeps->bridgingHeaderBuildCommandLine),
create_set(swiftSourceDeps->textualModuleDetails.extraPCMArgs),
/*contextHash*/ create_null(),
/*contextHash*/
create_clone(
instance.getInvocation().getModuleScanningHash().c_str()),
/*isFramework*/ false,
/*CASFS*/
create_clone(swiftSourceDeps->textualModuleDetails
Expand Down
20 changes: 12 additions & 8 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,17 +1873,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
if (LoaderOpts.requestedAction ==
FrontendOptions::ActionType::ScanDependencies) {
// For a dependency scanning action, interface build command generation must
// inherit
// `-Xcc` flags used for configuration of the building instance's
// inherit `-Xcc` flags used for configuration of the building instance's
// `ClangImporter`. However, we can ignore Clang search path flags because
// explicit Swift module build tasks will not rely on them and they may be
// source-target-context-specific and hinder module sharing across
// compilation source targets.
// Clang module dependecies of this Swift dependency will be distinguished by
// their context hash for different variants, so would still cause a difference
// in the Swift compile commands, when different.
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
// If using DirectCC1Scan, the command-line reduction is handled inside
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
// anything here as the ExtraArgs from the invocation are clang driver
// options, not cc1 options.
// Clang module dependecies of this Swift dependency will be distinguished
// by their context hash for different variants, so would still cause a
// difference in the Swift compile commands, when different.
if (!clangImporterOpts.ClangImporterDirectCC1Scan)
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
genericSubInvocation.getFrontendOptions()
.DependencyScanningSubInvocation = true;
} else if (LoaderOpts.strictImplicitModuleContext ||
Expand Down Expand Up @@ -2610,7 +2614,7 @@ bool ExplicitCASModuleLoader::findModule(
// that are not located on disk.
auto moduleBuf = loadCachedCompileResultFromCacheKey(
Impl.CAS, Impl.Cache, Ctx.Diags, moduleCASID,
file_types::ID::TY_SwiftModuleFile);
file_types::ID::TY_SwiftModuleFile, moduleInfo.modulePath);
if (!moduleBuf) {
// We cannot read the module content, diagnose.
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
Expand Down
2 changes: 1 addition & 1 deletion test/CAS/module_deps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ import SubE
// CHECK: ],
// CHECK-NEXT: "details": {

// CHECK: "contextHash": "{{.*}}",
// CHECK: "commandLine": [
// CHECK: "-compile-module-from-interface"
// CHECK: "-target"
Expand All @@ -144,6 +143,7 @@ import SubE
// CHECK: "-swift-version"
// CHECK: "5"
// CHECK: ],
// CHECK: "contextHash": "{{.*}}",
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
// CHECK_NO_CLANG_TARGET-NEXT: "-target",
Expand Down
2 changes: 1 addition & 1 deletion test/CAS/module_deps_include_tree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ import SubE
// CHECK: ],
// CHECK-NEXT: "details": {

// CHECK: "contextHash": "{{.*}}",
// CHECK: "commandLine": [
// CHECK: "-compile-module-from-interface"
// CHECK: "-target"
Expand All @@ -138,6 +137,7 @@ import SubE
// CHECK: "-swift-version"
// CHECK: "5"
// CHECK: ],
// CHECK: "contextHash": "{{.*}}",
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
// CHECK_NO_CLANG_TARGET-NEXT: "-target",
Expand Down
58 changes: 58 additions & 0 deletions test/CAS/module_trace.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -emit-module -module-name B -o %t/B.swiftmodule -swift-version 5 \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
// RUN: -emit-module-interface-path %t/ignore/B.swiftinterface -enable-library-evolution \
// RUN: %t/B.swift

// RUN: %target-swift-frontend -emit-module -module-name A -o %t/ignore/A.swiftmodule -swift-version 5 \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
// RUN: -emit-module-interface-path %t/A.swiftinterface -enable-library-evolution -I %t \
// RUN: %t/A.swift

// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache %t/main.swift \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
// RUN: -o %t/deps.json -I %t -cache-compile-job -cas-path %t/cas -swift-version 5

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd

// RUN: %FileCheck %s --input-file=%t/A.cmd

// CHECK-NOT: -candidate-module-file

// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd

// RUN: %target-swift-frontend \
// RUN: -c -cache-compile-job -cas-path %t/cas \
// RUN: -disable-implicit-swift-modules -o %t/test.o\
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
// RUN: -emit-reference-dependencies-path %t/test.swiftdeps -emit-dependencies \
// RUN: -primary-file %t/main.swift @%t/MyApp.cmd -emit-loaded-module-trace -emit-loaded-module-trace-path %t/test.trace.json 2>&1 \
// RUN: | %FileCheck %s --check-prefix=WARNING --allow-empty

// WARNING-NOT: WARNING:

// RUN: %FileCheck %s --check-prefix=TRACE --input-file=%t/test.trace.json
// TRACE-DAG: A.swiftinterface

// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps_with_fingerprints.py %swift-dependency-tool %t/test.swiftdeps > %t/test-processed.swiftdeps
// RUN: %FileCheck %s --check-prefix=SWIFTDEPS --input-file=%t/test-processed.swiftdeps
// SWIFTDEPS: A.swiftinterface
// SWIFTDEPS: B.swiftmdoule


//--- main.swift
import A

//--- A.swift
import B
func test() {}

//--- B.swift
func b() {}
2 changes: 1 addition & 1 deletion test/CAS/plugin_cas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ import SubE
// CHECK: ],
// CHECK-NEXT: "details": {

// CHECK: "contextHash": "{{.*}}",
// CHECK: "commandLine": [
// CHECK: "-compile-module-from-interface"
// CHECK: "-target"
Expand All @@ -124,6 +123,7 @@ import SubE
// CHECK: "-swift-version"
// CHECK: "5"
// CHECK: ],
// CHECK: "contextHash": "{{.*}}",
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
// CHECK_NO_CLANG_TARGET-NEXT: "-target",
Expand Down
1 change: 0 additions & 1 deletion test/ModuleInterface/clang-session-transitive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import TestModule
// CHECK-NEXT: "details": {
// CHECK-NEXT: "swift": {
// CHECK-NEXT: "moduleInterfacePath":
// CHECK-NEXT: "contextHash":
// CHECK-NEXT: "compiledModuleCandidates": [
// CHECK-NEXT: TestModule.swiftmodule
// CHECK-NEXT: ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func foo() {
// CHECK-NEXT: "details": {
// CHECK-NEXT: "swift": {
// CHECK-NEXT: "moduleInterfacePath":
// CHECK-NEXT: "contextHash":
// CHECK-NEXT: "compiledModuleCandidates": [
// CHECK-NEXT: ],
// CHECK-NEXT: "commandLine": [
Expand Down
3 changes: 3 additions & 0 deletions test/ScanDependencies/direct_cc1_scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

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

// CHECK-NO-DIRECT-CC1-NOT: -direct-clang-cc1-module-build
// CHECK-DIRECT-CC1-SCAN: -direct-clang-cc1-module-build
// CHECK-DIRECT-CC1-SCAN-NOT: -ffile-compilation-dir
// CHECK-DIRECT-CC1-SCAN-NOT: -ferror-limit=1

//--- A.swift
func a() {}
Expand Down
1 change: 1 addition & 0 deletions test/ScanDependencies/module_deps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import SubE
// CHECK-DAG: "swift": "_cross_import_E"
// CHECK: ],

// CHECK: "contextHash":
// CHECK: "extraPcmArgs": [
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "-target",
Expand Down
3 changes: 2 additions & 1 deletion test/ScanDependencies/module_deps_cache_reuse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import SubE
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
// CHECK: ],

// CHECK: "contextHash":
// CHECK: "extraPcmArgs": [
// CHECK-NEXT: "-Xcc",
// CHECK-NEXT: "-target",
Expand Down Expand Up @@ -95,7 +96,6 @@ import SubE
// CHECK: ],
// CHECK-NEXT: "details": {

// CHECK: "contextHash": "{{.*}}",
// CHECK: "commandLine": [
// CHECK: "-compile-module-from-interface"
// CHECK: "-target"
Expand All @@ -104,6 +104,7 @@ import SubE
// CHECK: "-swift-version"
// CHECK: "5"
// CHECK: ],
// CHECK: "contextHash": "{{.*}}",
// CHECK" "extraPcmArgs": [
// CHECK" "-target",
// CHECK" "-fapinotes-swift-version=5"
Expand Down