-
Notifications
You must be signed in to change notification settings - Fork 447
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
Testgen: fix varbit handling #3761
Conversation
195fa63
to
5d973f1
Compare
2da70e1
to
5b10e40
Compare
@fruffy I decided to simplify this PR - it still solves the problem I'm facing, but without complex refactoring of varbit handling in testgen. The problem with |
Yes, inheriting from Type_Bits was intentional so that we can actually use all the compiler optimizations we apply without having to copy and extend them. We made some modifications to passes to preserve the type, too. Unfortunately, I do not know a better way to solve this. Maybe there is a way to preserve the type in |
In theory yes, type canonicalization can be customized, however the problematic pass is a re-used pass from bf-p4c compiler, i.e. a codebase which is completely Extracted_Varbits-oblivious. I'm surprised similar problems do not arise elsewhere, I consider Extracted_Varbits does break the substitution principle a bit (is it really substitutable by Type_Bits?).
In my opinion, more clean solution would be to preserve the varbit type in the IR, and storing bit values (and changing testgen internals to handle different type of key and value in the symbolic map). But it's relatively large change, and I'm still unsure if it's worth given that the current approach seems to work well in reality. Anyway, I think the change in this PR is still step in right direction, because the type in IR (keys in symbolic map) should determine how the member should be handled, not the type of the currently stored value. |
5b10e40
to
57e097c
Compare
Instead of enriching the program IR by a custom varbit type which remembers extracted size, assign bit<extracted_size> directly to varbit members.
The original approach with custom Extracted_Varbit type is problematic: the type inherits from bit type where X is the maximum size of corresponding varbit type, however the width_bits method is also overridden to return the actually extracted varbit size.