mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Macro][Dependencies] Properly model macro dependencies in the scanner
Add function to handle all macro dependencies kinds in the scanner,
including taking care of the macro definitions in the module interface
for its client to use. The change involves:
* Encode the macro definition inside the binary module
* Resolve macro modules in the dependencies scanners, including those
declared inside the dependency modules.
* Propagate the macro defined from the direct dependencies to track
all the potentially available modules inside a module compilation.
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/DiagnosticsSema.h"
|
||||
#include "swift/AST/ImportCache.h"
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/AST/ModuleDependencies.h"
|
||||
#include "swift/AST/PluginLoader.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/Defer.h"
|
||||
#include "swift/Basic/FileTypes.h"
|
||||
@@ -477,6 +479,26 @@ SerializedModuleLoaderBase::getImportsOfModule(
|
||||
importedHeader};
|
||||
}
|
||||
|
||||
std::optional<MacroPluginDependency>
|
||||
SerializedModuleLoaderBase::resolveMacroPlugin(const ExternalMacroPlugin ¯o,
|
||||
StringRef packageName) {
|
||||
if (macro.MacroAccess == ExternalMacroPlugin::Access::Internal)
|
||||
return std::nullopt;
|
||||
|
||||
if (macro.MacroAccess == ExternalMacroPlugin::Access::Package &&
|
||||
packageName != Ctx.LangOpts.PackageName)
|
||||
return std::nullopt;
|
||||
|
||||
auto &loader = Ctx.getPluginLoader();
|
||||
auto &entry =
|
||||
loader.lookupPluginByModuleName(Ctx.getIdentifier(macro.ModuleName));
|
||||
if (entry.libraryPath.empty() && entry.executablePath.empty())
|
||||
return std::nullopt;
|
||||
|
||||
return MacroPluginDependency{entry.libraryPath.str(),
|
||||
entry.executablePath.str()};
|
||||
}
|
||||
|
||||
llvm::ErrorOr<ModuleDependencyInfo>
|
||||
SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework,
|
||||
bool isTestableImport) {
|
||||
@@ -562,6 +584,15 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework,
|
||||
definingModulePath, isFramework, loadedModuleFile->isStaticLibrary(),
|
||||
/*module-cache-key*/ "", userModuleVer);
|
||||
|
||||
for (auto ¯o : loadedModuleFile->getExternalMacros()) {
|
||||
auto deps =
|
||||
resolveMacroPlugin(macro, loadedModuleFile->getModulePackageName());
|
||||
if (!deps)
|
||||
continue;
|
||||
dependencies.addMacroDependency(macro.ModuleName, deps->LibraryPath,
|
||||
deps->ExecutablePath);
|
||||
}
|
||||
|
||||
return std::move(dependencies);
|
||||
}
|
||||
|
||||
@@ -1729,6 +1760,11 @@ void SerializedASTFile::getImportedModules(
|
||||
File.getImportedModules(imports, filter);
|
||||
}
|
||||
|
||||
void SerializedASTFile::getExternalMacros(
|
||||
SmallVectorImpl<ExternalMacroPlugin> ¯os) const {
|
||||
File.getExternalMacros(macros);
|
||||
}
|
||||
|
||||
void SerializedASTFile::collectLinkLibrariesFromImports(
|
||||
ModuleDecl::LinkLibraryCallback callback) const {
|
||||
llvm::SmallVector<ImportedModule, 8> Imports;
|
||||
|
||||
Reference in New Issue
Block a user