Skip to content
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

[6.1][ScanDependency] Swift source module should not have build args for modules #78339

Open
wants to merge 1 commit into
base: release/6.1
Choose a base branch
from
Open
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
86 changes: 47 additions & 39 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,36 +309,41 @@ class ExplicitModuleDependencyResolver {
llvm::Error handleSwiftInterfaceModuleDependency(
ModuleDependencyID depModuleID,
const SwiftInterfaceModuleDependenciesStorage &interfaceDepDetails) {
auto &path = interfaceDepDetails.moduleCacheKey.empty()
? interfaceDepDetails.moduleOutputPath
: interfaceDepDetails.moduleCacheKey;
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
path);
if (!resolvingDepInfo.isSwiftSourceModule()) {
auto &path = interfaceDepDetails.moduleCacheKey.empty()
? interfaceDepDetails.moduleOutputPath
: interfaceDepDetails.moduleCacheKey;
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
"=" + path);
}
addMacroDependencies(depModuleID, interfaceDepDetails);
return llvm::Error::success();
}

llvm::Error handleSwiftBinaryModuleDependency(
ModuleDependencyID depModuleID,
const SwiftBinaryModuleDependencyStorage &binaryDepDetails) {
auto &path = binaryDepDetails.moduleCacheKey.empty()
? binaryDepDetails.compiledModulePath
: binaryDepDetails.moduleCacheKey;
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
path);
// If this binary module was built with a header, the header's module
// dependencies must also specify a .modulemap to the compilation, in
// order to resolve the header's own header include directives.
for (const auto &bridgingHeaderDepID :
binaryDepDetails.headerModuleDependencies) {
auto optionalBridgingHeaderDepModuleInfo = cache.findKnownDependency(
bridgingHeaderDepID);
const auto bridgingHeaderDepModuleDetails =
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
commandline.push_back("-Xcc");
commandline.push_back("-fmodule-map-file=" +
cache.getScanService().remapPath(
bridgingHeaderDepModuleDetails->moduleMapFile));
if (!resolvingDepInfo.isSwiftSourceModule()) {
auto &path = binaryDepDetails.moduleCacheKey.empty()
? binaryDepDetails.compiledModulePath
: binaryDepDetails.moduleCacheKey;
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
"=" + path);
// If this binary module was built with a header, the header's module
// dependencies must also specify a .modulemap to the compilation, in
// order to resolve the header's own header include directives.
for (const auto &bridgingHeaderDepID :
binaryDepDetails.headerModuleDependencies) {
auto optionalBridgingHeaderDepModuleInfo =
cache.findKnownDependency(bridgingHeaderDepID);
const auto bridgingHeaderDepModuleDetails =
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
commandline.push_back("-Xcc");
commandline.push_back(
"-fmodule-map-file=" +
cache.getScanService().remapPath(
bridgingHeaderDepModuleDetails->moduleMapFile));
}
}
addMacroDependencies(depModuleID, binaryDepDetails);
return llvm::Error::success();
Expand All @@ -347,26 +352,29 @@ class ExplicitModuleDependencyResolver {
llvm::Error handleSwiftPlaceholderModuleDependency(
ModuleDependencyID depModuleID,
const SwiftPlaceholderModuleDependencyStorage &placeholderDetails) {
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
placeholderDetails.compiledModulePath);
if (!resolvingDepInfo.isSwiftSourceModule())
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
"=" + placeholderDetails.compiledModulePath);
return llvm::Error::success();
}

llvm::Error handleClangModuleDependency(
ModuleDependencyID depModuleID,
const ClangModuleDependencyStorage &clangDepDetails) {
if (!resolvingDepInfo.isClangModule()) {
commandline.push_back("-Xcc");
commandline.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
clangDepDetails.mappedPCMPath);
}
if (!clangDepDetails.moduleCacheKey.empty()) {
commandline.push_back("-Xcc");
commandline.push_back("-fmodule-file-cache-key");
commandline.push_back("-Xcc");
commandline.push_back(clangDepDetails.mappedPCMPath);
commandline.push_back("-Xcc");
commandline.push_back(clangDepDetails.moduleCacheKey);
if (!resolvingDepInfo.isSwiftSourceModule()) {
if (!resolvingDepInfo.isClangModule()) {
commandline.push_back("-Xcc");
commandline.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
clangDepDetails.mappedPCMPath);
}
if (!clangDepDetails.moduleCacheKey.empty()) {
commandline.push_back("-Xcc");
commandline.push_back("-fmodule-file-cache-key");
commandline.push_back("-Xcc");
commandline.push_back(clangDepDetails.mappedPCMPath);
commandline.push_back("-Xcc");
commandline.push_back(clangDepDetails.moduleCacheKey);
}
}

// Collect CAS deppendencies from clang modules.
Expand Down Expand Up @@ -1389,7 +1397,7 @@ bool swift::dependencies::batchScanDependencies(
return true;

auto batchScanResults = performBatchModuleScan(
instance, /*DependencyScanDiagnosticCollector*/ nullptr,
instance, /*DependencyScanDiagnosticCollector*/ nullptr,
cache, /*versionedPCMInstanceCache*/ nullptr, saver,
*batchInput);

Expand Down Expand Up @@ -1650,7 +1658,7 @@ swift::dependencies::performBatchModuleScan(
}
allDependencies = scanner.performDependencyScan(moduleID, cache);
}

batchScanResult.push_back(
generateFullDependencyGraph(instance, diagnosticCollector, cache,
allDependencies));
Expand Down
6 changes: 6 additions & 0 deletions test/CAS/symbol-graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd

// 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/Test.cmd
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
// RUN: -explicit-swift-module-map-file @%t/map.casid \
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph1 \
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-MISS

Expand All @@ -22,6 +25,7 @@
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
// RUN: -explicit-swift-module-map-file @%t/map.casid \
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph2 \
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-HIT

Expand All @@ -35,13 +39,15 @@
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
// RUN: -explicit-swift-module-map-file @%t/map.casid \
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph3 \
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job > %t/key.casid

// RUN: %swift-scan-test -action replay_result -cas-path %t/cas -id @%t/key.casid -- \
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
// RUN: -explicit-swift-module-map-file @%t/map.casid \
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph3 \
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job

Expand Down
4 changes: 4 additions & 0 deletions test/ScanDependencies/module_deps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// Check the contents of the JSON output
// RUN: %validate-json %t/deps.json | %FileCheck -check-prefix CHECK_NO_CLANG_TARGET %s

// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json deps | %FileCheck --check-prefix CHECK-NO-MODULES %s --allow-empty
// CHECK-NO-MODULES-NOT: -swift-module-file
// CHECK-NO-MODULES-NOT: -fmodule-file

// Check the contents of the JSON output
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix CHECK-NO-SEARCH-PATHS

Expand Down