Skip to content

Commit

Permalink
Merge pull request #66031 from artemcm/BreakOutOverlayDeps
Browse files Browse the repository at this point in the history
[Dependency Scanning] Break out Swift Overlay dependencies into separate output category
  • Loading branch information
artemcm committed May 23, 2023
2 parents 3212479 + 5ca9178 commit 4920e4a
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 140 deletions.
4 changes: 4 additions & 0 deletions include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ swiftscan_swift_textual_detail_get_context_hash(
SWIFTSCAN_PUBLIC bool swiftscan_swift_textual_detail_get_is_framework(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_textual_detail_get_swift_overlay_dependencies(
swiftscan_module_details_t details);

//=== Swift Binary Module Details query APIs ------------------------------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
Expand Down
27 changes: 25 additions & 2 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ struct CommonSwiftTextualModuleDependencyDetails {

/// (Clang) modules on which the bridging header depends.
std::vector<std::string> bridgingModuleDependencies;

/// Dependencies comprised of Swift overlay modules of direct and
/// transitive Clang dependencies.
std::vector<ModuleDependencyID> swiftOverlayDependencies;
};

/// Describes the dependencies of a Swift module described by an Swift interface file.
Expand Down Expand Up @@ -450,12 +454,26 @@ class ModuleDependencyInfo {
}

/// Resolve a dependency's set of `imports` with qualified Module IDs
void resolveDependencies(const std::vector<ModuleDependencyID> &dependencyIDs) {
void resolveDependencies(const ArrayRef<ModuleDependencyID> dependencyIDs) {
assert(!storage->resolved && "Resolving an already-resolved dependency");
storage->resolved = true;
storage->resolvedModuleDependencies.assign(dependencyIDs.begin(), dependencyIDs.end());
}

/// Set this module's set of Swift Overlay dependencies
void setOverlayDependencies(const ArrayRef<ModuleDependencyID> dependencyIDs) {
assert(isSwiftSourceModule() || isSwiftInterfaceModule());
CommonSwiftTextualModuleDependencyDetails *textualModuleDetails;
if (auto sourceDetailsStorage = dyn_cast<SwiftSourceModuleDependenciesStorage>(storage.get())) {
textualModuleDetails = &sourceDetailsStorage->textualModuleDetails;
} else if (auto interfaceDetailsStorage = dyn_cast<SwiftInterfaceModuleDependenciesStorage>(storage.get())) {
textualModuleDetails = &interfaceDetailsStorage->textualModuleDetails;
} else {
llvm_unreachable("Unknown kind of dependency module info.");
}
textualModuleDetails->swiftOverlayDependencies.assign(dependencyIDs.begin(), dependencyIDs.end());
}

void updateCommandLine(const std::vector<std::string> &newCommandLine) {
assert(isSwiftInterfaceModule() && "Can only update command line on Swift interface dependency");
cast<SwiftInterfaceModuleDependenciesStorage>(storage.get())->updateCommandLine(newCommandLine);
Expand Down Expand Up @@ -762,7 +780,12 @@ class ModuleDependenciesCache {
/// Resolve a dependency module's set of imports
/// to a kind-qualified set of module IDs.
void resolveDependencyImports(ModuleDependencyID moduleID,
const std::vector<ModuleDependencyID> &dependencyIDs);
const ArrayRef<ModuleDependencyID> dependencyIDs);

/// Resolve a dependency module's set of Swift module dependencies
/// that are Swift overlays of Clang module dependencies.
void setSwiftOverlayDependencues(ModuleDependencyID moduleID,
const ArrayRef<ModuleDependencyID> dependencyIDs);

StringRef getMainModuleName() const {
return mainScanModuleName;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/DependencyScan/DependencyScanImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ typedef struct {
/// (Clang) modules on which the bridging header depends.
swiftscan_string_set_t *bridging_module_dependencies;

/// (Swift) module dependencies by means of being overlays of
/// Clang module dependencies
swiftscan_string_set_t *swift_overlay_module_dependencies;

/// Options to the compile command required to build this module interface
swiftscan_string_set_t *command_line;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using llvm::BCVBR;
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 4;
/// Increment this on every change.
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 0;
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;

/// Various identifiers in this format will rely on having their strings mapped
/// using this ID.
Expand Down Expand Up @@ -139,7 +139,8 @@ using SwiftInterfaceModuleDetailsLayout =
FileIDField, // bridgingHeaderFile
FileIDArrayIDField, // sourceFiles
FileIDArrayIDField, // bridgingSourceFiles
FileIDArrayIDField // bridgingModuleDependencies
FileIDArrayIDField, // bridgingModuleDependencies
DependencyIDArrayIDField // swiftOverlayDependencies
>;

using SwiftSourceModuleDetailsLayout =
Expand All @@ -148,7 +149,8 @@ using SwiftSourceModuleDetailsLayout =
FileIDField, // bridgingHeaderFile
FileIDArrayIDField, // sourceFiles
FileIDArrayIDField, // bridgingSourceFiles
FileIDArrayIDField // bridgingModuleDependencies
FileIDArrayIDField, // bridgingModuleDependencies
DependencyIDArrayIDField // swiftOverlayDependencies
>;

using SwiftBinaryModuleDetailsLayout =
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,10 @@ def disable_clang_target : Flag<["-"], "disable-clang-target">,
Flags<[NewDriverOnlyOption]>,
HelpText<"Disable a separately specified target triple for Clang instance to use">;

def explain_module_dependency : Separate<["-"], "explain-module-dependency">,
Flags<[NewDriverOnlyOption]>,
HelpText<"Emit remark/notes describing why compilaiton may depend on a module with a given name.">;

def min_inlining_target_version : Separate<["-"], "target-min-inlining-version">,
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
HelpText<"Require inlinable code with no '@available' attribute to back-deploy "
Expand Down
12 changes: 11 additions & 1 deletion lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,21 @@ void ModuleDependenciesCache::updateDependency(
}

void ModuleDependenciesCache::resolveDependencyImports(ModuleDependencyID moduleID,
const std::vector<ModuleDependencyID> &dependencyIDs) {
const ArrayRef<ModuleDependencyID> dependencyIDs) {
auto optionalDependencyInfo = findDependency(moduleID.first, moduleID.second);
assert(optionalDependencyInfo.has_value() && "Resolving unknown dependency");
// Copy the existing info to a mutable one we can then replace it with, after resolving its dependencies.
auto dependencyInfo = *(optionalDependencyInfo.value());
dependencyInfo.resolveDependencies(dependencyIDs);
updateDependency(moduleID, dependencyInfo);
}

void ModuleDependenciesCache::setSwiftOverlayDependencues(ModuleDependencyID moduleID,
const ArrayRef<ModuleDependencyID> dependencyIDs) {
auto optionalDependencyInfo = findDependency(moduleID.first, moduleID.second);
assert(optionalDependencyInfo.has_value() && "Resolving unknown dependency");
// Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies.
auto dependencyInfo = *(optionalDependencyInfo.value());
dependencyInfo.setOverlayDependencies(dependencyIDs);
updateDependency(moduleID, dependencyInfo);
}

0 comments on commit 4920e4a

Please sign in to comment.