[SAoC 2021] Replace druntime Hooks with Templates: Milestone 1, Week 1

RazvanN razvan.nitu1305 at gmail.com
Thu Sep 23 16:30:57 UTC 2021


On Thursday, 23 September 2021 at 16:06:57 UTC, kinke wrote:
> On Thursday, 23 September 2021 at 15:15:32 UTC, Teodor Dutu 
> wrote:
>> We skipped lowering in expressionsem.d for snippets like `S[3] 
>> arr = [S(1), S(2), S(3)];`, as e2ir.d already handles such 
>> cases more elegantly.
>
> This is bad news for all non-DMD compilers, as e2ir.d is DMD 
> only, and LDC and GDC would have to duplicate thew lowerings in 
> the glue layer now. Please don't.

Just to clarify, there is no lowering happening in e2ir. What 
happens right now (before replacing the hook with template) is 
that in some situations the hook is bypassed (i.e. no call is 
made to druntime). We mimicked this logic in our implementation.

To clarify:

S[1] a = [S(1)];

would be lowered to:

_d_arrayCtor(a, [S(1)]);

which in turn gets rewritten to:

S[1] __arraystack_literal = [S(1)];
_d_arratCtor(a, __arraystack_literal);

Now, the first line, if we are not careful, will be lowered
to _d_arrayCtor hence the infinite loop.

Looking at the current state of e2ir [1], we saw that in the case
where rhs is an array literal the lowering is not performed
anymore. Instead, the literal is assigned element-wise.

What Teo meant is that in this situation we are not lowering to
_d_arrayctor, rather we just let the compiler handle the case as
it did up until now.

[1] https://github.com/dlang/dmd/blob/master/src/dmd/e2ir.d#L2519


More information about the Digitalmars-d mailing list