Skip to content

Commit 41be2a8

Browse files
reznikmmgodunko
andcommitted
Update rfc-class-wide-access-subtype.rst (#2)
Co-authored-by: Vadim Godunko <vgodunko@gmail.com>
1 parent 479b0ff commit 41be2a8

File tree

1 file changed

+15
-92
lines changed

1 file changed

+15
-92
lines changed

considered/rfc-class-wide-access-subtype.rst

+15-92
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ a more precise and clean code, eliminates the need of many extra
1313
type-conventions and extra subtype declarations. Example:
1414

1515
.. code-block:: ada
16+
1617
type Shape is abstract tagged private;
1718
type Shape_Access is access all Shape'Class;
1819
type Cube is new Shape with private;
@@ -41,6 +42,7 @@ As an example let's consider a typical pattern in OOP style. We declare a
4142
type hierarchy for geomerty shapes and a procedure to register shape objects.
4243

4344
.. code-block:: ada
45+
4446
type Shape is abstract tagged null record;
4547
type Shape_Access is access all Shape'Class;
4648
procedure Register (Object : Shape_Access);
@@ -52,6 +54,7 @@ Next code registers a Rectangle and a circle without using a new constraints.
5254
The first approach uses an extra access type:
5355

5456
.. code-block:: ada
57+
5558
type Rectangle_Access is access all Rectangle; -- an extra type
5659
declare
5760
My_Rectangle : Rectangle_Access := new Rectangle;
@@ -64,6 +67,7 @@ The first approach uses an extra access type:
6467
The first approach uses an extra type convention:
6568

6669
.. code-block:: ada
70+
6771
declare
6872
My_Rectangle : Shape_Access := new Rectangle;
6973
begin
@@ -75,6 +79,7 @@ The first approach uses an extra type convention:
7579
With new constraint the code is cleaner:
7680

7781
.. code-block:: ada
82+
7883
declare
7984
My_Rectangle : Shape_Access for access Rectangle := new Rectangle;
8085
begin
@@ -96,10 +101,6 @@ eliminates several issues with anonymous access types:
96101
All of these issues could be detected only during execution, and sometimes
97102
in corner cases only.
98103

99-
----
100-
Why are we doing this? What use cases does it support? What is the expected
101-
outcome?
102-
103104
Guide-level explanation
104105
=======================
105106

@@ -111,73 +112,54 @@ designated subtype is a class-wide type.
111112
With this constraint the author could define subtypes:
112113

113114
.. code-block:: ada
115+
114116
subtype Rectangle_Access is Shape_Access for access Rectangle;
115117
116118
The Rectangle_Access still has Shape_Access type and can be used whereevere
117119
Shape_Access is expected. In the same time (implicit or explicit) dereferenced value
118-
denotes Rectangle type (if the acess value is not null).
120+
denotes Rectangle type (if the access value is not null).
119121

120122
This constraint could be used in other places where constraint is allowed.
121123
For example,
122124

123125
- in an object declaration:
124126

125127
.. code-block:: ada
128+
126129
My_Rectangle : constant Shape_Access for access Rectangle := new Rectangle;
127130
128131
- in a return object declartion:
129132

130133
.. code-block:: ada
134+
131135
return Result : Shape_Access for access Rectangle := new Rectangle do
132136
Result.Witch := 10;
133137
Result.Height := 5;
134138
end return;
135139
136-
----
137-
Explain the proposal as if it was already included in the language and you were
138-
teaching it to another Ada/SPARK programmer. That generally means:
139-
140-
- Introducing new named concepts.
141-
142-
- Explaining the feature largely in terms of examples.
143-
144-
- Explaining how Ada/SPARK programmers should *think* about the feature, and
145-
how it should impact the way they use it. It should explain the impact as
146-
concretely as possible.
140+
The same syntax form of the constraint works for class-wide case:
147141

148-
- If applicable, provide sample error messages, deprecation warnings, or
149-
migration guidance.
142+
.. code-block:: ada
150143
151-
For implementation-oriented RFCs (e.g. for RFCS that have no or little
152-
user-facing impact), this section should focus on how compiler contributors
153-
should think about the change, and give examples of its concrete impact.
144+
subtype Rectangle_Access is Shape_Access for access Rectangle'Class;
154145
155-
For "bug-fixes" RFCs, this section should explain briefly the bug and why it
156-
matters.
146+
In this case dereference of the Rectangle_Access value has Rectangle'Class type.
157147

158148
Reference-level explanation
159149
===========================
160150

161151
Add to *scalar_constraint* (in 3.2.2) a new rule
162152

163153
.. code-block::
154+
164155
scalar_constraint ::=
165156
range_constraint | digits_constraint | delta_constraint
166157
| class_wide_access_constraint
167158
168159
class_wide_access_constraint ::=
169160
**for access** *type_*name
170161
171-
----
172-
This is the technical portion of the RFC. Explain the de# sufficient
173-
detail that:
174-
175-
- Its interaction with other features is clear.
176-
- It is reasonably clear how the feature would be implemented.
177-
- Corner cases are dissected by example.
178-
179-
The section should return to the examples given in the previous section, and
180-
explain more fully how the detailed proposal makes those examples work.
162+
Add a corresponding rules for dereferenced values.
181163

182164
Rationale and alternatives
183165
==========================
@@ -187,82 +169,23 @@ The nearest feature is anonymous access types, but they have issues (see above).
187169
In our point of view this new constraint kind fits well with Ada philosophy
188170
and best practices.
189171

190-
----
191-
- Why is this design the best in the space of possible designs?
192-
- What other designs have been considered and what is the rationale for not
193-
choosing them?
194-
- What is the impact of not doing this?
195-
- How does this feature meshes with the general philosophy of the languages ?
196-
197172
Drawbacks
198173
=========
199174

200175
None :)
201176

202-
----
203-
Why should we *not* do this?
204-
205177
Prior art
206178
=========
207179

208180
This is too Ada specific to have a precedent in other languages, I guess.
209181

210-
----
211-
Discuss prior art, both the good and the bad, in relation to this proposal.
212-
213-
- For language, library, and compiler proposals: Does this feature exist in
214-
other programming languages and what experience have their community had?
215-
216-
- Papers: Are there any published papers or great posts that discuss this? If
217-
you have some relevant papers to refer to, this can serve as a more detailed
218-
theoretical background.
219-
220-
This section is intended to encourage you as an author to think about the
221-
lessons from other languages, provide readers of your RFC with a fuller
222-
picture.
223-
224-
If there is no prior art, that is fine - your ideas are interesting to us
225-
whether they are brand new or if it is an adaptation from other languages.
226-
227-
Note that while precedent set by other languages is some motivation, it does
228-
not on its own motivate an RFC.
229-
230182
Unresolved questions
231183
====================
232184

233185
None found yet.
234186

235-
----
236-
- What parts of the design do you expect to resolve through the RFC process
237-
before this gets merged?
238-
239-
- What parts of the design do you expect to resolve through the implementation
240-
of this feature before stabilization?
241-
242-
- What related issues do you consider out of scope for this RFC that could be
243-
addressed in the future independently of the solution that comes out of this
244-
RFC?
245187

246188
Future possibilities
247189
====================
248190

249191
No other ideas yet.
250-
251-
----
252-
Think about what the natural extension and evolution of your proposal would
253-
be and how it would affect the language and project as a whole in a holistic
254-
way. Try to use this section as a tool to more fully consider all possible
255-
interactions with the project and language in your proposal.
256-
Also consider how the this all fits into the roadmap for the project
257-
and of the relevant sub-team.
258-
259-
This is also a good place to "dump ideas", if they are out of scope for the
260-
RFC you are writing but otherwise related.
261-
262-
If you have tried and cannot think of any future possibilities,
263-
you may simply state that you cannot think of anything.
264-
265-
Note that having something written down in the future-possibilities section
266-
is not a reason to accept the current or a future RFC; such notes should be
267-
in the section on motivation or rationale in this or subsequent RFCs.
268-
The section merely provides additional information.

0 commit comments

Comments
 (0)