|
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"
|
@@ -526,17 +526,8 @@ struct ASTContext::Implementation {
|
526 | 526 |
|
527 | 527 | llvm::StringMap<OptionSet<SearchPathKind>> SearchPathsSet;
|
528 | 528 |
|
529 |
| - /// Plugin registry. Lazily populated by get/setPluginRegistry(). |
530 |
| - /// NOTE: Do not reference this directly. Use ASTContext::getPluginRegistry(). |
531 |
| - PluginRegistry *Plugins = nullptr; |
532 |
| - |
533 |
| - /// `Plugins` storage if this ASTContext owns it. |
534 |
| - std::unique_ptr<PluginRegistry> OwnedPluginRegistry = nullptr; |
535 |
| - |
536 |
| - /// Map a module name to an executable plugin path that provides the module. |
537 |
| - llvm::DenseMap<Identifier, StringRef> ExecutablePluginPaths; |
538 |
| - |
539 |
| - llvm::StringSet<> LoadedPluginLibraryPaths; |
| 529 | + /// Plugin loader. |
| 530 | + std::unique_ptr<swift::PluginLoader> Plugins; |
540 | 531 |
|
541 | 532 | /// The permanent arena.
|
542 | 533 | Arena Permanent;
|
@@ -712,8 +703,6 @@ ASTContext::ASTContext(
|
712 | 703 | registerAccessRequestFunctions(evaluator);
|
713 | 704 | registerNameLookupRequestFunctions(evaluator);
|
714 | 705 |
|
715 |
| - createModuleToExecutablePluginMap(); |
716 |
| - |
717 | 706 | // Provide a default OnDiskOutputBackend if user didn't supply one.
|
718 | 707 | if (!OutputBackend)
|
719 | 708 | OutputBackend = llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
|
@@ -6280,34 +6269,33 @@ BuiltinTupleType *ASTContext::getBuiltinTupleType() {
|
6280 | 6269 | return result;
|
6281 | 6270 | }
|
6282 | 6271 |
|
6283 |
| -void ASTContext::setPluginRegistry(PluginRegistry *newValue) { |
6284 |
| - assert(getImpl().Plugins == nullptr && |
6285 |
| - "Too late to set a new plugin registry"); |
6286 |
| - getImpl().Plugins = newValue; |
| 6272 | +void ASTContext::setPluginLoader(std::unique_ptr<PluginLoader> loader) { |
| 6273 | + getImpl().Plugins = std::move(loader); |
6287 | 6274 | }
|
6288 | 6275 |
|
6289 |
| -PluginRegistry *ASTContext::getPluginRegistry() const { |
6290 |
| - PluginRegistry *®istry = getImpl().Plugins; |
| 6276 | +PluginLoader &ASTContext::getPluginLoader() { return *getImpl().Plugins; } |
6291 | 6277 |
|
6292 |
| - // Create a new one if it hasn't been set. |
6293 |
| - if (!registry) { |
6294 |
| - registry = new PluginRegistry(); |
6295 |
| - getImpl().OwnedPluginRegistry.reset(registry); |
6296 |
| - } |
| 6278 | +Optional<std::string> |
| 6279 | +ASTContext::lookupLibraryPluginByModuleName(Identifier moduleName) { |
| 6280 | + return getImpl().Plugins->lookupLibraryPluginByModuleName(moduleName); |
| 6281 | +} |
6297 | 6282 |
|
6298 |
| - assert(registry != nullptr); |
6299 |
| - return registry; |
| 6283 | +Optional<StringRef> |
| 6284 | +ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) { |
| 6285 | + return getImpl().Plugins->lookupExecutablePluginByModuleName(moduleName); |
6300 | 6286 | }
|
6301 | 6287 |
|
6302 |
| -void ASTContext::createModuleToExecutablePluginMap() { |
6303 |
| - for (auto &arg : SearchPathOpts.getCompilerPluginExecutablePaths()) { |
6304 |
| - // Create a moduleName -> pluginPath mapping. |
6305 |
| - assert(!arg.ExecutablePath.empty() && "empty plugin path"); |
6306 |
| - auto pathStr = AllocateCopy(arg.ExecutablePath); |
6307 |
| - for (auto moduleName : arg.ModuleNames) { |
6308 |
| - getImpl().ExecutablePluginPaths[getIdentifier(moduleName)] = pathStr; |
6309 |
| - } |
6310 |
| - } |
| 6288 | +Optional<std::pair<std::string, std::string>> |
| 6289 | +ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { |
| 6290 | + return getImpl().Plugins->lookupExternalLibraryPluginByModuleName(moduleName); |
| 6291 | +} |
| 6292 | + |
| 6293 | +LoadedLibraryPlugin *ASTContext::loadLibraryPlugin(StringRef path) { |
| 6294 | + return getImpl().Plugins->loadLibraryPlugin(path); |
| 6295 | +} |
| 6296 | + |
| 6297 | +LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) { |
| 6298 | + return getImpl().Plugins->loadExecutablePlugin(path); |
6311 | 6299 | }
|
6312 | 6300 |
|
6313 | 6301 | Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
|
@@ -6345,105 +6333,6 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
|
6345 | 6333 | return decl->getDeclaredInterfaceType();
|
6346 | 6334 | }
|
6347 | 6335 |
|
6348 |
| -Optional<std::string> |
6349 |
| -ASTContext::lookupLibraryPluginByModuleName(Identifier moduleName) { |
6350 |
| - auto fs = SourceMgr.getFileSystem(); |
6351 |
| - |
6352 |
| - // Look for 'lib${module name}(.dylib|.so)'. |
6353 |
| - SmallString<64> expectedBasename; |
6354 |
| - expectedBasename.append("lib"); |
6355 |
| - expectedBasename.append(moduleName.str()); |
6356 |
| - expectedBasename.append(LTDL_SHLIB_EXT); |
6357 |
| - |
6358 |
| - // Try '-plugin-path'. |
6359 |
| - for (const auto &searchPath : SearchPathOpts.PluginSearchPaths) { |
6360 |
| - SmallString<128> fullPath(searchPath); |
6361 |
| - llvm::sys::path::append(fullPath, expectedBasename); |
6362 |
| - if (fs->exists(fullPath)) { |
6363 |
| - return std::string(fullPath); |
6364 |
| - } |
6365 |
| - } |
6366 |
| - |
6367 |
| - // Try '-load-plugin-library'. |
6368 |
| - for (const auto &libPath : SearchPathOpts.getCompilerPluginLibraryPaths()) { |
6369 |
| - if (llvm::sys::path::filename(libPath) == expectedBasename) { |
6370 |
| - return libPath; |
6371 |
| - } |
6372 |
| - } |
6373 |
| - |
6374 |
| - return None; |
6375 |
| -} |
6376 |
| - |
6377 |
| -Optional<StringRef> |
6378 |
| -ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) { |
6379 |
| - auto &execPluginPaths = getImpl().ExecutablePluginPaths; |
6380 |
| - auto found = execPluginPaths.find(moduleName); |
6381 |
| - if (found == execPluginPaths.end()) |
6382 |
| - return None; |
6383 |
| - return found->second; |
6384 |
| -} |
6385 |
| - |
6386 |
| -Optional<std::pair<std::string, std::string>> |
6387 |
| -ASTContext::lookupExternalLibraryPluginByModuleName(Identifier moduleName) { |
6388 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6389 |
| - for (auto &pair : SearchPathOpts.ExternalPluginSearchPaths) { |
6390 |
| - SmallString<128> fullPath(pair.SearchPath); |
6391 |
| - llvm::sys::path::append(fullPath, "lib" + moduleName.str() + LTDL_SHLIB_EXT); |
6392 |
| - |
6393 |
| - if (fs->exists(fullPath)) { |
6394 |
| - return {{std::string(fullPath), pair.ServerPath}}; |
6395 |
| - } |
6396 |
| - } |
6397 |
| - return None; |
6398 |
| -} |
6399 |
| - |
6400 |
| -LoadedExecutablePlugin *ASTContext::loadExecutablePlugin(StringRef path) { |
6401 |
| - SmallString<128> resolvedPath; |
6402 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6403 |
| - if (auto err = fs->getRealPath(path, resolvedPath)) { |
6404 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6405 |
| - err.message()); |
6406 |
| - return nullptr; |
6407 |
| - } |
6408 |
| - |
6409 |
| - // Load the plugin. |
6410 |
| - auto plugin = getPluginRegistry()->loadExecutablePlugin(resolvedPath); |
6411 |
| - if (!plugin) { |
6412 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6413 |
| - llvm::toString(plugin.takeError())); |
6414 |
| - return nullptr; |
6415 |
| - } |
6416 |
| - |
6417 |
| - return plugin.get(); |
6418 |
| -} |
6419 |
| - |
6420 |
| -LoadedLibraryPlugin *ASTContext::loadLibraryPlugin(StringRef path) { |
6421 |
| - // Remember the path (even if it fails to load.) |
6422 |
| - getImpl().LoadedPluginLibraryPaths.insert(path); |
6423 |
| - |
6424 |
| - SmallString<128> resolvedPath; |
6425 |
| - auto fs = this->SourceMgr.getFileSystem(); |
6426 |
| - if (auto err = fs->getRealPath(path, resolvedPath)) { |
6427 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6428 |
| - err.message()); |
6429 |
| - return nullptr; |
6430 |
| - } |
6431 |
| - |
6432 |
| - // Load the plugin. |
6433 |
| - auto plugin = getPluginRegistry()->loadLibraryPlugin(resolvedPath); |
6434 |
| - if (!plugin) { |
6435 |
| - Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, path, |
6436 |
| - llvm::toString(plugin.takeError())); |
6437 |
| - return nullptr; |
6438 |
| - } |
6439 |
| - |
6440 |
| - return plugin.get(); |
6441 |
| -} |
6442 |
| - |
6443 |
| -const llvm::StringSet<> &ASTContext::getLoadedPluginLibraryPaths() const { |
6444 |
| - return getImpl().LoadedPluginLibraryPaths; |
6445 |
| -} |
6446 |
| - |
6447 | 6336 | bool ASTContext::supportsMoveOnlyTypes() const {
|
6448 | 6337 | // currently the only thing holding back whether the types can appear is this.
|
6449 | 6338 | return SILOpts.LexicalLifetimes != LexicalLifetimesOption::Off;
|
|
0 commit comments