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

Fix for issue #542 #544

Merged
merged 3 commits into from
Mar 5, 2018
Merged

Fix for issue #542 #544

merged 3 commits into from
Mar 5, 2018

Conversation

mihaibudiu
Copy link
Contributor

No description provided.

@jnfoster
Copy link
Collaborator

LGTM, but probably we should discuss briefly at the January P4 LDWG meeting?

@jnfoster jnfoster self-requested a review December 23, 2017 04:05
@@ -3620,6 +3635,10 @@ parser Tcp_option_parser(packet_in b, out Tcp_option_stack vec) {
}
~End P4Example

Two header unions can be compared for equality (==) or inequality (!=)
if they have the exact same type. The unions are equal if and only if
all their corresponding fields are equal.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only one field in a union can be "hot" so the "all" seems potentially confusing.

@@ -3620,6 +3635,10 @@ parser Tcp_option_parser(packet_in b, out Tcp_option_stack vec) {
}
~End P4Example

Two header unions can be compared for equality (==) or inequality (!=)
if they have the exact same type. The unions are equal if and only if
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use the same phrasing as for structs here? (i.e., "same type and fields can be recursively...") I'm not sure why this is "exact same type."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps this is opening a can of worms by asking this question, but it seems that most places in P4_16 use what I think @jnfoster called "structural typing", which I believe means that two types are considered "compatible" for purposes of comparison, assignment, and passing as a run-time parameter, if they have the same number of sub-elements, in the same relative order, and recursively those also have compatible types. For example, the existing spec and open source tools treat any values typedef'd with different names, but with the same bit<17> underlying type, as compatible.

This is as opposed to "nominal typing", I think, where such an assignment between two typedef'd values with different typedef names, but the same underlying bit<17> type, would require an explicit cast or it would be a type error?

If I've got those definitions at least approximately correct, then it sounds like @jnfoster's comment here is that "exact same type" is misleading, if structural typing is allowed for determining whether two values can be compared via == or !=. They don't have to be the exact same type, just structurally the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typedef just introduces another name for the same type, but the type is essentially the same.
This is like C.
Everywhere we require types to be the same, not structurally the same.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So is there a reason that one of these proposed additions says "exact same types", but the others do not?

@mihaibudiu
Copy link
Contributor Author

This is ready for re-review.

Copy link
Collaborator

@jafingerhut jafingerhut left a 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. Thanks.

Two header stacks can be compared for equality (==) or inequality (!=)
only if they have the same element type and the same length. Two
stacks are equal if and only if all their corresponding elements are
equal.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, one comment here. Do we want to explicitly say that the 'nextIndex' hidden state that exists at least during parsing time is not relevant for equality comparisons between header stacks? I know that is implicit in the way it is worded here, but explicit might be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes me realize that the situation is pretty ugly: since assignment is supposed to preserve the nextIndex field, this means that this should field should be even preserved between architectural blocks. So the nextIndex left over in the ingress parser could be accessed in the egress parser!

It probably should not be used for comparisons, although one could argue either way.

Copy link
Collaborator

@jafingerhut jafingerhut Jan 26, 2018

Choose a reason for hiding this comment

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

In PSA, the only way to preserve an already-parsed header from ingress to egress would be to carry the header in user-defined metadata. Kind of an odd choice, but I guess not currently disallowed by the architecture spec.

Not sure if there would be any desired use cases for preserving this kind of thing, but I guess you are worrying about the general case of everything possible (unless it has been explicitly prohibited).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you considered the idea of allowing constructs that are not in the base P4_16 language spec in the intermediate representations that you can spit out in the compiler? That would allow you to explicitly define a my_hdr_stack_variable.nextIndex field in that slightly extended language, even if it is not available to P4_16 developers.

Or just go for it and make such a field part of the language explicitly, available everywhere, but not for P4_16 programmer convenience, but because it is helpful in some compilers?

@jnfoster jnfoster merged commit dc5c650 into master Mar 5, 2018
@mihaibudiu mihaibudiu deleted the issue542 branch May 16, 2018 22:46
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.

3 participants