comp.lang.ada
 help / color / mirror / Atom feed
* Elaboration problem with a task
@ 2006-01-05 10:04 JP Thornley
  2006-01-05 10:16 ` Martin Dowie
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: JP Thornley @ 2006-01-05 10:04 UTC (permalink / raw)


I'm getting an elaboration error and I don't understand why. It seems
to be caused by having a task in a package body that calls a procedure
in a child of that package.

Various restructurings, such as moving the task to a second child
package, have failed to clear the error.

I'm using Gnat 3.15p (GPS 2.1.0 on XP Pro).

The error goes away if I replace the direct call to the procedure in
the child (Child_C1.Proc1 in the code) by an indirect call to a local
procedure in the package body that then makes the call (Parent_Proc2)
but I guess that is only hiding the problem rather than solving it.


with Parent_P;
procedure Proc_P is
begin
    Parent_P.Parent_Proc1;
end Proc_P;


package Parent_P is
    procedure Parent_Proc1;
private
    Data1 : Integer;
end Parent_P;


with Parent_P.Child_C1;
package body Parent_P is

    procedure Parent_Proc1 is
    begin
       null;
    end Parent_Proc1;

    procedure Parent_Proc2 is
    begin
       Child_C1.Proc1 (Data1);
    end Parent_Proc2;

    task Parent_T;
    task body Parent_T is
    begin
       Child_C1.Proc1 (Data1);
    end Parent_T;

end Parent_P;


package Parent_P.Child_C1 is
    procedure Proc1 (P1 : in     Integer);
end Parent_P.Child_C1;


package body Parent_P.Child_C1 is

    procedure Proc1 (P1 : in     Integer) is
    begin
       null;
    end Proc1;

end Parent_P.Child_C1;


gnatbind -static -x proc_p.ali
error: elaboration circularity detected
info:    "parent_p (body)" must be elaborated before "parent_p (body)"
info:       reason: Elaborate_All probably needed in unit "parent_p 
(body)"
info:       recompile "parent_p (body)" with -gnatwl for full details
info:          "parent_p (body)"
info:             must be elaborated along with its spec:
info:          "parent_p (spec)"
info:             which is withed by:
info:          "parent_p.child_c1 (spec)"
info:             which is withed by:
info:          "parent_p (body)"

gnatmake: *** bind failed.


Adding pragma Elaborate_All(Parent_P.Child_C1); to the body of Parent_P
(as suggested) produces the same error except that the pragma is now
given as the reason for the circularity.

Using -gnatwl doesn't produce any additional information.

An unexpected part of the error message is that the body of Parent_P
"must be elaborated along with its spec". Can anyone explain why this is 
or otherwise suggest how to avoid the problem.

Cheers, and TIA,

Phil Thornley
-- 
JP Thornley



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

* Re: Elaboration problem with a task
  2006-01-05 10:04 Elaboration problem with a task JP Thornley
@ 2006-01-05 10:16 ` Martin Dowie
  2006-01-05 11:13   ` JP Thornley
  2006-01-05 19:34 ` Jeffrey R. Carter
  2006-01-05 20:42 ` Simon Wright
  2 siblings, 1 reply; 7+ messages in thread
From: Martin Dowie @ 2006-01-05 10:16 UTC (permalink / raw)


JP Thornley wrote:
> gnatbind -static -x proc_p.ali
> error: elaboration circularity detected
> info:    "parent_p (body)" must be elaborated before "parent_p (body)"
> info:       reason: Elaborate_All probably needed in unit "parent_p (body)"
> info:       recompile "parent_p (body)" with -gnatwl for full details
> info:          "parent_p (body)"
> info:             must be elaborated along with its spec:
> info:          "parent_p (spec)"
> info:             which is withed by:
> info:          "parent_p.child_c1 (spec)"
> info:             which is withed by:
> info:          "parent_p (body)"
> 
> gnatmake: *** bind failed.
> 
> 
> Adding pragma Elaborate_All(Parent_P.Child_C1); to the body of Parent_P
> (as suggested) produces the same error except that the pragma is now
> given as the reason for the circularity.
> 
> Using -gnatwl doesn't produce any additional information.
> 
> An unexpected part of the error message is that the body of Parent_P
> "must be elaborated along with its spec". Can anyone explain why this is 
> or otherwise suggest how to avoid the problem.

Have you tried "-gnatE"?

Cheers

-- Martin



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

* Re: Elaboration problem with a task
  2006-01-05 10:16 ` Martin Dowie
@ 2006-01-05 11:13   ` JP Thornley
  2006-01-05 14:18     ` Martin Dowie
  0 siblings, 1 reply; 7+ messages in thread
From: JP Thornley @ 2006-01-05 11:13 UTC (permalink / raw)


In article <dpirm7$cs1$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>, Martin 
Dowie <martin.dowie@btopenworld.com> writes
>Have you tried "-gnatE"?

Hmmm, the error goes away and the code (with some Text_IO added) runs 
OK. So the error report is spurious?

Thanks for that.

Cheers,

Phil
-- 
JP Thornley



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

* Re: Elaboration problem with a task
  2006-01-05 11:13   ` JP Thornley
@ 2006-01-05 14:18     ` Martin Dowie
  2006-01-05 16:35       ` Pascal Obry
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Dowie @ 2006-01-05 14:18 UTC (permalink / raw)


JP Thornley wrote:
> In article <dpirm7$cs1$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>, Martin 
> Dowie <martin.dowie@btopenworld.com> writes
> 
>> Have you tried "-gnatE"?
> 
> 
> Hmmm, the error goes away and the code (with some Text_IO added) runs 
> OK. So the error report is spurious?
> 
> Thanks for that.

No probs - the default GNAT behaviour is to use it's own rules about 
elaboration, not the Ada rules. They are supposed to be 'better' than 
the Ada rules but if you want Ada rather than GNAT, you always have to 
use "-gnatE", rather like using "-gnato".

Cheers

-- Martin



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

* Re: Elaboration problem with a task
  2006-01-05 14:18     ` Martin Dowie
@ 2006-01-05 16:35       ` Pascal Obry
  0 siblings, 0 replies; 7+ messages in thread
From: Pascal Obry @ 2006-01-05 16:35 UTC (permalink / raw)
  To: Martin Dowie

Martin,

> No probs - the default GNAT behaviour is to use it's own rules about
> elaboration, not the Ada rules. They are supposed to be 'better' than
> the Ada rules but if you want Ada rather than GNAT, you always have to
> use "-gnatE", rather like using "-gnato".

You can put it this way or... GNAT by default does a static analysis of
the elaboration and generates elaboration that does work in 99% of the
cases. If this default behavior is not working in your case then -gnatE
which does a dynamic elaboration checking.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Elaboration problem with a task
  2006-01-05 10:04 Elaboration problem with a task JP Thornley
  2006-01-05 10:16 ` Martin Dowie
@ 2006-01-05 19:34 ` Jeffrey R. Carter
  2006-01-05 20:42 ` Simon Wright
  2 siblings, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-01-05 19:34 UTC (permalink / raw)


JP Thornley wrote:

> I'm getting an elaboration error and I don't understand why. It seems
> to be caused by having a task in a package body that calls a procedure
> in a child of that package.

FWIW, same error with 3.4.2 (mingw-special). -gnatE solves the problem.

-- 
Jeff Carter
"That was the most fun I've ever had without laughing."
Annie Hall
43



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

* Re: Elaboration problem with a task
  2006-01-05 10:04 Elaboration problem with a task JP Thornley
  2006-01-05 10:16 ` Martin Dowie
  2006-01-05 19:34 ` Jeffrey R. Carter
@ 2006-01-05 20:42 ` Simon Wright
  2 siblings, 0 replies; 7+ messages in thread
From: Simon Wright @ 2006-01-05 20:42 UTC (permalink / raw)


This compiles & runs OK (GNAT/GPL on MacOS):

   with Parent_P.Child_C1;
   pragma Elaborate (Parent_P.Child_C1);
   package body Parent_P is

The normal rule-of-thumb with GNAT is to avoid creating tasks during
elaboration; try to use task types and create the actual tasks after
elaboration has completed. I know this tends to add complication to
the design!



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

end of thread, other threads:[~2006-01-05 20:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-05 10:04 Elaboration problem with a task JP Thornley
2006-01-05 10:16 ` Martin Dowie
2006-01-05 11:13   ` JP Thornley
2006-01-05 14:18     ` Martin Dowie
2006-01-05 16:35       ` Pascal Obry
2006-01-05 19:34 ` Jeffrey R. Carter
2006-01-05 20:42 ` Simon Wright

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