-
Notifications
You must be signed in to change notification settings - Fork 80
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
Introduce local compile-time known values #1213
Introduce local compile-time known values #1213
Conversation
will add this to the agenda for today |
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.
This is just to simplify the definition such that it becomes obvious that all "compile-time known values" are also "local compile-time known values".
The definition should be not changed from the original definition.
@apinski-cavium, actually, I had inverted the definitions -- local compile-time known is more restrictive. See my latest commit which fixes this and adopts your streamlining suggestions. |
Yes I didn't even noticed that until now and yes this is now +1 from me. |
Would be nice for Petra to validate this. |
Anyone else have comments or suggestions on this one? |
Any further comments on this or should we merge it? |
I do have some open questions about generics and literals. |
Sure. Can you provide a pointer to those questions? I might be missing something but I don't see them in the conversation on this issue. |
Looks like I forgot to submit the comments. Somehow github has preserved them for a long time... |
@jnfoster, let me know when this is ready for me to do a review. |
Co-authored-by: Vladimír Štill <git@vstill.eu>
Co-authored-by: Vladimír Štill <git@vstill.eu>
Co-authored-by: Vladimír Štill <git@vstill.eu>
By a very quick test, it seems that the compiler does reject constructor parameters as well as generic-parameter-derived values in type declarations: int<4> fn<T>(inout bit<4> data) {
int<(T.minSizeInBits())> v = 42;
v = v + data;
return v;
}
control C(inout bit<4> data)(int cnt) {
int<(cnt)> var;
apply {
}
} # ./p4test test.p4
test.p4(2): [--Werror=expected] error: T.minSizeInBits(): expected a constant
int<(T.minSizeInBits())> v = 42;
^^^^^^^^^^^^^^^^^
test.p4(8): [--Werror=expected] error: cnt: expected a constant
int<(cnt)> var;
^^^ So at least this one case should be safe and we would not be restricting what the compiler already compiles. |
However, typedef int<4> T;
int<4> fn(inout bit<4> data) {
int<(T.minSizeInBits())> v = 42;
v = v + data;
return v;
}
const int cnt = 4;
control C(inout bit<4> data) {
int<(cnt)> var;
apply {
}
} $ ./p4test test.p4
test.p4(4): [--Werror=expected] error: T.minSizeInBits(): expected a constant
int<(T.minSizeInBits())> v = 42;
^^^^^^^^^^^^^^^^^ |
Here is a small example showing what control C(inout bit<8> x);
package P(C c);
const int f = 42;
int g(int x) { return x; }
control MyB(inout bit<8> x, inout bit<8> y)(int n) {
bit<(1 + 1)> a = 0;
bit<(f)> b = 1;
bit<(f / 2)> c = 2;
// These are all currently errors, and they should be
// bit<(g(3))> d = 3;
// bit<(n)> e = 3;
// bit<(x)> f = 4;
apply {
x = y;
}
}
control MyC(inout bit<8> x)(int o) {
MyB(o) b;
bit<8> y = 0;
apply {
b.apply(x, y);
}
}
P(MyC(9)) main; |
@jonathan-dilorenzo this is ready for you to take a look. |
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 great! Merging!
Actually @jnfoster, can you say why you also wanted to remove the experimenting with bison file? Doesn't look obviously related to this... |
For greater clarity, this commit moves the comment about the calling convention for directionless parameters of extern object type out of an itemized list. Instead, it is a standalone sentence below the list.
0c726e8
to
8fb0338
Compare
55cd6ea
to
630a54c
Compare
Good catch. I've fixed that. (Sorry for the force-pushes. I was trying to rebase and squash these to tidy it up, which is perhaps ill-advised on a public PR.) |
|
||
- A simple integer constant has type `int`. | ||
- An integer has type `int`. |
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.
This is specifically referring to integer literals with no width prefix -- those with width prefixes are covered by the subsequent bullet points. Maybe this point should be last and should say "an integer with no width prefix has type int
"
- an unsigned integer, i.e. `bit<W>` for some compile-time known `W`. | ||
- a signed integer, i.e. `int<W>` for some compile-time known `W`. | ||
- an unsigned integer, i.e. `bit<W>` for some compile-time known value `W`. | ||
- a signed integer, i.e. `int<W>` for some compile-time known value `W`. |
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.
Should these be "some locally compile-time known value"?
Np! Looks good to me. Merging. |
@jnfoster @ChrisDodd If Nate agrees that some of Chris Dodd's latest comments/questions justify changes, it would be good to create a separate issue to track those. |
The suggestions are good, but creating an issue for something that can be implemented in a few minutes seems like overkill. I created #1286. If people agree, I think it would be safe without discussing this at the LDWG -- all of the changes only increase clarity, but don't change meaning. Of course, we can also discuss it, so we feel good about the process and about PRs being applied :-) |
Made an executive decision to merge. Obvious and simple improvements aren't worth the discussion imo, but feel free to push back if you feel otherwise. |
Fixes #1001 and #932.