[enhancement][dslx] Consider the best way we might encode one-hot in the type system
- 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)
One hot is a property of underlying data that lends itself nicely to a "witness type"; i.e. imagine you run `one_hot` on a value and then you pass that value to a function, it would have to similarly run `one_hot` on the value to know that it was indeed in one hot form. If we had a type that said "this value has been validated to be one hot" we could make the value's invariants more self documenting and avoid the need for redundant checks.
### Current best alternative workaround (limit 100 words)
As noted above running one_hot on values to ensure they're canonically one hot, and perhaps adding asserts to check this when it is a precondition that it should be given as one hot.
### Your view of the "best case XLS enhancement" (limit 100 words)
Perhaps a built-in type like `oN[N]` to complement `uN[N]` and `sN[N]`? A standard library struct wrapper wouldn't allow built-ins to take or produce the type as easily.
Contributor guide
Assessment
This issue has not been assessed yet.