comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Dowie <martin@re.mo.ve.thedowies.com>
Subject: Re: Elaboration circularity with generics
Date: Sat, 14 Jan 2012 10:13:13 -0600
Date: 2012-01-14T10:13:13-06:00	[thread overview]
Message-ID: <2125280501348249894.650394martin-re.mo.ve.thedowies.com@news.btinternet.com> (raw)
In-Reply-To: 583b1bfe-95bd-4669-b16b-c733c81e8f88@w4g2000vbc.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> wrote:
> Consider:
> 
> --  p.ads:
> package P is
>    procedure Proc;
> end P;
> 
> --  p.adb:
> with P.Q;
> package body P is
>    package P_Int is new P.Q (T => Integer);
> 
>    procedure Proc is
>    begin
>       P_Int.Proc;
>    end Proc;
> end P;
> 
> --  p-q.ads:
> generic
>    type T is private;
> package P.Q is
>    procedure Proc;
> end P.Q;
> 
> --  p-q.adb:
> package body P.Q is
>    procedure Proc is
>    begin
>       null;
>    end Proc;
> end P.Q;
> 
> --  test.adb:
> with P;
> 
> procedure Test is
> begin
>    null;
> end Test;
> 
> The idea is that P.Q is a child, helper unit for P and P.Q is used in
> the body of P.
> Ideally it should be a private child, but these cannot be generic
> (why?).
> 
> Forget the Proc procedures, they do not contribute to the actual
> problem, but where needed to have meaningful source units.
> The problem above is:
> 
> $ 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.
> 
> Why this circular dependency? It does not exist if P.Q is not generic.
> My initial version of P.Q was a regular package and I have found this
> problem after turning it into a generic package.
> 
> A simple workaround is to make P_Q instead of P.Q, but I would like
> understand where the circularity comes from. The -gnatwl option says
> that some Elaborate_All is introduced at the instantiation of P.Q, but
> I see no reason for circularity there.
> 
> --
> Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com

I think a better way is to make the instantiation another child, e.g.

package P.Q.Integers is new P.Q (Integer);
pragma Preelaborate (P.Q.Integers);

Then it is available to other packages that may need it too.


-- Martin
-- 
-- Sent from my iPad



  reply	other threads:[~2012-01-14 16:13 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 [this message]
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
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