Skip to content
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

Possible updates/corrections to P4_16 spec grammar #928

Merged

Conversation

jafingerhut
Copy link
Contributor

I found a few differences between the latest p4lang/p4c P4_16 grammar, as compared to the grammar.mdk file in the P4_16 spec repository, when reviewing another issue on the spec recently.

I suspect that some of these differences might be due to experimental features in p4c, but some of them look like things we might want to update in the spec's grammar.mdk file. Happy to get comments about which differences are in which category, and update this PR.

p4-16/spec/grammar.mdk Outdated Show resolved Hide resolved
p4-16/spec/grammar.mdk Outdated Show resolved Hide resolved
p4-16/spec/grammar.mdk Outdated Show resolved Hide resolved
@jafingerhut
Copy link
Contributor Author

@mbudiu-vmw So you believe the other occurrences of THIS added by this PR are not related to abstract methods, and should be included in spec grammar?

@mihaibudiu
Copy link
Contributor

this is only used with abstract methods.

@jafingerhut
Copy link
Contributor Author

@mbudiu-vmw The annotationToken had one production in grammar.mdk annotationToken -> THIS which I have removed in my latest commit, along with the two occurrences of THIS that earlier commits of this PR added. Not sure if it should be in the annotationToken rule or not, in the spec.

@mihaibudiu
Copy link
Contributor

@mbudiu-vmw to check the "voids".

@@ -2642,6 +2642,7 @@ P4 supports extern object declarations and extern function declarations using th
externDeclaration
: optAnnotations EXTERN nonTypeName optTypeParameters '{' methodPrototypes '}'
| optAnnotations EXTERN functionPrototype ';'
| optAnnotations EXTERN name ';'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jafingerhut Action item for me to propose adding a sentence or two to the spec for this. The basic idea is that it enables giving a kind of forward declaration for an extern name, before it is fully defined. Chris Dodd believes the motivation for this being in the grammar was for Register and RegisterAction definition in TNA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some proposed text for this, which should be reviewed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During 2021-May-03 LDWG meeting it was decided to leave forward extern declarations out of the spec. It will remain in the p4c implementation, which already includes several features marked experimental that are not in the spec.

AI Andy: Remove this part of this PR and update it today.

@@ -3057,6 +3058,7 @@ typeArg
: DONTCARE
| typeRef
| nonTypeName
| VOID
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbudiu-vmw Mihai took the action item in LDWG meeting to think about why VOID is here, and also the occurrence in the production of the realTypeArg nonterminal of the grammar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this may make sense for some extern objects that could be instantiated with "void" for some type parameters.

;
~ End P4Grammar

The last case is a forward extern declaration, intended for declaring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this allows mutually-recursive declarations (instantiations). Otherwise this would be impossible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know of an example, other than Chris Dodd's mention during the LDWG meeting that perhaps this was added because of the way that the TNA architecture defines the Register and RegisterAction externs. He did not sound confident that this was the motivating reason, so it might be some other reason. I do not see any occurrences of forward declarations of externs in this public file, for example: https://github.com/barefootnetworks/Open-Tofino/blob/master/share/p4c/p4include/tofino.p4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following discussion at the 2021-May-03 LDWG meeting, I have removed all changes related to forward extern declarations from this PR.

It shall remain an experimental feature implemented in p4c, but not
made part of the language spec without further consideration.
@jafingerhut
Copy link
Contributor Author

@mbudiu-vmw I do not recall whether it was decided to merge this PR into the spec today, but if it was, note that I have removed all of the changes related to the forward declarations of externs from this PR, as suggested during today's LDWG meeting.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have agreed to merge.

@mihaibudiu mihaibudiu merged commit c542447 into p4lang:main May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants