Bug 12751 – Avoid heap allocations in some cases of array concatenation

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-16T07:56:18Z
Last change time
2024-12-13T18:20:36Z
Keywords
pull
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18827 →

Comments

Comment #0 by bearophile_hugs — 2014-05-16T07:56:18Z
void main() { int[10] a; int[20] b; int[30] c = a ~ b; } Compiled with -O -release -inline -noboundscheck (dmd 2.066alpha) gives: __Dmain comdat L0: sub ESP,0F8h mov ECX,0Ah xor EAX,EAX push EBX push ESI push EDI lea EDI,0Ch[ESP] rep stosd mov ECX,014h lea EDI,03Ch[ESP] rep stosd mov EAX,0Ah mov EBX,offset FLAT:_D11TypeInfo_Ai6__initZ push 078h lea ECX,040h[ESP] push ECX push 014h lea EDX,018h[ESP] push EDX push EAX push EBX call near ptr __d_arraycatT add ESP,014h push EDX lea ESI,094h[ESP] push ESI call near ptr _memcpy add ESP,0Ch xor EAX,EAX pop EDI pop ESI pop EBX add ESP,0F8h ret But the compiler should perform that operation without heap allocations. So that should also be writeable: void main() @nogc { int[10] a; int[20] b; int[30] c = a ~ b; }
Comment #1 by bearophile_hugs — 2014-06-02T17:37:55Z
Other basic cases that can be supported: void main() @nogc { int[2] a = [10, 20]; int[3] b = [40, 50, 60]; int[6] c = a ~ 30 ~ b; } Currently DMD 2.066alpha gives: test.d(4,16): Error: cannot use operator ~ in @nogc function main test.d(4,16): Error: cannot use operator ~ in @nogc function main
Comment #2 by k.hara.pg — 2015-06-12T12:09:40Z
Comment #3 by stanislav.blinov — 2021-12-08T17:38:54Z
I'm guessing the intent on enabling this enhancement left with Kenji Hara, and reminders about it left with bearophile?
Comment #4 by robert.schadek — 2024-12-13T18:20:36Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18827 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB