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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,16e3a8dd4f3ab3f3 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Elaboration order Date: 1996/03/15 Message-ID: #1/1 X-Deja-AN: 142841223 references: <314701A1.469D@lfwc.lockheed.com> <31494143.3825@lfwc.lockheed.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-03-15T00:00:00+00:00 List-Id: In article <31494143.3825@lfwc.lockheed.com>, Ken Garlington wrote: >Robert A Duff wrote: > >[the standard answer, except it didn't explain...] > >Why doesn't the subprogram body have to be elaborated before the call? Not sure what you're asking -- why was the language designed this way, or why do the existing language rules imply this. >Should I expect this problem anytime I call a subroutine? It seems >counter-intuitive... When you say "with P;", you are depending on the *spec* of P, and the rules in chap 10 say that this spec will be elaborated before you. You do not depend on the *body* of P, so it might get elaborated later, causing a nasty bug. To fix it, you have to put in one of the elaboration-controlling pragmas. Now, if we said that "with P;" introduced a requirement that spec AND BODY of P be elaborated earlier, then you couldn't write mutually recursive packages -- e.g. body of P says "with Q;", and body of Q says "with P;". That's an important feature. One could imagine other solutions, though. During the design of Ada 95, we considered trying to solve this problem, but it's not easy (especially given the requirement for upward compatibility), and we eventually just didn't do it. It's a real problem, primarily because you have no way of knowing whether this bug exists in your code -- your compiler might just *happen* to elaborate things in an order that makes your code work, but the bug appears when you use a different compiler, or make some unrelated change in the with_clauses. Here's one idea: By default, "with P;" means both spec and body of P get elaborated before me. If there are mutually-recursive packages, you have to put in a special pragma that says, "don't bother elaborating the body of P earlier than me". I think turning it around this way would reduce the number of cases where you have to put in a pragma, and would make the safe case be the default. This would not be upward compatible. The designers of Ada 83 struggled with this issue. In Ada 80 (or so), the compiler was required to do an extraordinarily complex analysis at link time, to determine the order, so there was no need for run-time checks on calls. This was changed in order to simplify implementation. - Bob