Thread overview
[SAoC 2022] Replace druntime Hooks with Templates: Milestone 3, Weeks 1 & 2
Nov 29, 2022
Teodor Dutu
Nov 29, 2022
rikki cattermole
Nov 29, 2022
Teodor Dutu
November 29, 2022

Hi,

These weeks I fixed the final bugs of the new _d_arraycatnTX hook. When cleaning up the code, Razvan and I took a closer look at the extra lines produced by -profile-gc. They are referring to the new _d_arraycatnTX and seemed to indicate that it allocates some extra memory. In this forum post I asked how to deal with them. Following Max's advice, I did some digging and 2 things turned out:

  1. the old hook uses a private function called __arrayAlloc() to allocate the concatenated array, which is not instrumented, whereas the new one simply sets the .length of the resulting array. This expression is further lowered to _d_arraysetlengthT and this hook is instrumented. It is possible that this is the cause of the differences.

  2. My implementation of _d_arraycatnTXTrace() was buggy. This caused some unnecessary bytes to be allocated. After fixing this, I'll be able to better look into point 1 from above and be more certain regarding the newly added lines when -profile-gc is enabled.

Regarding _d_newitemU, we decided it would be more rational to move more of the lowering logic to the hook, as DRuntime already handles struct and context pointer initialisation in copyEmplace(). I am going to use the same logic in the new _d_newitemT (instead of _d_newitemU) hook, together with calling the struct's ctor. What's problematic with this approach is that I need to make the compiler create a "dummy" object before calling _d_newitemT, so the lowering would look like this:

// original expression:
S* s = new S(args);

// lowering:
S* s = (void[0] ctxPointerTmp, _d_newitemT!S(ctxPointerTmp))

I would like to be able to obtain the context pointer in the frontend of the compiler without having to allocate any other objects. I asked about this in this forum. I am looking forward that the community will help me find a cleaner solution.

Thanks,
Teodor

November 30, 2022
Hopefully this work will mean that some code will be removed from rt.

That bunch of code is a real problem.

Right now no one can implement a GC without compiling it into druntime or reimplementing stuff in rt. Not a great situation!

It also contains my most disliked set of hooks, memset as they could be very easily removed entirely.
November 29, 2022

On Tuesday, 29 November 2022 at 21:04:22 UTC, rikki cattermole wrote:

>

Hopefully this work will mean that some code will be removed from rt.

Absolutely. All these PRs add new template hooks and also remove the old ones.
And most of the old hooks are in rt. For example, all the old hooks I am working to replace now are in rt/lifetime.d.