Skip to content

[SyntaxParse] Parse collection expression #27565

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 8 commits into from
Oct 9, 2019

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Oct 7, 2019

  • Parse super expression
  • Refactor parseListSyntax() and update parseTypeTupleBody() for that
  • Implement Parser::parseExpressionSyntax()
  • Implement ASTGen::advanceLocEnd()
  • Parse ArrayExpr/DictionaryExpr

@rintaro rintaro force-pushed the syntaxparse-exprcollection branch 4 times, most recently from 2fbce85 to 888fabc Compare October 8, 2019 17:21
@rintaro rintaro changed the title [WIP][SyntaxParse] Parse collection expression [SyntaxParse] Parse collection expression Oct 8, 2019
@rintaro rintaro marked this pull request as ready for review October 8, 2019 17:22
@rintaro
Copy link
Member Author

rintaro commented Oct 8, 2019

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Oct 8, 2019

@nathawes
I included your parseExpressionSyntax() and advanceLocEnd() function from #27460 in this PR.

@rintaro rintaro requested a review from nathawes October 8, 2019 17:25
@rintaro
Copy link
Member Author

rintaro commented Oct 8, 2019

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Oct 8, 2019

Build failed
Swift Test Linux Platform
Git Sha - 888fabc0be3af599a7039c23da9795efe3b59336

@swift-ci
Copy link
Contributor

swift-ci commented Oct 8, 2019

Build failed
Swift Test OS X Platform
Git Sha - 888fabc0be3af599a7039c23da9795efe3b59336

Optimize for libSyntax parsing.
The new 'parseListSyntax()' receives a vector storage, passes element
builder to the callback for populating the elements, then automatically
parses trailing commas. Also, it performs automatic recovery if the
element has an error (e.g. Skip until ',' or ')').
(Implemented by Nathan Hawes @nathawes)
(implemented by Nathan Hawes @nathawes)

Advance \p Loc to the last non-missing token of the specified or, if it
doesn't contain any, the last non-missing token preceding it in the
tree.
For non-migrated expression / decl attributes. Clean-up the slot after
the use. Assert there's no existing element at the location.
In AST token range, string literal token must be treated as a single
token.
@rintaro rintaro force-pushed the syntaxparse-exprcollection branch from 888fabc to fa991ba Compare October 9, 2019 06:11
Comment on lines +1454 to +1469
void ASTGen::addExpr(Expr *E, const SourceLoc Loc) {
assert(!hasExpr(Loc));
Exprs[Loc] = E;
}

bool ASTGen::hasExpr(const SourceLoc Loc) const {
return Exprs.find(Loc) != Exprs.end();
}

Expr *ASTGen::takeExpr(const SourceLoc Loc) {
auto I = Exprs.find(Loc);
assert(I != Exprs.end());
auto expr = I->second;
Exprs.erase(I);
return expr;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@nathawes To deal with backtracking, I modified this to erase the slot in the map after the use.

Comment on lines -246 to +247
CharSourceRange getDeferredLayoutRange(bool includeTrivia) const {
CharSourceRange getDeferredLayoutRange() const {
assert(DK == DataKind::DeferredLayout);
auto HasValidRange = [includeTrivia](const ParsedRawSyntaxNode &Child) {
return !Child.isNull() && !Child.isMissing() &&
Child.getDeferredRange(includeTrivia).isValid();
};
auto first = llvm::find_if(getDeferredChildren(), HasValidRange);
if (first == getDeferredChildren().end())
return CharSourceRange();
auto last = llvm::find_if(llvm::reverse(getDeferredChildren()),
HasValidRange);
auto firstRange = first->getDeferredRange(includeTrivia);
firstRange.widen(last->getDeferredRange(includeTrivia));
return firstRange;
return DeferredLayout.Range;
Copy link
Member Author

Choose a reason for hiding this comment

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

This function used to be exponential.

if (!Node.isMissing()) {
// NOTE: We cannot use 'getLastToken()' because it doesn't take string
// literal expressions into account.
if (Node.isToken() || Node.is<StringLiteralExprSyntax>())
Copy link
Member Author

Choose a reason for hiding this comment

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

Since StringLiteralExprSyntax is like { quote (literal-segment | interpolation-segment)* quote },
This used to return the location of the end quote. In this case, we have to return the location of the start quote instead.

@rintaro
Copy link
Member Author

rintaro commented Oct 9, 2019

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Oct 9, 2019

Build failed
Swift Test Linux Platform
Git Sha - 888fabc0be3af599a7039c23da9795efe3b59336

@swift-ci
Copy link
Contributor

swift-ci commented Oct 9, 2019

Build failed
Swift Test OS X Platform
Git Sha - 888fabc0be3af599a7039c23da9795efe3b59336

@rintaro rintaro merged commit 1724f5b into swiftlang:master Oct 9, 2019
@rintaro rintaro deleted the syntaxparse-exprcollection branch October 9, 2019 21:55
rintaro added a commit to rintaro/swift that referenced this pull request Oct 14, 2019
…xprcollection"

This reverts commit 1724f5b, reversing
changes made to bc1a3ea.
rintaro added a commit to rintaro/swift that referenced this pull request Oct 14, 2019
…xparse-exprcollection""

This reverts commit 2f40f24.
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