Skip to content

[SourceKit] Use a single PluginRegistry in multiple ASTContexts #64655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Mar 27, 2023

Make a single PluginRegistry and share it between SwiftASTManager, IDEInspectionInstance, and CompileInstance. And inject the plugin registry to ASTContext right after CompilerInstance.setup()

That way, all sema-capable ASTContext in SourceKit share a single PluginRegistry.

Make a single 'PluginRegistry' and share it between SwiftASTManager,
IDEInspectionInstance, and CompileInstance. And inject the plugin
registry to ASTContext right after 'CompilerInstance.setup()'

That way, all sema-capable ASTContext in SourceKit share a single
PluginRegistry.
@rintaro
Copy link
Member Author

rintaro commented Mar 27, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Mar 27, 2023

@swift-ci Please smoke test macOS

@@ -139,6 +139,8 @@ class PluginRegistry {
/// Flag to dump plugin messagings.
bool dumpMessaging = false;

std::mutex mtx;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLoadedLibraryPlugins() needs to lock this, too.

Copy link
Member Author

@rintaro rintaro Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to remove getLoadedLibraryPlugins() method in follow-ups soon.
Currently only swift::emitLoadedModuleTraceIfNeeded() is using it for dependency tracking. However since PluginRegistry might be shared between different compilations, getLoadedLibraryPlugins() may contain unrelated entries. Instead, each ASTContext should track loaded libraries separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a commit in this PR removing PluginRegistry::getLoadedLibraryPlugins().

PluginRegistry is now shared between multiple ASTContext. ASTContext
should track its loaded plugin library paths separately.
@rintaro rintaro force-pushed the sourcekit-single-pluginregistry branch from 2d5d934 to 59f744c Compare March 28, 2023 00:00
@rintaro
Copy link
Member Author

rintaro commented Mar 28, 2023

@swift-ci Please smoke test

Comment on lines 6399 to +6401
void *ASTContext::loadLibraryPlugin(StringRef path) {
// Remember the path (even if it fails to load.)
getImpl().LoadedPluginLibraryPaths.insert(path);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to track failed libraries? If not, I can just move this after getPluginRegistry()->loadLibraryPlugin(resolvedPath) .

Also, do we want the VFS path or the "real" path here? I guess it doesn't matter because we only use this to get the module name from the filename. cc: @rxwei

@rintaro rintaro merged commit c9172d1 into swiftlang:main Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants