From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Elaboration circularity with generics
Date: Mon, 16 Jan 2012 09:15:04 -0800 (PST)
Date: 2012-01-16T09:15:04-08:00 [thread overview]
Message-ID: <2c9456e6-17d4-4493-8d7e-8017a4540d8c@w4g2000vbc.googlegroups.com> (raw)
In-Reply-To: m2y5t7d6qp.fsf@pushface.org
On 16 Jan., 16:09, Simon Wright <si...@pushface.org> wrote:
> AdaMagica <christ-usch.gr...@t-online.de> writes:
> > On 14 Jan., 23:46, Simon Wright <si...@pushface.org> wrote:
> >> AdaMagica <christ-usch.gr...@t-online.de> writes:
> >> > A unit can only be instantiated if it is fully elaborated.
> >> > I guess GNAT chose the elaboration order P'Spec, P.Q'Spec, P'Body
> >> > (crash since P.Q'body is not elaborated).
> >> > This dependence is not present for nongeneric units.
>
> >> > Perhaps addition of pragma Elaborate_Body to P.Q helps.
>
> >> with P.Q;
> >> pragma Elaborate (P.Q); <<<<<<< does the trick for me
> >> package body P is
>
> > Of course this works, but in my opinion, Elaborate_Body is better
> > because it has to be applied just once to P.Q, whereas Elaborate has
> > to be applied on every unit withing P.Q.
>
> > As a general rule of thumb I think Elaborate_Body should be applied
> > whenever a unit provides functions that are used in the spec of other
> > units providing initial values or constants, such like:
>
> > package P is
> > pragma Elaborate_Body; -- prevents elaboration error when F is
> > called
> > function F (...) return T;
> > end P;
>
> > with P; -- no need for "pragma Elaborate (P);"
> > package Q is
> > V: [constant] T := P.F (...);
> > end Q;
>
> That may be true in general, but *in this case* it does not solve the
> problem;
>
> generic
> type T is private;
> package P.Q is
> pragma Elaborate_Body;
> procedure Proc;
> end P.Q;
>
> then
>
> $ gnatmake test
> gcc -c test.adb
> gcc -c p.adb
> gcc -c p-q.adb
> gnatbind -x test.ali
> error: elaboration circularity detected
> info: "p (body)" must be elaborated before "p (body)"
> info: reason: implicit Elaborate_All in unit "p (body)"
> info: recompile "p (body)" with -gnatwl for full details
> info: "p (body)"
> info: must be elaborated along with its spec:
> info: "p (spec)"
> info: which is withed by:
> info: "p.q (spec)"
> info: which is withed by:
> info: "p (body)"
>
> gnatmake: *** bind failed.
>
> -gnatE still succeeds (provided you remember to rebuild the world!)
Ha, yes, because of the implicit Elaborate_All implied by the
nonstandard behaviour of GNAT (I didn't think of this connection).
Obviously with standard Ada behaviour (-gnatE), GNAT can find a good
order without the pragma (there is no Elaborate_All in this case).
But I think the rule of thumb should be followed nevertheless. (It's
only a rule of thumb because Elaborate_Body is sometimes impossible.)
next prev parent reply other threads:[~2012-01-16 17:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-14 15:09 Elaboration circularity with generics Maciej Sobczak
2012-01-14 16:13 ` Martin Dowie
2012-01-14 16:17 ` AdaMagica
2012-01-14 22:46 ` Simon Wright
2012-01-15 16:55 ` AdaMagica
2012-01-16 15:09 ` Simon Wright
2012-01-16 17:15 ` AdaMagica [this message]
2012-01-14 16:26 ` AdaMagica
2012-01-14 22:01 ` Georg Bauhaus
2012-01-15 17:15 ` Maciej Sobczak
2012-01-15 17:43 ` AdaMagica
2012-01-16 17:02 ` Adam Beneschan
2012-01-16 14:34 ` Robert A Duff
2012-01-16 21:29 ` Maciej Sobczak
2012-01-16 21:52 ` Adam Beneschan
2012-01-16 22:25 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox