Skip to content

[Parse] Reduce branches by running lexTrivia always #15137

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 1 commit into from
Mar 10, 2018

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Mar 10, 2018

This PR reduce branches in Lexer by running lexTrivia always for leading trivia in lexImpl.
Especially, Restart label and loop flow also eliminated in lexImpl.

For compatibility to current result with WithoutTrivia,
LeadingTrivia and TrailingTrivia are filter out in lex.
And skip lexTrivia for trailing trivia in formToken if WithoutTrivia.

By our recently achievement of perfect trivia lexing (and diagnostics),
we don't need trivia skipping logic in lexImpl anymore.

The idea of this PR got from my previous PR and conversation with @rintaro about it.
#15081

@rintaro
Copy link
Member

rintaro commented Mar 10, 2018

@swift-ci Please smoke test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Looks good.
I measured the performance. With 56MiB 840k lines of syntactically valid swift file, this change actually reduces -frontend -parse time from 0.790 to 0.777.

goto Restart; // Skip presumed whitespace.
assert(
ShouldTokenize &&
"Invalid UTF-8 sequence should be eaten by lexTrivia as LeadingTrivia");
Copy link
Member

Choose a reason for hiding this comment

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

This may cause unused variable warning in --no-assertion build. Please add (void)ShouldTokenize; line here.

@omochi
Copy link
Contributor Author

omochi commented Mar 10, 2018

I confirmed warning and updated.

@rintaro
Copy link
Member

rintaro commented Mar 10, 2018

@swift-ci Please smoke test

@rintaro
Copy link
Member

rintaro commented Mar 10, 2018

@swift-ci Please smoke test Linux platform

@rintaro rintaro merged commit 5e55586 into swiftlang:master Mar 10, 2018
@omochi omochi deleted the lex-less-branch branch March 10, 2018 14:58
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.

2 participants