comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Choice of OO primitives in Ada95
Date: 1996/02/23
Date: 1996-02-23T00:00:00+00:00	[thread overview]
Message-ID: <Dn94BE.9ty@world.std.com> (raw)
In-Reply-To: 312C236B.2344@informatik.uni-stuttgart.de

In article <312C236B.2344@informatik.uni-stuttgart.de>,
Bernd Holzmueller  <holzmuel@informatik.uni-stuttgart.de> wrote:
>Actually, the compiler _can_ work out if a tag is necessary. ...

Are you saying that if I have a program that contains no dispatching at
all (i.e. nothing is ever converted to a class-wide type), then it is
possible for the compiler to avoid ever storing tags?  I don't see how
that can be true, because of re-dispatching.  Consider:

    package P1 is
       type T1 is tagged null record;
       procedure P(X: T1);
       procedure Q(X: T1);
    end P1;

    with P1; use P1;
    package P2 is
       type T2 is new T1 with null record;
       -- Override Q, but not P:
       procedure Q(X: T2);
    end P2;

    with P1; use P1;
    with P2; use P2;
    procedure Client is
       Object: T2;
    begin
       P(T1(X)); -- This is *not* a dispatching call.
    end Client;

I claim that the tag of Object (namely the tag representing type T2)
must be made available to procedure P1.P.  The tag could be stored as a
hidden component of Object, or it could be passed as an extra parameter
to P.  Either way, there is some overhead in doing this.  Now, suppose
there's no dispatching anywhere in the program.  For example, P might
look like this:

    procedure P(X: T1) is
    begin
       Q(X); -- This is *not* a dispatching call.
    end P;

Then we've wasted some time and space by making that tag available to P.
Distributed overhead.

So, what if we eliminate that tag?  Well, then if P looks like this:

    procedure P(X: T1) is
    begin
       Q(T1'Class(X)); -- This *is* a dispatching call.
    end P;

it won't work, because the above call is supposed to call the version of
Q for T2.

But the compiler cannot know, at compile time of Client, what the body
of P looks like.  Therefore, it *must* pass that information to P, just
*in case* P does a dispatching call.

QED.

Unless, of course, you're willing to generate code at link time.

- Bob




  reply	other threads:[~1996-02-23  0:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <DMqHqF.9F1.0.-s@inmet.camb.inmet.com>
     [not found] ` <DMu9yw.5ts@assip.csasyd.oz>
     [not found]   ` <4g2f8v$15lc@watnews1.watson.ibm.com>
1996-02-19  0:00     ` Choice of OO primitives in Ada95 Don Harrison
1996-02-19  0:00       ` Robert A Duff
1996-02-20  0:00         ` Don Harrison
1996-02-20  0:00           ` Jon S Anthony
1996-02-22  0:00             ` Real OO (was Choice of OO primitives in Ada95) Don Harrison
1996-02-22  0:00               ` Jon S Anthony
1996-02-22  0:00               ` Robert Dewar
1996-02-23  0:00                 ` Gene Ouye
1996-02-26  0:00                   ` James O'Connor
1996-02-26  0:00                     ` Gene Ouye
1996-02-24  0:00               ` Robert A Duff
1996-02-26  0:00                 ` Don Harrison
1996-02-26  0:00                 ` Matthew B. Kennel
1996-02-24  0:00               ` Valery Croizier
1996-02-26  0:00               ` So called Real OO (was blah blah blah...) Jon S Anthony
1996-02-20  0:00           ` Choice of OO primitives in Ada95 Ray Toal
1996-02-21  0:00             ` Don Harrison
1996-02-23  0:00               ` Robert A Duff
1996-02-22  0:00             ` Bernd Holzmueller
1996-02-23  0:00               ` Robert A Duff [this message]
1996-02-23  0:00           ` Robert A Duff
1996-02-19  0:00       ` Norman H. Cohen
1996-02-21  0:00       ` Robert I. Eachus
1996-02-21  0:00     ` John DiCamillo
1996-02-22  0:00       ` Don Harrison
1996-02-24  0:00         ` Robert A Duff
     [not found] <4fmrhk$7k3@erinews.ericsson.se>
1996-02-19  0:00 ` Richard A. O'Keefe
replies disabled

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