Skip to content

Object Orientation update #106

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 78 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
ab42a97
Initial proposal
QuentinOchem May 4, 2020
7b73934
Added further details.
QuentinOchem May 4, 2020
e1c4919
Fixed typos.
QuentinOchem May 4, 2020
437bbf6
Added extra information on constructor calls
QuentinOchem May 4, 2020
8751681
Added missing information on constructors and final classes.
QuentinOchem May 4, 2020
2e85d40
Added comment on final classes and definite.
QuentinOchem May 4, 2020
ab1d4f5
Fixed formatting.
QuentinOchem May 4, 2020
4fc8d6f
Minor changes.
QuentinOchem May 4, 2020
7d85f57
Minor fixes and precisions.
QuentinOchem May 4, 2020
2a3783a
Added details on copy constructors.
QuentinOchem May 4, 2020
82b878c
Minor fixes and updates.
QuentinOchem May 4, 2020
6d8e83b
Added considerations, in particular on regular records.
QuentinOchem May 5, 2020
19efc92
Added considerations for non-dispatching operations.
QuentinOchem May 5, 2020
5516390
Added comment on package bodies.
QuentinOchem May 5, 2020
67089b2
Added specific body syntax for type implementation
QuentinOchem May 5, 2020
820978c
Modified considerations on primitives.
QuentinOchem May 5, 2020
a519d45
introduced assignment overload
QuentinOchem Aug 20, 2023
c1b10fb
added considerations for private fields and operations declared in th…
QuentinOchem Aug 20, 2023
390dbe7
minor fix
QuentinOchem Sep 7, 2023
1bbd458
added mention of move semantics in future possibilities
QuentinOchem Sep 7, 2023
dfb75b1
started re-factoring oop RFC into smaller chunks
QuentinOchem Sep 8, 2023
aa724e1
further refinments
QuentinOchem Sep 11, 2023
7e74687
added index
QuentinOchem Sep 11, 2023
ad9b548
added additional examples on 'Super on generics
QuentinOchem Oct 2, 2023
5495391
added mention of universal root object
QuentinOchem Oct 2, 2023
cb305f3
added considerations on constructors removal
QuentinOchem Oct 2, 2023
d3e181d
added additional considerations on destructors
QuentinOchem Oct 2, 2023
fadffb6
added information on constructor order
QuentinOchem Oct 2, 2023
1fe4123
updated with latest considerations on super
QuentinOchem Oct 2, 2023
5beb3d8
fixed formatting
QuentinOchem Oct 2, 2023
ccda732
updated following latest discussions
QuentinOchem Oct 3, 2023
7e7b316
added further consideration on unconstrained super references
QuentinOchem Oct 5, 2023
a019c31
Merge branch 'AdaCore:master' into oop
QuentinOchem Oct 10, 2023
669bd04
included latest comments
QuentinOchem Oct 11, 2023
26f9f0e
fixed super, added new pragma for tagged types
QuentinOchem Oct 16, 2023
d566c76
completed proposal
QuentinOchem Oct 16, 2023
491fc1f
updated following latest discussions
QuentinOchem Oct 17, 2023
2e9d415
updated following latest discussions
QuentinOchem Oct 17, 2023
4f49437
updated aggregate syntax in an attempt at avoiding ambiguities
QuentinOchem Oct 27, 2023
ffacb1b
fixed typo
QuentinOchem Oct 27, 2023
bb0ff24
updated new proposal for constructor syntax and fixed typos
QuentinOchem Nov 1, 2023
92b0976
initial attempt at introducing initialization list
QuentinOchem Nov 20, 2023
e15d09b
fixed typos:
QuentinOchem Nov 20, 2023
1cfb1ac
updated following last live discussion
QuentinOchem Dec 7, 2023
75b7fa8
minor fixes
QuentinOchem Dec 7, 2023
7ae3ba1
fixed various typos
QuentinOchem Dec 8, 2023
3758482
taking into acount next round of comments
QuentinOchem Dec 8, 2023
d93053f
Fill in first controlling RFC
raph-amiard Dec 8, 2023
a1d76c0
Merge pull request #2 from AdaCore/oop
QuentinOchem Dec 8, 2023
59eaf83
updated following last meeting
QuentinOchem Dec 14, 2023
5516400
completed fixes on aggregate semantics
QuentinOchem Dec 14, 2023
f07cab3
minor tweaks
QuentinOchem Dec 14, 2023
f9fb88a
updated following latest discussions
QuentinOchem Jan 18, 2024
44815ad
fixed typo
QuentinOchem Jan 18, 2024
fb8dcb6
fixed typo
QuentinOchem Jan 18, 2024
0dc4a5e
clarified destructor sequences
QuentinOchem Jan 18, 2024
8f0984e
added proposal for implicit discriminants
QuentinOchem Jan 19, 2024
ac4ee1e
fixed layout
QuentinOchem Jan 19, 2024
b043a96
updated proposal to feature more 'unscoped' syntax
QuentinOchem Jan 22, 2024
488a69d
fix example still refering to super as a type
QuentinOchem Jan 24, 2024
768df72
added precisions on derived types
QuentinOchem Jan 24, 2024
0c8e8ab
updated following live discussions
QuentinOchem Feb 1, 2024
23601bf
updated OOP RFC following last discussions
QuentinOchem Feb 24, 2024
6fbef9d
updated following last discussions
QuentinOchem Feb 26, 2024
65073e0
clarified last sentence
QuentinOchem Feb 26, 2024
a5aea09
added attribute RFC
QuentinOchem Feb 26, 2024
305bcd8
fixed attribute name in the example
QuentinOchem Feb 26, 2024
aca0c78
Update rfc-oop-first-controlling.rst
raph-amiard Feb 28, 2024
71c231c
Update rfc-oop-first-controlling.rst
raph-amiard Feb 28, 2024
7b32a6b
Update rfc-oop-first-controlling.rst
raph-amiard Feb 28, 2024
45efe21
updated following last discussion
QuentinOchem Mar 15, 2024
808cf19
made clear that constructor is an attribute of the type
QuentinOchem Mar 19, 2024
38d1e05
First version of a proposal on visibility
eliericha Mar 21, 2024
52fb02a
following live discussions, we don't need class record anymore with p…
QuentinOchem Apr 11, 2024
92ead5b
added missing udpate
QuentinOchem Apr 11, 2024
07d1683
fix typo
QuentinOchem Apr 22, 2024
328d1dd
updated Scoped_Primitives aspect
QuentinOchem May 6, 2024
a35d3c1
removed files that have been carved out
QuentinOchem May 30, 2024
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
91 changes: 91 additions & 0 deletions considered/rfc-oop-access.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
- Feature Name: Standard OOP model
- Start Date: May 5th 2020
- RFC PR:
- RFC Issue:

Summary
=======

Motivation
==========

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

This capability is available to all types (including simple records). The idea
here is to have an access type declared implicitely at the same level as the
type and accessible through the 'Ref notation. An attribute 'Unchecked_Free is
also declared, doing unchecked deallocation. 'Unchecked_Free can also be called
directly on the object. For example:

.. 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;

procedure Some_Procedure is
V : T1'Ref := new T1;
V2 : T1'Ref := new T1;
begin
T1'Unchecked_Free (V);
V2'Unchecked_Free;
end Some_Procedure;

For homogenity, 'Ref and 'Unchecked_Free are available to all Ada type -
including pointers themsleves. It's now possible to write:

.. code-block:: ada

V : T1'Ref'Ref := new T1'Ref;

Contrary to tagged types, 'Ref access types for a given class object are
compatible in the case of upcast, but need explicit conversions to downcast.
You can write:

.. code-block:: ada

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

type B is new T1 with record
procedure P (Self : in out T1);
end B;
end P;

procedure Some_Procedure is
A1 : A'Ref := new B;
A2 : A'Ref;

B1 : B'Ref := new B;
B2 : B'Ref;
begin
A2 := B1; -- OK, upcast, no need for pointer conversion
B2 := A1; -- Illegal, downcast
B2 := B'Ref (A1); -- OK, explicit downcast.
end Some_Procedure;

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

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

Drawbacks
=========


Prior art
=========

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

Future possibilities
====================
168 changes: 168 additions & 0 deletions considered/rfc-oop-aggregates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
- Feature Name: Standard OOP model
- Start Date: May 5th 2020
- RFC PR:
- RFC Issue:

Summary
=======

Motivation
==========

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

In the presence of constructors, aggregates values are evaluated and assigned
after the contructor is executed. So the full sequence of evaluation for
fields of a class record is:

- the constructor
- any value from the aggregate

This respects the fundamental rule that constructors can never be bypassed. For
example:

.. code-block:: ada

function Print_And_Return (S : String) return Integer is
begin
Put_Line (S);

return 0;
end;

type R1 is record
V, W : Integer := Print_And_Return ("Default");
end record;

type R2 is record
V, W : Integer := Print_And_Return ("Default");

procedure R2 (Self : in out R2);
end record;

V1 : R1 := (1, 2); -- prints Default Default
V2 : R2 := (1, 2); -- also prints Default Default

This means that units compiled with the new version of Ada will have a specific
backward incompatible change. Specifically, record initialized with an aggregate
used to bypass default initialization, they would not anymore. From a
functional standpoint, this would result in more code as well as different
behavior if the default initialization has side effects. This can be fixed
by offering constructors with the right parameters. These issues could be
identified statically by migration tools.

There is a specific question on performances impact, as the new semantic would
evaluate default value where the current Ada semantic would not. This can be
solved by not using default initialization in the type, but to provide instead
a constructor that takes parameters to value all components. For example:

.. code-block:: ada

type R1 is record
V, W : Integer := Some_Value;
end record;

Can become:

.. code-block:: ada

type R1 is record
V, W : Integer;

procedure R1 (Self : in out R1; V, W : Integer);
end record;

type body R1 is record
procedure R1 (Self : in out R1; V, W : Integer) is
begin
Self.V := V;
Self.W := W;
end R;
end record;

As a consequence, writing:

.. code-block:: ada

V1 : R1 := R1'Make(1, 2);

Can be made compiled as efficiently as before (in particular if the constructors
are inlined)

In terms of syntax, in the presence of an implicit or explicit parameterless
constructors, aggregates can be written as usual. The parameterless constructor
will be called implicitly before modification of the values by the aggregate.

If a non-parameterless constructor needs to be called, two syntaxes are available:
- if only some values need to be modified, a delta aggregate can be used
- if all values need to be modified, the syntax is "(<constructor call> with <values>)"
which is very close to the current notation for extension aggregates. For example:

.. code-block:: ada

type R is record
V, W : Integer;

procedure R (Self : in out R);

procedure R (Self : in out R; V : Integer);
end record;

type R is record
procedure R (Self : in out R) is
begin
Put_Line ("Default");
end R;

procedure R (Self : in out R; V : Integer) is
begin
Put_Line (f"V = {V}");
end R;

end record;

V1 : R := (1, 2); -- prints "Default"
V2 : R := (R'Make (42) with delta V => 1); -- prints "V = 42"
V3 : R := (R'Make (42) with 1, 2); -- also prints "V = 42"

One of the consequences of the rules above is that it's not possible to use an
aggregate within a constructor as it would create an infinite recursion:

.. code-block:: ada

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

A, B, C : Integer;
end T1;
end P;

package body P is
type body T1 is tagged record
procedure T1 (Self : in out T1) is
begin
Self := (1, 2, 3); -- infinite recursion
end T1;
end T1;
end P;

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

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


Drawbacks
=========

Prior art
=========

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

Future possibilities
====================
80 changes: 80 additions & 0 deletions considered/rfc-oop-attributes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
- Feature Name: Standard OOP model
- Start Date:
- RFC PR:
- RFC Issue:

Summary
=======

Motivation
==========

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

Today, specifying a subprogram attribute of a type requires to declare a
subprogram and then to use an aspect or an attribute to link it to a type, e.g.

.. code-block:: ada

type T is null record;

for T'Write use My_Write;

procedure My_Write(
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : in T);

This proposal allows to define directly the procedure as being an attribute of
the type:

.. code-block:: ada

type T is null record;

procedure T'Write(
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : in T);

In addition, this can be used as a scoped attribute, possibly with re-ordering
of parameters to ensure that the first parameter is conceptually the one
"owning" the primitive, e.g.:

.. code-block:: ada

type T is tagged record

procedure T'Write(
Stream : not null access Ada.Streams.Root_Stream_Type'Class;
Item : in T);

end T;

This provide a seamless solution in particular to scope a destructor:


.. code-block:: ada

type T is tagged record
procedure T'Destructor (Self : in out T);
end record;

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

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

Drawbacks
=========

Prior art
=========

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

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


50 changes: 50 additions & 0 deletions considered/rfc-oop-body.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- Feature Name: Standard OOP model
- Start Date: May 5th 2020
- RFC PR:
- RFC Issue:

Summary
=======

Motivation
==========

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

One limitation of the tagged record to lift under this system is the ability to
declare a primitives in the body of a package. As long as the type itself is
also declared in the body, this should be legal:

.. code-block:: ada

package body Pkg is
type T is tagged record
F : Integer;
end T;

procedure P (Self : in out T; V : Integer);

procedure P (Self : in out T; V : Integer) is
begin
Self.F := V;
end P;
end Pkg;

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

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

Drawbacks
=========

Prior art
=========

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

Future possibilities
====================
Loading