Release D 2.072.0

Jonathan M Davis via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Nov 5 02:31:51 PDT 2016


On Friday, November 04, 2016 00:45:18 Johan Engelen via Digitalmars-d-
announce wrote:
> On Friday, 4 November 2016 at 00:42:48 UTC, Johan Engelen wrote:
> > On Thursday, 3 November 2016 at 15:51:22 UTC, Steven
> >
> > Schveighoffer wrote:
> >> Any cycles that are "newly discovered" were already there.
> >> What was happening is that the runtime did not detect the
> >> cycle, and was arbitrarily choosing an order for initializing
> >> these modules. Either a) the arbitrary order happened to be
> >> right, or b) the order didn't matter. Most of the time it's b,
> >> because most static ctors don't depend on externally
> >> initialized items.
> >
> > My question is: any cycle is invalid?
>
> nevermind, I found this:
> https://dlang.org/spec/module.html#order_of_static_ctor

Yeah, that's why we avoid static constructors in Phobos if we can. In
theory, they're great, but in practice, they have a tendency to cause
problems. Modules which don't import much of anything else from within the
same library tend to be fine, but once a library or application has modules
which import other modules within that library, you can get circular imports
surprisingly easily, and Phobos is rife with them. There are cases where we
actually have other modules specifically to do the static constructors for
another module in order to avoid having static constructors in the import
cycle (e.g. std.stdiobase does that for std.stdio) - but that doesn't play
well with stuff like immutable, just mutable stuff that needs to be
initialized at runtime.

- Jonathan M Davis



More information about the Digitalmars-d-announce mailing list