Empty value type ?
John Rose
john.r.rose at oracle.com
Fri Jun 29 20:06:46 UTC 2018
On Jun 29, 2018, at 12:31 PM, Frederic Parain <frederic.parain at oracle.com> wrote:
>
> I’d be cautious about “zero-length” values, especially if the assumption is that
> they will be flattened and their memory cost would be strictly equal to zero.
They are not trivial to implement, but they are very useful with
specialized generic data structures, so they need to be on the table.
I'm reminded that C++ supports empty classes, but in some versions
it sticks in a synthetic char field, to avoid paradoxes like you describe.
We could do that trick also.
But Remi's fix is better. Basically, every zero-length value of a given
type T is identical to T.default. This means that, although there might
need to be an objectFieldOffset for such a value inside a container,
that offset doesn't need to actually point at a byte inside the object.
It can be whatever value we need it to be, given that it won't ever
be used to load payload from the container. In effect, instance
fields of type T (where T is empty) translate automatically to
static fields of the same type.
— John
More information about the valhalla-dev
mailing list