-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTGen] Move logic in BridgedASTContext.getIdentifier()
to ASTGen
#70220
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
Conversation
swiftlang/swift-syntax#2383 |
10c067f
to
1f46f64
Compare
@swift-ci Please smoke test |
if rawText == "_" { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this now check for tokenKind == .wildcard
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokenKind
instantiate String
. Let's expose TokenSyntax.tokenView.rawKind
as TokenSyntax.rawTokenKind
as a SPI, in followups.
func bridgedIdentifier(token: TokenSyntax?) -> BridgedIdentifier { | ||
token.map(bridgedIdentifier(token:)) ?? nil | ||
} | ||
|
||
/// Obtains the start location of the node excluding leading trivia in the | ||
/// source buffer. | ||
func bridgedSourceLoc(syntax node: some SyntaxProtocol) -> BridgedSourceLoc { | ||
BridgedSourceLoc(at: node.positionAfterSkippingLeadingTrivia, in: self.base) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the token:
and syntax:
argument labels aren't adding much useful information, could they be replaced by for:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the old variants of all these methods were marked @inline(__always)
, does that need to be preserved?
path: node.path.lazy.map { | ||
$0.name.bridgedIdentifierAndSourceLoc(in: self) as BridgedIdentifierAndSourceLoc | ||
self.bridgedIdentifierAndSourceLoc(token: $0.name) as BridgedIdentifierAndSourceLoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize this was already the case, but the return type overloading here makes me sad, maybe we should rename BridgedIdentifierAndSourceLoc
to BridgedLocatedIdentifier
or something and rename this overload of the method too
if rawText.count > 2 && rawText.hasPrefix("`") && rawText.hasSuffix("`") { | ||
text = .init(rebasing: text.dropFirst().dropLast()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess SwiftSyntax doesn't have a better way of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like .trim("`")
? No.
This is basically just slicing RandomAccessCollection
, and I think this is the simplest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant a utility for getting the actual identifier for an escaped identifier (e.g we have getText
vs getRawText
on Token in the old parser)
1f46f64
to
6adbd18
Compare
@swift-ci Please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per offline discussion, renamed:
bridgedIdentifier(token:)
-> generateIdentifier(_:)
bridgedSourceLoc(syntax:)
-> generateSourceLoc(_:)
etc.
6adbd18
to
d695726
Compare
@swift-ci Please smoke test |
Ideally ASTBriding should only do the neccessary work for briding. All non-trivial logic should be in ASTGen.
Now that `getIdentifier()` has some logic in it. It's not a simple bridging.
To avoid conflicts while migration. When all usage are migrated, this commit should be reverted.
d695726
to
2f46e6f
Compare
@swift-ci Please smoke test |
@available(*, deprecated, message: "use ASTContext.bridgedIdentifier(token:)") | ||
@inline(__always) | ||
func bridgedIdentifier(in astgen: ASTGenVisitor) -> BridgedIdentifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant "use ASTGenVisitor.generateIdentifier(_:)"
. Ditto other deprecations. Do we even need them though? It looks like you already audited all the calls.
getIdentifier()
has some logic includning_
->Identifier()
and stripping escaped identifier.Ideally,
ASTBridging
should only do the necessary work for bridging. All non-trivial logic should be in ASTGen.Also, move-back
getBridgedIdentifier()
,getBridgedSourceLoc()
, etc toASTGenVisitor
. Now thatgetIdentifier()
has some logic, so it's more natural inASTGenVisitor
. As forgetBridgedSourceLoc()
this provides syntactic consistency withgenerate(xxx:)
functions, e.g.