www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [SAoC 2021] Replace druntime Hooks with Templates: Milestone 4, Week 1

reply Teodor Dutu <teodor.dutu gmail.com> writes:
Hi,

This milestone I am planning to finish replacing the hooks to 
`_d_arrayappend{T,cTX}` with templates. This week I almost 
finished this task.
There is still a bug when inlining a function such as:
```d
int[] arr;
void foo()
{
	(arr ~= 2) ~= 1;
}
```
The first concatenation causes an `ArrayIndexError` because the 
location of the array length is incorrectly referred in the 
resulting executable. I am yet to find the source of this error. 
I dissected inline.d, and the resulting statement looks alright.

After this, I plan to convert `_d_newThrowable` and 
`_d_newitem{U,iT,T}` to templates. I started working on 
`_d_newThrowable`, but I'm having trouble recreating [these 
`assert`s](https://github.com/dlang/druntime/blob/fd9a45448244fb9dd4326520ad8526c540895eb0/src/r
/ehalloc.d#L35-L36) as the template doesn't store those flags.

Merry Christmas!

Thanks,
Teodor
Dec 24 2021
parent max haughton <maxhaton gmail.com> writes:
On Friday, 24 December 2021 at 18:59:07 UTC, Teodor Dutu wrote:
 Hi,

 This milestone I am planning to finish replacing the hooks to 
 `_d_arrayappend{T,cTX}` with templates. This week I almost 
 finished this task.
 There is still a bug when inlining a function such as:
 ```d
 int[] arr;
 void foo()
 {
 	(arr ~= 2) ~= 1;
 }
 ```
 The first concatenation causes an `ArrayIndexError` because the 
 location of the array length is incorrectly referred in the 
 resulting executable. I am yet to find the source of this 
 error. I dissected inline.d, and the oddresulting statement 
 looks alright.

 After this, I plan to convert `_d_newThrowable` and 
 `_d_newitem{U,iT,T}` to templates. I started working on 
 `_d_newThrowable`, but I'm having trouble recreating [these 
 `assert`s](https://github.com/dlang/druntime/blob/fd9a45448244fb9dd4326520ad8526c540895eb0/src/r
/ehalloc.d#L35-L36) as the template doesn't store those flags.

 Merry Christmas!

 Thanks,
 Teodor
The frontend inliner leads to such strange issues that I think we should delete it and use something in the backend instead. As far as I'm aware Walter has one in DMC, but it doesn't have a heuristic so it's only if you ask for inlining explicitly.
Dec 24 2021