Skip to content

[libSyntax] Incremental syntax colouring #18016

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 7 commits into from
Jul 19, 2018

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jul 17, 2018

This PR enables incremental syntax parsing from the SourceKit API.
This can be used in two scenarios:

  1. If just the syntax tree is retrieved, it is now parsed incrementally for every edit that gets submitted
  2. If key.forcelibsyntaxbasedprocessing is specified (and thus the syntax map generated from the syntax tree), the syntax tree will also be parsed incrementally.

Also, this PR adds an option to pass the regions that were reused as part of incremental parsing back to the caller via SourceKit, which enabled the editor to visualise the reused regions for e.g. debugging purposes.

@ahoppen ahoppen requested review from rintaro and nkcsgexi July 17, 2018 21:25
@ahoppen
Copy link
Member Author

ahoppen commented Jul 17, 2018

@swift-ci Please smoke test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Looking good overall! Some minor comments.

@@ -353,13 +358,19 @@ class Output {
bool PrettyPrint;
bool NeedBitValueComma;
bool EnumerationMatchFound;
UserInfoMap UserInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

UserInterprettedConfiguration Config; or something similar seems to be better naming. It's good to document that this field is not used in a generic way.

Copy link
Member Author

@ahoppen ahoppen Jul 17, 2018

Choose a reason for hiding this comment

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

I was leaning on the Cocoa paradigm of calling a map of arbitrary values user info where it is well established. Should I still change it? In swiftSyntax I'm also planning to call it user info and I feel on that side the name fits nicely because swiftSyntax will likely often be used in conjunction with Cocoa/CocoaTouch.

if (EditorDoc->getSyntaxTree().hasValue()) {
SyntaxCache.emplace(EditorDoc->getSyntaxTree().getValue());
SyntaxCache->addEdit(Offset, Offset + Length, Buf->getBufferSize());
SyntaxCache->setRecordReuseInformation();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can SyntaxCache hold a SourceFile* instead of an old syntax tree? Then we don't need these lines, and we won't worry pulling syntax trees from a wrong source file.


bool syntaxReuseInfoEnabled() override { return Opts.EnableSyntaxReuseInfo; }
bool handleSyntaxReuseRegions(
std::vector<std::pair<unsigned, unsigned>> ReuseRegions) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

Define a struct instead of using std::pair<unsigned, unsigned>. In general, avoid using std::pair in a non-local context since we don't get any interesting information from it. For instance, are these unsigned offset, line-column, or something else?

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 wanted to do that, but the data is generated in swiftParse and used in SourceKit. Neither one imports the other (which I believe is a good thing), so the question comes up where this new type should be defined or if we want to convert between two different types in soucekitd. I decided that using std::pair is the lesser of three evils but am open to better suggestions.

@ahoppen ahoppen force-pushed the 003-incremental-syntax-coloring branch from ab4fc62 to e88cae0 Compare July 17, 2018 23:15
@ahoppen
Copy link
Member Author

ahoppen commented Jul 17, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the 003-incremental-syntax-coloring branch from e88cae0 to 65e2238 Compare July 18, 2018 01:34
@ahoppen
Copy link
Member Author

ahoppen commented Jul 18, 2018

@swift-ci Please smoke test

ahoppen added 6 commits July 18, 2018 13:35
Since we are reusing syntax nodes as part of incremental parsing, we
cannot rely on the buffer always outliving the syntax nodes.
This will allow us to customize the serialization of a syntax tree like
not serializing the node's IDs.
If enabled using the environment variable
SOURCEKIT_INCREMENTAL_PARSE_VALIDATION, the incrementally parsed syntax
tree will be compared to the from-scratch parsing syntax tree. If they
differ a warning is emitted and log files showing the difference written
to a temporary directory.
@ahoppen ahoppen force-pushed the 003-incremental-syntax-coloring branch from 65e2238 to 21dc447 Compare July 18, 2018 20:35
@ahoppen
Copy link
Member Author

ahoppen commented Jul 18, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ab4fc6224fa786db07ec0e19841a9df7bd73fd69

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ab4fc6224fa786db07ec0e19841a9df7bd73fd69

@ahoppen ahoppen merged commit 1df1dc7 into swiftlang:master Jul 19, 2018
@ahoppen ahoppen deleted the 003-incremental-syntax-coloring branch July 19, 2018 16:19
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