Convert Sum Types to Integers #1175
Replies: 3 comments
-
|
Thinking more about this, making it into something customizable might be better (e.g. a contract that needs to incorporate a datum from another contract not written in Aiken). Perhaps it makes sense to include this in #1100? |
Beta Was this translation helpful? Give feedback.
-
|
I would agree that a decorator would make the most sense for this feature and I definitely would like to see this too. A lot of on-chain code that isn't written using Aiken uses this encoding for enums. |
Beta Was this translation helpful? Give feedback.
-
|
Maybe a future decorator actually |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What is your idea? Provide a use case.
Inspired by the optimization done by @MicroProofs in Bullet, it seems like a low-hanging fruit to auto-convert to integers any sum types that none of their constructors hold values.
As an example, if a datum carries a boolean, its
False(orTrue, not sure which has index 0 😅) is encoded asd87980in CBOR. This can be reduced by 2 bytes to a simple00in CBOR to represent the index without the overhead.Why is it a good idea?
Currently data encoding of sum types translate to the
Constrvariant ofData, which carries an index, and a list ofdatavalues:This list is always empty for constructors without values (e.g.
TrueandFalseofBool). So this empty list becomes an unused overhead.By having the compiler auto-convert such sum types, we get to drop the empty list and reduce on-chain data bloat.
What is the current alternative and why is it not good enough?
Using
builtin.unconstr_indexgives a cheap access to the index of aConstr(as implemented here in Bullet). However, this can reduce maintainability of the code as the compiler won't be able to catch changes to the underlying sum type.Beta Was this translation helpful? Give feedback.
All reactions