Skip to content

Conversation

Albert24GG
Copy link
Contributor

I am not sure why, but the dynamic array creation still relies on the old hooks, despite having templated versions of _d_newarray* that the expressions are lowered to in expressionsem. The old hooks are soon going to be removed, because they were only used by AA hooks but now that is no longer the case.

I did not remove DtoNewDynArray since it is still used for ArrayLiteralExp,at least until the templated version of _d_arrayliteralTX will be integrated.

@kinke
Copy link
Member

kinke commented Aug 8, 2025

Thx! I don't really recall whether the GC2Stack regressions were the reason, but they are definitely a problem. - We have an extra LLVM pass that looks for GC allocations that don't escape their scope (after inlining & optimizing), and convert them to stack allocations instead. This was all based on the old non-templated druntime hooks, based on TypeInfos etc.

So for instance, this now fails:

int foo1()
{
// NOOPT: call{{.*}}_d_newarrayT
// CHECK-NOT: _d_newarrayT
int[] i = new int[5];
i[3] = 42;
// CHECK: ret
return i[3];
}

as the GC2Stack pass doesn't eliminate the superfluos GC allocation anymore when switching to the templated lowering.

@Albert24GG
Copy link
Contributor Author

@kinke I took a look over the GC2Stack pass and I see it is indeed one of the last passes. The current implementation that uses the TypeInfo version is based on the fact that the call itself will not be inlined since the function is extern and needs to be linked. Now when switching to the templated version, the pass does not find any call to _d_newarrayT since it was probably inlined. Do you have any idea/suggestion on how to deal with it?

@kinke
Copy link
Member

kinke commented Aug 12, 2025

Once everything GC-related is templated (or at least the stuff that makes sense), the GC2Stack would need to be overhauled, incl. accounting for the new unstable mangled names and populating the TypeInfo LLVM meta data (that we emit in IR for the later GC2Stack pass) differently etc. That's probably a bigger task, and I think only makes sense tackling once all hooks have been revised.

In the meantime, here for array GC allocations, I went the conservative route of using the old non-templated hook to keep GC2Stack working, as the druntime helpers are still available.

@Albert24GG
Copy link
Contributor Author

@kinke Okay, then I'll leave this PR open until everything is ready so that the idea does not get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants