[enhancement][DSLX] Add support for `#[derive(Pack, Unpack)]` to generate `type_{from,to}_bits` helpers
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
### What's hard to do? (limit 100 words)
Right now for complex structures you have to create bit and byte encoders and decoders by hand which can be error prone and not as amenable to metaprogramming.
### Current best alternative workaround (limit 100 words)
You can write them by hand.
### Your view of the "best case XLS enhancement" (limit 100 words)
We add annotations on struct definitions of the form `#[derive(Pack, Unpack)]` and that will generate `${type|lower}_{from,to}_bits` functions. If so desired we could add least significant bit metadata to the annotation request.
Note that this would generate an "emphemeral" (not in the source text) function, likely as an integrated part of the DSLX type inference process, which is where we do other macro-esque actions that need type information. We would likely benefit from a more solid way to report any errors in emphemeral functions even though they were not present in the source text, but that seems like it might be supplemental if the generated functions generally could not have errors, but you can imagine things like reporting what went wrong in the callee where the callee was emphemeral so it was harder to point at what went wrong -- we do some of this already for BuiltinNameDefs though.
Contributor guide
Assessment
This issue has not been assessed yet.