-
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
SideEffectOrdering: Regression? #2288
Comments
The sample program is missing the |
Just adding another instance of this issue with side-effects in table calls. The program control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
action simple_action_0() {
h.eth_hdr.eth_type = 16w3;
}
action dummy_action_0(inout bit<16> val1, in bit<16> val2) {
}
table simple_table_0 {
key = {
h.eth_hdr.src_addr: exact @name("key1") ;
}
actions = {
simple_action_0();
}
default_action = simple_action_0();
}
apply {
dummy_action_0(h.eth_hdr.eth_type, (simple_table_0.apply().hit ? 16w1 : 16w2));
}
} is transformed into control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
action simple_action_0() {
h.eth_hdr.eth_type = 16w3;
}
action dummy_action_0(inout bit<16> val1, in bit<16> val2) {
}
table simple_table_0 {
key = {
h.eth_hdr.src_addr: exact @name("key1") ;
}
actions = {
simple_action_0();
}
default_action = simple_action_0();
}
bool tmp;
bit<16> tmp_0;
bit<16> tmp_1;
apply {
{
tmp = simple_table_0.apply().hit;
if (tmp) {
tmp_0 = 16w1;
} else {
tmp_0 = 16w2;
}
tmp_1 = tmp_0;
dummy_action_0(h.eth_hdr.eth_type, tmp_1);
}
}
} which also misses the copy-out. |
@fruffy I do not see what is wrong with the after vs. before code you describe in this comment: #2288 (comment) It is synthesizing code to evaluate the expression Or perhaps what I am missing here is "what should the initial value of the first parameter of |
Well tmp = h.eth_hdr.eth_type;
tmp_0 = simple_table_0.apply().hit;
if (tmp_0) {
tmp_1 = 16w1;
} else {
tmp_1 = 16w2;
}
tmp_2 = tmp_1;
dummy_action_0(tmp, tmp_2);
h.eth_hdr.eth_type = tmp; // copy inout result back into h.eth_hdr.eth_type So that the initial value of Edit: Just saw the update. Yeah the code is very odd, the extern example is much more convincing. But it is the same kind of problem as discussed in Section |
So in your proposed modified code in this comment: #2288 (comment) note that (a) it should be the same as it was before the call to (b) it should be as modified by the call to |
My bad. The code was missing the final copy-out line. With that the result should be whatever modification has been applied to |
And if we can get confused about it, that is the reason why I have sometimes mentioned that I would consider it semi-reasonable if a P4 compiler (at least the front end) rejected such programs as errors, because it depends so subtly upon the order of evaluation. If not that (which I know is probably a kind of odd thing to propose that a language actually treat such things as errors, versus warnings or unspecified behavior), then at least have a lint tool that can warn programmers about such strange things. |
I personally think it would make sense to prohibit method calls with side-effects as function call arguments. They can cause a lot of confusion and pain (in addition, there are also things like |
Change made in sideEffects.cpp and sideEffects.h There are side efects when two arguments are aliases and one of them is in and other is out or inout. In addition to a simple example such as this f(val, val) (T f(in T x, inout T y) ) the following cases have been treated - f(g(val), s[val].x) - f(s[val].x, g(val)) - f(val, g(val)) - f(g(val), val) - and other similar cases with multiple arguments.
I appreciate @milicaperic . I am reviewing this. |
Hello.
I have the following program, which I reduced to look just like the example in the spec:
After
SideEffectOrdering
, the program looks like thiswhich implies that
h.h.a
is3
instead of being unchanged.According to section
6.7
, I would expect the transformation to look something likeso the value of
h.h.a
does not change since f does not modify the input.2288.p4.txt
2288.stf.txt
The text was updated successfully, but these errors were encountered: