Add support for compound assignment operators#3669
Conversation
This patch adds support for compound assignment expressions of the form `E1 op= E2`. Signed-off-by: Radostin Stoyanov <radostin.stoyanov@eng.ox.ac.uk>
| $1, $3, $6); | ||
| $$ = new IR::MethodCallStatement(@1 + @7, mc); } | ||
|
|
||
| | lvalue "+=" expression ";" |
There was a problem hiding this comment.
I am not sure this is the right semantics. This implementation will repeat the side effects on the lhs twice.
There was a problem hiding this comment.
Note most lvalue by definition could not have a side effect.
The only one which I can think of is: headerstack[f(a)].b where f is defined to take 1 arguments which is inout (you could do something similar with externs too).
There was a problem hiding this comment.
regardless of the inout arguments, a method call may have arbitrary side effects within in, and the way this code duplicates the reference to the lhs, a method call inside an index would end up being called twice. We have a pass (DoSimplifyExpressions) that exists to deal with this kind of program, but there are a number of other passes that currently must run before it (such as typeChecking) that would need to understand what is going on. So this almost certainly needs a new IR node type (some kind of op-assignment statement) to represent this until SimplifyExpressions can turn it into a normal AssignmentStatement, and all the passes that run before need to know about it.
|
We will need to be careful if we want to ensure that l-values never have side effects. I am not even sure that's true of the current language design and it would be fragile to ensure it going forward. |
|
@rst0git are you still interested in completing this feature? Do you need help with the |
|
@rst0git, can you let us know if you are still working on this? We'd be glad to see it added, but need to fix the side-effect issue... |
|
@jnfoster I'm sorry for the delayed response. I will update the pull request in the next few days. |
|
Superceeded by #5108 |
This pull request adds support for compound assignment expressions of the form
E1 op= E2as discussed in p4lang/p4-spec#1144 and p4lang/p4-spec#1139.Fixes #3258