Skip to content

SyntaxNodes: DotSelfExpr should have optional base expression. #21926

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
Jan 17, 2019

Conversation

nkcsgexi
Copy link
Contributor

rdar://46935325

@nkcsgexi nkcsgexi requested review from rintaro and akyrtzi January 16, 2019 19:53
@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi force-pushed the dot-self-optional-base branch from eabadad to 9c42e97 Compare January 16, 2019 20:03
@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test and merge

@@ -532,7 +532,7 @@ struct S : Q, Equatable {
@_implements(P, x)
var y: String
@_implements(P, g())
func h() {}
func h() { _ = \.self }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a keypath, not a DotSelfExpr. I don't think its correct that DotSelfExpr's base is optional; you should instead parse keypaths differently. CC @jckarter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We parse them as DotSelfExpr too for AST, see here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see it parses like this:

        (keypath_expr type='<null>'
          <<null>>
          (dot_self_expr type='<null>'
            (key_path_dot_expr implicit type='<null>')))))))

So the base is a KeyPathDotExpr. Do you not have an equivalent in SwiftSyntax? It would be better if the base was never optional here and with MemberExpr also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Syntax tree doesn't have equivalent implicit nodes in general. All nodes should cover at least one underlying token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only exception is collection syntax like CodeBlockItemList, which can be an empty set of items.

Copy link
Contributor

Choose a reason for hiding this comment

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

a.self is creating a DotSelfExpr syntax node while .self is creating a ImplicitMemberExpr one. If we want to be consistent here then shouldn't \.self be a KeyPathExpr wrapping an ImplicitMemberExpr ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also there is a difference in .a creating a ImplicitMemberExpr node while \.a is a MemberAccessExpr wrapped by KeyPathExpr.

Copy link
Contributor

Choose a reason for hiding this comment

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

a.self is creating a DotSelfExpr syntax node while .self is creating a ImplicitMemberExpr one. If we want to be consistent here then shouldn't \.self be a KeyPathExpr wrapping an ImplicitMemberExpr ?

After further discussion with Xi, this is explained by the parser treating these differently, .self being a unresolved_member_expr while \.self creating a dot_self_expr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, makes sense. Since SwiftSyntax is trying to be more uniform and elegant perhaps it would make sense if .self in all contexts was a MemberRefExpr with an identifier of self? Does it make sense for it to be its own thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i think this suggestion makes sense. We could reuse existing MemberAccessExpr to cover DotSelfExpr. We could also use MemberAccessExpr to represent ImplicitMemberExpr to further reduce the type complexity.

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi merged commit d2095a8 into swiftlang:master Jan 17, 2019
@nkcsgexi nkcsgexi deleted the dot-self-optional-base branch January 17, 2019 07:37
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