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

Compiler Bug: Null stat #2258

Closed
fruffy opened this issue Mar 23, 2020 · 3 comments
Closed

Compiler Bug: Null stat #2258

fruffy opened this issue Mar 23, 2020 · 3 comments
Assignees
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.

Comments

@fruffy
Copy link
Collaborator

fruffy commented Mar 23, 2020

Using MethodCallExpressions with the function return value as key in tables leads to a compiler bug in the functionsInlining pass.

function_call_as_key.p4.txt

@mihaibudiu mihaibudiu self-assigned this Mar 23, 2020
@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Mar 23, 2020
@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Mar 23, 2020
@mihaibudiu mihaibudiu removed the fixed This topic is considered to be fixed. label May 1, 2020
@DarinkaNesovic
Copy link

I've read comments related to this issue on issue #2259 and I understand that it's needed to allow function calls inside table key parameters.
In the example that is given on this issue, function that is used as key value is pure.
So, my question is: What kind of functions should be inside key values? Only pure or functions with side effect as well?

@mihaibudiu
Copy link
Contributor

We have had a few discussions about places where side-effects are forbidden in the language design working group, but we haven't reached consensus. I believe that the current thinking is that we can actually support function calls in key expressions, because the compiler can lift them before the table application. So what is needed is a pass to do this properly.

@jafingerhut
Copy link
Contributor

This change was approved for adding to the official P4_16 language spec some month ago: https://github.com/p4lang/p4-spec/pull/834/files

At least for table key expressions, it explicitly allows side effects, and requires a particular evaluation order.

The code transformation shown in that example would be best not to do for all tables, but preferably only for those tables that have at least one key expression with a side effect. e.g. If only @pure and @nosideeffects annotated extern functions are used, or isValid(), then there should not be any need to create temporary variables.

@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Jun 21, 2021
@fruffy fruffy closed this as completed Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.
Projects
None yet
Development

No branches or pull requests

4 participants