-
Notifications
You must be signed in to change notification settings - Fork 446
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
Semicolons in the parser are seen as invalid #2127
Comments
If you see the p4-16 grammar for the parser and its parser statement, an emptyStatement or https://github.com/p4lang/p4-spec/blob/master/p4-16/spec/grammar.mdk#L138 If you patch these code changes in your p4c workspace, you will see the error of this issue go away.
|
Whether this is a bug, seems to depend upon whether it is considered a bug by the p4c developers that the --top4 option can produce a P4 program at some intermediate compiler step that is not syntactically correct according to the spec. It does seem to be creating such a syntactically incorrect program in this case. |
Adding this to the language (allowing emtpy |
Ah, sorry, I just used fruffy's P4 program and thought the program has the issue. Now, I see some pass is adding the emptyStatement to the p4i file. Sure, then it's an issue with some pass because if the grammar does not support the statement a pass should not add such a statement to any parser code. Before we go to the LDWG, it would be good to find out why a pass is generating incorrect grammar. However, if the emptyStatement is removed by the time FrontEndLast pass is invoked, we could discuss more what to do with this issue. |
@fruffy I wonder if fabric.p4 is a p4-14 program which was used? I googled for the program and found one which is p4-14 code. |
@hesingh fabric.p4 is a P4_16 program, with a version from a particular date copied into the p4c source code. These comments in the p4c copy tell where the original version was copied from, and what few small changes were made in the p4c copy: https://github.com/p4lang/p4c/blob/master/testdata/p4_16_samples/fabric_20190420/fabric.p4#L17-L30 |
@jafingerhut thanks. I do see the same issue with fabric.p4 that fruffy reported. However, when I just dumped FrontEndLast, the issue does not exist. As I said before, if FrontEndLast does not show any incorrect code, I wonder if one should chase any intermediate pass's incorrect code? |
"I wonder if one should chase any intermediate pass's incorrect code?" That is really up to the people who spend the most time maintaining p4c, which is my point of this earlier comment: #2127 (comment) I do not presume to answer that question for them. |
The situation is a bit tricky. There are places where the compiler temporarily generates internally code that is not serializable as pure P4-16, but then eliminates such constructs. For example, there's an optimization pass which generates That being said, we could allow empty statements in the parser. Maybe even ifs? |
I don't see any ambiguity if an empty statement is added to the parser. Regarding if-statements in parser, I have my reservations. The parser's |
I also do not think this is a critical issue but it may be worth documenting. For context, we are currently working on a tool that analyzes correctness of individual passes in the P4 compiler and inconsistencies like these occasionally pop up. |
@fruffy The latest p4c should now accept empty statements in a parser. Can you try testing again, and if all goes well, close this issue as fixed? |
Yes, the issue got fixed so we can close this now. |
There is another expression that is seen as invalid by the p4-parser. This again happens in the parser function and is generated by some passes.
This error can be reproduced by simply adding
;
after state_start.An example where this occurs is fabric.p4 after the
fabric-FrontEnd_31_SimplifyDefUse
pass:then run
./p4c/build/p4c dmp/fabric-FrontEnd_31_SimplifyDefUse.p4i
on the generated file.
This may or may not be related to #2126. Are semicolons valid in the parser? They seem to be in control functions.
2127.txt
The text was updated successfully, but these errors were encountered: