comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Elaboration circularity with generics
Date: Mon, 16 Jan 2012 15:09:18 +0000
Date: 2012-01-16T15:09:18+00:00	[thread overview]
Message-ID: <m2y5t7d6qp.fsf@pushface.org> (raw)
In-Reply-To: 3a04e681-8180-4722-9b19-414173073d8e@m4g2000vbc.googlegroups.com

AdaMagica <christ-usch.grein@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!)



  reply	other threads:[~2012-01-16 15:09 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 [this message]
2012-01-16 17:15         ` AdaMagica
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