-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[CodeCompletion] Replace main module instead of file #32147
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
Conversation
Rather than replacing the code completion file on the `CompilerInstance` whenever we do a cached top-level completion, let's set a new main module instead. This allows us to properly update the `LoadedModules` map, and allows the retrieval of the code completion file to be turned into a request.
|
@swift-ci please test |
rintaro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thank you!
|
@swift-ci please smoke test macOS |
| auto *newM = | ||
| ModuleDecl::create(oldM->getName(), Ctx, oldM->getImplicitImportInfo()); | ||
| auto *newM = ModuleDecl::createMainModule(Ctx, oldM->getName(), | ||
| oldM->getImplicitImportInfo()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often does this happen in practice? We are adding up to the cache each time we retrieve the completion file for a new main module, even though the old ones are thrown away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only perform a limited number of cached completions before throwing away the CompilerInstance (and therefore both the ASTContext and evaluator cache), so I don't think this should be an issue in practice. Note this doesn't just apply to the evaluator's cache, there are also a bunch of other allocations that we make per module and file (including the AST nodes themselves) that won't be deallocated until the ASTContext is torn down.
Eventually we'd like code completion to take full advantage of the request evaluator by having it invalidate certain parsing requests, which would invalidate any dependant requests and ensure we only need to re-compute the minimal amount depending on what was changed. Once we get to this point, we'll hopefully be able to tie memory lifetimes such that request invalidation causes the deallocation of any state previously computed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very informative, thank you.
Rather than replacing the code completion file on the
CompilerInstancewhen we do a cached top-level completion, let's set a new main module instead.This allows us to properly update the
LoadedModulesmap, and allows the retrieval of the code completion file to be turned into a request.