From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Possible Ada deficiency?
Date: 09 Jan 2005 15:10:20 -0500
Date: 2005-01-09T15:10:20-05:00 [thread overview]
Message-ID: <wccu0pql5xv.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: gemini.ia2bxv002sq5o02vo.nick.roberts@acm.org
Nick Roberts <nick.roberts@acm.org> writes:
> Robert A Duff <bobduff@shell01.TheWorld.com> wrote:
> > The main thing is that the compiler needs to know the size of a private
> > type in order to allocate things, unless it treats all private types as
> > dynamic-sized, which would be annoying -- you shouldn't have to pay an
> > efficiency cost to get the benefits of encapsulation, information hiding,
> > etc. So if the full type were in the body, the compiler would have to
> > look at the body (at least in optimizing mode).
>
> I agree completely.
Well, I don't. ;-)
I said "at least in optimizing mode", implying that the compiler could
choose a compile-time-efficient method of record layout (not looking at
the body) or a run-time-efficient one (looking at the body), depending
on some optimization switch. But now that I think about it, that might
not be a good idea. It might be disconcerting to programmers if record
layout changes depending on compiler switches, especially if those
records are written to files. Hmm...
> I don't think it would have to be that fancy.
Well, I don't think incremental compilers are trivial. (I've built
them, but not for Ada.) But I agree they are feasible and desirable.
The granularity of incrementality need not be very fine in order to get
the benefits.
>... A simple but effective
> strategy would be for the compiler to remember the size of each private type
But it's not just the size of private types and a couple of other
things. It's any piece of information that affects the generated code.
This depends on how much optimization is done, but it could include all
kinds of things: alignment, whether a type contains tasks, whether a
type has finalization, whether a parameter is small enough to pass in a
register, whether the value of a deferred constant is known at compile
time, and if so, the value, whether various dope (such as array bounds)
is known at compile time, and if so, the values, &c.
And if you forget one such item, you've got a very nasty compiler bug:
rebuilding misses some changes to your code.
The source-based compilation model of GNAT and AdaMagic seems much
simpler, although much less efficient at compile time.
Another problem with moving private-part stuff into the body would be
elaboration order problems. The freezing rules wouldn't work at all.
(The freezing rules are an abomination, though, and I wouldn't mind a
total redesign of that area.) But the point is, you need to prevent
things like creating an object of a given type before its full type has
been elaborated. We do run-time checks for subprograms, which is
somewhat ugly in my opinion; I suppose that could work for private
types, too.
Another issue: I wonder if it would wreak havoc with representation
clauses.
> I suppose it is slightly idle speculation (not that I'm averse to idle
> speculation ;-) but I think we all have our own ideas about how the perfect
> language should have been.
I've got lots of ideas. ;-)
And I think programming language design is in its infancy.
There may never be a "perfect" language, but we can do a lot better
than any existing language.
>... (By the way, on a historical note JDI stands for
> 'Jean Ichbiah', the leader of the team who developed the Ada 83 standard.)
Yes, thank you. I shouldn't have assumed everybody knows that.
And Tucker was the leader of the Ada 95 design team, of which I
was a member.
> One idea would have been to eliminate the principle of having to declare
> things in advance of their use. Ada takes this approach to goto labels, in
> fact. When something was used, for example a procedure call:
>
> Foo(Bar,Hum);
>
> the compiler would simply note the need for an object Bar, and an object
> Hum, and a procedure with profile Foo(Bar'Type,Hum'Type).
>
> At the end of the compilation process, the compiler would say "Was there a
> declaration of an object Bar?" Assuming there was, its type must now be
> known, let's say T1. The compiler would do the same thing with Hum, let's
> say its type was T2. Then the compiler would say "Was there a declaration of
> a procedure fitting profile Foo(T1,T2)?" If there wasn't, or if there was an
> ambiguity, it could report the error.
Nick, I don't know how to say this politely: You're stark raving mad! ;-)
If Foo is overloaded, the above mechanism would be complicated beyond
belief. And note that Bar could be a parameterless function.
If Ada allowed forward references, a two-pass semantic analysis
algorithm could work reasonably. But the above-suggested method seems
completely infeasible to me.
Anyway, I think the main reason for disallowing forward references was
to make code more readable, not just to make the compiler's life easier.
Allowing forward references also introduces elaboration-order problems,
and circularity problems. Probably solvable, but more rules would be
needed. For example:
type T1 is range 1..T2'Last; -- currently illegal
type T2 is range 1..T1'Last;
> This way, package specifications wouldn't be needed. You would actually have
> a private part in the body, which would contain the declarations of things
> not to be exported.
>
> Of course, this approach didn't fit the prevailing compilation model of
> those days (the 1980s). Just an idle thought.
Package specs are not (primarily) for the benefit of the compiler.
They are there to provide a contract -- a definition of the interface
between a package and its clients. The visible part is a Good Thing.
It's just the private part that seems kludgy.
- Bob
next prev parent reply other threads:[~2005-01-09 20:10 UTC|newest]
Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-31 18:15 Possible Ada deficiency? danmcleran
2004-12-31 19:12 ` Jeffrey Carter
2005-01-01 1:52 ` danmcleran
2005-01-01 2:37 ` Jeffrey Carter
2005-01-01 2:02 ` danmcleran
2005-01-01 14:11 ` Martin Krischik
2005-01-01 15:27 ` danmcleran
2005-01-02 17:49 ` Martin Krischik
2005-01-01 15:30 ` Stephen Leake
2005-01-01 15:57 ` danmcleran
2005-01-03 23:37 ` Randy Brukardt
2005-01-07 17:26 ` Nick Roberts
2005-01-07 18:26 ` danmcleran
2005-01-07 21:32 ` Randy Brukardt
2005-01-08 3:56 ` Nick Roberts
2005-01-08 18:15 ` Robert A Duff
2005-01-08 19:11 ` Jeffrey Carter
2005-01-08 20:03 ` Robert A Duff
2005-01-09 3:40 ` Jeffrey Carter
2005-01-09 17:30 ` Robert A Duff
2005-01-09 19:24 ` Jeffrey Carter
2005-01-09 21:56 ` Nick Roberts
2005-01-10 13:47 ` Dmitry A. Kazakov
2005-01-10 16:46 ` Duncan Sands
2005-01-10 17:58 ` Pascal Obry
2005-01-10 18:45 ` Dmitry A. Kazakov
2005-01-10 19:44 ` Pascal Obry
2005-01-11 10:05 ` Dmitry A. Kazakov
2005-01-11 7:24 ` Vinzent 'Gadget' Hoefler
2005-01-11 9:48 ` Dmitry A. Kazakov
2005-01-11 13:57 ` Vinzent 'Gadget' Hoefler
2005-01-11 21:52 ` Robert A Duff
2005-01-12 11:22 ` Dmitry A. Kazakov
2005-01-09 17:23 ` danmcleran
2005-01-09 17:46 ` Robert A Duff
2005-01-10 3:05 ` danmcleran
2005-01-09 18:41 ` Nick Roberts
2005-01-09 19:06 ` Martin Krischik
2005-01-09 20:10 ` Robert A Duff [this message]
2005-01-09 20:15 ` Robert A Duff
2005-01-11 14:13 ` Possible Ada deficiency? (goto) Peter Hermann
2005-01-11 14:54 ` Nick Roberts
2005-01-11 22:15 ` Robert A Duff
2005-01-12 10:17 ` Peter Hermann
2005-01-15 17:34 ` Robert A Duff
2005-01-15 17:58 ` Dmitry A. Kazakov
2005-01-15 19:34 ` Robert A Duff
2005-01-10 20:15 ` Possible Ada deficiency? Randy Brukardt
2005-01-10 21:51 ` Robert A Duff
2005-01-11 20:23 ` Randy Brukardt
2005-01-11 21:24 ` Robert A Duff
2005-01-12 19:57 ` Randy Brukardt
2005-01-02 15:51 ` Adrian Hoe
2005-01-04 16:06 ` Peter Hermann
2005-01-01 23:36 ` tmoran
2005-01-02 3:38 ` danmcleran
2004-12-31 19:16 ` Martin Dowie
2005-01-01 2:32 ` Jeffrey Carter
2004-12-31 23:23 ` Nick Roberts
2005-01-01 1:56 ` danmcleran
2005-01-01 11:43 ` Dmitry A. Kazakov
2005-01-01 15:46 ` danmcleran
2005-01-01 17:58 ` Larry Kilgallen
2005-01-01 19:43 ` danmcleran
2005-01-02 0:36 ` Ed Falis
2005-01-02 3:36 ` danmcleran
2005-01-02 15:53 ` Ed Falis
2005-01-07 18:31 ` danmcleran
2005-01-07 18:44 ` Pascal Obry
2005-01-07 19:29 ` danmcleran
2005-01-07 21:28 ` Pascal Obry
2005-01-01 23:28 ` danmcleran
2005-01-02 10:26 ` Dmitry A. Kazakov
2005-01-02 15:51 ` danmcleran
2005-01-03 23:48 ` Randy Brukardt
2005-01-01 14:06 ` Martin Krischik
2005-01-01 15:53 ` danmcleran
2005-01-07 21:33 ` Robert A Duff
2005-01-09 17:15 ` danmcleran
2005-01-09 17:38 ` Robert A Duff
2005-01-10 3:16 ` danmcleran
2005-01-09 18:41 ` Martin Dowie
2005-01-10 3:18 ` danmcleran
2005-01-10 20:32 ` Randy Brukardt
2005-01-10 21:42 ` danmcleran
2005-01-10 21:36 ` Robert A Duff
2005-01-10 21:44 ` danmcleran
2005-01-09 19:01 ` Jeffrey Carter
2005-01-10 3:20 ` danmcleran
2005-01-10 22:16 ` Robert A Duff
2005-01-10 22:29 ` danmcleran
2005-01-11 20:12 ` Georg Bauhaus
2005-01-11 20:30 ` danmcleran
2005-01-11 21:44 ` Robert A Duff
2005-01-11 0:06 ` Jeffrey Carter
2005-01-11 0:46 ` Robert A Duff
2005-01-11 20:37 ` danmcleran
2005-01-11 21:08 ` Robert A Duff
2005-01-17 4:40 ` Tucker
2005-01-18 13:46 ` danmcleran
2005-01-18 21:29 ` Nick Roberts
2005-01-24 17:23 ` danmcleran
-- strict thread matches above, loose matches on Subject: below --
2004-12-31 19:06 danmcleran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox