Skip to content

Commit ee52608

Browse files
authored
Merge pull request #66936 from artemcm/ExplicitModule59CherrySeason
[5.9 🍒] Miscellaneous Dependency Scanner and Explicit Modules Improvements
2 parents 5ff0f41 + 112d6c4 commit ee52608

21 files changed

+367
-145
lines changed

include/swift-c/DependencyScan/DependencyScan.h

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ swiftscan_swift_textual_detail_get_context_hash(
150150
SWIFTSCAN_PUBLIC bool swiftscan_swift_textual_detail_get_is_framework(
151151
swiftscan_module_details_t details);
152152

153+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
154+
swiftscan_swift_textual_detail_get_swift_overlay_dependencies(
155+
swiftscan_module_details_t details);
156+
153157
//=== Swift Binary Module Details query APIs ------------------------------===//
154158

155159
SWIFTSCAN_PUBLIC swiftscan_string_ref_t

include/swift/AST/ModuleDependencies.h

+25-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ struct CommonSwiftTextualModuleDependencyDetails {
137137

138138
/// (Clang) modules on which the bridging header depends.
139139
std::vector<std::string> bridgingModuleDependencies;
140+
141+
/// Dependencies comprised of Swift overlay modules of direct and
142+
/// transitive Clang dependencies.
143+
std::vector<ModuleDependencyID> swiftOverlayDependencies;
140144
};
141145

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

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

463+
/// Set this module's set of Swift Overlay dependencies
464+
void setOverlayDependencies(const ArrayRef<ModuleDependencyID> dependencyIDs) {
465+
assert(isSwiftSourceModule() || isSwiftInterfaceModule());
466+
CommonSwiftTextualModuleDependencyDetails *textualModuleDetails;
467+
if (auto sourceDetailsStorage = dyn_cast<SwiftSourceModuleDependenciesStorage>(storage.get())) {
468+
textualModuleDetails = &sourceDetailsStorage->textualModuleDetails;
469+
} else if (auto interfaceDetailsStorage = dyn_cast<SwiftInterfaceModuleDependenciesStorage>(storage.get())) {
470+
textualModuleDetails = &interfaceDetailsStorage->textualModuleDetails;
471+
} else {
472+
llvm_unreachable("Unknown kind of dependency module info.");
473+
}
474+
textualModuleDetails->swiftOverlayDependencies.assign(dependencyIDs.begin(), dependencyIDs.end());
475+
}
476+
459477
void updateCommandLine(const std::vector<std::string> &newCommandLine) {
460478
assert(isSwiftInterfaceModule() && "Can only update command line on Swift interface dependency");
461479
cast<SwiftInterfaceModuleDependenciesStorage>(storage.get())->updateCommandLine(newCommandLine);
@@ -773,7 +791,12 @@ class ModuleDependenciesCache {
773791
/// Resolve a dependency module's set of imports
774792
/// to a kind-qualified set of module IDs.
775793
void resolveDependencyImports(ModuleDependencyID moduleID,
776-
const std::vector<ModuleDependencyID> &dependencyIDs);
794+
const ArrayRef<ModuleDependencyID> dependencyIDs);
795+
796+
/// Resolve a dependency module's set of Swift module dependencies
797+
/// that are Swift overlays of Clang module dependencies.
798+
void setSwiftOverlayDependencues(ModuleDependencyID moduleID,
799+
const ArrayRef<ModuleDependencyID> dependencyIDs);
777800

778801
StringRef getMainModuleName() const {
779802
return mainScanModuleName;

include/swift/Basic/LangOptions.h

+4
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ namespace swift {
879879
/// and completely bypass the Clang driver.
880880
bool DirectClangCC1ModuleBuild = false;
881881

882+
/// Disable implicitly-built Clang modules because they are explicitly
883+
/// built and provided to the compiler invocation.
884+
bool DisableImplicitClangModules = false;
885+
882886
/// Return a hash code of any components from these options that should
883887
/// contribute to a Swift Bridging PCH hash.
884888
llvm::hash_code getPCHHashComponents() const {

include/swift/DependencyScan/DependencyScanImpl.h

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ typedef struct {
7979
/// (Clang) modules on which the bridging header depends.
8080
swiftscan_string_set_t *bridging_module_dependencies;
8181

82+
/// (Swift) module dependencies by means of being overlays of
83+
/// Clang module dependencies
84+
swiftscan_string_set_t *swift_overlay_module_dependencies;
85+
8286
/// Options to the compile command required to build this module interface
8387
swiftscan_string_set_t *command_line;
8488

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using llvm::BCVBR;
3838
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
3939
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 4;
4040
/// Increment this on every change.
41-
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 0;
41+
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
4242

4343
/// Various identifiers in this format will rely on having their strings mapped
4444
/// using this ID.
@@ -136,7 +136,8 @@ using SwiftInterfaceModuleDetailsLayout =
136136
FileIDField, // bridgingHeaderFile
137137
FileIDArrayIDField, // sourceFiles
138138
FileIDArrayIDField, // bridgingSourceFiles
139-
FileIDArrayIDField // bridgingModuleDependencies
139+
FileIDArrayIDField, // bridgingModuleDependencies
140+
DependencyIDArrayIDField // swiftOverlayDependencies
140141
>;
141142

142143
using SwiftSourceModuleDetailsLayout =
@@ -145,7 +146,8 @@ using SwiftSourceModuleDetailsLayout =
145146
FileIDField, // bridgingHeaderFile
146147
FileIDArrayIDField, // sourceFiles
147148
FileIDArrayIDField, // bridgingSourceFiles
148-
FileIDArrayIDField // bridgingModuleDependencies
149+
FileIDArrayIDField, // bridgingModuleDependencies
150+
DependencyIDArrayIDField // swiftOverlayDependencies
149151
>;
150152

151153
using SwiftBinaryModuleDetailsLayout =

include/swift/Frontend/FrontendOptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ class FrontendOptions {
313313
/// By default, we include ImplicitObjCHeaderPath directly.
314314
llvm::Optional<std::string> BridgingHeaderDirForPrint;
315315

316-
/// Disable implicitly built Swift modules because they are explicitly
317-
/// built and given to the compiler invocation.
316+
/// Disable implicitly-built Swift modules because they are explicitly
317+
/// built and provided to the compiler invocation.
318318
bool DisableImplicitModules = false;
319319

320320
/// Disable building Swift modules from textual interfaces. This should be

include/swift/Option/Options.td

+4
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ def disable_clang_target : Flag<["-"], "disable-clang-target">,
12721272
Flags<[NewDriverOnlyOption]>,
12731273
HelpText<"Disable a separately specified target triple for Clang instance to use">;
12741274

1275+
def explain_module_dependency : Separate<["-"], "explain-module-dependency">,
1276+
Flags<[NewDriverOnlyOption]>,
1277+
HelpText<"Emit remark/notes describing why compilaiton may depend on a module with a given name.">;
1278+
12751279
def min_inlining_target_version : Separate<["-"], "target-min-inlining-version">,
12761280
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
12771281
HelpText<"Require inlinable code with no '@available' attribute to back-deploy "

lib/AST/ModuleDependencies.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,21 @@ void ModuleDependenciesCache::updateDependency(
447447
}
448448

449449
void ModuleDependenciesCache::resolveDependencyImports(ModuleDependencyID moduleID,
450-
const std::vector<ModuleDependencyID> &dependencyIDs) {
450+
const ArrayRef<ModuleDependencyID> dependencyIDs) {
451451
auto optionalDependencyInfo = findDependency(moduleID.first, moduleID.second);
452452
assert(optionalDependencyInfo.has_value() && "Resolving unknown dependency");
453453
// Copy the existing info to a mutable one we can then replace it with, after resolving its dependencies.
454454
auto dependencyInfo = *(optionalDependencyInfo.value());
455455
dependencyInfo.resolveDependencies(dependencyIDs);
456456
updateDependency(moduleID, dependencyInfo);
457457
}
458+
459+
void ModuleDependenciesCache::setSwiftOverlayDependencues(ModuleDependencyID moduleID,
460+
const ArrayRef<ModuleDependencyID> dependencyIDs) {
461+
auto optionalDependencyInfo = findDependency(moduleID.first, moduleID.second);
462+
assert(optionalDependencyInfo.has_value() && "Resolving unknown dependency");
463+
// Copy the existing info to a mutable one we can then replace it with, after setting its overlay dependencies.
464+
auto dependencyInfo = *(optionalDependencyInfo.value());
465+
dependencyInfo.setOverlayDependencies(dependencyIDs);
466+
updateDependency(moduleID, dependencyInfo);
467+
}

lib/ClangImporter/ClangImporter.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,16 @@ importer::getNormalInvocationArguments(
668668
}
669669

670670
const std::string &moduleCachePath = importerOpts.ModuleCachePath;
671-
if (!moduleCachePath.empty()) {
671+
if (!moduleCachePath.empty() && !importerOpts.DisableImplicitClangModules) {
672672
invocationArgStrs.push_back("-fmodules-cache-path=");
673673
invocationArgStrs.back().append(moduleCachePath);
674674
}
675675

676+
if (importerOpts.DisableImplicitClangModules) {
677+
invocationArgStrs.push_back("-fno-implicit-modules");
678+
invocationArgStrs.push_back("-fno-implicit-module-maps");
679+
}
680+
676681
if (ctx.SearchPathOpts.DisableModulesValidateSystemDependencies) {
677682
invocationArgStrs.push_back("-fno-modules-validate-system-headers");
678683
} else {

0 commit comments

Comments
 (0)