how to avoid "cycle detected"?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 3 02:34:53 PDT 2015


On Thursday, July 02, 2015 06:56:26 Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 7/1/15 6:25 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > On Wednesday, July 01, 2015 08:52:38 Steven Schveighoffer via Digitalmars-d-learn wrote:
> >> The runtime cannot introspect the code to detect the circular
> >> dependency, so it makes a conservative decision. I'm waiting on an
> >> introduction of RTInfo for modules [1] to allow us to mark static ctors
> >> as standalone, then we can probably fix this problem through a sort of
> >> "trust the programmer" mechanism.
> >
> > I wouldn't mind that, but Walter shot that idea down previously when I was
> > arguing for adding a way to the language to tell the compiler that a static
> > constructor didn't depend on anything else. He didn't want a "trust the
> > programmer" mechanism in this case. I don't remember what his arguments were
> > though.
>
> With RTInfo for modules, we don't need any additional language support.
>
> In Dconf '14, Walter said it was a good idea to add the RTInfo support
> for modules. I don't know if he voiced an opinion on the usage of it for
> flagging whether the static ctors are all standalone.
>
> But with support for modifying the runtime to reflect compile-time
> traits, we can at least play around with it.
>
> There are some things that are so obviously not dependent on anything
> (like initializing an AA), it's really quite annoying to have the
> runtime conservatively flag those as error.

The last discussion that I had with Walter on supporting a way to tell the
compiler that a static constructor did not depend on another module was at
least a couple of years ago I'd guess. So, he may have a different opinion
on it now, and by using RTInfo, we wouldn't need his approval in quite the
same way, so we may very well be able to do it now, but he was against the
concept when we discussed it last (I don't think that the fact that we'd be
adding language support vs runtime support was really an issue - it was the
idea that we'd even have a way for the programmer to do what we're
suggesting here by any mechanism). IIRC, part of the problem was the idea
that it wouldn't be very hard for code to be marked as independent but
inadvertently become depedent later and silent cause problems.

In any case, I do tend to like the idea, since as it stands, we have to weed
most static constructors out of Phobos, and it can be _very_ annoying, so I
would not be averse to exploring the possibility, but just be aware that
Walter has opposed it in the past, and it may take some doing to convince
him (though maybe he's changed his opinion by now).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list