comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@rfc1149.net>
Subject: Re: Question about circular elaboration order error (GNAT).
Date: Sun, 13 Apr 2008 21:43:19 +0200
Date: 2008-04-13T21:45:01+02:00	[thread overview]
Message-ID: <87skxppmlk.fsf@willow.rfc1149.net> (raw)
In-Reply-To: 48024d11$0$19786$4d3efbfe@news.sover.net

>>>>> "Peter" == Peter C Chapin <pchapin@sover.net> writes:

Peter> I don't understand where the circularity is coming from. Isn't
Peter> the following elaborate order acceptable:

No. pragma Elaborate_All is transitive, and forces the elaboration of
Parent body (since Parent.Child has an implicit dependency on Parent)
before... Parent body elaboration. Hence the circular elaboration
order.

But you can fix the situation by providing GNAT with the necessary
elaboration information:

  - put a "pragma Elaborate (Parent.Child)" in Parent body to indicate
    that Parent elaboration requires Parent.Child to be elaborated; this
    pragma isn't transitive, so you have to ensure that subprograms of
    Parent.Child called during the elaboration of Parent do not
    themselves require that other packages be elaborated first, or add
    the required pragma;

  - put a "pragma Elaborate_Body" in Parent.Child spec if you know
    that this package is likely to be called during the elaboration of
    other packages; this requires that the body be elaborated just
    after the spec.

Using only the "pragma Elaborate_Body" will not be enough for GNAT, so
the "pragma Elaborate" is required. That is because GNAT is
overcautious and adds implicit "pragma Elaborate_All" unless you
provide explicit "pragma Elaborate".

Note that having GNAT be overcautious by default is actually a good
thing: I spent three hours two weeks ago debugging a tricky
elaboration problem in a software written for an embedded system. The
original author incorrectly used "pragma Elaborate". Had he done
nothing, GNAT would have warned him about the dangerous situation.

I hope this clarifies things.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



  reply	other threads:[~2008-04-13 19:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-13 18:12 Question about circular elaboration order error (GNAT) Peter C. Chapin
2008-04-13 19:43 ` Samuel Tardieu [this message]
2008-04-13 20:20   ` Robert A Duff
2008-04-13 21:20     ` Samuel Tardieu
2008-04-14 20:21       ` Robert A Duff
2008-04-14 23:36         ` Adam Beneschan
2008-04-15  7:13           ` Georg Bauhaus
2008-04-13 19:46 ` Robert A Duff
2008-04-13 22:49   ` Peter C. Chapin
2008-04-14 13:56     ` Robert A Duff
2008-04-14 17:33 ` Jeffrey R. Carter
2008-04-14 17:52   ` 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