From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5f9c25380ec58962 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.73.229 with SMTP id o5mr8107282pbv.7.1326734966702; Mon, 16 Jan 2012 09:29:26 -0800 (PST) Path: lh20ni189297pbb.0!nntp.google.com!news2.google.com!postnews.google.com!w4g2000vbc.googlegroups.com!not-for-mail From: AdaMagica Newsgroups: comp.lang.ada Subject: Re: Elaboration circularity with generics Date: Mon, 16 Jan 2012 09:15:04 -0800 (PST) Organization: http://groups.google.com Message-ID: <2c9456e6-17d4-4493-8d7e-8017a4540d8c@w4g2000vbc.googlegroups.com> References: <583b1bfe-95bd-4669-b16b-c733c81e8f88@w4g2000vbc.googlegroups.com> <3a04e681-8180-4722-9b19-414173073d8e@m4g2000vbc.googlegroups.com> NNTP-Posting-Host: 91.7.40.70 Mime-Version: 1.0 X-Trace: posting.google.com 1326734966 7578 127.0.0.1 (16 Jan 2012 17:29:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 16 Jan 2012 17:29:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w4g2000vbc.googlegroups.com; posting-host=91.7.40.70; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.0; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-01-16T09:15:04-08:00 List-Id: On 16 Jan., 16:09, Simon Wright wrote: > AdaMagica writes: > > On 14 Jan., 23:46, Simon Wright wrote: > >> AdaMagica 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. > > >> =A0 =A0with P.Q; > >> =A0 =A0pragma Elaborate (P.Q); =A0 =A0 =A0 =A0 =A0<<<<<<< does the tri= ck for me > >> =A0 =A0package 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 > > =A0 pragma Elaborate_Body; =A0-- prevents elaboration error when F is > > called > > =A0 function F (...) return T; > > end P; > > > with P; =A0-- no need for "pragma Elaborate (P);" > > package Q is > > =A0 V: [constant] T :=3D P.F (...); > > end Q; > > That may be true in general, but *in this case* it does not solve the > problem; > > =A0 =A0generic > =A0 =A0 =A0 type T is private; > =A0 =A0package P.Q is > =A0 =A0 =A0 pragma Elaborate_Body; > =A0 =A0 =A0 procedure Proc; > =A0 =A0end P.Q; > > then > > =A0 =A0$ gnatmake test > =A0 =A0gcc -c test.adb > =A0 =A0gcc -c p.adb > =A0 =A0gcc -c p-q.adb > =A0 =A0gnatbind -x test.ali > =A0 =A0error: elaboration circularity detected > =A0 =A0info: =A0 =A0"p (body)" must be elaborated before "p (body)" > =A0 =A0info: =A0 =A0 =A0 reason: implicit Elaborate_All in unit "p (body)= " > =A0 =A0info: =A0 =A0 =A0 recompile "p (body)" with -gnatwl for full detai= ls > =A0 =A0info: =A0 =A0 =A0 =A0 =A0"p (body)" > =A0 =A0info: =A0 =A0 =A0 =A0 =A0 =A0 must be elaborated along with its sp= ec: > =A0 =A0info: =A0 =A0 =A0 =A0 =A0"p (spec)" > =A0 =A0info: =A0 =A0 =A0 =A0 =A0 =A0 which is withed by: > =A0 =A0info: =A0 =A0 =A0 =A0 =A0"p.q (spec)" > =A0 =A0info: =A0 =A0 =A0 =A0 =A0 =A0 which is withed by: > =A0 =A0info: =A0 =A0 =A0 =A0 =A0"p (body)" > > =A0 =A0gnatmake: *** bind failed. > > -gnatE still succeeds (provided you remember to rebuild the world!) Ha, yes, because of the implicit Elaborate_All implied by the nonstandard behaviour of GNAT (I didn't think of this connection). Obviously with standard Ada behaviour (-gnatE), GNAT can find a good order without the pragma (there is no Elaborate_All in this case). But I think the rule of thumb should be followed nevertheless. (It's only a rule of thumb because Elaborate_Body is sometimes impossible.)