Open vlstill opened 1 month ago
The primary reason for introducing these methods was for applying them to variables with a header type, so if the spec is not explicit that this should be supported, that sounds like a good change to make to the spec.
Any other values or types it can apply to are simply bonuses, in my opinion.
The specifications says
But it is not very explicit what kinds of expressions these can be. From the description below the table, it it seems it is applicable to
typedef
- andtype
-introduced types. But what else?bit<N>
, i.e. bothbit<4>.minSizeInBits()
and(bit<4>).minSizeInBits()
fails (with different errors).bit<4> test<T>() { return T.minSizeInBits(); }
does not work. And this does not work also for generic values.Frankly, I find this syntax a bit clunky, but given its existence, I think this should be cleaned up. I find it weird, that it can be applied to some concrete types (like headers), while not to others (like
bit<4>
). Also, I wonder if it should be permitted to use it for generic types (although I don't see a use case right now). Obviously such value would not be local compile time know. It can be only know after the function is inlined and the types are know. But at the very least, we should make the constraints much more explicit in the specification.