DRuntime: Move Functions from `rt/lifetime.d` to `core.lifetime.d` as Templates

Teodor Dutu teodor.dutu at gmail.com
Thu Jun 22 04:02:27 UTC 2023


On Wednesday, 21 June 2023 at 11:52:41 UTC, RazvanN wrote:
> On Wednesday, 21 June 2023 at 03:54:16 UTC, Teodor Dutu wrote:
>> So my approach now is to convert these new templates to "real" 
>> templates, that use their template argument instead of 
>> `TypeInfo`. This will help use `TypeInfo` less (and hopefully 
>> at some point not use it at all in the runtime) but may lead 
>> to a lot of template bloating. To reduce this, it's worth 
>> noting that `__setArrayAllocLength()` only uses `TypeInfo` to 
>> place it at the end of the allocated array. Therefore, the 
>> template implementation can be split into a small template 
>> (that only handles this part) and a larger non-template 
>> function that does everything else (which is common for all 
>> types).
>
> 1. Can we get rid of putting typeinfo in the array or does the 
> GC rely on that?
>
> 2. Why is the larger function a non-template? Shouldn't that 
> also be a template with no template arguments?

1. Yes, the GC may use the `TypeInfo` field, for example to [mark 
indirections](https://github.com/dlang/dmd/blob/035d9268ab9caa0856a46231827faf4a1bbb77ce/druntime/src/core/internal/gc/impl/conservative/gc.d#LL3980C1-L3980C1) for [precise GGs](https://github.com/dlang/dmd/blob/035d9268ab9caa0856a46231827faf4a1bbb77ce/druntime/src/core/internal/gc/impl/conservative/gc.d#L3531). And since [allocation functions take a `TypeInfo` argument](https://github.com/dlang/dmd/blob/035d9268ab9caa0856a46231827faf4a1bbb77ce/druntime/src/core/internal/gc/impl/conservative/gc.d#L475-L620), it would be unwise to ignore it.

2. Right, the larger function can be a template without 
arguments, but it wouldn't make much of a difference regarding 
executable sizes or compilation times. Since 
`__setArrayAllocLength()` is used for every array (re)allocation, 
the template is likely to be instantiated (albeit only once) for 
most D programs.


More information about the Digitalmars-d mailing list