Skip to content

Commit 59f744c

Browse files
committed
[Macros] Track loaded plugin paths in each ASTContext
PluginRegistry is now shared between multiple ASTContext. ASTContext should track its loaded plugin library paths separately.
1 parent a4d1fc6 commit 59f744c

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

include/swift/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,8 @@ class ASTContext final {
15031503
/// This should be called before any plugin is loaded.
15041504
void setPluginRegistry(PluginRegistry *newValue);
15051505

1506+
const llvm::StringSet<> &getLoadedPluginLibraryPaths() const;
1507+
15061508
private:
15071509
friend Decl;
15081510

include/swift/AST/PluginRegistry.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ class PluginRegistry {
152152
/// If \p path plugin is already loaded, this returns the cached object.
153153
llvm::Expected<LoadedExecutablePlugin *>
154154
loadExecutablePlugin(llvm::StringRef path);
155-
156-
const llvm::StringMap<void *> &getLoadedLibraryPlugins() const {
157-
return LoadedPluginLibraries;
158-
}
159155
};
160156

161157
} // namespace swift

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ struct ASTContext::Implementation {
534534
/// Map a module name to an executable plugin path that provides the module.
535535
llvm::DenseMap<Identifier, StringRef> ExecutablePluginPaths;
536536

537+
llvm::StringSet<> LoadedPluginLibraryPaths;
538+
537539
/// The permanent arena.
538540
Arena Permanent;
539541

@@ -6395,6 +6397,9 @@ LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) {
63956397
}
63966398

63976399
void *ASTContext::loadLibraryPlugin(StringRef path) {
6400+
// Remember the path (even if it fails to load.)
6401+
getImpl().LoadedPluginLibraryPaths.insert(path);
6402+
63986403
SmallString<128> resolvedPath;
63996404
auto fs = this->SourceMgr.getFileSystem();
64006405
if (auto err = fs->getRealPath(path, resolvedPath)) {
@@ -6413,6 +6418,10 @@ void *ASTContext::loadLibraryPlugin(StringRef path) {
64136418
return plugin.get();
64146419
}
64156420

6421+
const llvm::StringSet<> &ASTContext::getLoadedPluginLibraryPaths() const {
6422+
return getImpl().LoadedPluginLibraryPaths;
6423+
}
6424+
64166425
bool ASTContext::supportsMoveOnlyTypes() const {
64176426
// currently the only thing holding back whether the types can appear is this.
64186427
return SILOpts.LexicalLifetimes != LexicalLifetimesOption::Off;

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,7 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
760760
}
761761

762762
// Add compiler plugin libraries as dependencies.
763-
auto *pluginRegistry = ctxt.getPluginRegistry();
764-
for (auto &pluginEntry : pluginRegistry->getLoadedLibraryPlugins())
763+
for (auto &pluginEntry : ctxt.getLoadedPluginLibraryPaths())
765764
depTracker->addDependency(pluginEntry.getKey(), /*IsSystem*/ false);
766765

767766
std::vector<SwiftModuleTraceInfo> swiftModules;

0 commit comments

Comments
 (0)