You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current handling of varbit fields in testgen is somewhat cumbersome and leads to some non-well-typed expressions. When the program contains varbit field, the testgen needs to remember the actual extracted size and it needs to work with the field accordingly.
When the field is emitted, the actual size is emitted.
When one varbit field is assigned into another (possibly as part of a header), the size of the source is also propagated to the destination. This may change the actual size of the destination.
The current solution uses SizedVarbit/Extracted_Varbit type, which has some problems. E.g., when there is just a varbit extracted (e.g. testgen-p4c-bmv2-protobuf-ir/issue447-bmv2.p4), the packet expression is something like 0 ++ (SizedVarbit<32><16>)|pktvar_0(bit<16>)| which is of type bit<16> but the optimizer turns it into (SizedVarbit<32><16>)|pktvar_0(bit<16>)| which is SizedVarbit<32><16>.
Looking at the other code that relates to varbits, it seems like these are mostly special cases that treat SizedVarbit<M><N> as bit<N>. However, because of varbit assignments, it is not possible to just replace varbit<M> with bit<N> when it is extracted, as that would lead to wrong assignments. At the same time, it is not sufficient to keep the value just as varbit<M> in the header as ween need to keep the runtime size known.
One possibility I can think of would be to save bit<N> in the packet buffer, but something like VarbitCast<M, N> in the header's varbit field. VarbitCast<M, N> would be an expression that would contain a bit<N> typed expression, but it would itself be of type varbit<M>. This way, it would be possible to assign these expressions and the program should be well typed.
More discussion on the problem can be found in PR #4300.
The text was updated successfully, but these errors were encountered:
The current handling of
varbit
fields in testgen is somewhat cumbersome and leads to some non-well-typed expressions. When the program containsvarbit
field, the testgen needs to remember the actual extracted size and it needs to work with the field accordingly.The current solution uses
SizedVarbit
/Extracted_Varbit
type, which has some problems. E.g., when there is just a varbit extracted (e.g. testgen-p4c-bmv2-protobuf-ir/issue447-bmv2.p4), the packet expression is something like0 ++ (SizedVarbit<32><16>)|pktvar_0(bit<16>)|
which is of typebit<16>
but the optimizer turns it into(SizedVarbit<32><16>)|pktvar_0(bit<16>)|
which isSizedVarbit<32><16>
.Looking at the other code that relates to varbits, it seems like these are mostly special cases that treat
SizedVarbit<M><N>
asbit<N>
. However, because of varbit assignments, it is not possible to just replacevarbit<M>
withbit<N>
when it is extracted, as that would lead to wrong assignments. At the same time, it is not sufficient to keep the value just asvarbit<M>
in the header as ween need to keep the runtime size known.One possibility I can think of would be to save
bit<N>
in the packet buffer, but something likeVarbitCast<M, N>
in the header'svarbit
field.VarbitCast<M, N>
would be an expression that would contain abit<N>
typed expression, but it would itself be of typevarbit<M>
. This way, it would be possible to assign these expressions and the program should be well typed.More discussion on the problem can be found in PR #4300.
The text was updated successfully, but these errors were encountered: