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

[experimental] Allow actions to instantiate externs #3938

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mihaibudiu
Copy link
Contributor

This shows an example that would allow the effect of Direct registers in P4.

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@mihaibudiu mihaibudiu requested a review from jafingerhut March 24, 2023 22:52
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("C.RW") action RW() {
@name("C.local") Local<bit<32>>() local_0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change permit multiple actions in the same control C that each declare a local extern instance with the same name local? Local declarations inside of action bodies definitely seems to imply that this should be possible.

Note that adding the action name to the auto-generated @name annotation IS NOT ENOUGH to make that possible right now, because we also allow multiple actions with the same name to be defined in the same control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

two externs declarations in separate actions will be distinct objects, even if they have the same local name.

Copy link
Contributor

Choose a reason for hiding this comment

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

The @name annotation "C.local" is "enclosing_control_name.local_instance_name_inside_action", yes?

I guess I will try out this PR's changes myself and find out, but what if there was another action that also had an instance with the same name local inside of control C? Would their @name annotations be identical? That should be considered a bug, shouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

See the attached test program action-register2.p4, which is just a minor variation of your action-register.p4. Look at the output program from the last FrontEnd pass. It has two DirectRegister instances with @name("C.local").
It seems like a bug to me that p4c is intentionally generating identical @name annotations for two different instances.

If you do not consider that a bug, why not?

What can a control plane API generation pass do with this that is possibly useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Attaching zip file this time.
p4c-pr-3938-maybe-bug.zip

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: I am not saying that I think if this is considered a bug, that it needs to be fixed right away. It would be best to worry about it only if we do move forward with enhancing the language with the ability to instantiate extern objects within action bodies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The right solution is to also use the action name as part of the generated name.

Copy link
Contributor

Choose a reason for hiding this comment

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

But don't we allow more than one action with the same name, too?

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 am not sure we do. Even if we do, they can use annotations to specify different names.

@mihaibudiu mihaibudiu marked this pull request as draft March 27, 2023 20:43

control C() {
action RW() {
Local<bit<32>>() local;
Copy link
Contributor

Choose a reason for hiding this comment

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

How many instantiations does this create? I assume from the following comment on the merge request:

This shows an example that would allow the effect of Direct registers in P4.

... that there is a separate instance per P4 table entry that invokes this action, and also per each apply block call-site that directly invokes this action, rather than there being e.g. one instance or one per P4 table or anything like that. And further, there's no kind of connection between any of the instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably would restrict such actions to being called from tables only. At least that is the use case that is requested.
Your interpretation is the intended one otherwise.

@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants