@@ -13,6 +13,7 @@ a more precise and clean code, eliminates the need of many extra
13
13
type-conventions and extra subtype declarations. Example:
14
14
15
15
.. code-block :: ada
16
+
16
17
type Shape is abstract tagged private;
17
18
type Shape_Access is access all Shape'Class;
18
19
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
41
42
type hierarchy for geomerty shapes and a procedure to register shape objects.
42
43
43
44
.. code-block :: ada
45
+
44
46
type Shape is abstract tagged null record;
45
47
type Shape_Access is access all Shape'Class;
46
48
procedure Register (Object : Shape_Access);
@@ -52,6 +54,7 @@ Next code registers a Rectangle and a circle without using a new constraints.
52
54
The first approach uses an extra access type:
53
55
54
56
.. code-block :: ada
57
+
55
58
type Rectangle_Access is access all Rectangle; -- an extra type
56
59
declare
57
60
My_Rectangle : Rectangle_Access := new Rectangle;
@@ -64,6 +67,7 @@ The first approach uses an extra access type:
64
67
The first approach uses an extra type convention:
65
68
66
69
.. code-block :: ada
70
+
67
71
declare
68
72
My_Rectangle : Shape_Access := new Rectangle;
69
73
begin
@@ -75,6 +79,7 @@ The first approach uses an extra type convention:
75
79
With new constraint the code is cleaner:
76
80
77
81
.. code-block :: ada
82
+
78
83
declare
79
84
My_Rectangle : Shape_Access for access Rectangle := new Rectangle;
80
85
begin
@@ -96,10 +101,6 @@ eliminates several issues with anonymous access types:
96
101
All of these issues could be detected only during execution, and sometimes
97
102
in corner cases only.
98
103
99
- ----
100
- Why are we doing this? What use cases does it support? What is the expected
101
- outcome?
102
-
103
104
Guide-level explanation
104
105
=======================
105
106
@@ -111,73 +112,54 @@ designated subtype is a class-wide type.
111
112
With this constraint the author could define subtypes:
112
113
113
114
.. code-block :: ada
115
+
114
116
subtype Rectangle_Access is Shape_Access for access Rectangle;
115
117
116
118
The Rectangle_Access still has Shape_Access type and can be used whereevere
117
119
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).
119
121
120
122
This constraint could be used in other places where constraint is allowed.
121
123
For example,
122
124
123
125
- in an object declaration:
124
126
125
127
.. code-block :: ada
128
+
126
129
My_Rectangle : constant Shape_Access for access Rectangle := new Rectangle;
127
130
128
131
- in a return object declartion:
129
132
130
133
.. code-block :: ada
134
+
131
135
return Result : Shape_Access for access Rectangle := new Rectangle do
132
136
Result.Witch := 10;
133
137
Result.Height := 5;
134
138
end return;
135
139
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:
147
141
148
- - If applicable, provide sample error messages, deprecation warnings, or
149
- migration guidance.
142
+ .. code-block :: ada
150
143
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;
154
145
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.
157
147
158
148
Reference-level explanation
159
149
===========================
160
150
161
151
Add to *scalar_constraint * (in 3.2.2) a new rule
162
152
163
153
.. code-block ::
154
+
164
155
scalar_constraint ::=
165
156
range_constraint | digits_constraint | delta_constraint
166
157
| class_wide_access_constraint
167
158
168
159
class_wide_access_constraint ::=
169
160
**for access** *type_*name
170
161
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.
181
163
182
164
Rationale and alternatives
183
165
==========================
@@ -187,82 +169,23 @@ The nearest feature is anonymous access types, but they have issues (see above).
187
169
In our point of view this new constraint kind fits well with Ada philosophy
188
170
and best practices.
189
171
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
-
197
172
Drawbacks
198
173
=========
199
174
200
175
None :)
201
176
202
- ----
203
- Why should we *not * do this?
204
-
205
177
Prior art
206
178
=========
207
179
208
180
This is too Ada specific to have a precedent in other languages, I guess.
209
181
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
-
230
182
Unresolved questions
231
183
====================
232
184
233
185
None found yet.
234
186
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?
245
187
246
188
Future possibilities
247
189
====================
248
190
249
191
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