-
Notifications
You must be signed in to change notification settings - Fork 455
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
The Evaluator pass is not able to properly complex instantiation arguments #5149
Comments
I think instantiations should be explicitly resolved very early – somewhere close to generic types specializations. Constructor parameters effectively make "stateless" objects (per spec) something with internal state. E.g. this is a valid code: parser p(in int<10> sinit, out bool matches)(bool ctorParam) {
int<10> s = ctorParam ? sinit : 0;
state start {
s = 1;
transition next;
}
state next {
s = 2;
matches = true;
transition accept;
}
} While per spec
So, it seems that in reality constructor parameters should be treated as "template arguments" and instantiated as early as possible. |
@asl, your point is a bit different than I had originally in mind. Sorry I did not provide the example right away. Here is a snippet (full test that fails in Register<ValueType, bit<4>>(8, (ValueType){
c = 42,
a = 1,
b = -1,
nested = (Nested){a = (TN16)4, b = 16}
}) r0;
Namely the problem is the Register<TN16, bit<4>>(8, (TN16)4) r0;
The problem is that This basically prevents any backend/target from using such expressions. On the other hand, what @asl describes might depend on the target and the kind of object being instantiated (i.e. it might make sense for instances of |
Oh, you are right. It might appear as different issue, but I think it is still the same generic question: what is considered as a compile-time constant, when and how they should be evaluated. The spec provides guidance for I agree that there should be no "whole constant expression hierarchy" and some canonical representation of the code (with constants folded / evaluated in proper places) should be made. |
@vlstill actually, if we'd modify my example above we'll end with complex constant expression as well:
Here |
The evaluator pass, which is running in frontend and in many other places in compilation, is not able to properly handle complex arguments in instantiations. Namely the cast operation does not work, and there is no corresponding representation for cast in
P4::IR::CompileTimeValue
. However, if cast is allowed, we can easily end up with having to replicate basically all expressions in theCompileTimeValue
-- there can be compile time struct expressions, casts, struct field accesses, additions, etc (as compile time values can be arbitrary). I think this requires a different approach. Maybe we can get rid ofCompileTimeValue
completely and just enforce that the instantiation parameters can be constant evaluated in the result of evaluator -- I don't think it makes sense to replicate (almost) the entire expression tree in constant versions (for example, LLVM does this and it is a major pain).The text was updated successfully, but these errors were encountered: