Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 246 - [Implementation] Reference symbol initializers should be done at runtime
Summary: [Implementation] Reference symbol initializers should be done at runtime
Status: NEW
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: All All
: --- enhancement
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2016-10-29 09:51 CEST by Iain Buclaw
Modified: 2016-10-29 09:51 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.