comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Elaboration order
Date: 1996/03/15
Date: 1996-03-15T00:00:00+00:00	[thread overview]
Message-ID: <DoBI9D.KH6@world.std.com> (raw)
In-Reply-To: 31494143.3825@lfwc.lockheed.com

In article <31494143.3825@lfwc.lockheed.com>,
Ken Garlington  <garlingtonke@lfwc.lockheed.com> 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




  parent reply	other threads:[~1996-03-15  0:00 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <314701A1.469D@lfwc.lockheed.com>
1996-03-15  0:00 ` Elaboration order Robert I. Eachus
1996-03-15  0:00   ` Robert Dewar
     [not found] ` <1996Mar14.021345.9856@enterprise.rdd.lmsc.lockheed.com>
     [not found]   ` <314829CD.4FA9@lfwc.lockheed.com>
1996-03-15  0:00     ` Tucker Taft
1996-03-15  0:00       ` Ken Garlington
1996-03-16  0:00     ` Joe Wierzbowski
1996-03-26  0:00       ` AdaWorks
1996-03-26  0:00         ` Robert Dewar
1996-03-26  0:00           ` Robert A Duff
1996-03-26  0:00             ` Robert Dewar
1996-03-26  0:00           ` IO in Pure packages, debugging Laurent Guerby
1996-03-26  0:00         ` Elaboration order Robert A Duff
1996-03-16  0:00     ` Ted Dennison
1996-03-26  0:00     ` Laurent Guerby
1996-03-26  0:00       ` Robert A Duff
1996-03-18  0:00 ` Ken Garlington
1996-03-18  0:00 ` Ted Dennison
1996-03-19  0:00 ` Michel Gauthier
1996-03-20  0:00 ` DenReimer
1996-03-20  0:00   ` Tucker Taft
1996-03-20  0:00   ` Norman H. Cohen
1996-03-20  0:00   ` Robert A Duff
1996-03-20  0:00     ` Norman H. Cohen
1996-03-20  0:00       ` Robert Dewar
     [not found] ` <Do8JDv.A2v@world.std.com>
     [not found]   ` <31494143.3825@lfwc.lockheed.com>
1996-03-15  0:00     ` Mark A Biggar
1996-03-18  0:00       ` Ken Garlington
1996-03-19  0:00         ` Norman H. Cohen
1996-03-20  0:00           ` Cordes MJ
1996-03-19  0:00             ` Robert Dewar
1996-03-21  0:00               ` Ken Garlington
1996-03-21  0:00               ` Cordes MJ
1996-03-20  0:00             ` Robert A Duff
1996-03-20  0:00               ` Cordes MJ
1996-03-20  0:00                 ` Robert A Duff
1996-03-22  0:00                   ` Cordes MJ
1996-03-20  0:00                 ` Robert Dewar
1996-03-21  0:00                   ` Ken Garlington
1996-03-23  0:00                 ` JP Thornley
1996-03-25  0:00                   ` Robert Dewar
1996-03-26  0:00                 ` JP Thornley
1996-03-19  0:00         ` Chris McKnight
1996-03-21  0:00           ` Ken Garlington
1996-03-15  0:00     ` Robert A Duff [this message]
1996-03-18  0:00       ` Norman H. Cohen
     [not found]       ` <EACHUS.96Mar18143219@spectre.mitre.org>
1996-03-18  0:00         ` Robert Dewar
1996-03-19  0:00           ` Ted Dennison
1996-03-18  0:00         ` Robert Dewar
1996-03-20  0:00         ` David Emery
1996-03-20  0:00   ` Robert I. Eachus
1996-03-22  0:00   ` Robert I. Eachus
1996-03-22  0:00   ` Robert I. Eachus
1999-11-15  0:00 Elaboration Order Wolf-Dieter Heker
1999-11-15  0:00 ` Robert Dewar
1999-11-16  0:00   ` Wolf-Dieter Heker
1999-11-16  0:00     ` Robert Dewar
1999-11-16  0:00     ` Robert Dewar
1999-11-20  0:00       ` Simon Wright
1999-11-22  0:00         ` Robert Dewar
1999-11-23  0:00           ` Mats Weber
1999-11-16  0:00     ` David C. Hoos, Sr.
1999-11-15  0:00 ` Jean-Pierre Rosen
1999-11-15  0:00   ` Robert Dewar
1999-11-16  0:00     ` Jean-Pierre Rosen
1999-11-20  0:00       ` Simon Wright
     [not found] <DoDMLL.1F9@world.std.com>
1996-03-18  0:00 ` Elaboration order Chris McKnight
  -- strict thread matches above, loose matches on Subject: below --
1996-03-18  0:00 Jean-Pierre Rosen
1996-03-21  0:00 ` Ken Garlington
replies disabled

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