Skip to content

[RFC] OOP - Dispatching #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions considered/rfc-oop-dispatching.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
- Feature Name: Standard OOP model
- Start Date: May 5th 2020
- RFC PR:
- RFC Issue:

Summary
=======

Motivation
==========

Guide-level explanation
=======================

Dispatching and Class Wide Views
--------------------------------

A new library / partition level pragma is introduced, Default_Dispatching_Calls.
When active, calls to primitives are dispatching (when the tag can be
determined statically, the compiler may optimize the call to be static) unless
explicitelly marked as static (for example, through 'Super). E.g:

.. code-block:: ada

pragma Default_Dispatching_Calls (On);

type Root is tagged null record;

procedure P (Self : in out Root);

type Child is new Root with null record;

procedure P (Self : in out Root);

type A_Root is access all Root;

procedure P (V : in out Root) is
begin
V.P2; -- Dispatching
end P;

V : A_Root := new Child;

V.P; -- dispatching

Default_Dispatching_Calls is On by default on new version of the language.

Reference-level explanation
===========================


Rationale and alternatives
==========================

It is a potential vulnerability not to call an overriden primitive. This may
lead to an object to be in an state that has not been anticipated, in particular
when the role of the overriden primitive is to keep the state of the derived
object consistant. It's also commonly the case in most OOP languages that
dispatching is the default expected behavior and non dispatching the exception.

This also fix a common confusion in Ada, where the dispatching parameter of A
primitive is itself non-dispatching and requires so-called redispatching. The
following code becomes then much more natural to write:

.. code-block:: ada

package P is
type T1 is tagged record
procedure P (Self : in out T1);

procedure P2 (Self : in out T1);
end T1;
end P;

package P is
type body T1 is tagged record
procedure P (Self : in out T1) is
begin
Self.P2; -- Dispatching
end P;
end T1;
end P;


Drawbacks
=========


Prior art
=========


Unresolved questions
====================

Future possibilities
====================