|
41 | 41 | #include "swift/AST/NameLookup.h"
|
42 | 42 | #include "swift/AST/PackConformance.h"
|
43 | 43 | #include "swift/AST/ParameterList.h"
|
44 |
| -#include "swift/AST/PluginRegistry.h" |
| 44 | +#include "swift/AST/PluginLoader.h" |
45 | 45 | #include "swift/AST/PrettyStackTrace.h"
|
46 | 46 | #include "swift/AST/PropertyWrappers.h"
|
47 | 47 | #include "swift/AST/ProtocolConformance.h"
|
|
67 | 67 | #include "llvm/ADT/Statistic.h"
|
68 | 68 | #include "llvm/ADT/StringMap.h"
|
69 | 69 | #include "llvm/ADT/StringSwitch.h"
|
70 |
| -#include "llvm/Config/config.h" |
71 | 70 | #include "llvm/IR/LLVMContext.h"
|
72 | 71 | #include "llvm/Support/Allocator.h"
|
73 | 72 | #include "llvm/Support/Compiler.h"
|
@@ -524,17 +523,8 @@ struct ASTContext::Implementation {
|
524 | 523 |
|
525 | 524 | llvm::StringMap<OptionSet<SearchPathKind>> SearchPathsSet;
|
526 | 525 |
|
527 |
| - /// Plugin registry. Lazily populated by get/setPluginRegistry(). |
528 |
| - /// NOTE: Do not reference this directly. Use ASTContext::getPluginRegistry(). |
529 |
| - PluginRegistry *Plugins = nullptr; |
530 |
| - |
531 |
| - /// `Plugins` storage if this ASTContext owns it. |
532 |
| - std::unique_ptr<PluginRegistry> OwnedPluginRegistry = nullptr; |
533 |
| - |
534 |
| - /// Map a module name to an executable plugin path that provides the module. |
535 |
| - llvm::DenseMap<Identifier, StringRef> ExecutablePluginPaths; |
536 |
| - |
537 |
| - llvm::StringSet<> LoadedPluginLibraryPaths; |
| 526 | + /// Plugin loader. |
| 527 | + std::unique_ptr<swift::PluginLoader> Plugins; |
538 | 528 |
|
539 | 529 | /// The permanent arena.
|
540 | 530 | Arena Permanent;
|
@@ -705,8 +695,6 @@ ASTContext::ASTContext(
|
705 | 695 | // Register any request-evaluator functions available at the AST layer.
|
706 | 696 | registerAccessRequestFunctions(evaluator);
|
707 | 697 | registerNameLookupRequestFunctions(evaluator);
|
708 |
| - |
709 |
| - createModuleToExecutablePluginMap(); |
710 | 698 | }
|
711 | 699 |
|
712 | 700 | ASTContext::~ASTContext() {
|
@@ -6266,34 +6254,33 @@ BuiltinTupleType *ASTContext::getBuiltinTupleType() {
|
6266 | 6254 | return result;
|
6267 | 6255 | }
|
6268 | 6256 |
|
6269 |
| -void ASTContext::setPluginRegistry(PluginRegistry *newValue) { |
6270 |
| - assert(getImpl().Plugins == nullptr && |
6271 |
| - "Too late to set a new plugin registry"); |
6272 |
| - getImpl().Plugins = newValue; |
| 6257 | +void ASTContext::setPluginLoader(std::unique_ptr<PluginLoader> loader) { |
| 6258 | + getImpl().Plugins = std::move(loader); |
6273 | 6259 | }
|
6274 | 6260 |
|
6275 |
| -PluginRegistry *ASTContext::getPluginRegistry() const { |
6276 |
| - PluginRegistry *®istry = getImpl().Plugins; |
| 6261 | +PluginLoader &ASTContext::getPluginLoader() { return *getImpl().Plugins; } |
6277 | 6262 |
|
6278 |
| - // Create a new one if it hasn't been set. |
6279 |
| - if (!registry) { |
6280 |
| - registry = new PluginRegistry(); |
6281 |
| - getImpl().OwnedPluginRegistry.reset(registry); |
6282 |
| - } |
| 6263 | +Optional<std::string> |
| 6264 | +ASTContext::lookupLibraryPluginByModuleName(Identifier moduleName) { |
| 6265 | + return getImpl().Plugins->lookupLibraryPluginByModuleName(moduleName); |
| 6266 | +} |
6283 | 6267 |
|
6284 |
| - assert(registry != nullptr); |
6285 |
| - return registry; |
| 6268 | +Optional<StringRef> |
| 6269 | +ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) { |
| 6270 | + return getImpl().Plugins->lookupExecutablePluginByModuleName(moduleName); |
6286 | 6271 | }
|
6287 | 6272 |
|
6288 |
| -void ASTContext::createModuleToExecutablePluginMap() { |
6289 |
| - for (auto &arg : SearchPathOpts.getCompilerPluginExecutablePaths()) { |
6290 |
| - // Create a moduleName -> pluginPath mapping. |
6291 |
| - assert(!arg.ExecutablePath.empty() && "empty plugin path"); |
6292 |
| - auto pathStr = AllocateCopy(arg.ExecutablePath); |
6293 |
| - for (auto moduleName : arg.ModuleNames) { |
6294 |
| - getImpl().ExecutablePluginPaths[getIdentifier(moduleName)] = pathStr; |
6295 |
| - } |
6296 |
| - } |
| 6273 | +Optional<std::pair<std::string, std::string>> |
| 6274 | +ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { |
| 6275 | + return getImpl().Plugins->lookupExternalLibraryPluginByModuleName(moduleName); |
| 6276 | +} |
| 6277 | + |
| 6278 | +LoadedLibraryPlugin *ASTContext::loadLibraryPlugin(StringRef path) { |
| 6279 | + return getImpl().Plugins->loadLibraryPlugin(path); |
| 6280 | +} |
| 6281 | + |
| 6282 | +LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) { |
| 6283 | + return getImpl().Plugins->loadExecutablePlugin(path); |
6297 | 6284 | }
|
6298 | 6285 |
|
6299 | 6286 | Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
|
@@ -6331,105 +6318,6 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
|
6331 | 6318 | return decl->getDeclaredInterfaceType();
|
6332 | 6319 | }
|
6333 | 6320 |
|
6334 |
| -Optional<std::string> |
6335 |
| -ASTContext::lookupLibraryPluginByModuleName(Identifier moduleName) { |
6336 |
| - auto fs = SourceMgr.getFileSystem(); |
6337 |
| - |
6338 |
| - // Look for 'lib${module name}(.dylib|.so)'. |
6339 |
| - SmallString<64> expectedBasename; |
6340 |
| - expectedBasename.append("lib"); |
6341 |
| - expectedBasename.append(moduleName.str()); |
6342 |
| - expectedBasename.append(LTDL_SHLIB_EXT); |
6343 |
| - |
6344 |
| - // Try '-plugin-path'. |
6345 |
| - for (const auto &searchPath : SearchPathOpts.PluginSearchPaths) { |
6346 |
| - SmallString<128> fullPath(searchPath); |
6347 |
| - llvm::sys::path::append(fullPath, expectedBasename); |
6348 |
| - if (fs->exists(fullPath)) { |
6349 |
| - return std::string(fullPath); |
6350 |
| - } |
6351 |
| - } |
6352 |
| - |
6353 |
| - // Try '-load-plugin-library'. |
6354 |
| - for (const auto &libPath : SearchPathOpts.getCompilerPluginLibraryPaths()) { |
6355 |
| - if (llvm::sys::path::filename(libPath) == expectedBasename) { |
6356 |
| - return libPath; |
6357 |
| - } |
6358 |
| - } |
6359 |
| - |
6360 |
| - return None; |
6361 |
| -} |
6362 |
| - |
6363 |
| -Optional<StringRef> |
6364 |
| -ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) { |
6365 |
| - auto &execPluginPaths = getImpl().ExecutablePluginPaths; |
6366 |
| - auto found = execPluginPaths.find(moduleName); |
6367 |
| - if (found == execPluginPaths.end()) |
6368 |
| - return None; |
6369 |
| - return found->second; |
6370 |
| -} |
6371 |
| - |
6372 |
| -Optional<std::pair<std::string, std::string>> |
6373 |
| -ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { |
6374 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6375 |
| - for (auto &pair : SearchPathOpts.ExternalPluginSearchPaths) { |
6376 |
| - SmallString<128> fullPath(pair.SearchPath); |
6377 |
| - llvm::sys::path::append(fullPath, "lib" + moduleName.str() + LTDL_SHLIB_EXT); |
6378 |
| - |
6379 |
| - if (fs->exists(fullPath)) { |
6380 |
| - return {{std::string(fullPath), pair.ServerPath}}; |
6381 |
| - } |
6382 |
| - } |
6383 |
| - return None; |
6384 |
| -} |
6385 |
| - |
6386 |
| -LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) { |
6387 |
| - SmallString<128> resolvedPath; |
6388 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6389 |
| - if (auto err = fs->getRealPath(path, resolvedPath)) { |
6390 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6391 |
| - err.message()); |
6392 |
| - return nullptr; |
6393 |
| - } |
6394 |
| - |
6395 |
| - // Load the plugin. |
6396 |
| - auto plugin = getPluginRegistry()->loadExecutablePlugin(resolvedPath); |
6397 |
| - if (!plugin) { |
6398 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6399 |
| - llvm::toString(plugin.takeError())); |
6400 |
| - return nullptr; |
6401 |
| - } |
6402 |
| - |
6403 |
| - return plugin.get(); |
6404 |
| -} |
6405 |
| - |
6406 |
| -LoadedLibraryPlugin *ASTContext::loadLibraryPlugin(StringRef path) { |
6407 |
| - // Remember the path (even if it fails to load.) |
6408 |
| - getImpl().LoadedPluginLibraryPaths.insert(path); |
6409 |
| - |
6410 |
| - SmallString<128> resolvedPath; |
6411 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6412 |
| - if (auto err = fs->getRealPath(path, resolvedPath)) { |
6413 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6414 |
| - err.message()); |
6415 |
| - return nullptr; |
6416 |
| - } |
6417 |
| - |
6418 |
| - // Load the plugin. |
6419 |
| - auto plugin = getPluginRegistry()->loadLibraryPlugin(resolvedPath); |
6420 |
| - if (!plugin) { |
6421 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6422 |
| - llvm::toString(plugin.takeError())); |
6423 |
| - return nullptr; |
6424 |
| - } |
6425 |
| - |
6426 |
| - return plugin.get(); |
6427 |
| -} |
6428 |
| - |
6429 |
| -const llvm::StringSet<> &ASTContext::getLoadedPluginLibraryPaths() const { |
6430 |
| - return getImpl().LoadedPluginLibraryPaths; |
6431 |
| -} |
6432 |
| - |
6433 | 6321 | bool ASTContext::supportsMoveOnlyTypes() const {
|
6434 | 6322 | // currently the only thing holding back whether the types can appear is this.
|
6435 | 6323 | return SILOpts.LexicalLifetimes != LexicalLifetimesOption::Off;
|
|
0 commit comments