Skip to content

Commit 89268e9

Browse files
committed
[6.2 🍒][Dependency Scanning] Consider '-swift-module-file' inputs when looking for dependencies
Previously this flag was only used to pass explicit dependencies to compilation tasks. This change adds support for the dependency scanner to also consider these inputs when resolving dependencies. Resolves swiftlang/swift-driver#1951
1 parent 61157cd commit 89268e9

File tree

15 files changed

+84
-24
lines changed

15 files changed

+84
-24
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ class ModuleLoader {
375375
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
376376
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
377377
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
378+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
378379
InterfaceSubContextDelegate &delegate,
379380
llvm::PrefixMapper *mapper = nullptr,
380381
bool isTestableImport = false) = 0;

include/swift/AST/SearchPathOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class SearchPathOptions {
519519

520520
/// Module inputs specified with -swift-module-input,
521521
/// <ModuleName, Path to .swiftmodule file>
522-
std::vector<std::pair<std::string, std::string>> ExplicitSwiftModuleInputs;
522+
llvm::StringMap<std::string> ExplicitSwiftModuleInputs;
523523

524524
/// A map of placeholder Swift module dependency information.
525525
std::string PlaceholderDependencyModuleMap;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ class ClangImporter final : public ClangModuleLoader {
509509
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
510510
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
511511
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
512+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
512513
InterfaceSubContextDelegate &delegate,
513514
llvm::PrefixMapper *mapper,
514515
bool isTestableImport = false) override;

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class ModuleDependencyScanningWorker {
101101
std::vector<std::string> swiftModuleClangCC1CommandLineArgs;
102102
// Working directory for clang module lookup queries
103103
std::string clangScanningWorkingDirectoryPath;
104+
105+
/// Module inputs specified with -swift-module-input,
106+
llvm::StringMap<std::string> explicitSwiftModuleInputs;
104107

105108
// CAS instance.
106109
std::shared_ptr<llvm::cas::ObjectStore> CAS;

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class ExplicitSwiftModuleLoader: public SerializedModuleLoaderBase {
176176
create(ASTContext &ctx,
177177
DependencyTracker *tracker, ModuleLoadingMode loadMode,
178178
StringRef ExplicitSwiftModuleMap,
179-
const std::vector<std::pair<std::string, std::string>> &ExplicitSwiftModuleInputs,
179+
const llvm::StringMap<std::string> &ExplicitSwiftModuleInputs,
180180
bool IgnoreSwiftSourceInfoFile);
181181

182182
/// Append visible module names to \p names. Note that names are possibly
@@ -224,8 +224,7 @@ class ExplicitCASModuleLoader : public SerializedModuleLoaderBase {
224224
create(ASTContext &ctx, llvm::cas::ObjectStore &CAS,
225225
llvm::cas::ActionCache &cache, DependencyTracker *tracker,
226226
ModuleLoadingMode loadMode, StringRef ExplicitSwiftModuleMap,
227-
const std::vector<std::pair<std::string, std::string>>
228-
&ExplicitSwiftModuleInputs,
227+
const llvm::StringMap<std::string> &ExplicitSwiftModuleInputs,
229228
bool IgnoreSwiftSourceInfoFile);
230229

231230
/// Append visible module names to \p names. Note that names are possibly

include/swift/Sema/SourceLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class SourceLoader : public ModuleLoader {
102102
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
103103
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
104104
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
105+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
105106
InterfaceSubContextDelegate &delegate,
106107
llvm::PrefixMapper *mapper,
107108
bool isTestableImport) override;

include/swift/Serialization/ScanningLoaders.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
4646
/// Clang-specific (-Xcc) command-line flags to include on
4747
/// Swift module compilation commands
4848
std::vector<std::string> swiftModuleClangCC1CommandLineArgs;
49+
/// Module inputs specified with -swift-module-input
50+
llvm::StringMap<std::string> explicitSwiftModuleInputs;
4951

5052
public:
5153
std::optional<ModuleDependencyInfo> dependencies;
@@ -55,13 +57,15 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
5557
InterfaceSubContextDelegate &astDelegate,
5658
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
5759
std::vector<std::string> swiftModuleClangCC1CommandLineArgs,
60+
llvm::StringMap<std::string> explicitSwiftModuleInputs,
5861
ScannerKind kind = MDS_plain)
5962
: SerializedModuleLoaderBase(ctx, nullptr, LoadMode,
6063
/*IgnoreSwiftSourceInfoFile=*/true),
6164
kind(kind), moduleName(moduleName), astDelegate(astDelegate),
6265
moduleOutputPath(moduleOutputPath),
6366
sdkModuleOutputPath(sdkModuleOutputPath),
64-
swiftModuleClangCC1CommandLineArgs(swiftModuleClangCC1CommandLineArgs) {}
67+
swiftModuleClangCC1CommandLineArgs(swiftModuleClangCC1CommandLineArgs),
68+
explicitSwiftModuleInputs(explicitSwiftModuleInputs) {}
6569

6670
std::error_code findModuleFilesInDirectory(
6771
ImportPath::Element ModuleID, const SerializedModuleBaseName &BaseName,
@@ -73,6 +77,10 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
7377
bool SkipBuildingInterface, bool IsFramework,
7478
bool IsTestableDependencyLookup) override;
7579

80+
bool canImportModule(ImportPath::Module named, SourceLoc loc,
81+
ModuleVersionInfo *versionInfo,
82+
bool isTestableImport) override;
83+
7684
virtual void collectVisibleTopLevelModuleNames(
7785
SmallVectorImpl<Identifier> &names) const override {
7886
llvm_unreachable("Not used");
@@ -105,7 +113,7 @@ class PlaceholderSwiftModuleScanner : public SwiftModuleScanner {
105113
StringRef moduleOutputPath,
106114
StringRef sdkModuleOutputPath)
107115
: SwiftModuleScanner(ctx, LoadMode, moduleName, astDelegate,
108-
moduleOutputPath, sdkModuleOutputPath, {},
116+
moduleOutputPath, sdkModuleOutputPath, {}, {},
109117
MDS_placeholder) {
110118
// FIXME: Find a better place for this map to live, to avoid
111119
// doing the parsing on every module.

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
266266
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
267267
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
268268
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
269+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
269270
InterfaceSubContextDelegate &delegate,
270271
llvm::PrefixMapper *mapper,
271272
bool isTestableImport) override;

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
275275
StringRef sdkModuleOutputPath,
276276
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
277277
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
278+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
278279
InterfaceSubContextDelegate &delegate,
279280
llvm::PrefixMapper *mapper,
280281
bool isTestableImport) {

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ ModuleDependencyScanningWorker::ModuleDependencyScanningWorker(
259259
swiftModuleClangCC1CommandLineArgs.push_back("-fno-implicit-module-maps");
260260
}
261261

262+
explicitSwiftModuleInputs =
263+
workerCompilerInvocation->getSearchPathOptions().ExplicitSwiftModuleInputs;
264+
262265
// Set up the Swift interface loader for Swift scanning.
263266
swiftScannerModuleLoader = ModuleInterfaceLoader::create(
264267
*workerASTContext,
@@ -275,8 +278,8 @@ ModuleDependencyScanningWorker::scanFilesystemForSwiftModuleDependency(
275278
bool isTestableImport) {
276279
return swiftScannerModuleLoader->getModuleDependencies(
277280
moduleName, moduleOutputPath, sdkModuleOutputPath,
278-
{}, swiftModuleClangCC1CommandLineArgs, *scanningASTDelegate,
279-
prefixMapper, isTestableImport);
281+
{}, swiftModuleClangCC1CommandLineArgs, explicitSwiftModuleInputs,
282+
*scanningASTDelegate, prefixMapper, isTestableImport);
280283
}
281284

282285
ModuleDependencyVector
@@ -299,8 +302,7 @@ ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency(
299302
auto clangModuleDependencies = clangScanningTool.getModuleDependencies(
300303
moduleName.str(), clangScanningModuleCommandLineArgs,
301304
clangScanningWorkingDirectoryPath,
302-
alreadySeenModules,
303-
lookupModuleOutput);
305+
alreadySeenModules, lookupModuleOutput);
304306
if (!clangModuleDependencies) {
305307
auto errorStr = toString(clangModuleDependencies.takeError());
306308
// We ignore the "module 'foo' not found" error, the Swift dependency

0 commit comments

Comments
 (0)