On Monday, 25 November 2019 at 12:08:54 UTC, Per Nordlöw wrote:
On Monday, 25 November 2019 at 08:22:02 UTC, Jacob Carlborg wrote:
On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote:
I guess we need a builtin language qualifier for scoped classes for that to work, right?

We have that:

scope a = new Object;

—
/Jacob Carlborg

Ahh, nice.

Does/Will DMD/GDC/LDC (in release builds) make the allocation of `Object` happen on the stack?

class C {
    int x;
    this(int n) { x = n; }
}

int heap() {
    auto x = new C(2); // vgc: `new` causes a GC allocation
    return x.x;
}
/+
int example.heap():
        sub     rsp, 8
        mov     edi, OFFSET FLAT:example.C.__Class
        call    _d_newclass
        mov     DWORD PTR [rax+16], 2
        mov     eax, 2
        add     rsp, 8
        ret
+/

int stack() {
    scope x = new C(2); // (no vgc output)
    return x.x;
}
/+
int example.stack():
        sub     rsp, 40
        mov     rdi, rsp
        mov     QWORD PTR [rsp], OFFSET FLAT:example.C.__vtbl
        mov     QWORD PTR [rsp+8], 0
        mov     DWORD PTR [rsp+16], 2
        call    _d_callfinalizer
        mov     eax, 2
        add     rsp, 40
        ret
+/

gdc assembly. ldc eliminates the object entirely.

Reply via email to