From: stt@dsd.camb.inmet.com (Tucker Taft)
Subject: Re: Static in 9X
Date: Fri, 16 Sep 1994 10:26:48 GMT
Date: 1994-09-16T10:26:48+00:00 [thread overview]
Message-ID: <Cw7x0p.7M4@inmet.camb.inmet.com> (raw)
In-Reply-To: Cw6F9K.n57@inmet.camb.inmet.com
By the way, in private conversation it became clear
that the real goal was more link-time initialization of
large data structures. Although staticness is only defined
for scalars and certain string expressions, there is no
reason an implementation should not be *much* more aggressive
in performing link-time initialization of data structures.
RM9X does talk about preelaborability, which is closer to
what is appropriate for link-time initialization, but even
preelaborability is too conservative in many cases (and a bit
too liberal in others).
The goal of every Ada implementation should be that if there
is no calculation that *needs* to be performed at run-time to
initialize a data structure, then the data structure should
be link-time initialized. Of course no implementation can
really fulfill this goal -- it is probably equivalent to solving
the halting problem -- but this should be the goal.
The user can help out by avoiding things like:
1) anything that depends heavily on the run-time system
(such as uses of allocators, anything tasking-related, etc.)
and hence might involve building up linked lists, etc.
2) references to other variables or large constants in the
aggregate initializing a large constant you hope will
be link-time initialized. Just because something is
link-time initialized, *don't* presume the compiler can
perform indexing or selection into it at compile-time,
because that implies keeping all of the data in memory,
rather than just dumping it into the object module.
For example:
X : constant Blah := (1, 5, 8, 7, "abcde", 3.5, ...);
Y : constant Boffo := (4, 7, X.F, 9, X.G, 2.7, ...);
Expecting X to be link-time initialized is reasonable.
Expecting Y to be is not, given the references to X inside it.
3) Any calls on user-defined functions, even if their bodies are
"trivial" or inlined.
Probably some compilers can handle even things like the above. In
particular, there is a recommendation that allocators for
access-to-constant types be handled at link-time, and I hope
most Ada 9X compilers will do so. This should enable tables of
pointers to error messages (or equivalent) to be link-time initialized.
For example:
type Error_Message is access constant String;
Error_Table : array(Positive range <>) of Error_Message :=
(new String'("Naughty, naughty"),
new String'("No way, Jose'"),
new String'("You have got to be kidding"),
...
);
The above should be link-time initializable. For those familiar
with C and how string literals are represented (by a pointer
into link-time allocated storage), the above should be treated as
approximately equivalent to:
char *error_table[] = {
"Naughty, naughty",
"No way, Jose'",
"You have got to be kidding",
...
};
It is not exactly the same because in Ada, strings have array
bounds rather than a null terminator, but that shouldn't interfere
with link-time initialization of a data structure like the above.
Note that access-to-variable allocators can't be easily handled
with link-time allocation, because unchecked-deallocation is allowed
for access-to-variable types (it is not allowed for access-to-constant
types in 9X).
S. Tucker Taft stt@inmet.com
Ada 9X Mapping/Revision Team
Intermetrics, Inc.
Cambridge, MA 02138
next prev parent reply other threads:[~1994-09-16 10:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <940914130023_73672.2025_DHR31-2@compuserve.com>
1994-09-15 15:05 ` Static in 9X Tucker Taft
1994-09-16 10:26 ` Tucker Taft [this message]
1994-09-19 23:40 Ken Garlington
-- strict thread matches above, loose matches on Subject: below --
1994-09-16 3:03 Ken Garlington
1994-09-17 3:13 ` Robert Dewar
1994-09-14 13:00 Ken Garlington
1994-09-15 13:37 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox