Skip to content

[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

Merged

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 7, 2020

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

@rintaro
Copy link
Member Author

rintaro commented Jan 7, 2020

@swift-ci Please smoke test

@rintaro rintaro force-pushed the ide-completion-fasttoplevel-rdar58378157 branch from 463c385 to ee883d9 Compare January 7, 2020 22:38
@rintaro
Copy link
Member Author

rintaro commented Jan 7, 2020

@swift-ci Please smoke test

@rintaro rintaro force-pushed the ide-completion-fasttoplevel-rdar58378157 branch 3 times, most recently from 58c1b19 to b570f6a Compare January 15, 2020 01:01
@rintaro rintaro marked this pull request as ready for review January 15, 2020 01:02
@rintaro
Copy link
Member Author

rintaro commented Jan 15, 2020

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Jan 15, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 463c385e24fb308452d26aac57e07b911ffa909d

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 463c385e24fb308452d26aac57e07b911ffa909d

@rintaro rintaro requested a review from benlangmuir January 15, 2020 07:48
@@ -344,6 +344,11 @@ class SourceFile final : public FileUnit {
return BufferID;
}

void setBufferID(int Val) {
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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.

@rintaro rintaro force-pushed the ide-completion-fasttoplevel-rdar58378157 branch from b570f6a to 2da6044 Compare January 16, 2020 21:35
@rintaro
Copy link
Member Author

rintaro commented Jan 16, 2020

@swift-ci Please smoke test

Comment on lines 306 to 308
oldSF->truncateTopLevelDecls(0);
oldSF->clearLookupCache();
oldSF->setBufferID(newBufferID);
Copy link
Member Author

@rintaro rintaro Jan 17, 2020

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.

Copy link
Member Author

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.

@rintaro rintaro force-pushed the ide-completion-fasttoplevel-rdar58378157 branch from 2da6044 to 2140e3f Compare February 25, 2020 20:38
@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2020

@swift-ci Please smoke test

@rintaro rintaro requested a review from benlangmuir February 25, 2020 21:44
@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2020

@benlangmuir Could you take another look?

@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2020

@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
@rintaro rintaro force-pushed the ide-completion-fasttoplevel-rdar58378157 branch from 2140e3f to 0a0cde9 Compare February 25, 2020 23:56
@rintaro
Copy link
Member Author

rintaro commented Feb 25, 2020

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2020

@swift-ci Please smoke test macOS

@rintaro
Copy link
Member Author

rintaro commented Feb 26, 2020

@swift-ci Please smoke test OS X platform

@rintaro rintaro merged commit 75c3661 into swiftlang:master Feb 26, 2020
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