-
Notifications
You must be signed in to change notification settings - Fork 80
Bytecode padding directive #301
Comments
What about making this a new jump table that does this instead of a new #define token ? It seems a convenient add for the "regular" and "packed" ones. Is there any case for which we wouldn't be able to determine the size of the "stop wall" at compile-time ? And also, does that mean that every jump location has to be less than x bytes long which might be constraining at some point ? |
To construct a more efficient function dispatcher you want to directly convert a function selector into a jump destination while avoiding having to do a lookup in some table. This typically requires the entry
However rarely will all your functions be exactly the length you need, so you need to add some padding e.g. (visualizations not actual Huff):
The issue is what if you change the logic of one your functions because you found an optimization or want to add a feature, the padding is now invalid:
Ideally I have some directive I can use to wrap my functions in so that the padding is adjust automatically and I get helpful error message if I happen to exceed the set size e.g.:
Not quite sure how a new jump table type would achieve these, I guess it would change how you define the constraint of distance between labels, do you mean smth like this?:
I like this less as it feels less direct. Having padding be defined in macros seems cleaner and would allow you to reuse such blocks via macros. |
I'd love a directive that allows me to indicate a size
n
that at compile time should:0x00
(STOP
) bytes up to sizen
n
The use case for this is efficient function dispatchers or internal switch-like statements that require code sections to be padded up to a consistent size. In METH this leads not only to relatively ugly code:
But is also very error-prone, if optimize a macro and it results in smaller/larger bytecode and I forget to adjust the padding all subsequent functions are broken due to the corrupted block boundaries. I've had to write a somewhat janky script that helps me identify where the initial block boundary violation happened.
I'd imagine the syntax for this to be something like this:
I'm offering a $100 bounty (to be paid in mainnet ETH) to the contributor who implements this once merged.
The text was updated successfully, but these errors were encountered: