-
Notifications
You must be signed in to change notification settings - Fork 442
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
Implict cast fix #4399
Merged
Merged
Implict cast fix #4399
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <core.p4> | ||
|
||
enum bit<2> foo_t { A = 0, B = 1, C = 2, D = 3 } | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
action set_x(foo_t v) { m.x = v; } | ||
|
||
table t { | ||
key = { m.y : exact; } | ||
actions = { set_x; } | ||
default_action = set_x(2w0); // not allowed to implicitly cast to serenum | ||
} | ||
|
||
apply { | ||
t.apply(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <core.p4> | ||
|
||
enum bit<2> foo_t { | ||
A = 0, | ||
B = 1, | ||
C = 2, | ||
D = 3 | ||
} | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
action set_x(foo_t v) { | ||
m.x = v; | ||
} | ||
table t { | ||
key = { | ||
m.y: exact; | ||
} | ||
actions = { | ||
set_x; | ||
} | ||
default_action = set_x(2w0); | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
serEnumImplCast.p4(16): [--Werror=type-error] error: '2w0': values of type 'bit<2>' cannot be implicitly cast to type 'foo_t' | ||
default_action = set_x(2w0); // not allowed to implicitly cast to serenum | ||
^^^ | ||
serEnumImplCast.p4(3) | ||
enum bit<2> foo_t { A = 0, B = 1, C = 2, D = 3 } | ||
^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <core.p4> | ||
control generic<M>(inout M m); | ||
package top<M>(generic<M> c); | ||
|
||
enum bit<2> foo_t { A = 0, B = 1, C = 2, D = 3 } | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
action set_x(bit<2> v) { m.x = v; } | ||
|
||
table t { | ||
key = { m.y : exact; } | ||
actions = { set_x; } | ||
default_action = set_x(foo_t.A); | ||
} | ||
|
||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
top(c()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <core.p4> | ||
|
||
control generic<M>(inout M m); | ||
package top<M>(generic<M> c); | ||
enum bit<2> foo_t { | ||
A = 2w0, | ||
B = 2w1, | ||
C = 2w2, | ||
D = 2w3 | ||
} | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
action set_x(bit<2> v) { | ||
m.x = v; | ||
} | ||
table t { | ||
key = { | ||
m.y: exact @name("m.y"); | ||
} | ||
actions = { | ||
set_x(); | ||
} | ||
default_action = set_x(foo_t.A); | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
top<meta_t>(c()) main; |
35 changes: 35 additions & 0 deletions
35
testdata/p4_16_samples_outputs/serEnumImplCast-frontend.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <core.p4> | ||
|
||
control generic<M>(inout M m); | ||
package top<M>(generic<M> c); | ||
enum bit<2> foo_t { | ||
A = 2w0, | ||
B = 2w1, | ||
C = 2w2, | ||
D = 2w3 | ||
} | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
@name("c.set_x") action set_x(@name("v") bit<2> v) { | ||
m.x = v; | ||
} | ||
@name("c.t") table t_0 { | ||
key = { | ||
m.y: exact @name("m.y"); | ||
} | ||
actions = { | ||
set_x(); | ||
} | ||
default_action = set_x(foo_t.A); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
top<meta_t>(c()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <core.p4> | ||
|
||
control generic<M>(inout M m); | ||
package top<M>(generic<M> c); | ||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
@name("c.set_x") action set_x(@name("v") bit<2> v) { | ||
m.x = v; | ||
} | ||
@name("c.t") table t_0 { | ||
key = { | ||
m.y: exact @name("m.y"); | ||
} | ||
actions = { | ||
set_x(); | ||
} | ||
default_action = set_x(2w0); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
top<meta_t>(c()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <core.p4> | ||
|
||
control generic<M>(inout M m); | ||
package top<M>(generic<M> c); | ||
enum bit<2> foo_t { | ||
A = 0, | ||
B = 1, | ||
C = 2, | ||
D = 3 | ||
} | ||
|
||
struct meta_t { | ||
bit<2> x; | ||
bit<6> y; | ||
} | ||
|
||
control c(inout meta_t m) { | ||
action set_x(bit<2> v) { | ||
m.x = v; | ||
} | ||
table t { | ||
key = { | ||
m.y: exact; | ||
} | ||
actions = { | ||
set_x; | ||
} | ||
default_action = set_x(foo_t.A); | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
top(c()) main; |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 elaborate on that bug? Maybe we can fix the DPDK back end.
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.
Basically, the DPDK backend creates new code that is not type-correct, so a following TypeChecking pass tries to introduce new implicit casts, but fails as the
readOnly
flag is set. I'm not sure why it only fails after this change, as it seems like it should fail regardless. Specifically the incorrect added code is an action call where the actual argument type does not exactly match the formal parameter type (but can be converted implicitly). It seems that typeChecking is not correctly checking this case, and this change fixes that (as part of getting the serializable enum casts working)I tried adding a additional TypeInferencing pass in the DPDK backend to introduce the implicit casts correctly, but that caused some other problems. This feels like a bit of a hack, leaving the code as semi-type-incorrect (not making the implicit cast explicit) when the readOnly flag is set.
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.
Which pass is this? Maybe we can fix the generation of this action call in the first place?
I think this is something the DPDK back end needs to fix before we add more workarounds to the type checker. The class is already complicated.
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.
The problem is in DPDK::PrependPDotToActionArgs (line ~1318) where it is creating a ListExpression rather than a StructExpression to initialize a struct. The typechecker wants this to be a StructExpression, so will introduce a "cast" (actually rewrite the ListExpression as a StructExpression), which then causes a problem as it is running with
readOnly = true
(backend.cpp line 107). If I change that call to have readOnly = false, then it doesn't assert and just makes the change. However, it then has problems later in the backend with code that doesn't know what to do with a StructExpression.Without my change, the typeChecker does not correctly type check action args, so it doesn't try to insert the conversion.
The easiest fix is probably just to add a call to P4::TypeInference with readOnly = false somewhere, and fix the backend code to understand a StructExpression.
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.
@usha1830 Could you take a look at 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.
#4553
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.
Sure. I will check this out.