Re: Optimization for OOP

"Dmitry A. Kazakov" <>
Tue, 6 May 2008 09:35:25 +0200

          From comp.compilers

Related articles
Optimization for OOP (2008-05-03)
Re: Optimization for OOP (2008-05-05)
Re: Optimization for OOP (Dmitry A. Kazakov) (2008-05-05)
Re: Optimization for OOP (Tony Finch) (2008-05-05)
Re: Optimization for OOP ( (2008-05-05)
Re: Optimization for OOP (Dmitry A. Kazakov) (2008-05-06)
Re: Optimization for OOP (2008-05-06)
| List of all articles for this month |

From: "Dmitry A. Kazakov" <>
Newsgroups: comp.compilers
Date: Tue, 6 May 2008 09:35:25 +0200
Organization: cbb software GmbH
References: 08-05-008 08-05-010 08-05-011 08-05-017
Keywords: OOP, optimize
Posted-Date: 06 May 2008 14:39:18 EDT

On Mon, 5 May 2008 18:51:58 -0700 (PDT), wrote:

> On 5 May, 17:37, "Dmitry A. Kazakov" <>
> wrote:
>> I think a consistent types system would be a better way. In Ada it
>> is always known if a call is dispatching or not. That is because of
>> proper typing. When an object is of a specific type, its methods
>> never dispatch, for that obvious reason, that the type is known to
>> be specific.
> From what I've read about it, in Ada you can actually statically or
> dynamically dispatch depending on *how* you call the subprogram. I've
> not tried this BTW, but would love to see an example :D

Strictly speaking it does not depend on "how", it depends on "what", i.e.
on the object's type:

      type T is tagged null record; -- a type
      procedure Foo (X : T); -- a method of T

      type S is new T with null record; -- a derived type
      procedure Foo (X : S); -- Foo gets overridden for S

      O1 : T; -- the type is specific T
      O2 : S; -- the type is specific S
      O3 : T'Class := O1; -- the type is unspecific, any derived from T
      O4 : T'Class := O2; -- like above

      Foo (O1); -- statically resolved to Foo of T
      Foo (O2); -- statically resolved to Foo of S
      Foo (O3); -- dispatches to Foo of T
      Foo (O4); -- dispatches to Foo of S

O3 and O4 are polymorphic objects (Ada uses the term "class-wide"). IFF a
method (Ada calls it "primitive operation") of some type T is called on a
polymorphic object from the class of T, that dispatches according to the
type tag of the object.

The types of polymorphic and specific objects are different in Ada. They
are T'Class and T respectively. This eliminates re-dispatch in methods and,
though Ada does not go that far, potentially allows an implementation of
multiple dispatch, as well as classes of small scalar types with value
semantics, like Boolean and Integer (without space/performance overhead).

Dmitry A. Kazakov

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.