-
Notifications
You must be signed in to change notification settings - Fork 441
Move SyntaxClassifier to a separate module #999
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
Move SyntaxClassifier to a separate module #999
Conversation
ed47e46
to
f4f4dbf
Compare
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.
Rewrite SyntaxClassifier in terms of Syntax nodes? @rintaro I think you tried this and it wasn’t performant enough, right?
I actually didn't try this. Maybe it's interning to try it, but I'm totally OK with using SPI RawSyntax
here.
Expose RawSyntax as UnsafeSyntax (or something like that) instead of as SPI
Leave SyntaxClassifier in the SwiftSyntax module
I strongly prefer keeping RawSyntax
a SPI. SPI is not a big deal, it's just a user side declaration "yes, I import extra types/functions knowing what I am doing".
But I don't think we want to expose SyntaxData
even as SPI. When we want to expose any SyntaxData
API, we can do that by implementing Syntax
API, and it doesn't cost much.
@@ -10,6 +10,8 @@ | |||
// | |||
//===----------------------------------------------------------------------===// | |||
|
|||
@_spi(RawSyntax) @_spi(SyntaxData) import SwiftSyntax |
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 SyntaxData.contextualClassification
doesn't need to be SyntaxData
, could you rewrite it to Syntax.contextualClassification
?
@@ -148,7 +148,8 @@ extension RawSyntax { | |||
} | |||
|
|||
/// Whether or not this node is a token one. | |||
var isToken: Bool { | |||
@_spi(RawSyntax) | |||
public var isToken: Bool { |
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 far as the type itself is marked as @_spi(Name)
, those members doesn't need to be @_spi(Name)
. We can just make them public
, without @_spi
. (I know other members e.g. var kind
has it).
Sources/SwiftSyntax/SyntaxData.swift
Outdated
struct SyntaxData { | ||
@_spi(SyntaxData) | ||
public struct SyntaxData { |
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.
Let's avoid exposing SyntaxData
by rewriting SyntaxData.contextualClassification
to Syntax.contextualClassification
.
f4f4dbf
to
db6c5d0
Compare
I updated the PR to not use There is a small performance penalty associated with the move (I believe because we can’t do whole module optimization anymore), but I think it’s acceptable (measurements from Release
Debug
|
@swift-ci Please test |
db6c5d0
to
856115e
Compare
@swift-ci Please 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.
LGTM!
856115e
to
85837e7
Compare
85837e7
to
19e9f7f
Compare
@swift-ci Please test |
The goal of this PR is to move
SyntaxClassifier
out of theSwiftSyntax
module into its own dedicated. I’m not really happy with the PR yet becauseSyntaxClassifier
usesRawSyntax
pretty extensively and this requires us to expose more methods from SwiftSyntax as SPI. AFAICT the options here are:SyntaxClassifier
requires the use of SPISyntaxClassifier
in terms ofSyntax
nodes? @rintaro I think you tried this and it wasn’t performant enough, right?RawSyntax
asUnsafeSyntax
(or something like that) instead of as SPISyntaxClassifier
in theSwiftSyntax
moduleI thought I set up this PR as a base for discussion.
rdar://98318240