-
Notifications
You must be signed in to change notification settings - Fork 298
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
[FIRRTL][FIRParser] Tokenize Commas #7206
Conversation
9b69933
to
b9bbe93
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.
The implementation generally looks good to me! I agree that comma as whitespace is weird and should be fixed but practically I guess the hack improved parser performance quite a bit :) I'm curious how parser performance changes due to increased toke size.
b9bbe93
to
15b0c09
Compare
Technically this is only mandatory as of 4.0.0, chipsalliance/firrtl-spec#191 . However I think just requiring this regardless is fine re:compatibility. I too am interested in impact of this. |
@dtzSiFive Thanks for pointing that out. I feel like I removed that verbiage and then forgot it. And thank you for pointing out that I didn't feature-gate this. I'm not sure how I should proceed on that point. I had plans to add a lot of small tweaks to the syntax, but it could easily make it a bit of spaghetti to keep strict backwards compat. But then again, I don't know much people care about that compatibility. |
Note: no version of Chisel that I have ever seen has ever not emitted commas unconditionally. There should be no risk in changing this and it should be backwards compatible. |
42fd587
to
d6085df
Compare
c89b7ff
to
406b95c
Compare
if (consumeIf(FIRToken::comma)) { | ||
if (parseRUW(ruw) || parseOptionalInfo()) | ||
return failure(); | ||
} |
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 parseOptionalInfo needs to be called regardless of RUW.
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.
Yea, this both allows a dangling comma and doesn't properly parse optional parts. I think most consumeIf calls I saw are probably wrong.
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.
Thanks for the catch, @uenoku.
@darthscsi I'm not sure what you mean. Feel free to add more information. If you have an example that should be added to the parse-errors file, that would 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.
Thanks for pushing on this! Left some feedback, still going through but wanted to submit that much now.
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.
Please add explicit tests that dangling commas in lists and before optional components are rejected.
406b95c
to
2bf2484
Compare
Add a few more tests.
805a57f
to
529903b
Compare
Done. |
If there are no other comments, could someone merge? |
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 but can we merge after firtool 1.77 release? I don't believe this PR will cause an issue but just in case.
Sounds good to me, @uenoku |
Due to historical circumstances, the SFC parser for FIRRTL treated commas (
,
) as whitespace. This behavior was carried over into the CIRCT implementation offirtool
.This behavior is utterly bizarre.
Moreover, the FIRRTL spec has indicated comma tokens (
,
) for at least every version since last year.This PR removes this quirk and properly tokenizes commas, requiring them in the places dictated by the FIRRTL spec.
The impact of this PR should be low, but it may break code (in CIRCT, in Chisel, and elsewhere) in places where FIRRTL was being emitted with a loose interpretation, or where the spec was ambiguous.
Changes:
','
from the list of "horizontal whitespace" and added an explicitFIRToken::comma
token.parse*()
methods to consume the tokens.first
to skip parsing comma tokens on the first iteration. Please check me here, since I learned C++ before lambdas were a thing.smem
).layer
decls need commas. I opted for commas. I can swap if I got this backwards.parseRUW()
as a non-optional variant ofparseOptionalRUW()
, since the comma token can be used to determine optionality in one case.