comp.lang.ada
 help / color / mirror / Atom feed
* Constant elaboration order
@ 2001-11-30 21:59 Thierry BERNIER
  2001-12-01  1:25 ` Ted Dennison
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry BERNIER @ 2001-11-30 21:59 UTC (permalink / raw)


Bonjour,

From those who learn the RM each evening before sleep, I would like to know
if I can assert that elaboration order is always the same for a given
executable.
It seems clearly true for GNAT when you read the binder generated startup
code (b~foo.adb), but what about the law ?

An interesting advice I found is following, but it does not answer (and is
only an advice).

--
Thierry Bernier:


RM95-10.2.1(12) says :
In an implementation, a type declared in a preelaborated package should have
the same representation in every elaboration of a given version of the
package, whether the elaborations occur in distinct executions of the same
program, or in executions of distinct programs or partitions that include
the given version.







^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Constant elaboration order
  2001-11-30 21:59 Constant elaboration order Thierry BERNIER
@ 2001-12-01  1:25 ` Ted Dennison
  2001-12-01 16:43   ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Ted Dennison @ 2001-12-01  1:25 UTC (permalink / raw)


In article <3c0800dc$0$211$626a54ce@news.free.fr>, Thierry BERNIER says...
>From those who learn the RM each evening before sleep, I would like to know
>if I can assert that elaboration order is always the same for a given
>executable.

No. However, I know of no compiler that actually does that. The DEC Ada compiler
was capable of changing it from compile to compile. (It would optimize harder if
it happened to have more resources available at compile time).

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Constant elaboration order
  2001-12-01  1:25 ` Ted Dennison
@ 2001-12-01 16:43   ` Robert Dewar
  2001-12-06 22:16     ` Thierry BERNIER
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Dewar @ 2001-12-01 16:43 UTC (permalink / raw)


Ted Dennison<dennison@telepath.com> wrote in message news:<gkWN7.44693$xS6.75190@www.newsranger.com>...

> No. However, I know of no compiler that actually does 
> that.

This is misinformation. For a given compiler, you can be
certain that the order of elaboration will be consistent,
assuming that the order of compilation is consistent (for
source based systems that do not have a required order
of elaboration, the latter condition is likely irrelevant,
it certainly is irrelevant for GNAT).


> The DEC Ada compiler
> was capable of changing it from compile to compile. (It
> would optimize harder if
> it happened to have more resources available at compile 
> time).

I understand that this purports to be a counter example.
I believe this is misinformation as well.

Probably the confusion here is that of course in a traditional Ada 83
system, the elaboration order can
depend on the order of compilation, because of inlining,
but for a given order of compilation you will of course
get a consistent elaboration order.

However, big however! that order may well differ from
one compiler to another, or from one version of the same
compiler to another.

For information on elaboration, read the chapter on the
subject in the GNAT user's guide. I wrote that chapter, and
as far as I know it is the most comprehensive treatment
of the subject. It is of course tied into the way GNAT
does things, but even if you are not using GNAT, you can
learn a lot from this chapter.

Robert Dewar



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Constant elaboration order
  2001-12-01 16:43   ` Robert Dewar
@ 2001-12-06 22:16     ` Thierry BERNIER
  2001-12-06 22:33       ` Matthew Heaney
  2001-12-07 14:34       ` Stephen Leake
  0 siblings, 2 replies; 6+ messages in thread
From: Thierry BERNIER @ 2001-12-06 22:16 UTC (permalink / raw)


Bonjour,

Thanks to Ted and Robert, I just read the indicated chapter nn GNAT user's
guide. Interesting and I will read it again with less noise around. May be I
will try to move some elaboration code to public packages's sub-program and
call them explicitely in the main program (as it is proposed in the GNAT
UG).

BUT,
my question was about a given executable. When the compiler, binder and
linker have processed source files. My executable is here and I would like
to assert that from one run to another of this executable; elaboration code
chunks are executed in the same order (the one statically choosen by the
binder).

I understand this is true for GNAT, but found no rule in the RM (we can
forget annex E here).

Thierry Bernier






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Constant elaboration order
  2001-12-06 22:16     ` Thierry BERNIER
@ 2001-12-06 22:33       ` Matthew Heaney
  2001-12-07 14:34       ` Stephen Leake
  1 sibling, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 2001-12-06 22:33 UTC (permalink / raw)



"Thierry BERNIER" <tajz@free.fr> wrote in message
news:3c0fedf4$0$203$626a54ce@news.free.fr...
> Bonjour,
>
> Thanks to Ted and Robert, I just read the indicated chapter nn GNAT user's
> guide. Interesting and I will read it again with less noise around. May be
I
> will try to move some elaboration code to public packages's sub-program
and
> call them explicitely in the main program (as it is proposed in the GNAT
> UG).

Yes.  This is always a good idea:

package Subsystem is
   procedure Initialize;
...
end Subsystem;

And then in your main subprogram, simply call Subsystem.Initialize.

Lots of Ada programmers have gotten it into their heads that they should
stuff all kinds of hairy initialization code into the begin part of a
package body, but anything other than trivial initialization of package
state is a mistake.  Use the technique above.

This is especially relevant when you have tasks, because a task "activates"
when you hit the begin part of the body.  So if it tries to make a call to
another package, there's no guarantee that that other package has been
elaborated yet, and mayhem will ensue.

(Actually, I'm not sure what the exact rule is. Do all the library-level
tasks activate only after you hit the executable region of the main
subprogram?  Or does each task activate immediately following the
elaboration of its enclosing package?)






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Constant elaboration order
  2001-12-06 22:16     ` Thierry BERNIER
  2001-12-06 22:33       ` Matthew Heaney
@ 2001-12-07 14:34       ` Stephen Leake
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2001-12-07 14:34 UTC (permalink / raw)


"Thierry BERNIER" <tajz@free.fr> writes:

> <snip>
> my question was about a given executable. When the compiler, binder and
> linker have processed source files. My executable is here and I would like
> to assert that from one run to another of this executable; elaboration code
> chunks are executed in the same order (the one statically choosen by the
> binder).

This is true. Any executable will give the same results when run
again, unless it depends on some random external factor (like time or
user input). Since there are no external factors determining
elaboration order, it is repeatable.

Hmm. I guess it is _possible_ to put external IO and tasks in
elaboration code, which _could_ affect the final elaboration order.
But you'd have to really work at it!

> I understand this is true for GNAT, but found no rule in the RM (we
> can forget annex E here).

Hmm. The closest rule I can find is 10.2.1 (26), which defines pragmas
Elaborate_Body and Elaborate_All. However, to really understand an
issue like this, you need to consider the RM as a whole, which can be
hard. That's why ACT made the effort of writing their user guide,
which is far more understandable (as you discovered).

In sum, elaboration order, in the absence of elaboration order
pragmas, is left to the implementation. If you want to guarrantee that
the elaboration order is safe, put in the elaboration pragmas
suggested by GNAT.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-12-07 14:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-30 21:59 Constant elaboration order Thierry BERNIER
2001-12-01  1:25 ` Ted Dennison
2001-12-01 16:43   ` Robert Dewar
2001-12-06 22:16     ` Thierry BERNIER
2001-12-06 22:33       ` Matthew Heaney
2001-12-07 14:34       ` Stephen Leake

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