diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 70f680df5b1f8..c78a45cd567bc 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -246,7 +246,7 @@ def windows_sdk_root : Separate<["-"], "windows-sdk-root">, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>, HelpText<"Windows SDK Root">, MetaVarName<"">; def windows_sdk_version : Separate<["-"], "windows-sdk-version">, - Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption, + Flags<[FrontendOption, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>, HelpText<"Windows SDK Version">, MetaVarName<"">; def visualc_tools_root : Separate<["-"], "visualc-tools-root">, @@ -254,7 +254,7 @@ def visualc_tools_root : Separate<["-"], "visualc-tools-root">, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>, HelpText<"VisualC++ Tools Root">, MetaVarName<"">; def visualc_tools_version : Separate<["-"], "visualc-tools-version">, - Flags<[ArgumentIsPath, FrontendOption, SwiftAPIExtractOption, + Flags<[FrontendOption, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>, HelpText<"VisualC++ ToolSet Version">, MetaVarName<"">; diff --git a/lib/DependencyScan/ScanDependencies.cpp b/lib/DependencyScan/ScanDependencies.cpp index fbaefe7494c5e..841c4d12b257e 100644 --- a/lib/DependencyScan/ScanDependencies.cpp +++ b/lib/DependencyScan/ScanDependencies.cpp @@ -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, @@ -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'; @@ -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 @@ -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 diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 587e6ba278798..04e93b05f1a13 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -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 || @@ -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, diff --git a/test/CAS/module_deps.swift b/test/CAS/module_deps.swift index 49897a44bb970..be04d1236b09d 100644 --- a/test/CAS/module_deps.swift +++ b/test/CAS/module_deps.swift @@ -133,7 +133,6 @@ import SubE // CHECK: ], // CHECK-NEXT: "details": { -// CHECK: "contextHash": "{{.*}}", // CHECK: "commandLine": [ // CHECK: "-compile-module-from-interface" // CHECK: "-target" @@ -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", diff --git a/test/CAS/module_deps_include_tree.swift b/test/CAS/module_deps_include_tree.swift index ed5afb4f02fc3..8850132211a90 100644 --- a/test/CAS/module_deps_include_tree.swift +++ b/test/CAS/module_deps_include_tree.swift @@ -127,7 +127,6 @@ import SubE // CHECK: ], // CHECK-NEXT: "details": { -// CHECK: "contextHash": "{{.*}}", // CHECK: "commandLine": [ // CHECK: "-compile-module-from-interface" // CHECK: "-target" @@ -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", diff --git a/test/CAS/module_trace.swift b/test/CAS/module_trace.swift new file mode 100644 index 0000000000000..251e76d840d6c --- /dev/null +++ b/test/CAS/module_trace.swift @@ -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() {} diff --git a/test/CAS/plugin_cas.swift b/test/CAS/plugin_cas.swift index ab79d01d16e13..9a689b755e04b 100644 --- a/test/CAS/plugin_cas.swift +++ b/test/CAS/plugin_cas.swift @@ -115,7 +115,6 @@ import SubE // CHECK: ], // CHECK-NEXT: "details": { -// CHECK: "contextHash": "{{.*}}", // CHECK: "commandLine": [ // CHECK: "-compile-module-from-interface" // CHECK: "-target" @@ -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", diff --git a/test/ModuleInterface/clang-session-transitive.swift b/test/ModuleInterface/clang-session-transitive.swift index dba526c783380..ae6ef6e6ef4df 100644 --- a/test/ModuleInterface/clang-session-transitive.swift +++ b/test/ModuleInterface/clang-session-transitive.swift @@ -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: ], diff --git a/test/ModuleInterface/extension-transitive-availability.swift b/test/ModuleInterface/extension-transitive-availability.swift index 4795ef7663df9..318986238f24a 100644 --- a/test/ModuleInterface/extension-transitive-availability.swift +++ b/test/ModuleInterface/extension-transitive-availability.swift @@ -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": [ diff --git a/test/ScanDependencies/direct_cc1_scan.swift b/test/ScanDependencies/direct_cc1_scan.swift index 073d84836b9e3..996fdec35832b 100644 --- a/test/ScanDependencies/direct_cc1_scan.swift +++ b/test/ScanDependencies/direct_cc1_scan.swift @@ -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() {} diff --git a/test/ScanDependencies/module_deps.swift b/test/ScanDependencies/module_deps.swift index 334f356a098a1..9371e8cb49382 100644 --- a/test/ScanDependencies/module_deps.swift +++ b/test/ScanDependencies/module_deps.swift @@ -57,6 +57,7 @@ import SubE // CHECK-DAG: "swift": "_cross_import_E" // CHECK: ], +// CHECK: "contextHash": // CHECK: "extraPcmArgs": [ // CHECK-NEXT: "-Xcc", // CHECK-NEXT: "-target", diff --git a/test/ScanDependencies/module_deps_cache_reuse.swift b/test/ScanDependencies/module_deps_cache_reuse.swift index 0e9ead12d99c1..4012e5d406597 100644 --- a/test/ScanDependencies/module_deps_cache_reuse.swift +++ b/test/ScanDependencies/module_deps_cache_reuse.swift @@ -44,6 +44,7 @@ import SubE // CHECK-DAG: "clang": "_SwiftConcurrencyShims" // CHECK: ], +// CHECK: "contextHash": // CHECK: "extraPcmArgs": [ // CHECK-NEXT: "-Xcc", // CHECK-NEXT: "-target", @@ -95,7 +96,6 @@ import SubE // CHECK: ], // CHECK-NEXT: "details": { -// CHECK: "contextHash": "{{.*}}", // CHECK: "commandLine": [ // CHECK: "-compile-module-from-interface" // CHECK: "-target" @@ -104,6 +104,7 @@ import SubE // CHECK: "-swift-version" // CHECK: "5" // CHECK: ], +// CHECK: "contextHash": "{{.*}}", // CHECK" "extraPcmArgs": [ // CHECK" "-target", // CHECK" "-fapinotes-swift-version=5"