-
Notifications
You must be signed in to change notification settings - Fork 440
Generate token spec sets #1741
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
Generate token spec sets #1741
Conversation
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.
@ahoppen opened this PR to start a discussion if I'm on the right way. Added someinline comments.
I would also like a first round of some initial toughts of yours
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
case message | ||
case renamed | ||
case introduced | ||
case obsoleted | ||
case deprecated |
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 found that this doesn't contain the same as in AvailabilityArgumentKind
It have also a special handling
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.
These are exactly the interesting cases. A short-term solution would probably be to define the case from AvailabilityArgumentKind
that aren’t in AvailabilityLabeledArgumentLabel
in a separate TokenSpecSet
and then use self.at(anyIn:or:)
in Availability.swift:104. In general for these cases, we might need to consider if there is a bug in the parser or if we can model the syntax tree better so that the generated TokenSpecSet
matches the parser.
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.
Thank you. This is great. I wonder how many previously handwritten TokenSpecSet
we can replace by the generated ones.
I also wonder whether we can use the generated TokenSpecSet
in RawSyntaxValidation.swift.
case message | ||
case renamed | ||
case introduced | ||
case obsoleted | ||
case deprecated |
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.
These are exactly the interesting cases. A short-term solution would probably be to define the case from AvailabilityArgumentKind
that aren’t in AvailabilityLabeledArgumentLabel
in a separate TokenSpecSet
and then use self.at(anyIn:or:)
in Availability.swift:104. In general for these cases, we might need to consider if there is a bug in the parser or if we can model the syntax tree better so that the generated TokenSpecSet
matches the parser.
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
b9b176f
to
efaf78d
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.
Looks good to me. Only one comment inline.
CC @bnbarham because we talked about this at some point as well.
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserTokenSpecSetFile.swift
Outdated
Show resolved
Hide resolved
efaf78d
to
86cfd7f
Compare
@ahoppen we get this extension SimpleTypeIdentifierSyntax {
enum NameOptions: TokenSpecSet {
case identifier
case `self`
case `Self`
case `Any`
case keyword
case wildcard
init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.identifier):
self = .identifier
case TokenSpec(.`self`):
self = .`self`
case TokenSpec(.`Self`):
self = .`Self`
case TokenSpec(.`Any`):
self = .`Any`
case TokenSpec(.keyword):
self = .keyword
case TokenSpec(.wildcard):
self = .wildcard
default:
return nil
}
}
var spec: TokenSpec {
switch self {
case .identifier:
return .identifier
case .`self`:
return .keyword(.`self`)
case .`Self`:
return .keyword(.`Self`)
case .`Any`:
return .keyword(.`Any`)
case .keyword:
return .keyword
case .wildcard:
return .wildcard
}
}
}
} The This is the node Node(
kind: .simpleTypeIdentifier,
base: .type,
nameForDiagnostics: "type",
children: [
Child(
name: "Name",
kind: .token(choices: [
.token(tokenKind: "IdentifierToken"),
.keyword(text: "self"),
.keyword(text: "Self"),
.keyword(text: "Any"),
.token(tokenKind: "KeywordToken"),
.token(tokenKind: "WildcardToken"),
]),
classification: "TypeIdentifier"
),
Child(
name: "GenericArgumentClause",
kind: .node(kind: .genericArgumentClause),
isOptional: true
),
]
) |
86cfd7f
to
c18e339
Compare
c18e339
to
9c4f2e3
Compare
This is the solution: #1769 |
a527707
to
826f4d8
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.
I found very few usage of the new generated spec sets that matched 1-1.
I can try to find more.
And second, I found also some cases where there was a mismatch between the generated ones and the handwritten ones.
Should I try to apply your suggestion above, so we can see how many cases there are so we need what to do?
4b61ca8
to
c12f1d4
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.
I found very few usage of the new generated spec sets that matched 1-1.
🤩 Nice. Those were more than I expected, honestly. I like it.
And second, I found also some cases where there was a mismatch between the generated ones and the handwritten ones.
Should I try to apply your suggestion above, so we can see how many cases there are so we need what to do?
Trying to move more parser calls to the generated TokenSpecSet
would be great. I’d just like to do it in a follow-up PR do make it easier to review.
))) { (arena, _) in | ||
))) {(arena, _) in |
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.
Do you know where these changes come from?
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.
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.
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 normally also run swift package update
and swift package resolve
each time.
But forgot it 😅
But thanks for the tip!
Should we file a bug in spm repo?
It would be nice if it checked that automatically.
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.
Does swift package update
and swift package resolve
always fix the issue for you? Recently I didn’t have the feeling but I think I only ever ran one of the two commands, not both.
I think it’s expected that you need to run swift package update
. That matches the SwiftPM behavior when you depend on branches where you also only want to update your dependencies (and thus Package.resolved) when you explicitly request it. We should add that to our documentation.
If swift package resolve
is also necessary, I would say that’s a but in SwiftPM. If you could file an issue for that, that’d be great.
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.
Hmmm. Just had a look at the docs, maybe swift package resolve
is what we should be running? swift package update
will update Package.resolved
with the new hash and then swift package resolve
would update the packages to match that version:
The swift package resolve command resolves the dependencies, taking into account the current version restrictions in the Package.swift manifest and Package.resolved resolved versions file, and issuing an error if the graph cannot be resolved. For packages which have previously resolved versions recorded in the Package.resolved file, the resolve command will resolve to those versions as long as they are still eligible. If the resolved version's file changes (e.g., because a teammate pushed a new version of the file) the next resolve command will update packages to match that file. After a successful resolve command, the checked out versions of all dependencies and the versions recorded in the resolved versions file will match. In most cases the resolve command will perform no changes unless the Package.swift manifest or Package.resolved file have changed.
But having said that:
Most SwiftPM commands will implicitly invoke the swift package resolve functionality before running, and will cancel with an error if dependencies cannot be resolved.
So maybe it's a bug if we have to run it, unsure.
c12f1d4
to
30eade9
Compare
@swift-ci please test |
@swift-ci please test windows |
30eade9
to
d5f4a79
Compare
@swift-ci please test |
kind: .node(kind: .token), | ||
kind: .token(choices: [ | ||
.keyword(text: "target"), | ||
.keyword(text: "availability"), | ||
.keyword(text: "exported"), | ||
.keyword(text: "kind"), | ||
.keyword(text: "spi"), | ||
.keyword(text: "spiModule"), | ||
.keyword(text: "available"), | ||
]), |
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.
d5f4a79
to
35f61b0
Compare
35f61b0
to
34724b5
Compare
@swift-ci please test |
@swift-ci please test windows |
Context: #1727 (comment)