[GSoC] 'Replace Runtime Hooks with Templates' progress and update thread

Dan Printzell xwildn00bx at gmail.com
Wed Jun 26 01:49:37 UTC 2019


On Tuesday, 28 May 2019 at 10:47:03 UTC, Dan Printzell wrote:
> [...]


Week 3
======

This week
~~~~~~~~~

- Debugged the phobos unittest problems for the _d_arrayappendcT 
PRs.
   - The problem is probably that the order the postblit and the
     assignments are swapped compared to the current hook
     implementation. The assignment and the postblit probably need 
to be
     moved to the outside of the to _d_arrayappendcT function.
- Ported over _d_arrayctor, _d_arraysetctor, _d_arraycatT, and
   _d_arraycatnTX to templates.
- Implemented lowering code for _d_arrayctor, _d_arraysetctor.
   - The whole functions for these could be moved to a template 
function,
     so these no longer depend on TypeInfo.
- Worked on the lowering code for _d_arraycatT and _d_arraycatnTX.
   - Debating if _d_arraycatT should be dropped and only use
     _d_arraycatnTX, to help with the lowering code.


Next week
~~~~~~~~~

- Finish the _d_arraycat{T,nTX} hook.
   - Probably merge _d_arraycatT into _d_arraycatnTX to help the 
lowering
     code.
- Make and submit the PRs for _d_array*ctor and 
_d_arraycat{T,nTX}.
- Move the assignment of _d_arrayappendcT back outside the hook 
to fix
   the problem.


Blockers
~~~~~~~~

As mentioned in /This week/ about _d_arrayappendcT, the problem 
is that
phobos unittests passes, even if the unittest works for druntime. 
  The
only thing I can think of is that the postblit is called before 
the
object is sent to _d_arrayappendcT instead of after the
assignment. Moving the assignment back outside of 
_d_arrayappendcTX
should fix this, to restore what is currently done with the hook.

I have not focused too much time on this issue because I wanted 
to get
the _d_array*ctor and _d_arraycat* up and running first as I did 
not
know what problem I would encounter with these.

--

The lowering code for _d_arraycat{T,nTX} is currently pretty ugly
because I need to handle many cases of the lowering. For example:

  ```d
  S[2] a;
  S[] a4 = a ~ a ~ a ~ a;
  // Step 1:
  S[] a4 = _d_arraycatT(a, a) ~ a ~ a;
  // Step 2:
  S[] a4 = (S[][3] __cat2 = [a, a, a];) , 
_d_arraycatnTX(cast(S[][])__cat2)  ~ a;
  // Step 3:
  S[] a4 = (S[][4] __cat4 = [a, a, a, a];) , 
_d_arraycatnTX(cast(S[][])__cat4);
  ```
(This will '__cat*' is used to not allocate memory heap and break 
the
'scope' requirement code.)

The rewrites steps are like this because it works from the inside
outwards compared to the outside inwards, like what is done in 
e2ir.d.

As mention in /Next week/ I will merge _d_arraycatT into nTX to 
help
with all the different edge cases and to get more manageable and
reviewable code.


Week 4
======

This week
~~~~~~~~~

- Worked on more _d_arrayappend{T,cTX}, _d_arraycatnTX and
   _d_array{set,}ctor.
- I got _d_arrayappend{T,cTX} working after moving the assignment 
back
   outside of the _d_arrayappendcTX call.

dmd PR: [https://github.com/dlang/dmd/pull/9982]
druntime PR: [https://github.com/dlang/druntime/pull/2632]

- I've submitted PR for _d_arraycatnTX, even if the dmd lowering 
code is
   not working right now.
dmd PR: [https://github.com/dlang/dmd/pull/10064]
druntime PR: [https://github.com/dlang/druntime/pull/2648]


Next week
~~~~~~~~~

Rework my timetable to see if I will be able to finish the rest 
of the
hook for the allocated timeslots. The rework is needed because
_d_arraycat{T,nTX} and _d_array{set,}ctor are still not done due 
to bugs
that are hard to understand and fix. The goals is to with my 
acquired
knowledge of what I've done now be able to better classify the
difficulty level of each hook. As I've really realized that the
line-of-code metric was a really bad one that did not at-all show 
the
difficulty level of the hooks.

Continue the work on _d_arraycat{T,nTX} and _d_array{set,}ctor to 
make
sure that they are finish before the second evaluation. I will 
probably
have to put these temporary on the backlog while figuring out how 
hard
the next hook will be to port, which will probably be
_d_arraysetlength{,i}T.


Blockers
~~~~~~~~

As mentioned before I had postblit problems with the previous
_d_arrayappendcT function, but now when I moved the assignment 
outside
it passes all the unittests.

_d_arraycatnTX is currently not working because my lowering code 
somehow
send in a temporary incorrectly into a hook, and it also break a 
assert
inside the dmd backend code. More information about this can be 
found
inside the dmd PR.

The last hooks that isn't done is the _d_array{set,}ctor, here I 
still
have left to finish the logic for when to write AssignExp 
expressions,
as some of the expression should not be rewritten. I also need to 
add
logic to the hook for when to export the interface as nothrow. If 
I
force it to be nothrow this unittest will fail:
[https://github.com/dlang/druntime/blob/9f44ee59ac784e28c19631dd0be2b868766f4348/src/object.d#L3538]
But if I don't force it, it will always default to throw and it 
will
break code that calls this hook from nothrow scopes. So I need to
implement some logic that determine when to export as nothrow and 
when
to export it as throw.


Reflections on progress so far
==============================

Now that the first evaluation is in progress I wanted to just 
write
about what my thoughts are after working on three hooks during 
these
four weeks. I added this section to add some transparency of what 
is
happening behind the scenes of my GSoC work, and to document 
everything
in case it could be good to know. I also enjoy being critical 
about what
I have done to get a teachable moment out of it.


Planning
~~~~~~~~

The metric I used in my proposal, lines of code, was a really bad
choice. I've realized that it is not the amount of code that the 
hook is
called that describes its difficulty but than in what context it 
is
called and with that data it is called with. I have started to 
going
through the rest of the hooks I have not started with to try and 
build
up new metrics that I can use to better evaluate the difficulty 
of the
hook and to make sure I allocate enough time to be able to 
success with
the translation within the allocated timeslots.

Because I did not fully realize the difficulty, i.e. possible 
blockers,
of the hooks so far I have not been able to finish all of them 
within
the timeslot I wanted. I got the array append hook working, but 
it was
in the last minute before the week four ended.

With the knowledge of everything I did not previously know, did 
not plan
for, or even maybe overlooks, I want to be able to in the future 
of GSoC
identify these problem and know what to do to fix them.


More information about the Digitalmars-d mailing list