Skip to content

[Parser] Simplify sequence expression parsing #628

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 2 commits into from
Aug 24, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Aug 23, 2022

(Depends on swiftlang/swift#60731)

SequenceExprSyntax now gurantees that it has odd number elements using UnresolvedTernaryExpr/UnresolvedAsExpr/UnresolvedIsExpr.

Factored out the operator parsing into parseSequenceExpressionOperator() which returns the operator expresssion, and optionally the RHS, so we can avoid nested loops.
Also, parseSequenceExprssion() now has a performance optimization that avoids heap Array construction unless the expression is actually sequenced.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This is fantastic, and a huge help for the operator-precedence library in #619.

@@ -42,23 +42,6 @@ extension Parser {
}

extension Parser {
struct PendingTernary {
Copy link
Member

Choose a reason for hiding this comment

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

I'm so glad to see this struct go away. The parser is much simpler now!

/// type-casting-operator → 'is' type
/// type-casting-operator → 'as' type
/// type-casting-operator → 'as' '?' type
/// type-casting-operator → 'as' '!' type
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to document the arrow operator here?

`SequenceExprSyntax` now gurantees that it has odd number elements using
`UnresolvedTernaryExpr`/`UnresolvedAsExpr`/`UnresolvedIsExpr`.

Factored out the operator parsing into `parseSequenceExpressionOperator()`
which returns the operator expresssion, and optionally the RHS, so we can
avoid nested loops.
Also, `parseSequenceExprssion()` now has a performance optimization that
avoids heap `Array` construction unless the expression is actually
sequenced.
@rintaro rintaro force-pushed the parse-sequenceexpr branch from a6eaf4b to f78fc5d Compare August 23, 2022 22:46
@rintaro
Copy link
Member Author

rintaro commented Aug 23, 2022

swiftlang/swift#60731
@swift-ci Please test

@DougGregor DougGregor merged commit 33a5780 into swiftlang:main Aug 24, 2022
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