Sum Type by Struct
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Sep 13 10:32:59 UTC 2024
On 13/09/2024 10:25 PM, IchorDev wrote:
> On Thursday, 12 September 2024 at 11:28:56 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> The layout of the sumtype is variable size, allowing for copy
>> constructors, destructors and no value (if size zero).
>
> So this would enable variable-sized stack return? Do you have any plans
> for how that might be implemented?
> Also this might be the only way to create a zero-sized type! (Hurray!)
It is not variable sized in that sense.
A specific sumtype would be fixed at compile time based upon the
constraint set. The value you get from ``.sizeof`` is the size in assembly.
The variable size layout enables eliding aspects of it like destructors
which are not used by a given constraint set.
> Also how costly do you think this version of sum types will be for
> compile times?
Each of the three designs require a declaration to define a sumtype.
There is no inline declarations, so I expect that all three will be at
the same cost.
Mostly dependent upon the set operations.
So as long as the constraint set is kept small, shouldn't be noticeable
I would think.
More information about the dip.ideas
mailing list