-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Code Completion] Split code completion results into context free part that can be cached and contextual part displayed to the user #40471
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
@swift-ci Please smoke test |
include/swift/IDE/CodeCompletion.h
Outdated
/// Maps USRs to \c CodeCompletionResultTypes that have already been | ||
/// constructed. | ||
static llvm::StringMap<CodeCompletionResultType *> USRCache; | ||
|
||
/// Maps Types to \c CodeCompletionResultTypes that have already been | ||
/// constructed. | ||
static llvm::DenseMap<Type, CodeCompletionResultType *> TypeCache; |
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.
Global cache without clearing. This is a little scary, and they leaks. I believe these are tied to an ASTContext. Doesn't it make sense to move this to ASTContext instance member?
Also, can CodeCompletionResultType
be allocated on the ASTContext
?
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.
Oh, I thought that cache would only be introduced by the next PR, sorry.
I will store them in a dedicate arena with ahoppen@e9ef698 but because that change is >200 LOC as well, I didn’t want to inflate this PR even further. Do you think we should pull that commit into this PR or should we just fix it in a follow-up PR?
We can’t store CodeCompletionResultType
in the ASTContext
because they are used for cached results, which are used for multiple code completion sessions and thus outlive the ASTContext
.
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 can’t store CodeCompletionResultType in the ASTContext because they are used for cached results, which are used for multiple code completion sessions and thus outlive the ASTContext.
I'm not sure the cache should outlive the ASTContext. An ASTContext is used for multiple code completion sessions as long as fast-completion is working. If fast-completion is not working and the ASTContext is destroyed, I think the cache should be cleared, or what cache can we reuse?
@swift-ci Please smoke test Windows |
@swift-ci Please test Windows |
a704547
to
23f0d6e
Compare
I refactored the PR to make a cleaner distinction between USR-based and ASTContext-based types. For now In a follow-up PR I will add the option to back |
@swift-ci Please smoke test |
include/swift/IDE/CodeCompletion.h
Outdated
/// A single code completion result enriched with information that depend on | ||
/// the completion's usage context. | ||
class CodeCompletionResult { | ||
ContextFreeCodeCompletionResult ContextFree; |
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.
ContextFreeCodeCompletionResult
is fairly big object. Instead of copying it, could CodeCompletionResult
just hold a reference to it?
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.
I thought about the same but decided against it, because
- this way, we are sure that
ContextFreeCodeCompletionResult
is allocated by the same allocator asCodeCompletionResult
and we don’t run into issues thatContextFreeCodeCompletionResult
might get deallocated whileCodeCompletionResult
is still referencing it - we only need to copy it when constructing
CodeCompletionResult
and I don’t think it makes much of a performance difference - We don’t have to do an indirection to
ContextFreeCodeCompletionResult
when accessing context-free properties of aCodeCompletionResult
Do you think this makes sense or would you think it’s worth to measure the performance impact of the copy?
23f0d6e
to
e0253ca
Compare
I have rebased this PR now that #40724 is merged and tried to make it as easy to review as possible:
|
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
1 similar comment
@swift-ci Please smoke test Windows |
…ultKind to top-level types Preliminary work to split `CodeCompletionResult` into a context-free and contextual part.
e0253ca
to
6f65af5
Compare
@swift-ci Please smoke test |
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.
LGTM!
include/swift/IDE/CodeCompletion.h
Outdated
CodeCompletionResultKind Kind : 3; | ||
static_assert(int(CodeCompletionResultKind::MAX_VALUE) < 1 << 3, ""); | ||
|
||
/// Opaque kind that is interpreted differently depending on |
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.
Nit: Incomplete comment? Probably:
/// Opaque kind that is interpreted differently depending on | |
/// Opaque kind that is interpreted differently depending on 'Kind'. |
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.
Thanks. That comment pre-dated the use of a union here. I just removed it.
…t that can be cached and contextual part displayed to the user This allows makes the distinction between cachable and non-cachable properties cleaner and allows us to more easily compute contextual information (like type relations) for cached items later.
6f65af5
to
fd72674
Compare
@swift-ci Please smoke test |
This is the first (of two) refactoring part of #40399, which has gotten a little big.
This allows makes the distinction between cachable and non-cachable properties cleaner and allows us to more easily compute contextual information (like type relations) for cached items later.