Consider making zero-field data classes not allocate anything
densh opened this issue · 1 comments
This has been previously explored in rust. Effectively zero-size data classes would become first-class equivalent of Unit
. Allocation would not call allocate
on allocator as followers of zero-size types are never followed. Fields of zero-size types are also zero-size making it very useful feature to augment specialisation.
Unfortunately this has some non-trivial feature interactions wrt current layout machinery that might need a complete rewrite to support this. Right now there is no compelling use case to do this but the idea is quite interesting and might be explored in the future.
I'd say that as zero-size data classes are observationally equivalent, they can simply be replaced by singleton objects. Which could be either stored on-heap or off-heap.