-
Notifications
You must be signed in to change notification settings - Fork 28
[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
QuentinOchem
wants to merge
5
commits into
AdaCore:master
Choose a base branch
from
QuentinOchem:oop-dispatching
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d89a40f
isolated file from the oop branch
QuentinOchem 8b4ad26
updated following comments
QuentinOchem 2a708f8
added considerations on multi parameters and returned types
QuentinOchem c50aefb
added consideration on access types and precisions
QuentinOchem a9f0051
minor fix
QuentinOchem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
QuentinOchem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
primitive is itself non-dispatching and requires so-called redispatching. The | ||
following code becomes then much more natural to write: | ||
QuentinOchem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. 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 | ||
==================== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.