comp.lang.ada
 help / color / mirror / Atom feed
* Elaboration circularity with generics
@ 2012-01-14 15:09 Maciej Sobczak
  2012-01-14 16:13 ` Martin Dowie
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Maciej Sobczak @ 2012-01-14 15:09 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-01-16 22:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox