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

Clarification on directionless action arguments behaving like direction in #1350

Closed
jaehyun1ee opened this issue Nov 25, 2024 · 6 comments
Closed

Comments

@jaehyun1ee
Copy link
Contributor

The spec mentions about directionless action arguments:

For an action, a directionless parameter indicates that it is “action data”. See Section 14.1 for the meaning of action data, but its meaning includes the following possibilities:

  • The parameter's value is provided in the P4 program. In this case, the parameter behaves as if the direction were in.

The phrase "behaves as if the direction were in", I believe, is not quite clear, particularly regarding compile-time known-ness.

The differences between an in parameter and a directionless parameters, aside their copy-in/out semantics, is:

  • in can be implicitly cast, while directionless cannot (as per the current spec)
  • directionless argument should be compile-time known, while no such restriction exists for in argument.

So, I wonder if "behaves as if the direction were in" also imply that the directionless arguments supplied to actions in a P4 program (not by the control plane) need not be a compile-time known value?

Relevant to this issue, issue473.p4 in the p4c test suite is expected to be rejected by the frontend.

action b(inout bit<32> x, bit<8> data) {
    meta.a = meta.a ^ (bit<4>) x ^ (bit<4>) data;
}
table t1 {
    key = { hdr.ethernet.srcAddr : exact; }
    actions = { b(meta.c); }
    default_action = b(meta.c, (bit<8>) meta.d);
}
issue473.p4(70): [--Werror=type-error] error: (bit<8>)meta.d: action argument must be a compile-time constant
        default_action = b(meta.c, (bit<8>) meta.d);
                                   ^^^^^^^^^^^^^^^
@jafingerhut
Copy link
Collaborator

Would it address your question fully if we were to replace this text of the spec:

The parameter's value is provided in the P4 program. In this case, the parameter behaves as if the direction were in.

with something like the following?

The parameter's value is provided in the P4 program. In this case, the parameter behaves as if the direction were in, with the restriction that arguments must be compile-time known.

@jaehyun1ee
Copy link
Contributor Author

Yes, I think it addresses my question :) Would it be alright if I create a PR based on your suggestion?

@jafingerhut
Copy link
Collaborator

Certainly. Please do.

@jaehyun1ee
Copy link
Contributor Author

I just found out that I overlooked the spec saying:

For an action, a directionless parameter indicates that it is "action data". See Section 14.1 for the meaning of action data, but its meaning includes the following possibilities:

  • The parameter’s value is provided in the P4 program. In this case, the parameter behaves as if the direction were in. Such an argument expression need not be a compile-time known value.

So it was stated that a directionless action argument need not be compile-time known.
Seems like the test program wasn't in line with the current spec.

@jafingerhut
Copy link
Collaborator

It is a small enough detail that it is easy to miss (I did in my comment above -- good that you found it later). Perhaps it would be more appropriate to file a bug against p4c, then, if it does not follow the spec?

@jaehyun1ee
Copy link
Contributor Author

I believe so. Closing in favor of p4c issue!

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

No branches or pull requests

2 participants