-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Fast completion for top-level code in single file script #29048
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
[CodeCompletion] Fast completion for top-level code in single file script #29048
Conversation
@swift-ci Please smoke test |
463c385
to
ee883d9
Compare
@swift-ci Please smoke test |
58c1b19
to
b570f6a
Compare
@swift-ci Please smoke test |
@swift-ci Please test |
Build failed |
Build failed |
include/swift/AST/SourceFile.h
Outdated
@@ -344,6 +344,11 @@ class SourceFile final : public FileUnit { | |||
return BufferID; | |||
} | |||
|
|||
void setBufferID(int Val) { |
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.
Why does the SourceFile
buffer ID need to be updated? What uses this info during completion?
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.
At least ParseMembersRequest::evaluate()
uses getBufferID()
for delayed member list parsing. https://github.com/apple/swift/blob/53c008f32cf7e83022c9f6643c960015b7f91da7/lib/Parse/ParseRequests.cpp#L36-L44
We can modify this to get bufferID from the decl location, like:
auto &SM = idc->getASTContext().SourceMgr;
unsigned bufferID = SM.findBufferContainingLoc(idc->getDecl()->getLoc());
But I'm not sure this is the only usage of getBufferID()
during completion.
What is your concern about setting the buffer id?
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 guess that's fine, it's just more state that we're mutating so I wanted to understand what effect it has.
b570f6a
to
2da6044
Compare
@swift-ci Please smoke test |
lib/IDE/CompletionInstance.cpp
Outdated
oldSF->truncateTopLevelDecls(0); | ||
oldSF->clearLookupCache(); | ||
oldSF->setBufferID(newBufferID); |
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.
It turned out that this doesn't clear the imported modules from the SourceFile
.
We need to clear them, except for implicitly imported modules.
Or, create a new SourceFile
, add implicitly imported modules, them replace the old SourcFile
with 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.
Updated to create a new module and source file.
2da6044
to
2140e3f
Compare
@swift-ci Please smoke test |
@benlangmuir Could you take another look? |
@swift-ci Please smoke test Linux |
…ript e.g. Playground. A single file script is like a single function body; the interface of the file does not affect any other files. So when a completion happens in a single file script, re-parse the whole file. But we are still be able to reuse imported modules. rdar://problem/58378157
2140e3f
to
0a0cde9
Compare
@swift-ci Please smoke test |
@swift-ci Please smoke test macOS |
@swift-ci Please smoke test OS X platform |
e.g. Playground.
A single file script is like a single function body; the interface of the file does not affect any other files. So when a completion happens in a single file script, re-parse the whole file. But we are still be able to reuse imported modules.
rdar://problem/58378157