Skip to content

Commit fe48800

Browse files
authored
Merge pull request #82939 from artemcm/62_DepScanExplicitInput
[6.2 🍒][Dependency Scanning] Consider `-swift-module-file` inputs when looking for dependencies
2 parents 9ae2bba + 29786c0 commit fe48800

17 files changed

+139
-24
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ ERROR(error_stdlib_module_name,none,
213213
"module name \"%0\" is reserved for the standard library"
214214
"%select{|; use -module-name flag to specify an alternate name}1",
215215
(StringRef, bool))
216+
WARNING(warn_multiple_module_inputs_same_name,none,
217+
"multiple Swift module file inputs with identifier \"%0\": replacing '%1' with '%2'",
218+
(StringRef, StringRef, StringRef))
216219

217220
ERROR(error_bad_export_as_name,none,
218221
"export-as name \"%0\" is not a valid identifier",

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
@@ -508,6 +508,7 @@ class ClangImporter final : public ClangModuleLoader {
508508
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
509509
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
510510
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
511+
const llvm::StringMap<std::string> &explicitSwiftModuleInputs,
511512
InterfaceSubContextDelegate &delegate,
512513
llvm::PrefixMapper *mapper,
513514
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) {

0 commit comments

Comments
 (0)