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 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,UTF8 Received: by 10.68.196.130 with SMTP id im2mr7829149pbc.3.1326726560006; Mon, 16 Jan 2012 07:09:20 -0800 (PST) Path: lh20ni188937pbb.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Elaboration circularity with generics Date: Mon, 16 Jan 2012 15:09:18 +0000 Organization: A noiseless patient Spider Message-ID: References: <583b1bfe-95bd-4669-b16b-c733c81e8f88@w4g2000vbc.googlegroups.com> <3a04e681-8180-4722-9b19-414173073d8e@m4g2000vbc.googlegroups.com> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="21355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18j3Jo54G9fdVzKDlxTOSyKSMFOlLky+cE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:K5e8gVk/8D1NdlZLIt1haWP6msk= sha1:k39hH5MtBSpIuynYLNNn3HyNFWg= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Date: 2012-01-16T15:09:18+00:00 List-Id: 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. >> >>    with P.Q; >>    pragma Elaborate (P.Q);          <<<<<<< does the trick for me >>    package 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 > pragma Elaborate_Body; -- prevents elaboration error when F is > called > function F (...) return T; > end P; > > with P; -- no need for "pragma Elaborate (P);" > package Q is > V: [constant] T := P.F (...); > end Q; That may be true in general, but *in this case* it does not solve the problem; generic type T is private; package P.Q is pragma Elaborate_Body; procedure Proc; end P.Q; then $ 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. -gnatE still succeeds (provided you remember to rebuild the world!)