-
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
Even in
arguments must be saved to temporaries if aliased
#2640
Conversation
I have tested your code for example
after SideEffectOrdering your code transformed to
but we expect the transformation look like
Are you going to post another issue with this? |
in
arguments must be saved to temporaries if aliased
You are right, this requires a recursive traversal of the argument expressions. I will try to post a fix that takes this insight into account. |
Here is another attempt to solve this problem. The solution is to compute all modified expressions in a call. These must be just left-values. Then scan all arguments and use temporaries for all which alias with one of the modified expressions. I have also realized that calls that invoke tables were not handled properly; such calls will invoke actions, and the actions can mutate all variables in scope. In the absence of a precise interprocedural analysis the conservative solution is to just copy in and out all arguments when one of them is a table invocation. Here is an example:
Since we don't know in this analysis what t.apply() will mutate, z must be copied in and out. |
What is the conclusion of discussion [https://github.com/p4lang/p4-spec/issues/867] about order-dependent constructs?
this:
or this?
|
I have one more question. I have looked at specification and there is:
Your code transformed to this
What is the right transformation? |
My result is still incorrect. |
I don't think that the discussion has reached a conclusion.
I think that the spec says you have to first evaluate the first argument, which means that you need to call g(h.h.a), which includes mutating h.h.a, before you evaluate the second argument. So that means that the first translation is the correct one. |
The current failure in Gauntlet is a false positive related to header indices. Those are tricky to get right because copy-in/copy-out has to be performed on symbolic indices. This is also the reason why the bug in |
I generated and tested 10000 programs for this particular pull request and did not find any new issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request has been sitting here for a while. I can't comment on the concrete code changes because I am lacking the context but I am approving this based on the fact that extensive fuzzing has not revealed any issues with these changes.
This fix is inspired by #2638, but it is simpler; it tweaks the existing function mayAlias instead of creating a new case to handle functions.
Fixes #2288.
Amazingly, there was a test called side_effects.p4 which was designed to test exactly these cases and the output produced for that test result was wrong! Hopefully people do not write such confusing programs in practice.