Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla

Bug 246

Summary: [Implementation] Reference symbol initializers should be done at runtime
Product: GDC Reporter: Iain Buclaw <ibuclaw>
Component: gdcAssignee: Iain Buclaw <ibuclaw>
Status: NEW ---    
Severity: enhancement    
Priority: ---    
Version: development   
Hardware: All   
OS: All   

Description Iain Buclaw 2016-10-29 09:51:26 CEST
Example:
---
class A
{
    char a;
}

class B : A
{   
    int b;

    this(char a, int b) pure
    {
        this.a = a;
        this.b = b;
    }
}

const A var = new B('E', 88);
---

This is achieved by creating a hidden static of the record type B, then initializing var with it's address.

Maybe (as a distinct implementation detail) we should instead initialize these variables at runtime, rather than putting them in static data.

We already generate module shared and static constructors, that are managed by druntime, so there's no additional scaffolding needed in place to support this.

This can be applied to dynamic creation of classes, structs, and dynamic arrays (where we use "C", "S", and "A" prefixed static decls respectively to initialize static user data).

There's no bugs for this as a result of what we do, the change is purely aesthetic.

Potential implementation blockers are the last components of the dt_t routines (notably ClassReference::toDt2), which could be removed completely instead of converted over to the shared visitor for generating runtime and static data expressions.