-
Notifications
You must be signed in to change notification settings - Fork 447
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
Fixing parserUnroll bug for sequential next operator usage #3193
Fixing parserUnroll bug for sequential next operator usage #3193
Conversation
Any way to write a test for this? It will take a while until the loops unrolling pull request for p4test is in. |
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.
Looks fine from my point of view. @mbudiu-vmw any comments?
midend/parserUnroll.cpp
Outdated
} | ||
if (expression->member.name == IR::Type_Stack::lastIndex) { | ||
return new IR::Constant(IR::Type_Bits::get(32), idx); | ||
} else { | ||
state->statesIndexes[expression->expr->toString()] = idx; | ||
state->statesIndexes[expression->expr->toString()] = idx + offset; |
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.
expression->expr->toString()
is there no better way to map this?
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.
clone_id can't be applied here. It is possible to implement operator< for IR::Member, but IR::Member::member still contains cstring. So, for now, I think that this is the best solution.
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.
clone_id can't be applied here. It is possible to implement operator< for IR::Member, but IR::Member::member still contains cstring. So, for now, I think that this is the best solution.
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.
node->toString() should only be used for reporting user messages.
Such usage in the compiler is unsafe, since the different expressions may generate identical toString outputs.
The spec does actually not mandate this behavior. The spec says that |
Filed p4lang/p4-spec#1048 |
midend/parserUnroll.cpp
Outdated
} | ||
if (expression->member.name == IR::Type_Stack::lastIndex) { | ||
return new IR::Constant(IR::Type_Bits::get(32), idx); | ||
} else { | ||
state->statesIndexes[expression->expr->toString()] = idx; | ||
state->statesIndexes[expression->expr->toString()] = idx + offset; |
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.
node->toString() should only be used for reporting user messages.
Such usage in the compiler is unsafe, since the different expressions may generate identical toString outputs.
I added StackVariable class to support std::map<IR::Member, ...> |
const IR::Expression& operator*() const { return *expr; } | ||
const IR::Expression* operator->() const { return expr; } | ||
|
||
// Implements comparisons so that StateVariables can be used as map keys. |
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.
If you use unordered_map you only need equality and hash.
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.
Does p4c have some hash for IR::Expression? I used std::map. So, I turned back to operator<
break; | ||
else | ||
idx = i; | ||
unsigned offset = 0; |
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.
can you explain what is happening here?
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.
if it is a next operator then we need to make offset = 1, otherwise it should be 0. I did some refactoring there.
You do not seem to have addressed the comments made in my previous review. |
It looks very strange, because in the documentation of P4C we have: |
See https://p4.org/p4-spec/docs/P4-16-v1.2.2.html#sec-packet-extract-one, in particular the pseudo-code for extract. It says nothing about header_unions. That is arguably wrong, but it should be changed if it is wrong. |
I see. So, you said that "we should first take this change to the language design committee". How to do that? |
For a change like this, which is sort of a bug fix, you can propose a PR on the p4-spec repository. Then we'll discuss at the next LDWG. |
@fruffy, @mbudiu-vmw Can we merge it? |
These changes fix bug of parserUnroll which appears in issue561-6-bmv2.p4 example.
This example contains the following code:
ParserUnroll generated the following state before these changes: