[Dependency Scanning] Model main module as separate dependency kind: SwiftSource

These kinds of modules differ from `SwiftTextual` modules in that they do not have an interface and have source-files.
It is cleaner to enforce this distinction with types, instead of checking for interface optionality everywhere.
This commit is contained in:
Artem Chikin
2021-09-13 16:46:54 -07:00
parent 8cd8ca01ad
commit e64a40451b
16 changed files with 473 additions and 158 deletions

View File

@@ -351,18 +351,28 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
bool ClangImporter::addBridgingHeaderDependencies(
StringRef moduleName,
ModuleDependenciesKind moduleKind,
ModuleDependenciesCache &cache) {
auto &ctx = Impl.SwiftContext;
auto currentSwiftSearchPathSet = ctx.getAllModuleSearchPathsSet();
auto targetModule = *cache.findDependencies(
moduleName,
{ModuleDependenciesKind::SwiftTextual,currentSwiftSearchPathSet});
{moduleKind,
currentSwiftSearchPathSet});
// If we've already recorded bridging header dependencies, we're done.
auto swiftDeps = targetModule.getAsSwiftTextualModule();
if (!swiftDeps->bridgingSourceFiles.empty() ||
!swiftDeps->bridgingModuleDependencies.empty())
return false;
if (auto swiftInterfaceDeps = targetModule.getAsSwiftInterfaceModule()) {
if (!swiftInterfaceDeps->bridgingSourceFiles.empty() ||
!swiftInterfaceDeps->bridgingModuleDependencies.empty())
return false;
} else if (auto swiftSourceDeps = targetModule.getAsSwiftSourceModule()) {
if (!swiftSourceDeps->bridgingSourceFiles.empty() ||
!swiftSourceDeps->bridgingModuleDependencies.empty())
return false;
} else {
llvm_unreachable("Unexpected module dependency kind");
}
// Retrieve or create the shared state.
auto clangImpl = getOrCreateClangImpl(cache);
@@ -404,7 +414,7 @@ bool ClangImporter::addBridgingHeaderDependencies(
// Update the cache with the new information for the module.
cache.updateDependencies(
{moduleName.str(), ModuleDependenciesKind::SwiftTextual},
{moduleName.str(), moduleKind},
std::move(targetModule));
return false;