Do you want to help me fix static AA initialization?
Steven Schveighoffer
schveiguy at gmail.com
Tue Jul 25 13:24:32 UTC 2023
On 7/25/23 4:45 AM, RazvanN wrote:
>
> Maybe this has been addressed in previous discussions, but why not rewrite:
>
> ```d
> int[string] b = ["mimi" : 2];
> ```
>
> to
>
> ```d
> int[string] b;
>
> static this()
> {
> b = ["mimi" : 2];
> }
> ```
>
> I know that we have problems with cycle detection in module
> constructors, but assuming this will be fixed by Adam's proposal, this
> seems like a lot easier to implement and does not stress compilation time.
>
Yes, this can be done. We can even mark the static ctor as standalone,
so it doesn't participate in cycles.
And then in the future if we can find a way to do it during CTFE, then
it can be seamlessly changed.
There are some hairy aspects -- like what you do if the initialized
value is done in a function call or the AA is a member of a type instead
of the thing being initialized, but those are surmountable.
Great idea!
-Steve
More information about the Digitalmars-d
mailing list