Skip to content
Merged
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
4 changes: 2 additions & 2 deletions include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_binary_detail_get_swift_overlay_dependencies(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_binary_detail_get_header_dependencies(
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_binary_detail_get_header_dependency(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC bool
Expand Down
48 changes: 37 additions & 11 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
const std::string &sourceInfoPath,
const std::vector<std::string> &moduleImports,
const std::vector<std::string> &optionalModuleImports,
const std::vector<std::string> &headerImports,
const std::string &headerImport,
const bool isFramework,
const std::string &moduleCacheKey)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftBinary,
moduleImports, optionalModuleImports, moduleCacheKey),
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
sourceInfoPath(sourceInfoPath), preCompiledBridgingHeaderPaths(headerImports),
sourceInfoPath(sourceInfoPath), headerImport(headerImport),
isFramework(isFramework) {}

ModuleDependencyInfoStorageBase *clone() const override {
Expand All @@ -348,8 +348,14 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependencyInfoStorageBas
/// The path to the .swiftSourceInfo file.
const std::string sourceInfoPath;

/// The paths of all the .pch dependencies of this module.
const std::vector<std::string> preCompiledBridgingHeaderPaths;
/// The path of the .h dependency of this module.
const std::string headerImport;

/// Source files on which the header inputs depend.
std::vector<std::string> headerSourceFiles;

/// (Clang) modules on which the header inputs depend.
std::vector<std::string> headerModuleDependencies;

/// A flag that indicates this dependency is a framework
const bool isFramework;
Expand Down Expand Up @@ -508,13 +514,13 @@ class ModuleDependencyInfo {
const std::string &sourceInfoPath,
const std::vector<std::string> &moduleImports,
const std::vector<std::string> &optionalModuleImports,
const std::vector<std::string> &headerImports,
const std::string &headerImport,
bool isFramework, const std::string &moduleCacheKey) {
return ModuleDependencyInfo(
std::make_unique<SwiftBinaryModuleDependencyStorage>(
compiledModulePath, moduleDocPath, sourceInfoPath,
moduleImports, optionalModuleImports,
headerImports, isFramework, moduleCacheKey));
headerImport, isFramework, moduleCacheKey));
}

/// Describe the main Swift module.
Expand Down Expand Up @@ -598,6 +604,26 @@ class ModuleDependencyInfo {
return storage->swiftOverlayDependencies;
}

const ArrayRef<std::string> getHeaderInputSourceFiles() const {
if (auto *detail = getAsSwiftInterfaceModule())
return detail->textualModuleDetails.bridgingSourceFiles;
else if (auto *detail = getAsSwiftSourceModule())
return detail->textualModuleDetails.bridgingSourceFiles;
else if (auto *detail = getAsSwiftBinaryModule())
return detail->headerSourceFiles;
return {};
}

const ArrayRef<std::string> getHeaderDependencies() const {
if (auto *detail = getAsSwiftInterfaceModule())
return detail->textualModuleDetails.bridgingModuleDependencies;
else if (auto *detail = getAsSwiftSourceModule())
return detail->textualModuleDetails.bridgingModuleDependencies;
else if (auto *detail = getAsSwiftBinaryModule())
return detail->headerModuleDependencies;
return {};
}

std::vector<std::string> getCommandline() const {
if (auto *detail = getAsClangModule())
return detail->buildCommandLine;
Expand Down Expand Up @@ -751,12 +777,12 @@ class ModuleDependencyInfo {
/// Add source files
void addSourceFile(StringRef sourceFile);

/// Add source files that the bridging header depends on.
void addBridgingSourceFile(StringRef bridgingSourceFile);
/// Add source files that the header input depends on.
void addHeaderSourceFile(StringRef bridgingSourceFile);

/// Add (Clang) module on which the bridging header depends.
void addBridgingModuleDependency(StringRef module,
llvm::StringSet<> &alreadyAddedModules);
/// Add (Clang) modules on which a non-bridging header input depends.
void addHeaderInputModuleDependency(StringRef module,
llvm::StringSet<> &alreadyAddedModules);

/// Add bridging header include tree.
void addBridgingHeaderIncludeTree(StringRef ID);
Expand Down
8 changes: 5 additions & 3 deletions include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,24 @@ class ClangImporter final : public ClangModuleLoader {
ModuleDependencyInfo &MDI,
const clang::tooling::dependencies::TranslationUnitDeps &deps);

/// Add dependency information for the bridging header.
/// Add dependency information for header dependencies
/// of a binary Swift module.
///
/// \param moduleID the name of the Swift module whose dependency
/// information will be augmented with information about the given
/// bridging header.
/// textual header inputs.
///
/// \param clangScanningTool The clang dependency scanner.
///
/// \param cache The module dependencies cache to update, with information
/// about new Clang modules discovered along the way.
///
/// \returns \c true if an error occurred, \c false otherwise
bool addBridgingHeaderDependencies(
bool addHeaderDependencies(
ModuleDependencyID moduleID,
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
ModuleDependenciesCache &cache);

clang::TargetInfo &getModuleAvailabilityTarget() const override;
clang::ASTContext &getClangASTContext() const override;
clang::Preprocessor &getClangPreprocessor() const override;
Expand Down
11 changes: 8 additions & 3 deletions include/swift/DependencyScan/DependencyScanImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ typedef struct {
/// Clang module dependencies
swiftscan_string_set_t *swift_overlay_module_dependencies;

/// (Clang) header dependencies of this binary module.
/// Typically pre-compiled bridging header.
swiftscan_string_set_t *header_dependencies;
/// (Clang) header (.h) dependency of this binary module.
swiftscan_string_ref_t header_dependency;

/// (Clang) module dependencies of the textual header inputs
swiftscan_string_set_t *header_dependencies_module_dependnecies;

/// Source files included by the header dependencies of this binary module
swiftscan_string_set_t *header_dependencies_source_files;

/// A flag to indicate whether or not this module is a framework.
bool is_framework;
Expand Down
4 changes: 2 additions & 2 deletions include/swift/DependencyScan/ModuleDependencyScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class ModuleDependencyScanner {
ModuleDependenciesCache &cache,
ModuleDependencyIDSetVector &directDependencies);

/// If a module has a bridging header, execute a dependency scan
/// If a module has a bridging header or other header inputs, execute a dependency scan
/// on it and record the dependencies.
void resolveBridgingHeaderDependencies(
void resolveHeaderDependencies(
const ModuleDependencyID &moduleID, ModuleDependenciesCache &cache,
std::vector<std::string> &allClangModules,
llvm::StringSet<> &alreadyKnownModules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ using SwiftInterfaceModuleDetailsLayout =
FileIDField, // bridgingHeaderFile
FileIDArrayIDField, // sourceFiles
FileIDArrayIDField, // bridgingSourceFiles
FileIDArrayIDField, // bridgingModuleDependencies
IdentifierIDField, // bridgingModuleDependencies
DependencyIDArrayIDField, // swiftOverlayDependencies
IdentifierIDField, // CASFileSystemRootID
IdentifierIDField, // bridgingHeaderIncludeTree
Expand All @@ -168,7 +168,9 @@ using SwiftBinaryModuleDetailsLayout =
FileIDField, // moduleDocPath
FileIDField, // moduleSourceInfoPath
DependencyIDArrayIDField, // swiftOverlayDependencies
ImportArrayIDField, // headerImports
FileIDField, // headerImport
IdentifierIDField, // headerModuleDependencies
FileIDArrayIDField, // headerSourceFiles
IsFrameworkField, // isFramework
IdentifierIDField // moduleCacheKey
>;
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {

struct BinaryModuleImports {
llvm::StringSet<> moduleImports;
llvm::StringSet<> headerImports;
std::string headerImport;
};

static llvm::ErrorOr<BinaryModuleImports>
Expand Down
28 changes: 22 additions & 6 deletions lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ std::optional<std::string> ModuleDependencyInfo::getBridgingHeader() const {
return swiftSourceStorage->textualModuleDetails.bridgingHeaderFile;
}
default:
llvm_unreachable("Unexpected dependency kind");
return std::nullopt;
}
}

Expand Down Expand Up @@ -325,7 +325,7 @@ void ModuleDependencyInfo::addBridgingHeader(StringRef bridgingHeader) {
}

/// Add source files that the bridging header depends on.
void ModuleDependencyInfo::addBridgingSourceFile(StringRef bridgingSourceFile) {
void ModuleDependencyInfo::addHeaderSourceFile(StringRef bridgingSourceFile) {
switch (getKind()) {
case swift::ModuleDependencyKind::SwiftInterface: {
auto swiftInterfaceStorage =
Expand All @@ -337,7 +337,14 @@ void ModuleDependencyInfo::addBridgingSourceFile(StringRef bridgingSourceFile) {
case swift::ModuleDependencyKind::SwiftSource: {
auto swiftSourceStorage =
cast<SwiftSourceModuleDependenciesStorage>(storage.get());
swiftSourceStorage->textualModuleDetails.bridgingSourceFiles.push_back(bridgingSourceFile.str());
swiftSourceStorage->textualModuleDetails.bridgingSourceFiles.push_back(
bridgingSourceFile.str());
break;
}
case swift::ModuleDependencyKind::SwiftBinary: {
auto swiftBinaryStorage =
cast<SwiftBinaryModuleDependencyStorage>(storage.get());
swiftBinaryStorage->headerSourceFiles.push_back(bridgingSourceFile.str());
break;
}
default:
Expand Down Expand Up @@ -380,21 +387,30 @@ void ModuleDependencyInfo::addSourceFile(StringRef sourceFile) {
}

/// Add (Clang) module on which the bridging header depends.
void ModuleDependencyInfo::addBridgingModuleDependency(
void ModuleDependencyInfo::addHeaderInputModuleDependency(
StringRef module, llvm::StringSet<> &alreadyAddedModules) {
switch (getKind()) {
case swift::ModuleDependencyKind::SwiftInterface: {
auto swiftInterfaceStorage =
cast<SwiftInterfaceModuleDependenciesStorage>(storage.get());
if (alreadyAddedModules.insert(module).second)
swiftInterfaceStorage->textualModuleDetails.bridgingModuleDependencies.push_back(module.str());
swiftInterfaceStorage->textualModuleDetails.bridgingModuleDependencies
.push_back(module.str());
break;
}
case swift::ModuleDependencyKind::SwiftSource: {
auto swiftSourceStorage =
cast<SwiftSourceModuleDependenciesStorage>(storage.get());
if (alreadyAddedModules.insert(module).second)
swiftSourceStorage->textualModuleDetails.bridgingModuleDependencies.push_back(module.str());
swiftSourceStorage->textualModuleDetails.bridgingModuleDependencies
.push_back(module.str());
break;
}
case swift::ModuleDependencyKind::SwiftBinary: {
auto swiftBinaryStorage =
cast<SwiftBinaryModuleDependencyStorage>(storage.get());
if (alreadyAddedModules.insert(module).second)
swiftBinaryStorage->headerModuleDependencies.push_back(module.str());
break;
}
default:
Expand Down
Loading