TypeInfo in struct ABI
Basile B.
b2.temp at gmx.com
Mon Jan 17 18:29:51 UTC 2022
On Monday, 17 January 2022 at 15:26:46 UTC, Teodor Dutu wrote:
> Hi,
>
> In order to allocate a `struct` type, two DRuntime hooks are
> used: `_d_newitemT` for uninitialised structs and
> `_d_newitemiT` for initialised ones. Both hooks call
> `_d_newitemU`, which allocates memory for the struct and
> [writes the struct’s
> `TypeInfo`](https://github.com/dlang/druntime/blob/9d99b1ccd90d1e66c31e27cc71b8a266612aa14a/src/rt/lifetime.d#L1122) at the end of the allocated chunk.
>
> We now attempt to convert these hooks to templates, with the
> goal of not using `TypeInfo` at all. However, the fact that the
> ABI of a struct contains its `TypeInfo` prevents us from
> achieving this goal. Is this `TypeInfo` object still necessary
> for anything, or are we free to remove it from the ABI
> altogether so that we have cleaner implementations for
> `_d_newitem{U,iT,T}`?
>
> Thanks,
> Teodor
That trailing info seems to be unused.
TypeInfo is retrieved using `typeid`. So let's took a closer look
at the code generated [for
that](https://github.com/dlang/dmd/blob/e4d6fe8ee5af972125624230ded5a81e55b40711/src/dmd/e2ir.d#L818-L838), in dmd.e2ir.d, which gives the best idea of the code executed by the program.
For structs it's clear that the static type is *always* used and
not that trailing stuff that's written passed the actual struct
instance space. For structs that uses the code generated in the
`if (Type t = isType(e.obj))` branch.
More information about the Digitalmars-d
mailing list