Skip to content

Commit fc23c6b

Browse files
committed
[Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
1 parent d6ce27b commit fc23c6b

File tree

11 files changed

+318
-304
lines changed

11 files changed

+318
-304
lines changed

include/swift/AST/ModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class ModuleLoader {
374374
getModuleDependencies(Identifier moduleName,
375375
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
376376
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
377-
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
377+
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
378378
InterfaceSubContextDelegate &delegate,
379379
llvm::PrefixMapper *mapper = nullptr,
380380
bool isTestableImport = false) = 0;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace tooling {
6464
namespace dependencies {
6565
struct ModuleDeps;
6666
struct TranslationUnitDeps;
67+
enum class ModuleOutputKind;
6768
using ModuleDepsGraph = std::vector<ModuleDeps>;
6869
}
6970
}
@@ -209,8 +210,7 @@ class ClangImporter final : public ClangModuleLoader {
209210
bool ignoreClangTarget = false);
210211

211212
std::vector<std::string>
212-
getClangDepScanningInvocationArguments(ASTContext &ctx,
213-
std::optional<StringRef> sourceFileName = std::nullopt);
213+
getClangDepScanningInvocationArguments(ASTContext &ctx);
214214

215215
static std::unique_ptr<clang::CompilerInvocation>
216216
createClangInvocation(ClangImporter *importer,
@@ -497,54 +497,32 @@ class ClangImporter final : public ClangModuleLoader {
497497
void verifyAllModules() override;
498498

499499
using RemapPathCallback = llvm::function_ref<std::string(StringRef)>;
500-
llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
500+
using LookupModuleOutputCallback =
501+
llvm::function_ref<std::string(const clang::tooling::dependencies::ModuleDeps &,
502+
clang::tooling::dependencies::ModuleOutputKind)>;
503+
504+
static llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
501505
bridgeClangModuleDependencies(
506+
const ASTContext &ctx,
502507
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
503508
clang::tooling::dependencies::ModuleDepsGraph &clangDependencies,
504509
StringRef moduleOutputPath, StringRef stableModuleOutputPath,
510+
LookupModuleOutputCallback LookupModuleOutput,
505511
RemapPathCallback remapPath = nullptr);
506512

507513
llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
508514
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
509515
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
510-
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
516+
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
511517
InterfaceSubContextDelegate &delegate,
512518
llvm::PrefixMapper *mapper,
513519
bool isTestableImport = false) override;
514520

515-
void recordBridgingHeaderOptions(
516-
ModuleDependencyInfo &MDI,
517-
const clang::tooling::dependencies::TranslationUnitDeps &deps);
518-
519-
void getBridgingHeaderOptions(
521+
static void getBridgingHeaderOptions(
522+
const ASTContext &ctx,
520523
const clang::tooling::dependencies::TranslationUnitDeps &deps,
521524
std::vector<std::string> &swiftArgs);
522525

523-
/// Query dependency information for header dependencies
524-
/// of a binary Swift module.
525-
///
526-
/// \param moduleID the name of the Swift module whose dependency
527-
/// information will be augmented with information about the given
528-
/// textual header inputs.
529-
///
530-
/// \param headerPath the path to the header to be scanned.
531-
///
532-
/// \param clangScanningTool The clang dependency scanner.
533-
///
534-
/// \param cache The module dependencies cache to update, with information
535-
/// about new Clang modules discovered along the way.
536-
///
537-
/// \returns \c true if an error occurred, \c false otherwise
538-
bool getHeaderDependencies(
539-
ModuleDependencyID moduleID, std::optional<StringRef> headerPath,
540-
std::optional<llvm::MemoryBufferRef> sourceBuffer,
541-
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
542-
ModuleDependenciesCache &cache,
543-
ModuleDependencyIDSetVector &headerClangModuleDependencies,
544-
std::vector<std::string> &headerFileInputs,
545-
std::vector<std::string> &bridgingHeaderCommandLine,
546-
std::optional<std::string> &includeTreeID);
547-
548526
clang::TargetInfo &getModuleAvailabilityTarget() const override;
549527
clang::ASTContext &getClangASTContext() const override;
550528
clang::Preprocessor &getClangPreprocessor() const override;

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ class ModuleDependencyScanningWorker {
5050
StringRef sdkModuleOutputPath, llvm::PrefixMapper *prefixMapper,
5151
bool isTestableImport = false);
5252

53+
/// Query dependency information for header dependencies
54+
/// of a binary Swift module.
55+
///
56+
/// \param moduleID the name of the Swift module whose dependency
57+
/// information will be augmented with information about the given
58+
/// textual header inputs.
59+
///
60+
/// \param headerPath the path to the header to be scanned.
61+
///
62+
/// \param clangScanningTool The clang dependency scanner.
63+
///
64+
/// \param cache The module dependencies cache to update, with information
65+
/// about new Clang modules discovered along the way.
66+
///
67+
/// \returns \c true if an error occurred, \c false otherwise
68+
bool scanHeaderDependenciesOfSwiftModule(
69+
const ASTContext &ctx,
70+
ModuleDependencyID moduleID, std::optional<StringRef> headerPath,
71+
std::optional<llvm::MemoryBufferRef> sourceBuffer,
72+
ModuleDependenciesCache &cache,
73+
ModuleDependencyIDSetVector &headerClangModuleDependencies,
74+
std::vector<std::string> &headerFileInputs,
75+
std::vector<std::string> &bridgingHeaderCommandLine,
76+
std::optional<std::string> &includeTreeID);
77+
78+
5379
/// Store cache entry for include tree.
5480
llvm::Error
5581
createCacheKeyForEmbeddedHeader(std::string embeddedHeaderIncludeTree,
@@ -65,7 +91,17 @@ class ModuleDependencyScanningWorker {
6591
clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
6692
// Swift and Clang module loaders acting as scanners.
6793
std::unique_ptr<ModuleInterfaceLoader> swiftScannerModuleLoader;
68-
std::unique_ptr<ClangImporter> clangScannerModuleLoader;
94+
95+
// Base command line invocation for clang scanner queries (both module and header)
96+
std::vector<std::string> clangScanningBaseCommandLineArgs;
97+
// Command line invocation for clang by-name module lookups
98+
std::vector<std::string> clangScanningModuleCommandLineArgs;
99+
// Clang-specific (-Xcc) command-line flags to include on
100+
// Swift module compilation commands
101+
std::vector<std::string> swiftModuleClangCC1CommandLineArgs;
102+
// Working directory for clang module lookup queries
103+
std::string clangScanningWorkingDirectoryPath;
104+
69105
// CAS instance.
70106
std::shared_ptr<llvm::cas::ObjectStore> CAS;
71107
std::shared_ptr<llvm::cas::ActionCache> ActionCache;

include/swift/Sema/SourceLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SourceLoader : public ModuleLoader {
101101
llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
102102
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
103103
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
104-
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
104+
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
105105
InterfaceSubContextDelegate &delegate,
106106
llvm::PrefixMapper *mapper,
107107
bool isTestableImport) override;

include/swift/Serialization/ScanningLoaders.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
4343
std::string moduleOutputPath;
4444
/// Location where pre-built SDK modules are to be built into.
4545
std::string sdkModuleOutputPath;
46+
/// Clang-specific (-Xcc) command-line flags to include on
47+
/// Swift module compilation commands
48+
std::vector<std::string> swiftModuleClangCC1CommandLineArgs;
4649

4750
public:
4851
std::optional<ModuleDependencyInfo> dependencies;
@@ -51,12 +54,14 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
5154
Identifier moduleName,
5255
InterfaceSubContextDelegate &astDelegate,
5356
StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
57+
std::vector<std::string> swiftModuleClangCC1CommandLineArgs,
5458
ScannerKind kind = MDS_plain)
5559
: SerializedModuleLoaderBase(ctx, nullptr, LoadMode,
5660
/*IgnoreSwiftSourceInfoFile=*/true),
5761
kind(kind), moduleName(moduleName), astDelegate(astDelegate),
5862
moduleOutputPath(moduleOutputPath),
59-
sdkModuleOutputPath(sdkModuleOutputPath) {}
63+
sdkModuleOutputPath(sdkModuleOutputPath),
64+
swiftModuleClangCC1CommandLineArgs(swiftModuleClangCC1CommandLineArgs) {}
6065

6166
std::error_code findModuleFilesInDirectory(
6267
ImportPath::Element ModuleID, const SerializedModuleBaseName &BaseName,
@@ -100,9 +105,8 @@ class PlaceholderSwiftModuleScanner : public SwiftModuleScanner {
100105
StringRef moduleOutputPath,
101106
StringRef sdkModuleOutputPath)
102107
: SwiftModuleScanner(ctx, LoadMode, moduleName, astDelegate,
103-
moduleOutputPath, sdkModuleOutputPath,
108+
moduleOutputPath, sdkModuleOutputPath, {},
104109
MDS_placeholder) {
105-
106110
// FIXME: Find a better place for this map to live, to avoid
107111
// doing the parsing on every module.
108112
if (!PlaceholderDependencyModuleMap.empty()) {

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
266266
virtual llvm::SmallVector<std::pair<ModuleDependencyID, ModuleDependencyInfo>, 1>
267267
getModuleDependencies(Identifier moduleName, StringRef moduleOutputPath, StringRef sdkModuleOutputPath,
268268
const llvm::DenseSet<clang::tooling::dependencies::ModuleID> &alreadySeenClangModules,
269-
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
269+
const std::vector<std::string> &swiftModuleClangCC1CommandLineArgs,
270270
InterfaceSubContextDelegate &delegate,
271271
llvm::PrefixMapper *mapper,
272272
bool isTestableImport) override;

0 commit comments

Comments
 (0)