Debian Codegraph @

source_2012/13b.mss

raw
1 @Part(13, Root="ada.mss")
2
3 @Comment{$Date: 2015/04/03 04:12:42 $}
4
5 @Comment{$Source: e:\\cvsroot/ARM/Source/13b.mss,v $}
6 @Comment{$Revision: 1.112 $}
7
8 @RMNewPage
9 @LabeledClause{The Package System}
10
11 @begin{Intro}
12 @redundant[For each implementation there is a library package called System
13 which includes the definitions of certain configuration-dependent
14 characteristics.]
15 @end{Intro}
16
17 @begin{StaticSem}
18 @Leading@;The following language-defined library package exists:
19 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
20 Text=[The contents of the visible part
21 of package System@Chg{Version=[2],New=[],Old=[and its language-defined children]}.]}
22 @begin{Example}
23 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
24 @RootLibUnit{System}@key[package] System @key[is]
25 @key{pragma} @Chg{Version=[2],New=[Pure],Old=[Preelaborate]}(System);
26
27 @key[type] @AdaTypeDefn{Name} @key[is] @RI{implementation-defined-enumeration-type};
28 @AdaObjDefn{System_Name} : @key[constant] Name := @RI{implementation-defined};
29
30
31 --@RI{ System-Dependent Named Numbers:}
32
33 @AdaObjDefn{Min_Int} : @key[constant] := @RI{root_integer}'First;
34 @AdaObjDefn{Max_Int} : @key[constant] := @RI{root_integer}'Last;
35
36 @AdaObjDefn{Max_Binary_Modulus} : @key[constant] := @RI{implementation-defined};
37 @AdaObjDefn{Max_Nonbinary_Modulus} : @key[constant] := @RI{implementation-defined};
38
39 @AdaObjDefn{Max_Base_Digits} : @key[constant] := @RI{root_real}'Digits;
40 @AdaObjDefn{Max_Digits} : @key[constant] := @RI{implementation-defined};
41
42 @AdaObjDefn{Max_Mantissa} : @key[constant] := @RI{implementation-defined};
43 @AdaObjDefn{Fine_Delta} : @key[constant] := @RI{implementation-defined};
44
45 @AdaObjDefn{Tick} : @key[constant] := @RI{implementation-defined};
46
47
48 --@RI{ Storage-related Declarations:}
49
50 @key[type] @AdaTypeDefn{Address} @key[is] @RI{implementation-defined};
51 @AdaObjDefn{Null_Address} : @key[constant] Address;
52
53 @AdaObjDefn{Storage_Unit} : @key[constant] := @RI{implementation-defined};
54 @AdaObjDefn{Word_Size} : @key[constant] := @RI{implementation-defined} * Storage_Unit;
55 @AdaObjDefn{Memory_Size} : @key[constant] := @RI{implementation-defined};
56
57 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
58 --@RI{ @Defn2{Term=[address], Sec=(comparison)}Address Comparison:}
59 @key(function) "<" (Left, Right : Address) @key(return) Boolean@Chg{Version=[3],New=[
60 @key(with) Convention => Intrinsic],Old=[]};
61 @key(function) "<="(Left, Right : Address) @key(return) Boolean@Chg{Version=[3],New=[
62 @key(with) Convention => Intrinsic],Old=[]};
63 @key(function) ">" (Left, Right : Address) @key(return) Boolean@Chg{Version=[3],New=[
64 @key(with) Convention => Intrinsic],Old=[]};
65 @key(function) ">="(Left, Right : Address) @key(return) Boolean@Chg{Version=[3],New=[
66 @key(with) Convention => Intrinsic],Old=[]};
67 @key(function) "=" (Left, Right : Address) @key(return) Boolean@Chg{Version=[3],New=[
68 @key(with) Convention => Intrinsic],Old=[]};
69 -- @key(function) "/=" (Left, Right : Address) @key(return) Boolean;
70 --@RI{ "/=" is implicitly defined}@Chg{Version=[3],New=[],Old=[
71 @key[pragma] Convention(Intrinsic, "<");
72 ... --@RI{ and so on for all language-defined subprograms in this package}]}
73
74
75 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00221-01]}
76 --@RI{ Other System-Dependent Declarations:}
77 @key[type] @AdaTypeDefn{Bit_Order} @key[is] (@AdaObjDefn{High_Order_First}, @AdaObjDefn{Low_Order_First});
78 @AdaObjDefn{Default_Bit_Order} : @key[constant] Bit_Order@Chg{Version=[2],New=[ := @RI{implementation-defined}],Old=[]};
79
80
81 --@RI{ Priority-related declarations (see @RefSecNum{Task Priorities}):}
82 @key{subtype} @AdaSubtypeDefn{Name=[Any_Priority],Of=[Integer]} @key{is} Integer @key{range} @RI{implementation-defined};
83 @key{subtype} @AdaSubtypeDefn{Name=[Priority],Of=[Any_Priority]} @key{is} Any_Priority @key{range} Any_Priority'First ..
84 @RI{implementation-defined};
85 @key{subtype} @AdaSubtypeDefn{Name=[Interrupt_Priority],Of=[Any_Priority]} @key{is} Any_Priority @key{range} Priority'Last+1 ..
86 Any_Priority'Last;
87
88 @AdaObjDefn{Default_Priority} : @key{constant} Priority :=
89 (Priority'First + Priority'Last)/2;
90
91 @key[private]
92 ... -- @RI{not specified by the language}
93 @key[end] System;
94 @end{Example}
95
96
97 Name is an enumeration subtype.
98 Values of type Name are the names of alternative machine
99 configura@!tions handled by the implementation.
100 System_Name represents the current machine configuration.
101
102 The named numbers Fine_Delta and Tick are of the type
103 @i{universal_real}; the others are of the type @i{universal_integer}.
104
105 @Leading@;The meanings of the named numbers are:
106 @begin{Description}
107 @Redundant[
108 Min_Int @\The smallest (most negative) value
109 allowed for the expressions of a
110 @nt{signed_@!integer_@!type_@!definition}.
111
112 Max_Int @\The largest (most positive) value
113 allowed for the expressions of a
114 @nt{signed_@!integer_@!type_@!definition}.
115
116 Max_Binary_Modulus @\A power of two such that it,
117 and all lesser positive powers of two, are allowed
118 as the modulus of a @nt<modular_type_definition>.
119
120 Max_Nonbinary_Modulus @\A value such that it,
121 and all lesser positive integers, are allowed
122 as the modulus of a @nt<modular_type_definition>.
123 @begin{Ramification}
124 There is no requirement that Max_Nonbinary_Modulus
125 be less than or equal to Max_Binary_Modulus,
126 although that's what makes most sense.
127 On a typical 32-bit machine, for example,
128 Max_Binary_Modulus will be 2**32
129 and Max_Nonbinary_Modulus will be 2**31,
130 because supporting nonbinary moduli in above 2**31
131 causes implementation difficulties.
132 @end{Ramification}
133
134 Max_Base_Digits @\The largest value allowed for the requested decimal
135 precision in a @nt{floating_@!point_@!definition}.
136
137 Max_Digits @\The largest value allowed for the requested decimal
138 precision in a @nt{floating_@!point_@!definition}
139 that has no @nt{real_@!range_@!specification}.
140 Max_Digits is less than or equal to Max_Base_Digits.
141
142 Max_Mantissa @\The largest possible number of binary digits in the mantissa
143 of machine numbers of a user-defined ordinary fixed point type.
144 (The mantissa is defined in @RefSecNum{Numerics}.)
145
146 Fine_Delta @\The smallest delta allowed in an @nt{ordinary_fixed_point_definition} that
147 has the @nt{real_@!range_@!specification} @key{range} @en@;1.0 .. 1.0.
148 ]
149
150 Tick @\A period in seconds approximating the real time interval during
151 which the value of Calendar.Clock remains constant.
152 @begin{Ramification}
153 There is no required relationship between System.Tick and
154 Duration'Small,
155 other than the one described here.
156
157 The inaccuracy of the @nt{delay_statement} has no relation to Tick.
158 In particular, it is possible that the clock used for the
159 @nt{delay_statement} is less accurate than Calendar.Clock.
160
161 We considered making Tick a run-time-determined quantity,
162 to allow for easier configurability.
163 However, this would not be upward compatible,
164 and the desired configurability can be achieved using
165 functionality defined in @RefSec{Real-Time Systems}.
166 @end{Ramification}
167
168 Storage_Unit @\The number of bits per storage element.
169
170 Word_Size @\The number of bits per word.
171
172 Memory_Size @\An implementation-defined value
173 @Redundant[that is intended to reflect the memory size of the
174 configuration in storage elements.]
175 @begin{Discussion}
176 It is unspecified whether this refers to the size of the
177 address space, the amount of physical memory on the machine,
178 or perhaps some other interpretation of @lquotes@;memory size.@rquotes@;
179 In any case, the value has to be given by a static expression,
180 even though the amount of memory on many modern machines is
181 a dynamic quantity in several ways.
182 Thus, Memory_Size is not very useful.
183 @end{Discussion}
184 @end{Description}
185
186 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]}
187 Address is @Chg{Version=[2],New=[],Old=[of ]}a definite, nonlimited
188 type@Chg{Version=[2],New=[ with preelaborable initialization (see
189 @RefSecNum{Elaboration Control})],Old=[]}.
190 Address represents machine addresses capable of addressing individual
191 storage elements.
192 Null_Address is an address that is distinct from the
193 address of any object or program unit.
194 @IndexSee{Term=[pointer],See=(type System.Address)}
195 @begin{Ramification}
196 The implementation has to ensure that there is at least one
197 address that nothing will be allocated to;
198 Null_Address will be one such address.
199 @end{Ramification}
200 @begin{Ramification}
201 Address is the type of the result of the attribute Address.
202 @end{Ramification}
203 @begin{Reason}
204 Address is required to be nonlimited and definite because
205 it is important to be able to assign addresses,
206 and to declare uninitialized address variables.
207 @end{Reason}
208 @begin{Ramification}
209 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
210 @ChgAdded{Version=[2],Text=[If System.Address is defined as a private type
211 (as suggested below), it might be necessary to add a pragma
212 Preelaborable_Initialization to the specification of System in order that
213 Address have preelaborable initialization as required.]}
214 @end{Ramification}
215
216 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00221-01]}
217 @Chg{Version=[2],New=[ Default_Bit_Order shall
218 be a static constant. ],Old=[]}See @RefSecNum{Bit Ordering} for an
219 explanation of Bit_Order and Default_Bit_Order.
220 @end{StaticSem}
221
222 @begin{ImplPerm}
223 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
224 An implementation may add additional implementation-defined
225 declarations to package System and its children.
226 @Redundant[However, it is usually better
227 for the implementation to provide
228 additional functionality via implementation-defined
229 children of System.]@Chg{Version=[2],New=[],Old=[
230 Package System may be declared pure.]}
231 @begin{Ramification}
232 The declarations in package System and its children can be implicit.
233 For example, since Address is not limited,
234 the predefined "=" and "/=" operations are probably sufficient.
235 However, the implementation is not @i{required} to use the predefined
236 "=".
237 @end{Ramification}
238 @end{ImplPerm}
239
240 @begin{ImplAdvice}
241 @ChgNote{Version=[1],Kind=[Revised]}@ChgNote{Remove bogus "of"}
242 Address should be @Chg{New=[],Old=[of ]}a private type.
243 @begin{Reason}
244 This promotes uniformity by avoiding having
245 implementation-defined predefined operations for the type.
246 We don't require it, because implementations may want to stick with
247 what they have.
248 @end{Reason}
249 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
250 Text=[Type System.Address should be a private type.]}]}
251 @begin{ImplNote}
252 It is not necessary for Address to be able to point at
253 individual bits within a storage element.
254 Nor is it necessary for it to be able to point at machine registers.
255 It is intended as a memory address that matches the hardware's notion
256 of an address.
257
258 The representation of the @key{null} value of a general access type should
259 be the same as that of Null_Address;
260 instantiations of Unchecked_Conversion should work accordingly.
261 If the implementation supports interfaces to other languages,
262 the representation of the @key{null} value of a general access type
263 should be the same as in those other languages, if appropriate.
264
265 Note that the children of the Interfaces package will generally provide
266 foreign-language-specific null values where appropriate.
267 See UI-0065 regarding Null_Address.
268 @end{ImplNote}
269 @end{ImplAdvice}
270
271 @begin{Notes}
272 There are also some language-defined child packages of System
273 defined elsewhere.
274 @end{Notes}
275
276 @begin{Extend83}
277 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{Presentation AI-00114}
278 @ChgAdded{Version=[1],Text=[@Defn{extensions to Ada 83}
279 The declarations Max_Binary_Modulus, Max_Nonbinary_Modulus, Max_Base_Digits,
280 Null_Address, Word_Size, Bit_Order, Default_Bit_Order, Any_Priority,
281 Interrupt_Priority, and Default_Priority are added to System in Ada 95.
282 The presence of ordering operators for type Address is also guaranteed (the
283 existence of these depends on the definition of Address in an Ada 83
284 implementation). We do not list these as incompatibilities, as the contents of
285 System can vary between implementations anyway; thus a program that depends on
286 the contents of System (by using @f{@key[use] System;} for example) is
287 already at risk of being incompatible when moved between Ada implementations.]}
288 @end{Extend83}
289
290 @begin{DiffWord83}
291 Much of the content of System is standardized,
292 to provide more uniformity across implementations.
293 Implementations can still add their own declarations to System,
294 but are encouraged to do so via children of System.
295
296 Some of the named numbers are defined more explicitly in terms of the
297 standard numeric types.
298
299 The pragmas System_Name, Storage_Unit, and Memory_Size are no
300 longer defined by the language.
301 However, the corresponding declarations in package
302 System still exist.
303 Existing implementations may continue to support the three
304 pragmas as implementation-defined pragmas,
305 if they so desire.
306
307 Priority semantics, including subtype Priority,
308 have been moved to the Real Time Annex.
309 @end{DiffWord83}
310
311 @begin{Extend95}
312 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
313 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
314 @b[Amendment Correction:] Type Address is defined to have preelaborable
315 initialization, so that it
316 can be used without restriction in preelaborated units. (If Address is
317 defined to be a private type, as suggested by the @ImplAdviceTitle,
318 in Ada 95 it cannot be used in some contexts in a preelaborated units.
319 This is an unnecessary portability issue.)]}
320
321 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00221-01]}
322 @ChgAdded{Version=[2],Text=[@b[Amendment Correction:] Default_Bit_Order
323 is now a static constant.]}
324
325 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
326 @ChgAdded{Version=[2],Text=[Package System is now Pure, so it can be
327 portably used in more places. (Ada 95 allowed it to be Pure, but did not
328 require that.)]}
329 @end{Extend95}
330
331
332 @LabeledSubClause{The Package System.Storage_Elements}
333
334 @begin{StaticSem}
335 @Leading@;The following language-defined library package exists:
336 @begin{Example}
337 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
338 @ChildUnit{Parent=[System],Child=[Storage_Elements]}@key[package] System.Storage_Elements @key[is]
339 @key{pragma} @Chg{Version=[2],New=[Pure(],Old=[Preelaborate(System.]}Storage_Elements);
340
341 @key[type] @AdaTypeDefn{Storage_Offset} @key[is] @key[range] @RI(implementation-defined);
342
343 @key[subtype] @AdaSubtypeDefn{Name=[Storage_Count],Of=[Storage_Offset]} @key[is] Storage_Offset @key[range] 0..Storage_Offset'Last;
344
345
346 @key[type] @AdaTypeDefn{Storage_Element} @key[is] @key[mod] @RI{implementation-defined};
347 @key[for] Storage_Element'Size @key[use] Storage_Unit;
348 @key[type] @AdaTypeDefn{Storage_Array} @key[is] @key[array]
349 (Storage_Offset @key[range] <>) @key[of] @key[aliased] Storage_Element;
350 @key[for] Storage_Array'Component_Size @key[use] Storage_Unit;
351
352
353 --@RI{ @Defn2{Term=[address], Sec=(arithmetic)}Address Arithmetic:}
354
355 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
356 @key(function) "+"(Left : Address; Right : Storage_Offset)@Chg{Version=[3],New=[],Old=[
357 ]} @key(return) Address@Chg{Version=[3],New=[
358 @key(with) Convention => Intrinsic],Old=[]};
359 @key(function) "+"(Left : Storage_Offset; Right : Address)@Chg{Version=[3],New=[],Old=[
360 ]} @key(return) Address@Chg{Version=[3],New=[
361 @key(with) Convention => Intrinsic],Old=[]};
362 @key(function) "-"(Left : Address; Right : Storage_Offset)@Chg{Version=[3],New=[],Old=[
363 ]} @key(return) Address@Chg{Version=[3],New=[
364 @key(with) Convention => Intrinsic],Old=[]};
365 @key(function) "-"(Left, Right : Address)@Chg{Version=[3],New=[],Old=[
366 ]} @key(return) Storage_Offset@Chg{Version=[3],New=[
367 @key(with) Convention => Intrinsic],Old=[]};
368
369
370 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
371 @key(function) "@key(mod)"(Left : Address; Right : Storage_Offset)
372 @key(return) Storage_Offset@Chg{Version=[3],New=[
373 @key(with) Convention => Intrinsic],Old=[]};
374
375
376 --@RI{ Conversion to/from integers:}
377
378 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
379 @key[type] @AdaTypeDefn{Integer_Address} @key[is] @RI{implementation-defined};
380 @key[function] @AdaSubDefn{To_Address}(Value : Integer_Address) @key[return] Address@Chg{Version=[3],New=[
381 @key(with) Convention => Intrinsic],Old=[]};
382 @key[function] @AdaSubDefn{To_Integer}(Value : Address) @key[return] Integer_Address@Chg{Version=[3],New=[
383 @key(with) Convention => Intrinsic],Old=[]};
384
385
386 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
387 @Chg{Version=[3],New=[],Old=[ @key[pragma] Convention(Intrinsic, "+");
388 @RI(-- ...and so on for all language-defined subprograms declared in this package.)
389 ]}@key[end] System.Storage_Elements;
390 @end{Example}
391 @begin{Reason}
392 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
393 The Convention @Chg{Version=[3],New=[aspects],Old=[@nt{pragma}s]} imply that
394 the attribute Access is not allowed for those operations.
395
396 The @key(mod) function is needed so that the
397 definition of Alignment makes sense.
398 @end{Reason}
399 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
400 Text=[The range of Storage_Elements.Storage_Offset, the modulus of
401 Storage_Elements.Storage_Element, and the declaration of
402 Storage_Elements.Integer_Address.]}.]}
403
404 Storage_Element represents a storage element.
405 Storage_Offset represents an offset in storage elements.
406 Storage_Count represents a number of storage elements.
407 @PDefn{contiguous representation}
408 @PDefn{discontiguous representation}
409 Storage_Array represents a contiguous sequence of storage elements.
410 @begin{Reason}
411 The index subtype of Storage_Array is Storage_Offset
412 because we wish to allow maximum flexibility.
413 Most Storage_Arrays will probably have a lower bound of 0 or 1,
414 but other lower bounds, including negative ones,
415 make sense in some situations.
416
417 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]}
418 @ChgDeleted{Version=[2],Text=[Note that there are some language-defined
419 subprograms that fill part of a Storage_Array, and return the index of the
420 last element filled as a Storage_Offset.
421 The Read procedures in
422 Streams (see @RefSecNum{The Package Streams}),
423 Streams.Stream_IO (see @RefSecNum{The Package Streams.Stream_IO}),
424 and System.RPC (see @RefSecNum{Partition Communication Subsystem})
425 behave in this manner.
426 These will raise Constraint_Error if the resulting Last value is not in
427 Storage_Offset.
428 This implies that the Storage_Array passed to these subprograms should
429 not have a lower bound of Storage_Offset'First,
430 because then a read of 0 elements would always raise Constraint_Error.
431 A better choice of lower bound is 1.]}
432 @end{Reason}
433
434 Integer_Address is a @Redundant[(signed or modular)] integer subtype.
435 To_Address and To_Integer convert back and forth between
436 this type and Address.
437 @end{StaticSem}
438
439 @begin{ImplReq}
440 Storage_Offset'Last shall be greater than or equal to Integer'Last or
441 the largest possible storage offset,
442 whichever is smaller.
443 Storage_Offset'First shall be <= (@en@;Storage_Offset'Last).
444 @end{ImplReq}
445
446 @begin{ImplPerm}
447 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00362-01]}
448 @ChgDeleted{Version=[2],Text=[Package System.Storage_Elements may be declared
449 pure.]}
450 @end{ImplPerm}
451 @begin{NotIso}
452 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 15 was
453 deleted.>}]}@Comment{This message should be deleted if the paragraphs
454 are ever renumbered.}
455 @end{NotIso}
456
457 @begin{ImplAdvice}
458 Operations in System and its children should reflect the
459 target environment semantics as closely as is reasonable.
460 For example, on most machines, it makes sense for address arithmetic
461 to @lquotes@;wrap around.@rquotes@;
462 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
463 Operations that do not make sense should raise
464 Program_Error.
465 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
466 Text=[Operations in System and its children should reflect the
467 target environment; operations that do not make sense should raise Program_Error.]}]}
468 @begin{Discussion}
469 For example, on a segmented architecture,
470 X < Y might raise Program_Error if X and Y do not point at the same
471 segment (assuming segments are unordered).
472 Similarly, on a segmented architecture,
473 the conversions between Integer_Address and Address
474 might not make sense for some values,
475 and so might raise Program_Error.
476 @end{Discussion}
477 @begin{Reason}
478 We considered making Storage_Element a private type.
479 However, it is better to declare it as a modular type in the visible part,
480 since code that uses it is already low level,
481 and might as well have access to the underlying representation.
482 We also considered allowing Storage_Element to be any
483 integer type, signed integer or modular, but it is better to have
484 uniformity across implementations in this regard, and viewing storage elements
485 as unsigned seemed to make the most sense.
486 @end{Reason}
487 @begin{ImplNote}
488 To_Address is intended for use in Address clauses.
489 Implementations should overload To_Address if appropriate.
490 For example, on a segmented architecture,
491 it might make sense to have a record type representing a
492 segment/offset pair, and have a To_Address conversion that
493 converts from that record type to type Address.
494 @end{ImplNote}
495 @end{ImplAdvice}
496
497 @begin{Extend95}
498 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
499 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
500 Package System.Storage_Elements is now Pure, so it can be
501 portably used in more places. (Ada 95 allowed it to be Pure, but did not
502 require that.)]}
503 @end{Extend95}
504
505
506
507 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
508 @LabeledSubClause{The Package System.Address_To_Access_Conversions}
509
510 @begin{StaticSem}
511
512 @Leading@;The following language-defined generic library package exists:
513 @begin{Example}
514 @ChildUnit{Parent=[System],Child=[Address_@!To_@!Access_@!Conversions]}@key[generic]
515 @key[type] Object(<>) @key[is] @key[limited] @key[private];
516 @key[package] System.Address_To_Access_Conversions @key[is]
517 @key[pragma] Preelaborate(Address_To_Access_Conversions);
518
519 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
520 @key[type] Object_Pointer @key[is] @key[access] @key[all] Object;
521 @key[function] @AdaSubDefn{To_Pointer}(Value : Address) @key[return] Object_Pointer@Chg{Version=[3],New=[
522 @key(with) Convention => Intrinsic],Old=[]};
523 @key[function] @AdaSubDefn{To_Address}(Value : Object_Pointer) @key[return] Address@Chg{Version=[3],New=[
524 @key(with) Convention => Intrinsic],Old=[]};
525
526 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
527 @Chg{Version=[3],New=[],Old=[ @key[pragma] Convention(Intrinsic, To_Pointer);
528 @key[pragma] Convention(Intrinsic, To_Address);
529 ]}@key[end] System.Address_To_Access_Conversions;
530 @end{Example}
531
532
533
534 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
535 The To_Pointer and To_Address subprograms
536 convert back and forth between
537 values of types Object_Pointer and Address.
538 To_Pointer(X'Address) is equal to X'Unchecked_Access
539 for any X that allows Unchecked_Access.
540 To_Pointer(Null_Address) returns @key[null].
541 @PDefn{unspecified}
542 For other addresses,
543 the behavior is unspecified.
544 To_Address(@key[null]) returns Null_Address@Chg{Version=[2],New=[],Old=[ (for
545 @key[null] of the appropriate type)]}.
546 To_Address(Y), where Y /= @key[null], returns Y.@key[all]'Address.
547 @begin{Discussion}
548 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
549 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
550 The programmer should ensure that
551 the address passed to To_Pointer is either Null_Address,
552 or the address of an object of type Object. @Chg{Version=[2],New=[(If Object is
553 not a @Chg{Version=[3],New=[],Old=[not ]}by-reference type, the object ought to
554 be aliased; recall that the Address attribute is not required to provide a
555 useful result @Chg{Version=[3],New=[for ],Old=[]}other objects.)],Old=[]}
556 Otherwise, the behavior of the program is unspecified;
557 it might raise an exception or crash, for example.
558 @end{Discussion}
559 @begin{Reason}
560 Unspecified is almost the same thing as erroneous;
561 they both allow arbitrarily bad behavior.
562 We don't say erroneous here, because the implementation
563 might allow the address passed to To_Pointer to point
564 at some memory that just happens to @lquotes@;look like@rquotes@; an
565 object of type Object.
566 That's not necessarily an error; it's just not portable.
567 However, if the actual type passed to Object is (for example)
568 an array type, the programmer
569 would need to be aware of any dope that the implementation expects to
570 exist, when passing an address that did not come from the Address
571 attribute of an object of type Object.
572
573 One might wonder why To_Pointer and To_Address are any better than
574 unchecked conversions. The answer is that Address does not necessarily
575 have the same representation as an access type. For example, an access
576 value might point at the bounds of an array when an address would point
577 at the first element. Or an access value might be an offset in words
578 from someplace, whereas an address might be an offset in bytes from the
579 beginning of memory.
580 @end{Reason}
581 @end{StaticSem}
582
583 @begin{ImplPerm}
584 An implementation may place restrictions on instantiations of
585 Address_To_Access_Conversions.
586 @begin{Ramification}
587 For example, if the hardware requires aligned loads and stores,
588 then dereferencing an access value that is not properly aligned might
589 raise an exception.
590
591 For another example,
592 if the implementation has chosen to use negative component offsets
593 (from an access value),
594 it might not be possible to preserve the semantics,
595 since negative offsets from the Address are not allowed.
596 (The Address attribute always points at
597 @lquotes@;the first of the storage elements....@rquotes@;)
598 Note that while the implementation knows how to convert an access
599 value into an address, it might not be able to do the reverse.
600 To avoid generic contract model violations,
601 the restriction might have to be detected at run time in some cases.
602 @end{Ramification}
603 @end{ImplPerm}
604
605 @LabeledClause{Machine Code Insertions}
606
607 @begin{Intro}
608 @redundant[@Defn{machine code insertion}
609 A machine code insertion can be achieved by a call to a subprogram whose
610 @nt{sequence_of_statements} contains @nt{code_statement}s.]
611 @end{Intro}
612
613 @begin{Syntax}
614 @Syn{lhs=<code_statement>,rhs="@Syn2{qualified_expression};"}
615
616 @begin{SyntaxText}
617 A @nt{code_statement} is only allowed in the
618 @nt{handled_sequence_of_@!statements} of a @nt{subprogram_@!body}.
619 If a @nt{subprogram_@!body} contains any @nt{code_@!statement}s, then within
620 this @nt{subprogram_@!body} the only allowed form of @nt{statement} is a
621 @nt{code_@!statement} (labeled or not),
622 the only allowed @nt{declarative_@!item}s are @nt{use_@!clause}s,
623 and no @nt{exception_@!handler} is allowed (@nt{comment}s and
624 @nt{pragma}s are allowed as usual).
625 @end{SyntaxText}
626 @end{Syntax}
627
628 @begin{Resolution}
629 @PDefn2{Term=[expected type],
630 Sec=(code_statement)}
631 The @nt{qualified_expression} is expected to be of any type.
632 @end{Resolution}
633
634 @begin{Legality}
635 The @nt{qualified_expression} shall be of a
636 type declared in package System.Machine_Code.
637 @begin{Ramification}
638 This includes types declared in children of System.Machine_Code.
639 @end{Ramification}
640
641 A @nt<code_statement> shall appear only within the scope of
642 a @nt<with_clause> that mentions package System.Machine_Code.
643 @begin{Ramification}
644 Note that this is not a note;
645 without this rule, it would be possible to write machine code
646 in compilation units which depend on System.Machine_Code only indirectly.
647 @end{Ramification}
648 @end{Legality}
649
650 @begin{StaticSem}
651 @Defn{System.Machine_Code}
652 @ChildUnit{Parent=[System],Child=[Machine_Code]}
653 The contents of the library package System.Machine_Code
654 (if provided) are implementation defined.
655 The meaning of @nt{code_statement}s is implementation defined.
656 @Redundant{Typically, each @nt{qualified_expression}
657 represents a machine instruction or assembly directive.}
658 @begin{Discussion}
659 For example, an instruction might be a record with an Op_Code
660 component and other components for the operands.
661 @end{Discussion}
662 @ImplDef{The contents of the visible part of package System.Machine_Code,
663 and the meaning of @nt{code_statement}s.}
664 @end{StaticSem}
665
666 @begin{ImplPerm}
667 An implementation may place restrictions on @nt{code_statement}s.
668 An implementation is not required to provide package System.Machine_Code.
669 @end{ImplPerm}
670
671 @begin{Notes}
672 An implementation may provide implementation-defined pragmas
673 specifying register conventions and calling conventions.
674
675 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
676 Machine code functions are exempt from the rule that a
677 @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}
678 is required. In fact,
679 @Chg{Version=[2],New=[return statements],Old=[@nt{return_@!statement}s]} are
680 forbidden, since only @nt{code_statement}s are allowed.
681 @begin{Discussion}
682 The idea is that the author of a machine code subprogram knows
683 the calling conventions, and refers to parameters and results
684 accordingly.
685 The implementation should document where to put the result of a
686 machine code function, for example,
687 @lquotes@;Scalar results are returned in register 0.@rquotes@;
688 @end{Discussion}
689
690 Intrinsic subprograms (see @RefSec{Conformance Rules})
691 can also be used to achieve machine code insertions.
692 Interface to assembly language can be achieved
693 using the features in @RefSec{Interface to Other Languages}.
694 @end{Notes}
695
696 @begin{Examples}
697 @leading@keepnext@i{Example of a code statement:}
698 @begin{Example}
699 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
700 M : Mask;
701 @key[procedure] Set_Mask@Chg{Version=[3],New=[
702 @key[with] Inline],Old=[]};@Chg{Version=[3],New=[],Old=[ @key[pragma] Inline(Set_Mask);]}
703
704 @key[procedure] Set_Mask @key[is]
705 @key[use] System.Machine_Code; --@RI{ assume @lquotes@;@key[with] System.Machine_Code;@rquotes@; appears somewhere above}
706 @key[begin]
707 SI_Format'(Code => SSM, B => M'Base_Reg, D => M'Disp);
708 --@RI{ Base_Reg and Disp are implementation-defined attributes}
709 @key[end] Set_Mask;
710 @end{Example}
711 @end{Examples}
712
713 @begin{Extend83}
714 @Defn{extensions to Ada 83}
715 Machine code functions are allowed in Ada 95;
716 in Ada 83, only procedures were allowed.
717 @end{Extend83}
718
719 @begin{DiffWord83}
720 The syntax for @nt{code_statement} is changed to say
721 @lquotes@;@nt{qualified_expression}@rquotes@; instead of
722 @lquotes@;@Syn2{subtype_mark}'@Syn2{record_aggregate}@rquotes@;.
723 Requiring the type of each instruction to be a record type is
724 overspecification.
725 @end{DiffWord83}
726
727 @LabeledClause{Unchecked Type Conversions}
728
729 @begin{Intro}
730 @redundant[@Defn{unchecked type conversion}
731 @Defn2{Term=[type conversion], Sec=(unchecked)}
732 @Defn2{Term=[conversion], Sec=(unchecked)}
733 @IndexSeeAlso{Term=[type_conversion],See=(unchecked type conversion)}
734 @IndexSee{Term=[cast],See=(unchecked type conversion)}
735 An unchecked type conversion can be achieved by a call to an instance
736 of the generic function Unchecked_Conversion.]
737 @end{Intro}
738
739 @begin{StaticSem}
740 @Leading@keepnext@;The following language-defined generic library function exists:
741 @begin{Example}
742 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
743 @key[generic]
744 @key[type] Source(<>) @key[is] @key[limited] @key[private];
745 @key[type] Target(<>) @key[is] @key[limited] @key[private];
746 @SubChildUnit{Parent=[Ada],Child=[Unchecked_Conversion]}@key[function] Ada.Unchecked_Conversion(S : Source) @key[return] Target@Chg{Version=[3],New=[
747 @key(with) Convention => Intrinsic],Old=[]};@Chg{Version=[3],New=[],Old=[
748 @key[pragma] Convention(Intrinsic, Ada.Unchecked_Conversion);]}
749 @key[pragma] Pure(Ada.Unchecked_Conversion);
750 @end{Example}
751 @begin{Reason}
752 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
753 The @Chg{Version=[3],New=[aspect],Old=[@nt{pragma}]} Convention implies that
754 the attribute Access is not allowed
755 for instances of Unchecked_Conversion.
756 @end{Reason}
757 @end{StaticSem}
758
759 @begin{RunTime}
760 The size of the formal parameter S in an instance of
761 Unchecked_Conversion is that of its subtype.
762 @Redundant[This is the actual subtype passed to Source,
763 except when the actual is an unconstrained composite subtype,
764 in which case the subtype is constrained by the bounds or
765 discriminants of the value of the actual expression passed to S.]
766
767 @Leading@;If all of the following are true,
768 the effect of an unchecked conversion is to return the
769 value of an object of the target subtype whose representation is the
770 same as that of the source object S:
771 @begin{Itemize}
772 S'Size = Target'Size.
773 @begin{Ramification}
774 Note that there is no requirement that the Sizes be known at compile
775 time.
776 @end{Ramification}
777
778 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0078-1]}
779 S'Alignment @Chg{Version=[3],New=[is a multiple of],Old=[=]}
780 Target'Alignment@Chg{Version=[3],New=[ or Target'Alignment is zero],Old=[]}.
781
782 The target subtype is not an unconstrained composite subtype.
783
784 @PDefn{contiguous representation}
785 @PDefn{discontiguous representation}
786 S and the target subtype both have a contiguous
787 representation.
788
789 The representation of S is a representation of
790 an object of the target subtype.
791 @end{Itemize}
792
793 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00426-01]}
794 Otherwise, @Chg{Version=[2],New=[if the result type is scalar, the result
795 of the function is implementation defined, and can have an invalid
796 representation (see @RefSecNum{Data Validity}).
797 If the result type is nonscalar, ],Old=[]}the effect is implementation defined;
798 in particular, the result can be abnormal
799 (see @RefSecNum{Data Validity}).
800
801 @ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[The result
802 of unchecked conversion for instances with scalar result types whose
803 result is not defined by the language.],Old=[]}]}
804 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
805 Text=[The effect of unchecked
806 conversion@Chg{Version=[2],New=[ for instances
807 with nonscalar result types whose effect is not defined by
808 the language],Old=[]}.]}
809 @begin{Reason}
810 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]}
811 @ChgAdded{Version=[2],Text=[Note the difference between these sentences;
812 the first only says that the bits returned are implementation defined, while
813 the latter allows any effect. The difference is because scalar objects should
814 never be abnormal unless their assignment was disrupted or if they are a
815 subcomponent of an abnormal composite object. Neither exception applies to
816 instances of Unchecked_Conversion.]}
817 @end{Reason}
818 @begin{Ramification}
819 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]}
820 Whenever unchecked conversions are used, it is the programmer's
821 responsibility to ensure that these conversions maintain the properties
822 that are guaranteed by the language for objects of the target type.
823 @Chg{Version=[2],New=[For nonscalar types, this],Old=[This]} requires the
824 user to understand the underlying run-time model of the implementation.
825 The execution of a program that violates these properties by means of
826 unchecked conversions @Chg{Version=[2],New=[returning a nonscalar type ],
827 Old=[]}is erroneous.@Chg{Version=[2],New=[ Properties of scalar types can
828 be checked by using the Valid attribute (see @RefSecNum{The Valid Attribute});
829 programs can avoid violating properties of the type (and erroneous
830 execution) by careful use of this attribute.],Old=[]}
831
832 An instance of Unchecked_Conversion can be applied to an object of a
833 private type, assuming the implementation allows it.
834 @end{Ramification}
835 @end{RunTime}
836
837 @begin{ImplPerm}
838 An implementation may return the result of
839 an unchecked conversion
840 by reference, if the Source type is not a by-copy type.
841 @Redundant[In this case, the result of the unchecked conversion represents
842 simply a different (read-only) view of the operand of the conversion.]
843 @begin{Ramification}
844 In other words, the result object of a call on an instance
845 of Unchecked_Conversion can occupy the same storage as the
846 formal parameter S.
847 @end{Ramification}
848
849 An implementation may place restrictions on Unchecked_Conversion.
850 @begin{Ramification}
851 For example, an instantiation of Unchecked_Conversion for types for
852 which unchecked conversion doesn't make sense may be disallowed.
853 @end{Ramification}
854 @end{ImplPerm}
855
856 @begin{ImplAdvice}
857 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00051-02]}
858 @Chg{Version=[2],New=[Since the],Old=[The]} Size of an array object
859 @Chg{Version=[2],New=[generally does],Old=[should]} not include its
860 bounds@Chg{Version=[2],New=[],Old=[; hence]}, the bounds should not be part
861 of the converted data.
862 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
863 Text=[Since the Size of an array object generally does not include its bounds,
864 the bounds should not be part of the converted data in an instance of
865 Unchecked_Conversion.]}]}
866 @begin{Ramification}
867 On the other hand, we have no advice to offer about
868 discriminants and tag fields.
869 @end{Ramification}
870
871 The implementation should not generate unnecessary run-time checks
872 to ensure that the representation of S is a representation of the target
873 type.
874 It should take advantage of the permission to return by reference
875 when possible.
876 Restrictions on unchecked conversions should be avoided
877 unless required by the target environment.
878 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
879 Text=[There should not be unnecessary run-time checks on the result of
880 an Unchecked_Conversion; the result should be returned by reference when
881 possible. Restrictions on Unchecked_Conversions should be avoided.]}]}
882 @begin{ImplNote}
883 As an example of an unnecessary run-time check,
884 consider a record type with gaps between components.
885 The compiler might assume that such gaps are always zero bits.
886 If a value is produced that does not obey that assumption,
887 then the program might misbehave.
888 The implementation should not generate extra code to check for zero bits
889 (except, perhaps, in a special error-checking mode).
890 @end{ImplNote}
891
892 @Leading@PDefn2{Term=[recommended level of support], Sec=(unchecked conversion)}
893 The recommended level of support for unchecked conversions is:
894 @begin{Itemize}
895 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
896 Unchecked conversions should be supported and should be reversible in
897 the cases where this @Chg{Version=[3],New=[subclause],Old=[clause]} defines
898 the result.@PDefn{contiguous representation}
899 @PDefn{discontiguous representation}
900 To enable meaningful use of unchecked conversion,
901 a contiguous representation should be used for elementary subtypes,
902 for statically constrained array subtypes whose component subtype is
903 one of the subtypes described in this paragraph,
904 and for record subtypes without discriminants
905 whose component subtypes are described in this paragraph.
906 @end{Itemize}
907 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
908 Text=[The recommended level of support for Unchecked_Conversion should be
909 followed.]}]}
910 @end{ImplAdvice}
911
912 @begin{DiffWord95}
913 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00051-02]}
914 @ChgAdded{Version=[2],Text=[The implementation advice about the size of
915 array objects was moved to 13.3 so that all of the advice about Size is
916 in one place.]}
917
918 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
919 @ChgAdded{Version=[2],Text=[Clarified that the result of Unchecked_Conversion
920 for scalar types can be invalid, but not abnormal.]}
921 @end{DiffWord95}
922
923 @begin{DiffWord2005}
924 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0078-1]}
925 @ChgAdded{Version=[3],Text=[@b<Correction:> Relaxed the alignment
926 requirement slightly, giving a defined result in more cases.]}
927 @ChgNote{This is not an extension, as a program taking advantage of this
928 change was (and very well might have worked) legal before the change; it's
929 just guaranteed to be portable now.}
930 @end{Diffword2005}
931
932
933 @LabeledSubClause{Data Validity}
934
935 @begin{Intro}
936 Certain actions that can potentially lead to erroneous execution are not
937 directly erroneous,
938 but instead can cause objects to become @i{abnormal}.
939 Subsequent uses of abnormal objects can be erroneous.
940
941 A scalar object can have an @i{invalid representation},
942 which means that the object's representation does not represent any
943 value of the object's subtype.
944 @RootDefn{uninitialized variables}
945 The primary cause of invalid representations is uninitialized variables.
946
947 Abnormal objects and invalid representations are explained in this
948 subclause.
949 @end{Intro}
950
951 @begin{RunTime}
952 @Leading@RootDefn{normal state of an object}
953 @RootDefn{abnormal state of an object}
954 When an object is first created, and any explicit or default
955 initializations have been performed, the object
956 and all of its parts are in the @i{normal} state.
957 Subsequent operations generally leave them normal.
958 However, an object or part of an object can become @i{abnormal}
959 in the following ways:
960 @begin{Itemize}
961 @Defn{disruption of an assignment}
962 An assignment to the object is disrupted due to an abort
963 (see @RefSecNum{Abort of a Task - Abort of a Sequence of Statements})
964 or due to the failure of a language-defined check
965 (see @RefSecNum{Exceptions and Optimization}).
966
967 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00426-01]}
968 The object is not scalar, and is passed to an @key[in out]
969 or @key[out] parameter of an imported procedure@Chg{Version=[2],New=[,
970 the Read procedure of an instance of Sequential_IO,
971 Direct_IO, or Storage_IO, or the stream attribute T'Read], Old=[ or
972 language-defined input procedure]},
973 if after return from the procedure the representation of the parameter
974 does not represent a value of the parameter's subtype.
975
976 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]}
977 @ChgAdded{Version=[2],Text=[The object is the return object of a function call
978 of a nonscalar type, and the function is an imported function, an instance of
979 Unchecked_Conversion, or the stream attribute T'Input, if after return from the
980 function the representation of the return object does not represent a value of
981 the function's subtype.]}
982
983 @begin{Discussion}
984 @ChgRef{Version=[2],Kind=[AddedNormal]}
985 @ChgAdded{Version=[2],Text=[We explicitly list the routines involved in order
986 to avoid future arguments. All possibilities are listed.]}
987
988 @ChgRef{Version=[2],Kind=[AddedNormal]}
989 @ChgAdded{Version=[2],Text=[We did not include Stream_IO.Read in the list
990 above. A Stream_Element should include all possible bit patterns, and thus it
991 cannot be invalid. Therefore, the parameter will always represent a value of
992 its subtype. By omitting this routine, we make it possible to write arbitrary
993 I/O operations without any possibility of abnormal objects.]}
994 @end{Discussion}
995
996 @end{Itemize}
997
998 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00426-01]}
999 @ChgAdded{Version=[2],Text=[@Redundant[For an imported object, it is the
1000 programmer's responsibility to ensure that the object remains in a normal
1001 state.]]}
1002 @begin{TheProof}
1003 @ChgRef{Version=[2],Kind=[AddedNormal]}
1004 @ChgAdded{Version=[2],Text=[This follows (and echos) the standard rule
1005 of interfacing; the programmer must ensure that Ada semantics are
1006 followed (see @RefSecNum{Interfacing Aspects}).]}
1007 @end{TheProof}
1008
1009 @PDefn{unspecified}
1010 Whether or not an object actually becomes abnormal in these cases is
1011 not specified.
1012 An abnormal object becomes normal again upon successful completion of
1013 an assignment to the object as a whole.
1014 @end{RunTime}
1015
1016 @begin{Erron}
1017 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1018 It is erroneous to evaluate a @nt<primary> that is a @nt<name>
1019 denoting an abnormal object,
1020 or to evaluate a @nt{prefix} that denotes an abnormal object.
1021 @begin{Ramification}
1022 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]}
1023 @Comment{There appears to be no justification for this statement; everything
1024 can become abnormal. We leave the prefix for the next paragraph, so we use
1025 Chg rather than ChgDeleted.}
1026 @Chg{Version=[2],New=[],Old=[Although a composite object with no
1027 subcomponents of an access type, and with static constraints all the way down
1028 cannot become abnormal, a scalar subcomponent of such an object can become
1029 abnormal.]}
1030
1031 The @key[in out] or @key[out] parameter case does not apply to scalars;
1032 bad scalars are merely invalid representations,
1033 rather than abnormal, in this case.
1034 @end{Ramification}
1035 @begin{Reason}
1036 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1037 The reason we allow access objects, and objects containing subcomponents of an
1038 access type, to become abnormal is because the correctness of an access
1039 value cannot necessarily be determined merely by looking at the bits of
1040 the object.
1041 The reason we allow scalar objects to become abnormal is that we wish to
1042 allow the compiler to optimize assuming that the value of a scalar
1043 object belongs to the object's subtype,
1044 if the compiler can prove that the object is initialized with a value
1045 that belongs to the subtype.
1046 The reason we allow composite objects to become abnormal
1047 @Chg{Version=[2],New=[],Old=[if some constraints are nonstatic ]}is
1048 that such object might be represented with implicit levels of indirection;
1049 if those are corrupted, then even assigning into a component of the
1050 object, or simply asking for its Address, might have an unpredictable
1051 effect. The same is true if the discriminants have been destroyed.
1052 @end{Reason}
1053 @end{Erron}
1054
1055 @begin{Bounded}
1056 @Leading@Defn{invalid representation}@PDefn2{Term=(bounded error),Sec=(cause)}
1057 If the representation of a scalar object does not represent a value of
1058 the object's subtype
1059 (perhaps because the object was not initialized),
1060 the object is said to have an @i{invalid representation}.
1061 It is a bounded error to evaluate the value of such
1062 an object.
1063 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
1064 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1065 If the error is detected, either Constraint_Error or Program_Error is
1066 raised.
1067 Otherwise, execution continues using the invalid representation.
1068 The rules of the language outside this subclause assume that all objects
1069 have valid representations.
1070 The semantics of operations on invalid representations are as follows:
1071
1072 @begin{Discussion}
1073
1074 The AARM is more explicit about what happens when
1075 the value of the case expression is an invalid representation.
1076
1077 @end{Discussion}
1078 @begin{Ramification}
1079 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
1080 @ChgAdded{Version=[2],Text=[This includes the result object of functions,
1081 including the result of Unchecked_Conversion, T'Input, and imported
1082 functions.]}
1083 @end{Ramification}
1084
1085 @begin{Itemize}
1086 If the representation of the object represents a value of the object's
1087 type, the value of the type is used.
1088
1089 If the representation of the object does not represent a value of the
1090 object's type,
1091 the semantics of operations on such representations is
1092 implementation-defined, but does not by itself lead to
1093 erroneous or unpredictable
1094 execution, or to other objects becoming abnormal.
1095 @begin{ImplNote}
1096 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
1097 @ChgAdded{Version=[2],Text=[This means that the implementation must take care
1098 not to use an invalid representation in a way that might cause erroneous
1099 execution. For instance, the exception mandated for @nt{case_statement}s
1100 must be raised. Array indexing must not cause memory outside of
1101 the array to be written (and usually, not read either). These cases and
1102 similar cases may require explicit checks by the implementation.]}
1103 @end{ImplNote}
1104
1105 @end{Itemize}
1106 @end{Bounded}
1107
1108 @begin{Erron}
1109 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]}
1110 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0279-1]}
1111 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1112 A call to an imported function or an instance of Unchecked_Conversion is
1113 erroneous if the result is scalar, @Chg{Version=[2],New=[],Old=[and ]}the
1114 result object has an invalid representation@Chg{Version=[2],New=[, and
1115 the result is used other than as the @nt{expression} of
1116 an @nt{assignment_statement} or an @nt{object_declaration},@Chg{Version=[3],New=[
1117 as the @SynI{object_}@nt{name} of an @nt{object_renaming_declaration},],Old=[]} or as the
1118 @nt{prefix} of a Valid attribute. If such a result object is used as the source
1119 of an assignment, and the assigned value is an invalid representation for the
1120 target of the assignment, then any use of the target object prior to a further
1121 assignment to the target object, other than as the @nt{prefix} of a Valid
1122 attribute reference, is erroneous],Old=[]}.
1123 @begin{Ramification}
1124 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]}
1125 In a typical implementation, every bit pattern that fits in an object of
1126 @Chg{Version=[2],New=[a signed],Old=[an]} integer subtype will represent a
1127 value of the type, if not of the subtype.
1128 However, for an enumeration or floating point type,@Chg{Version=[2],New=[ as
1129 well as some modular types,],Old=[]}
1130 there are typically bit patterns that do not represent any
1131 value of the type.
1132 In such cases, the implementation ought to define the semantics of
1133 operations on the invalid representations in the obvious manner
1134 (assuming the bounded error is not detected):
1135 a given representation should be equal to itself,
1136 a representation that is in between the internal codes of
1137 two enumeration literals should behave accordingly when passed to
1138 comparison operators and membership tests, etc.
1139 We considered @i{requiring} such sensible behavior,
1140 but it resulted in too much arcane verbiage,
1141 and since implementations have little incentive to behave
1142 irrationally, such verbiage is not important to have.
1143
1144 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]}
1145 If a stand-alone scalar object is initialized to a an in-range
1146 value, then the implementation can take advantage of the fact
1147 that @Chg{Version=[2],New=[the use of ],Old=[]}any out-of-range value
1148 has to be @Chg{Version=[2],New=[erroneous],Old=[abnormal]}.@ChgNote{Do you
1149 see "abnormal" in the rules above? Thought not.}
1150 Such an out-of-range value can be produced only by things like
1151 unchecked conversion, @Chg{Version=[2],New=[imported functions],Old=[input]},
1152 and @Chg{Version=[2],New=[abnormal values caused by ],Old=[]}disruption
1153 of an assignment due to abort or to failure of a
1154 language-defined check.
1155 This depends on out-of-range values being checked before
1156 assignment (that is, checks are not optimized away unless they
1157 are proven redundant).
1158
1159 @Leading@;Consider the following example:
1160 @begin{Example}
1161 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01]}
1162 @key[type] My_Int @key[is] @key[range] 0..99;
1163 @key[function] Safe_Convert @key[is] @key[new] Unchecked_Conversion(My_Int, Integer);
1164 @key[function] Unsafe_Convert @key[is] @key[new] Unchecked_Conversion(My_Int, Positive);
1165 X : Positive := Safe_Convert(0); --@RI{ Raises Constraint_Error.}
1166 Y : Positive := Unsafe_Convert(0); --@Chg{Version=[2],New=[@RI{ Bounded Error, may be invalid.}
1167 B : Boolean := Y'Valid; --@RI{ OK, B = False.}
1168 Z : Positive := Y+1; --@RI{ Erroneous to use Y.}],Old=[@RI{ Erroneous.}]}
1169
1170 @end{Example}
1171
1172 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00167-01],ARef=[AI95-00426-01]}
1173 The call to Unsafe_Convert @Chg{Version=[2],New=[ is a bounded error, which
1174 might raise Constraint_Error, Program_Error, or return an invalid value.
1175 Moreover, if an exception is not raised, most uses of that invalid value
1176 (including the use of Y) cause],Old=[causes]} erroneous execution. The call to
1177 Safe_Convert is not erroneous. The result object is an object of subtype
1178 Integer containing the value 0. The assignment to X is required to do a
1179 constraint check; the fact that the conversion is unchecked does not obviate
1180 the need for subsequent checks required by the language rules.
1181
1182 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00167-01],ARef=[AI95-00426-01]}
1183 @ChgAdded{Version=[2],Text=[The reason for delaying erroneous execution until
1184 the object is used is so that the invalid representation can be tested for
1185 validity using the Valid attribute (see @RefSecNum{The Valid Attribute})
1186 without causing execution to become erroneous. Note that this delay does not
1187 imply an exception will not be raised; an implementation could treat both
1188 conversions in the example in the same way and raise Constraint_Error.]}
1189
1190 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0279-1]}
1191 @ChgAdded{Version=[3],Text=[The rules are defined in terms of the result
1192 object, and thus the name used to reference that object is irrelevant.
1193 That is why we don't need any special rules to describe what happens
1194 when the function result is renamed.]}
1195
1196 @end{Ramification}
1197 @begin{ImplNote}
1198 If an implementation wants to have a @lquotes@;friendly@rquotes@; mode, it
1199 might always assign an uninitialized scalar a default initial value
1200 that is outside the object's subtype (if there is one), and check
1201 for this value on some or all reads of the object, so as to help
1202 detect references to uninitialized scalars.
1203 Alternatively, an implementation might want to provide an
1204 @lquotes@;unsafe@rquotes@; mode where it presumed even uninitialized scalars
1205 were always within their subtype.
1206 @end{ImplNote}
1207 @begin{Ramification}
1208 The above rules imply that it is a bounded error
1209 to apply a predefined operator to
1210 an object with a scalar subcomponent having an invalid representation,
1211 since this implies reading the value of each subcomponent.
1212 Either Program_Error or Constraint_Error is raised,
1213 or some result is produced, which if composite, might have a corresponding
1214 scalar subcomponent still with an invalid representation.
1215
1216 Note that it is not an error to assign, convert, or pass as a parameter
1217 a composite object with an uninitialized scalar subcomponent.
1218 In the other hand, it is a (bounded) error to apply
1219 a predefined operator such as =, <, and @key(xor)
1220 to a composite operand with an invalid scalar subcomponent.
1221 @end{Ramification}
1222
1223 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0054-2]}
1224 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1225 The dereference of an access value is erroneous if
1226 it does not designate an object of an appropriate type or a subprogram
1227 with an appropriate profile,
1228 if it designates a nonexistent object,
1229 or if it is an access-to-variable value that designates a
1230 constant object@Chg{Version=[3],New=[ and it did not originate from an
1231 attribute_reference applied to an aliased variable view
1232 of a controlled or immutably limited object],Old=[]}.
1233 @Redundant[@Chg{Version=[3],New=[An],Old=[Such an]} access value
1234 @Chg{Version=[3],New=[whose dereference is erroneous ],Old=[]}can exist,
1235 for example, because of
1236 Unchecked_Deallocation, Unchecked_Access, or Unchecked_Conversion.]
1237
1238 @begin{Ramification}
1239 The above mentioned Unchecked_... features are not the only causes
1240 of such access values.
1241 For example, interfacing to other languages can also cause the problem.
1242
1243 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0054-2]}
1244 @Chg{Version=[3],New=[We permit the use of access-to-variable
1245 values that designate constant objects so long as they originate
1246 from an aliased variable view of a controlled or immutably limited
1247 constant, such as during the initialization of a constant (both via
1248 the @ldquote@;current instance@rdquote and during a call to Initialize) or
1249 during an assignment (during a call to Adjust).],Old=[One obscure example is if
1250 the Adjust subprogram of a controlled type uses Unchecked_Access to create an
1251 access-to-variable value designating a subcomponent of its controlled parameter,
1252 and saves this access value in a global object. When Adjust is called during the
1253 initialization of a constant object of the type, the end result will be an
1254 access-to-variable value that designates a constant object.]}
1255 @end{Ramification}
1256 @end{Erron}
1257
1258 @begin{Notes}
1259 Objects can become abnormal due to other kinds of actions that directly
1260 update the object's representation;
1261 such actions are generally considered directly erroneous, however.
1262 @end{Notes}
1263
1264 @begin{DiffWord83}
1265 In order to reduce the amount of erroneousness,
1266 we separate the concept of an undefined value into
1267 objects with invalid representation (scalars only)
1268 and abnormal objects.
1269
1270 Reading an object with an invalid representation is a bounded error
1271 rather than erroneous;
1272 reading an abnormal object is still erroneous.
1273 In fact, the only safe thing to do to an abnormal object is
1274 to assign to the object as a whole.
1275 @end{DiffWord83}
1276
1277 @begin{DiffWord95}
1278 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00167-01]}
1279 @ChgAdded{Version=[2],Text=[The description of erroneous execution for
1280 Unchecked_Conversion and imported objects was tightened up so that
1281 using the Valid attribute to test such a value is not erroneous.]}
1282
1283 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
1284 @ChgAdded{Version=[2],Text=[Clarified the definition of objects that can
1285 become abnormal; made sure that all of the possibilities are included.]}
1286 @end{DiffWord95}
1287
1288 @begin{Diffword2005}
1289 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0054-2]}
1290 @ChgAdded{Version=[3],Text=[@b<Correction:> Common programming
1291 techniques such as squirreling away@Defn{squirrel away} an access to a
1292 controlled object during initialization and using a self-referencing
1293 discriminant (the so-called @ldquote@;Rosen trick@rdquote@Defn{Rosen trick})
1294 no longer are immediately erroneous if the object is declared constant,
1295 so these techniques can be used portably and safely. Practically,
1296 these techniques already worked as compilers did not take much advantage
1297 of this rule, so the impact of this change will be slight.]}
1298 @ChgNote{This is not an extension, as such a program was already legal
1299 (although erroneous).}
1300
1301 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0279-1]}
1302 @ChgAdded{Version=[3],Text=[@b<Correction:> The description of erroneous
1303 execution for Unchecked_Conversion and imported objects was adjusted to
1304 clarify that renaming such an object is not, by itself, erroneous.]}
1305 @end{Diffword2005}
1306
1307
1308
1309 @LabeledSubClause{The Valid Attribute}
1310
1311 @begin{Intro}
1312 The Valid attribute can be used to check the validity of data produced
1313 by unchecked conversion, input, interface to foreign languages,
1314 and the like.
1315 @end{Intro}
1316
1317 @begin{StaticSem}
1318 @Leading@;For @PrefixType{a @nt<prefix> X that
1319 denotes a scalar object @Redundant[(after any implicit dereference)]},
1320 the following attribute is defined:
1321 @begin(description)
1322 @Comment{We ought to have a separate change for version [3] here, but
1323 we don't have that capability.}
1324 @ChgAttribute{Version=[4],Kind=[Revised],ChginAnnex=[T],
1325 Leading=<F>, Prefix=<X>, AttrName=<Valid>,
1326 ARef=[AI05-0153-3], ARef=[AI12-0071-1], InitialVersion=[0],
1327 Text=<Yields True if and only if
1328 the object denoted by X is normal@Chg{Version=[3],New=[,],Old=[ and]} has a
1329 valid representation@Chg{Version=[3],New=[, and @Chg{Version=[4],New=[then,
1330 if the preceding conditions hold, the value of X also satisfies the
1331 predicates@Defn2{Term=[predicates satisfied required],Sec=[Valid attribute]}], Old=[the
1332 predicate@Defn2{Term=[predicate evaluated],Sec=[Valid attribute]}]}
1333 of the nominal subtype of X@Chg{Version=[4],New=[],Old=[ evaluates to
1334 True]}],Old=[]}. The value of this attribute is of the predefined type Boolean.>}
1335 @begin{Ramification}
1336 Having checked that X'Valid is True, it is safe to read the
1337 value of X without fear of erroneous execution caused by abnormality,
1338 or a bounded error caused by an invalid representation.
1339 Such a read will produce a value in the subtype of X.
1340 @end{Ramification}
1341 @end{description}
1342 @EndPrefixType{}
1343 @end{StaticSem}
1344
1345 @begin{Notes}
1346 @Leading@;Invalid data can be created in the following cases
1347 (not counting erroneous or unpredictable execution):
1348 @begin{Itemize}
1349 an uninitialized scalar object,
1350
1351 the result of an unchecked conversion,
1352
1353 input,
1354
1355 interface to another language (including machine code),
1356
1357 aborting an assignment,
1358
1359 disrupting an assignment due to the failure
1360 of a language-defined check
1361 (see @RefSecNum{Exceptions and Optimization}), and
1362
1363 use of an object whose Address has been specified.
1364 @end{Itemize}
1365
1366 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0071-1]}
1367 @Chg{Version=[4],New=[Determining whether X is normal and has a valid
1368 representation as part of the evaluation of ],Old=[]}X'Valid is not considered
1369 to @Chg{Version=[4],New=[include an evaluation],Old=[be a read]} of X;
1370 hence, it is not an error to check the validity
1371 of @Chg{Version=[4],New=[an object that is invalid or abnormal.
1372 Determining whether X satisfies the predicates of its nominal
1373 subtype may include an evaluation of X, but only after
1374 it has been determined that X has a valid representation],Old=[invalid data]}.
1375
1376 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
1377 @ChgAdded{Version=[4],NoPrefix=[T],Text=[If X is volatile, the evaluation of
1378 X'Valid is considered a read of X.]}
1379
1380 @begin{Reason}
1381 @ChgRef{Version=[4],Kind=[AddedNormal]}
1382 @ChgAdded{Version=[4],Text=[Since an implementation is not allowed to add,
1383 remove, or reorder accesses to volatile objects, we have to define X'Valid
1384 as a read so that it is implementable for most subtypes as the value
1385 of the object is required.]}
1386 @end{Reason}
1387
1388 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
1389 @ChgAdded{Version=[2],Text=[The Valid attribute may be used to check the
1390 result of calling an instance of Unchecked_Conversion (or any other
1391 operation that can return invalid values). However, an exception handler
1392 should also be provided because implementations are permitted to raise
1393 Constraint_Error or Program_Error if they detect the use of an invalid
1394 representation (see @RefSecNum{Data Validity}).]}
1395
1396 @begin{Ramification}
1397 If X is of an enumeration type with a representation clause, then
1398 X'Valid checks that the value of X when viewed as an integer is one of
1399 the specified internal codes.
1400 @end{Ramification}
1401 @begin{Reason}
1402 Valid is defined only for scalar objects because the implementation
1403 and description burden would be too high for other types.
1404 For example, given a typical run-time model, it is impossible to check
1405 the validity of an access value.
1406 The same applies to composite types implemented with internal pointers.
1407 One can check the validity of a composite object by checking the
1408 validity of each of its scalar subcomponents.
1409 The user should ensure that any composite types that need to be checked
1410 for validity are represented in a way that does not involve
1411 implementation-defined components, or gaps between components.
1412 Furthermore, such types should not contain access subcomponents.
1413
1414 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]}
1415 @ChgNote{This was never true, even in Ada 95}
1416 @ChgDeleted{Version=[2],Text=[Note that one can safely check the validity
1417 of a composite object with
1418 an abnormal value only if the constraints on
1419 the object and all of its subcomponents are static.
1420 Otherwise, evaluation of the @nt{prefix} of the @nt{attribute_reference}
1421 causes erroneous execution (see @RefSecNum{Names}).]}
1422 @end{Reason}
1423 @end{Notes}
1424
1425 @begin{Extend83}
1426 @Defn{extensions to Ada 83}
1427 X'Valid is new in Ada 95.
1428 @end{Extend83}
1429
1430 @begin{DiffWord95}
1431 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00426-01]}
1432 @ChgAdded{Version=[2],Text=[Added a note explaining that handlers for
1433 Constraint_Error and Program_Error are needed in the general case of
1434 testing for validity. (An implementation could document cases where these
1435 are not necessary, but there is no language requirement.)]}
1436 @end{DiffWord95}
1437
1438 @begin{DiffWord2005}
1439 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0153-3]}
1440 @ChgAdded{Version=[3],Text=[The validity check now also includes a check
1441 of the predicate aspects (see @RefSecNum{Subtype Predicates}), if any, of
1442 the subtype of the object.]}
1443 @end{DiffWord2005}
1444
1445 @begin{DiffWord2012}
1446 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0071-1]}
1447 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Updated wording of the
1448 attributes X'Valid to use the new term
1449 "satisfies the predicates" (see @RefSecNum{Subtype Predicates}).
1450 Also updated the notes to make sense when evaluating predicates and
1451 testing validity of volatile objects.]}
1452 @end{DiffWord2012}
1453
1454
1455 @LabeledClause{Unchecked Access Value Creation}
1456
1457 @begin{Intro}
1458 @redundant[The attribute Unchecked_Access is used to create access values
1459 in an unsafe manner @em the programmer is responsible for preventing
1460 @lquotes@;dangling references.@rquotes@;]
1461 @end{Intro}
1462
1463 @begin{StaticSem}
1464 @Leading@;The following attribute is defined for @PrefixType{a @nt{prefix} X that
1465 denotes an aliased view of an object}:
1466 @begin{Description}
1467 @Attribute{Prefix=<X>, AttrName=<Unchecked_Access>,
1468 Text=<All rules and semantics that apply to
1469 X'Access (see @RefSecNum{Operations of Access Types})
1470 apply also to X'Unchecked_Access,
1471 except that,
1472 for the purposes of accessibility rules and checks,
1473 it is as if X were declared immediately within a library package.>}
1474 @IndexSeeAlso{Term=[Access attribute],See=(Unchecked_Access attribute)}
1475 @end{Description}
1476 @EndPrefixType{}
1477
1478 @begin{Ramification}
1479 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1480 @ChgAdded{Version=[3],Text=[We say @ldquote@;rules and semantics@rdquote@;
1481 here so that library-level accessibility applies to the value created by
1482 X'Unchecked_Access as well as to the checks needed for the attribute itself.
1483 This means that any anonymous access values that inherit the accessibility of
1484 this attribute (such as access parameters) also act as if they have
1485 library-level accessibility. We don't want the "real" accessibility of the
1486 created value re-emerging at a later point @en that would create
1487 hard-to-understand bugs.]}
1488 @end{Ramification}
1489 @end{StaticSem}
1490
1491 @begin{Notes}
1492 This attribute is provided to support the situation where a local
1493 object is to be inserted into a global linked data structure, when the
1494 programmer knows that it will always be removed from the data structure prior
1495 to exiting the object's scope. The Access attribute would
1496 be illegal in this case
1497 (see @RefSec{Operations of Access Types}).
1498 @begin{Ramification}
1499 @PDefn2{Term=[expected type],
1500 Sec=(Unchecked_Access attribute)}
1501 The expected type for X'Unchecked_Access is as for X'Access.
1502
1503 If an @nt<attribute_reference> with Unchecked_Access is used
1504 as the actual parameter for an access parameter,
1505 an Accessibility_Check can never fail on that access
1506 parameter.
1507 @end{Ramification}
1508
1509 There is no Unchecked_Access attribute for subprograms.
1510 @begin{Reason}
1511 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]}
1512 Such an attribute would allow @Chg{Version=[2],New=[unsafe ],
1513 Old=[]}@lquotes@;downward closures@rquotes@;,
1514 where an access value designating a more nested subprogram is passed
1515 to a less nested subprogram.@Chg{Version=[2],New=[ (Anonymous
1516 access-to-subprogram parameters provide safe
1517 @lquotes@;downward closures@rquotes@;.)],Old=[]}
1518 This requires some means of reconstructing the global environment for
1519 the more nested subprogram,
1520 so that it can do up-level references to objects.
1521 The two methods of implementing up-level references are displays and
1522 static links.
1523 If @Chg{Version=[2],New=[unsafe ],Old=[]}downward closures were
1524 supported,
1525 each access-to-subprogram value would have to carry the static link
1526 or display with it.
1527 @Chg{Version=[2],New=[We don't want to require the space and time
1528 overhead of requiring the extra information for all access-to-subprogram
1529 types, especially as including it
1530 would make interfacing to other languages (like C) harder],Old=[In the case
1531 of displays, this was judged to be infeasible,
1532 and we don't want to disrupt implementations by forcing them
1533 to use static links if they already use displays]}.
1534
1535 If desired, an instance of Unchecked_Conversion can be used to create
1536 an access value of a global access-to-subprogram type that
1537 designates a local subprogram. The semantics of using
1538 such a value are not specified by the language.
1539 In particular, it is not specified what happens if such
1540 subprograms make up-level references; even if the frame
1541 being referenced still exists, the up-level reference might
1542 go awry if the representation of a value of a global access-to-subprogram
1543 type doesn't include a static link.
1544 @end{Reason}
1545
1546 @end{Notes}
1547
1548 @NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM}
1549 @LabeledClause{Storage Management}
1550
1551 @begin{Intro}
1552 @Redundant[
1553 @Defn{user-defined storage management}
1554 @Defn2{Term=[storage management], Sec=(user-defined)}
1555 @Defn{user-defined heap management}
1556 @Defn2{Term=[heap management], Sec=(user-defined)}
1557 Each access-to-object type has an associated storage
1558 pool.
1559 The storage allocated by an @nt{allocator} comes from the pool;
1560 instances of Unchecked_Deallocation return storage to the pool.
1561 Several access types can share the same pool.]
1562
1563 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00435-01]}
1564 @Redundant[A storage pool is a variable of a type in the class rooted
1565 at Root_Storage_Pool, which is an abstract limited controlled type.
1566 By default, the implementation chooses a @i{standard storage pool}
1567 for each access@Chg{Version=[2],New=[-to-object],Old=[]} type.
1568 The user may define new pool types,
1569 and may override the choice of pool for an access@Chg{Version=[2],New=[-to-object],Old=[]}
1570 type by specifying Storage_Pool for the type.]
1571 @begin{Ramification}
1572 By default, the implementation might choose to have a single global
1573 storage pool,
1574 which is used (by default) by all access types,
1575 which might mean that storage is reclaimed automatically only
1576 upon partition completion.
1577 Alternatively, it might choose to create a new pool
1578 at each accessibility level,
1579 which might mean that storage is reclaimed for an access type
1580 when leaving the appropriate scope.
1581 Other schemes are possible.
1582 @end{Ramification}
1583
1584 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Storage pool>,
1585 Text=<@ChgAdded{Version=[3],Text=[Each access-to-object type has an associated
1586 storage pool object. The storage for an object created by an @nt{allocator}
1587 comes from the storage pool of the type of the @nt{allocator}. Some storage
1588 pools may be partitioned into subpools in order to support finer-grained storage
1589 management.]}>}
1590
1591 @end{Intro}
1592
1593 @begin{Legality}
1594 If Storage_Pool is specified for a given access type,
1595 Storage_Size shall not be specified for it.
1596 @begin{Reason}
1597 The Storage_Pool determines the Storage_Size;
1598 hence it would not make sense to specify both.
1599 Note that this rule is simplified by the fact that the aspects in
1600 question cannot be specified for derived types,
1601 nor for nonfirst subtypes,
1602 so we don't have to worry about whether, say, Storage_Pool on a
1603 derived type overrides Storage_Size on the parent type.
1604 For the same reason, @lquotes@;specified@rquotes@; means the same thing as
1605 @lquotes@;directly specified@rquotes@; here.
1606 @end{Reason}
1607 @end{Legality}
1608
1609 @begin{StaticSem}
1610 @Leading@keepnext@;The following language-defined library package exists:
1611 @begin{Example}
1612 @key[with] Ada.Finalization;
1613 @key[with] System.Storage_Elements;
1614 @ChildUnit{Parent=[System],Child=[Storage_Pools]}@key[package] System.Storage_Pools @key[is]
1615 @key{pragma} Preelaborate(System.Storage_Pools);
1616
1617 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]}
1618 @key[type] @AdaTypeDefn{Root_Storage_Pool} @key[is]
1619 @key[abstract] @key[new] Ada.Finalization.Limited_Controlled @key[with] @key[private];@Chg{Version=[2],New=[
1620 @key[pragma] Preelaborable_Initialization(Root_Storage_Pool);],Old=[]}
1621
1622 @key[procedure] @AdaSubDefn{Allocate}(
1623 Pool : @key[in] @key[out] Root_Storage_Pool;
1624 Storage_Address : @key[out] Address;
1625 Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count;
1626 Alignment : @key[in] Storage_Elements.Storage_Count) @key[is] @key[abstract];
1627
1628 @key[procedure] @AdaSubDefn{Deallocate}(
1629 Pool : @key[in] @key[out] Root_Storage_Pool;
1630 Storage_Address : @key[in] Address;
1631 Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count;
1632 Alignment : @key[in] Storage_Elements.Storage_Count) @key[is] @key[abstract];
1633
1634 @key[function] @AdaSubDefn{Storage_Size}(Pool : Root_Storage_Pool)
1635 @key[return] Storage_Elements.Storage_Count @key[is] @key[abstract];
1636
1637 @key[private]
1638 ... -- @RI{not specified by the language}
1639 @key[end] System.Storage_Pools;
1640 @end{Example}
1641 @begin{Reason}
1642 The Alignment parameter is provided to Deallocate because some
1643 allocation strategies require it.
1644 If it is not needed, it can be ignored.
1645 @end{Reason}
1646
1647 @Defn{storage pool type}
1648 @Defn{pool type}
1649 A @i{storage pool type} (or @i{pool type}) is a descendant of
1650 Root_Storage_Pool.
1651 @Defn{storage pool element}
1652 @Defn{pool element}
1653 @Defn2{Term=[element], Sec=(of a storage pool)}
1654 The @i{elements} of a storage pool are the objects allocated in the
1655 pool by @nt{allocator}s.
1656 @begin{Discussion}
1657 In most cases, an element corresponds to a single memory block
1658 allocated by Allocate.
1659 However, in some cases the implementation may choose to associate
1660 more than one memory block with a given pool element.
1661 @end{Discussion}
1662
1663 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1664 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00435-01]}
1665 @Leading@;For @PrefixType{every access@Chg{Version=[2],New=[-to-object],Old=[]} subtype S},
1666 the following @Chg{New=[representation ],Old=[]}attributes are defined:
1667 @begin{Description}
1668 @Attribute{Prefix=<S>, AttrName=<Storage_Pool>,
1669 Text=<Denotes the storage pool of the type of S.
1670 The type of this attribute is Root_@!Storage_@!Pool'Class.>}
1671
1672 @Attribute{Prefix=<S>, AttrName=<Storage_Size>,
1673 Text=<Yields the result of calling
1674 Storage_Size(S'Storage_Pool)@Redundant{,
1675 which is intended to be a measure of the number of storage elements
1676 reserved for the pool.}
1677 The type of this attribute is @i{universal_integer}.>}
1678 @EndPrefixType{}
1679 @begin{Ramification}
1680 Storage_Size is also defined for task subtypes and objects
1681 @em see @RefSecNum{Operational and Representation Attributes}.
1682
1683 Storage_Size is not a measure of how much un-allocated space is
1684 left in the pool.
1685 That is, it includes both allocated and unallocated space.
1686 Implementations and users may provide a Storage_Available function
1687 for their pools, if so desired.
1688 @end{Ramification}
1689 @end{Description}
1690
1691 @PDefn2{Term=[specifiable], Sec=(of Storage_Size for
1692 a nonderived access-to-object type)}
1693 @PDefn2{Term=[specifiable], Sec=(of Storage_Pool for
1694 a nonderived access-to-object type)}
1695 @Defn{Storage_Pool clause}
1696 @Defn{Storage_Size clause}
1697 Storage_Size or Storage_Pool may be specified for
1698 a nonderived access-to-object type
1699 via an @nt{attribute_@!definition_@!clause};
1700 the @nt{name} in a Storage_Pool clause shall denote a
1701 variable.@Chg{Version=[3],New=[@AspectDefn{Storage_Pool}@AspectDefn{Storage_Size (access)}],Old=[]}
1702
1703 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Storage_Pool],
1704 Text=[@ChgAdded{Version=[3],Text=[Pool of memory from which @key[new] will
1705 allocate for a given access type.]}]}
1706
1707 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Storage_Size (access)],
1708 Text=[@ChgAdded{Version=[3],Text=[Sets memory size for allocations for an
1709 access type.]}]}
1710
1711
1712
1713 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0107-1],ARef=[AI05-0111-3],ARef=[AI05-0116-1]}
1714 An @nt{allocator} of @Chg{Version=[3],New=[a ],Old=[]}type @i<T>
1715 @Chg{Version=[3],New=[that does not support subpools ],Old=[]}allocates
1716 storage from @i<T>'s storage pool.
1717 If the storage pool is a user-defined object, then
1718 the storage is allocated by calling Allocate@Chg{Version=[3],New=[ as described
1719 below. @nt{Allocator}s for types that support subpools are described
1720 in @RefSecNum{Storage Subpools}.],Old=[,
1721 passing T'Storage_Pool as the Pool parameter.
1722 The Size_In_Storage_Elements parameter indicates the number of storage elements
1723 to be allocated,
1724 and is no more than D'Max_Size_In_Storage_Elements,
1725 where D is the designated subtype.
1726 The Alignment parameter is D'Alignment.
1727 @PDefn{contiguous representation}
1728 @PDefn{discontiguous representation}
1729 The result returned in the Storage_Address parameter is used by the
1730 @nt{allocator} as the address of the allocated storage,
1731 which is a contiguous block of memory of Size_In_@!Storage_@!Elements
1732 storage elements.
1733 @Redundant[Any exception propagated by Allocate is propagated by the
1734 @nt{allocator}.]]}
1735 @begin{Ramification}
1736 If the implementation chooses to represent the designated
1737 subtype in multiple pieces,
1738 one @nt{allocator} evaluation might result in more than one call upon
1739 Allocate.
1740 In any case, @nt{allocator}s for the access type obtain all the required
1741 storage for an object of the designated type by calling the
1742 specified Allocate procedure.
1743
1744 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0107-1]}
1745 @ChgDeleted{Version=[3],Text=[Note that the implementation does not turn other
1746 exceptions into Storage_Error.]}
1747
1748 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0111],ARef=[AI95-00103-01]}
1749 @ChgAdded{Version=[1],Text=[If @i<D> (the designated type of @i<T>) includes
1750 subcomponents of other access types, they will be allocated from the storage
1751 pools for those types, even if those @nt{allocator}s are executed as part of
1752 the @nt{allocator} of @i<T> (as part of the initialization of the object). For
1753 instance, an access-to-task type @i<TT> may allocate the data structures used to
1754 implement the task value from other storage pools. (In particular, the task
1755 stack does not necessarily need to be allocated from the storage pool for
1756 @i<TT>.)]}
1757 @end{Ramification}
1758
1759 @Defn{standard storage pool}
1760 If Storage_Pool is not specified for a type defined by an
1761 @nt{access_to_object_definition},
1762 then the implementation chooses a standard storage pool for it
1763 in an implementation-defined manner.
1764 @IndexCheck{Storage_Check}
1765 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
1766 In this case,
1767 the exception Storage_Error is raised by an @nt{allocator}
1768 if there is not enough storage.
1769 It is implementation defined whether or not the implementation
1770 provides user-accessible names for the standard pool type(s).
1771 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
1772 Text=[@ChgDeleted{Version=[2],Text=[The
1773 manner of choosing a storage pool for an access type when
1774 Storage_Pool is not specified for the type.]}]}
1775 @begin{Discussion}
1776 @ChgRef{Version=[2],Kind=[Added]}
1777 @ChgAdded{Version=[2],Text=[The manner of choosing a storage pool is
1778 covered by a @DocReqName below, so it is not summarized here.]}
1779 @end{Discussion}
1780 @ImplDef{Whether or not the implementation
1781 provides user-accessible names for the standard pool type(s).}
1782 @begin{Ramification}
1783 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1784 @ChgNote{This was never true.}@Chg{Version=[2],New=[],Old=[An anonymous access
1785 type has no pool. ]}An access-to-object type defined by a
1786 @nt{derived_type_definition}
1787 inherits its pool from its parent type, so
1788 all access-to-object types in the same derivation class share the same pool.
1789 Hence the @lquotes@;defined by an @nt{access_to_object_definition}@rquotes@; wording
1790 above.
1791
1792 @PDefn{contiguous representation}
1793 @PDefn{discontiguous representation}
1794 There is no requirement that all storage pools be implemented using a
1795 contiguous block of memory (although each allocation returns
1796 a pointer to a contiguous block of memory).
1797 @end{Ramification}
1798
1799 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0043-1]}
1800 If Storage_Size is specified for an access type@Chg{Version=[4],New=[ @i<T>,
1801 an implementation-defined pool @i<P> is used for the type. The],Old=[, then the]}
1802 Storage_Size of @Chg{Version=[4],New=[@i<P>],Old=[this pool]} is at least
1803 that requested, and the storage for @Chg{Version=[4],New=[@i<P>],Old=[the pool]}
1804 is reclaimed when the master containing
1805 the declaration of the access type is left.
1806 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
1807 If the implementation cannot satisfy the request, Storage_Error is raised at the
1808 @Chg{Version=[4],New=[freezing ],Old=[]}point of @Chg{Version=[4],New=[type
1809 @i<T>. The storage pool @i<P> is used only for allocators returning type @i<T>
1810 or other access types specified to use @i<T>'Storage_Pool. Storage_Error is
1811 raised by an @nt{allocator} returning such a type if the storage space of @i<P>
1812 is exhausted (additional memory is not allocated).],Old=[the
1813 @nt{attribute_@!definition_@!clause}. If neither Storage_Pool nor Storage_Size
1814 are specified, then the meaning of Storage_Size is implementation defined.]}
1815
1816 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0043-1]}
1817 @ChgAdded{Version=[4],Text=[If neither Storage_Pool nor Storage_Size are
1818 specified, then the meaning of Storage_Size is implementation defined.]}
1819
1820 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],Text=[The meaning of
1821 Storage_Size@Chg{Version=[2], New=[ when neither the
1822 Storage_Size nor the Storage_Pool is specified for an access type],Old=[]}.]}
1823 @begin{Ramification}
1824 The Storage_Size function and attribute will return the actual
1825 size, rather than the requested size.
1826 Comments about rounding up, zero, and negative
1827 on task Storage_Size apply here, as well.
1828 See also AI83-00557, AI83-00558, and AI83-00608.
1829
1830 The expression in a Storage_Size clause
1831 need not be static.
1832
1833 The reclamation happens after the master is finalized.
1834 @end{Ramification}
1835 @begin{ImplNote}
1836 For a pool allocated on the stack, normal stack cut-back can
1837 accomplish the reclamation.
1838 For a library-level pool, normal partition termination actions can
1839 accomplish the reclamation.
1840 @end{ImplNote}
1841
1842 If Storage_Pool is specified for an access type,
1843 then the specified pool is used.
1844
1845 @PDefn{unspecified}
1846 The effect of calling Allocate and Deallocate for a standard storage
1847 pool directly
1848 (rather than implicitly via an @nt{allocator} or an instance
1849 of Unchecked_Deallocation) is unspecified.
1850 @begin{Ramification}
1851 For example, an @nt{allocator} might put the pool element on a
1852 finalization list.
1853 If the user directly Deallocates it, instead of calling an instance
1854 of Unchecked_Deallocation, then the implementation would probably try
1855 to finalize the object upon master completion,
1856 which would be bad news.
1857 Therefore, the implementation should define such situations as
1858 erroneous.
1859 @end{Ramification}
1860 @end{StaticSem}
1861
1862 @begin{Erron}
1863 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1864 If Storage_Pool is specified for an access type,
1865 then if Allocate can satisfy the request,
1866 it should allocate a contiguous block of memory,
1867 and return the address of the first storage element in Storage_Address.
1868 The block should contain Size_In_Storage_Elements storage elements,
1869 and should be aligned according to Alignment.
1870 The allocated storage should not be used for any
1871 other purpose while the pool element remains in existence.
1872 If the request cannot be satisfied,
1873 then Allocate should propagate an exception
1874 @Redundant[(such as Storage_Error)].
1875 If Allocate behaves in any other manner,
1876 then the program execution is erroneous.
1877 @end{Erron}
1878
1879 @begin{ImplReq}
1880
1881 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0107-1],ARef=[AI05-0262-1]}
1882 @ChgAdded{Version=[3],Type=[Leading],Text=[The Allocate procedure of a
1883 user-defined storage pool object @i<P> may be called by the implementation only
1884 to allocate storage for a type @i<T> whose pool is @i<P>, only at the
1885 following points:]}
1886
1887 @begin{Itemize}
1888 @ChgRef{Version=[3],Kind=[Added]}
1889 @ChgAdded{Version=[3],Text=[During the execution of an @nt{allocator} of type
1890 @i<T>;]}
1891
1892 @begin{Ramification}
1893 @ChgRef{Version=[3],Kind=[AddedNormal]}
1894 @ChgAdded{Version=[3],Text=[This includes during the evaluation of the
1895 initializing expression such as an @nt{aggregate}; this is important if the
1896 initializing expression is built in place. We need to allow allocation to be
1897 deferred until the size of the object is known.]}
1898 @end{Ramification}
1899
1900 @ChgRef{Version=[3],Kind=[Added]}
1901 @ChgAdded{Version=[3],Text=[During the execution of a return statement for a
1902 function whose result is built-in-place in the result of an @nt{allocator}
1903 of type @i<T>;]}
1904
1905 @begin{Reason}
1906 @ChgRef{Version=[3],Kind=[AddedNormal]}
1907 @ChgAdded{Version=[3],Text=[We need this bullet as well as the preceding one
1908 in order that exceptions that propagate from such a call to Allocate can be
1909 handled within the return statement. We don't want to require the generation
1910 of special handling code in this unusual case, as it would add overhead to
1911 most return statements of composite types.]}
1912 @end{Reason}
1913
1914 @ChgRef{Version=[3],Kind=[Added]}
1915 @ChgAdded{Version=[3],Text=[During the execution of an assignment operation with
1916 a target of an allocated object of type @i<T> with a part that has an
1917 unconstrained discriminated subtype with defaults.]}
1918
1919 @begin{Reason}
1920 @ChgRef{Version=[3],Kind=[AddedNormal]}
1921 @ChgAdded{Version=[3],Text=[We allow Allocate to be called during assignment
1922 of objects with mutable parts so that mutable objects can be implemented with
1923 reallocation on assignment. (Unfortunately, the term "mutable" is only defined
1924 in the AARM, so we have to use the long-winded wording shown here.)]}
1925 @end{Reason}
1926
1927 @begin{Discussion}
1928 @ChgRef{Version=[3],Kind=[AddedNormal]}
1929 @ChgAdded{Version=[3],Text=[Of course, explicit calls to Allocate are also
1930 allowed and are not bound by any of the rules found here.]}
1931 @end{Discussion}
1932 @end{Itemize}
1933
1934 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0107-1],ARef=[AI05-0116-1],ARef=[AI05-0193-1],ARef=[AI05-0262-1],ARef=[AI05-0269-1]}
1935 @ChgAdded{Version=[3],Text=[For each of the calls of Allocate described above,
1936 @i{P} (equivalent to @i{T}'Storage_Pool) is passed as the Pool parameter. The
1937 Size_In_Storage_Elements parameter indicates the number of storage elements to
1938 be allocated, and is no more than @i{D}'Max_Size_In_Storage_Elements, where
1939 @i{D} is the designated subtype of @i{T}. The Alignment parameter is a nonzero
1940 integral multiple of @i{D}'Alignment if @i{D} is a specific type, and otherwise
1941 is a nonzero integral multiple of the alignment of the specific type identified
1942 by the tag of the object being created; it is
1943 unspecified if there is no such value. The Alignment parameter is no more than
1944 @i{D}'Max_Alignment_For_Allocation. The result returned in the Storage_Address
1945 parameter is used as the address of the allocated storage, which is a contiguous
1946 block of memory of Size_In_Storage_Elements storage elements. @Redundant[Any
1947 exception propagated by Allocate is propagated by the construct that contained
1948 the call.]]}
1949
1950 @begin{Ramification}
1951 @ChgRef{Version=[3],Kind=[AddedNormal]}
1952 @ChgAdded{Version=[3],Text=[Note that the implementation does not turn other
1953 exceptions into Storage_Error.]}@ChgNote{Moved from 13.11(16).}
1954
1955 @ChgRef{Version=[3],Kind=[AddedNormal]}
1956 @ChgAdded{Version=[3],Text=[@ldquote@;Nonzero integral multiple@rdquote
1957 of an alignment includes the alignment value itself, of course. The
1958 value is unspecified if the alignment of the specific type is zero.]}
1959 @end{Ramification}
1960
1961 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0107-1]}
1962 @ChgAdded{Version=[3],Text=[The number of calls to Allocate needed to implement
1963 an @nt{allocator} for any particular type is unspecified.@PDefn{unspecified}
1964 @PDefn{contiguous representation}
1965 @PDefn{discontiguous representation}
1966 The number of calls to Deallocate needed to implement an instance of
1967 Unchecked_Deallocation (see @RefSecNum{Unchecked Storage Deallocation}) for any
1968 particular object is the same as the number of Allocate calls for that object.]}
1969
1970 @begin{Reason}
1971 @ChgRef{Version=[3],Kind=[AddedNormal]}
1972 @ChgAdded{Version=[3],Text=[This supports objects that are allocated in one or
1973 more parts. The second sentence prevents extra or missing calls to Deallocate.]}
1974 @end{Reason}
1975
1976 @begin{Honest}
1977 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1978 @ChgAdded{Version=[3],Text=[The number of calls to Deallocate from all sources
1979 for an object always will be the same as the number of calls to Allocate from
1980 all sources for that object. However, in unusual cases, not all of those
1981 Deallocate calls may be made by an instance of Unchecked_Deallocation.
1982 Specifically, in the unusual case of assigning to an object of a mutable
1983 variant record type such that the variant changes, some of the Deallocate
1984 calls may be made by the assignment (as may some of the Allocate calls).]}
1985 @end{Honest}
1986
1987 @begin{Ramification}
1988 @ChgRef{Version=[3],Kind=[AddedNormal]}
1989 @ChgAdded{Version=[3],Text=[We do not define the relative order of multiple
1990 calls used to deallocate the same object @em that is, if the @nt{allocator}
1991 allocated two pieces @i{x} and @i{y}, then an instance of Unchecked_Deallocation
1992 might deallocate @i{x} and then @i{y}, or it might deallocate @i{y} and then
1993 @i{x}.]}@ChgNote{Moved from 13.11.2}
1994 @end{Ramification}
1995
1996
1997 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0107-1]}
1998 @ChgAdded{Version=[3],Text=[The Deallocate procedure of a user-defined storage
1999 pool object @i{P} may be called by the implementation to deallocate storage for a
2000 type @i{T} whose pool is @i{P} only at the places when an Allocate call is allowed for
2001 @i{P}, during the execution of an instance of Unchecked_Deallocation for @i{T}, or as
2002 part of the finalization of the collection of @i{T}. For such a call of Deallocate,
2003 @i{P} (equivalent to @i{T}'Storage_Pool) is passed as the Pool parameter. The
2004 value of the Storage_Address parameter for a call to Deallocate is the value
2005 returned in the Storage_Address parameter of the corresponding successful call
2006 to Allocate. The values of the Size_In_Storage_Elements and Alignment parameters
2007 are the same values passed to the corresponding Allocate call. Any exception
2008 propagated by Deallocate is propagated by the construct that contained the
2009 call.]}
2010
2011 @begin{Reason}
2012 @ChgRef{Version=[3],Kind=[AddedNormal]}
2013 @ChgAdded{Version=[3],Text=[We allow Deallocate to be called anywhere that
2014 Allocate is, in order to allow the recovery of storage from failed allocations
2015 (that is, those that raise exceptions); from extended return statements that
2016 exit via a goto, exit, or locally handled exception; and from objects that
2017 are reallocated when they are assigned. In each of these cases, we would have
2018 a storage leak if the implementation did not recover the storage (there is no
2019 way for the programmer to do it). We do not require such recovery, however, as
2020 it could be a serious performance drag on these operations.]}
2021 @end{Reason}
2022 @end{ImplReq}
2023
2024 @begin{DocReq}
2025 An implementation shall document
2026 the set of values that a user-defined Allocate procedure needs
2027 to accept for the Alignment parameter.
2028 An implementation shall document
2029 how the standard storage pool is chosen,
2030 and how storage is allocated by standard storage pools.
2031 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
2032 Text=[@ChgDeleted{Version=[2],
2033 Text=[Implementation-defined aspects of storage pools.]}]}
2034 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],Text=[
2035 The set of values that a user-defined Allocate procedure needs
2036 to accept for the Alignment parameter.
2037 How the standard storage pool is chosen, and how storage is allocated
2038 by standard storage pools.]}]}
2039 @end{DocReq}
2040
2041 @begin{ImplAdvice}
2042 An implementation should document any cases in which it dynamically
2043 allocates heap storage for a purpose other than the evaluation of an
2044 @nt{allocator}.
2045 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2046 Text=[Any cases in which heap storage is dynamically allocated other than
2047 as part of the evaluation of an @nt{allocator} should be documented.]}]}
2048 @begin{Reason}
2049 This is @lquotes@;@ImplAdviceTitle@rquotes@; because the term @lquotes@;heap storage@rquotes@;
2050 is not formally definable;
2051 therefore, it is not testable whether the implementation obeys this advice.
2052 @end{Reason}
2053
2054 A default (implementation-provided) storage pool for an
2055 access-to-constant type should
2056 not have overhead to support deallocation of individual objects.
2057 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2058 Text=[A default storage pool for an access-to-constant type should
2059 not have overhead to support deallocation of individual objects.]}]}
2060 @begin{Ramification}
2061 Unchecked_Deallocation is not defined for
2062 such types. If the access-to-constant type is library-level,
2063 then no deallocation (other than at partition completion) will
2064 ever be necessary, so if the size needed by an @nt{allocator}
2065 of the type is known at link-time, then the allocation
2066 should be performed statically.
2067 If, in addition, the initial value of the designated object is known
2068 at compile time, the object can be allocated to read-only memory.
2069 @end{Ramification}
2070 @begin{ImplNote}
2071 If the Storage_Size for an access type is specified,
2072 the storage pool should consist of a contiguous block of memory,
2073 possibly allocated on the stack.
2074 The pool should contain approximately this number of
2075 storage elements.
2076 These storage elements should be reserved at the place of the
2077 Storage_Size clause,
2078 so that @nt{allocator}s cannot raise Storage_Error due to running out
2079 of pool space until the appropriate number of storage elements has
2080 been used up.
2081 This approximate (possibly rounded-up) value should be used as a maximum;
2082 the implementation should not increase the size of the pool on the fly.
2083 If the Storage_Size for an access type is specified as zero,
2084 then the pool should not take up any storage space,
2085 and any @nt{allocator} for the type should raise Storage_Error.
2086 @end{ImplNote}
2087 @begin{Ramification}
2088 Note that most of this is approximate,
2089 and so cannot be (portably) tested.
2090 That's why we make it an Implementation Note.
2091 There is no particular number of allocations that is guaranteed to
2092 succeed, and there is no particular number of allocations that is
2093 guaranteed to fail.
2094 @end{Ramification}
2095
2096 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
2097 @ChgNote{Use ChgAdded to get conditional Leading}@ChgAdded{Version=[2],
2098 Type=[Leading],Text=[]}@Chg{Version=[2],New=[The],Old=[A]}
2099 storage pool @Chg{Version=[2],New=[used ],Old=[]}for
2100 @Chg{Version=[2],New=[an @nt{allocator} of ],Old=[]}an
2101 anonymous access type should be
2102 @Chg{Version=[2],New=[determined as follows:],Old=[created
2103 at the point of an allocator for the type, and be reclaimed when
2104 the designated object becomes inaccessible;]}
2105
2106 @begin{Itemize}
2107 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01],ARef=[AI95-00416-01]}
2108 @ChgAdded{Version=[2],Text=[If the @nt{allocator} is defining a
2109 coextension (see @RefSecNum{Operations of Access Types}) of an object
2110 being created by an outer @nt{allocator}, then
2111 the storage pool used for the outer @nt{allocator} should also be used for
2112 the coextension;]}
2113
2114 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
2115 @ChgAdded{Version=[2],Text=[For other access discriminants and access
2116 parameters, the storage pool should be created at the point of the
2117 @nt{allocator}, and be reclaimed when the allocated object becomes
2118 inaccessible;]}
2119
2120 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1]}
2121 @ChgAdded{Version=[3],Text=[If the @nt{allocator} defines the result of a
2122 function with an access result, the storage pool is determined as though the
2123 @nt{allocator} were in place of the call of the function. If the call is the
2124 operand of a type conversion, the storage pool is that of the target access type
2125 of the conversion. If the call is itself defining the result of a function with
2126 an access result, this rule is applied recursively;]}
2127
2128 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00230-01]}
2129 @ChgAdded{Version=[2],Text=[Otherwise, a default storage pool should be
2130 created at the point where the anonymous access type is elaborated; such
2131 a storage pool need not support deallocation of individual objects.]}
2132 @end{Itemize}
2133
2134 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2135 Text=[Usually, a storage pool for an access discriminant or access parameter
2136 should be created at the point of an @nt{allocator}, and be reclaimed when
2137 the designated object becomes inaccessible. For other anonymous access types,
2138 the pool should be created at the point where the type is elaborated and need
2139 not support deallocation of individual objects.]}]}
2140
2141 @begin{ImplNote}
2142 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
2143 @Chg{Version=[2],New=[For access parameters and access discriminants,],
2144 Old=[Normally]} the "storage pool" for an anonymous access type
2145 would not @Chg{Version=[2],New=[normally ],Old=[]}exist as a separate
2146 entity.
2147 Instead, the designated object of the allocator
2148 would be allocated, in the case of an access parameter,
2149 as a local aliased variable at the call site, and in the
2150 case of an access discriminant, contiguous with the object
2151 containing the discriminant.
2152 This is similar to the way storage for @nt{aggregate}s is typically
2153 managed.
2154
2155 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
2156 @ChgAdded{Version=[2],Text=[For other sorts of anonymous access types, this
2157 implementation is not possible in general, as the accessibility of the
2158 anonymous access type is that of its declaration, while the @nt{allocator}
2159 could be more nested. In this case, a "real" storage pool is required.
2160 Note, however, that this storage pool need not support (separate)
2161 deallocation, as it is not possible to instantiate Unchecked_Deallocation
2162 with an anonymous access type. (If deallocation is needed, the object should
2163 be allocated for a named access type and converted.) Thus, deallocation only
2164 need happen when the anonymous access type itself goes out of scope;
2165 this is similar to the case of an access-to-constant type.]}
2166 @end{ImplNote}
2167 @end{ImplAdvice}
2168
2169 @begin{Notes}
2170 A user-defined storage pool type can be obtained by extending the
2171 Root_Storage_Pool type,
2172 and overriding the primitive subprograms Allocate, Deallocate, and
2173 Storage_Size.
2174 A user-defined storage pool can then be obtained by declaring
2175 an object of the type extension.
2176 The user can override Initialize and Finalize if there is any need
2177 for nontrivial initialization and finalization for a user-defined
2178 pool type.
2179 For example, Finalize might reclaim blocks of storage that are allocated
2180 separately from the pool object itself.
2181
2182 @Leading@;The writer of the user-defined allocation and deallocation
2183 procedures, and users of @nt{allocator}s for the associated access
2184 type, are responsible for dealing with any interactions with
2185 tasking. In particular:
2186 @begin{itemize}
2187 If the @nt{allocator}s are used in different tasks, they require
2188 mutual exclusion.
2189
2190 If they are used inside protected objects, they cannot block.
2191
2192 If they are used by interrupt handlers
2193 (see @RefSec{Interrupt Support}),
2194 the mutual exclusion mechanism has to work properly in that context.
2195 @end{itemize}
2196
2197 The primitives Allocate, Deallocate, and Storage_Size are declared as
2198 abstract (see @RefSecNum{Abstract Types and Subprograms}),
2199 and therefore they have to be overridden when
2200 a new (nonabstract) storage pool type is declared.
2201 @begin{Ramification}
2202 Note that the Storage_Pool attribute denotes an object,
2203 rather than a value,
2204 which is somewhat unusual for attributes.
2205
2206 The calls to Allocate, Deallocate, and Storage_Size are dispatching
2207 calls @em this follows from the fact that the actual parameter for
2208 Pool is T'Storage_Pool, which is of type Root_Storage_Pool'Class. In
2209 many cases (including all cases in which Storage_Pool is not
2210 specified), the compiler can determine the tag statically.
2211 However, it is possible to construct cases where it cannot.
2212
2213 All access types in the same derivation class share the same pool,
2214 whether implementation defined or user defined.
2215 This is necessary because we allow type conversions among them
2216 (even if they are pool-specific),
2217 and we want pool-specific access values to always designate
2218 an element of the right pool.
2219 @end{Ramification}
2220 @begin{ImplNote}
2221 If an access type has a standard storage pool,
2222 then the implementation doesn't actually have to follow the pool
2223 interface described here,
2224 since this would be semantically invisible.
2225 For example, the allocator could conceivably be implemented with inline
2226 code.
2227 @end{ImplNote}
2228 @end{Notes}
2229
2230 @begin{Examples}
2231 @Leading@;To associate an access type with a storage pool object, the user
2232 first declares a pool object of some type derived from
2233 Root_Storage_Pool. Then, the user defines its Storage_Pool
2234 attribute, as follows:
2235
2236 @begin{Example}
2237 Pool_Object : Some_Storage_Pool_Type;
2238
2239 @key[type] T @key[is] @key[access] Designated;
2240 @key[for] T'Storage_Pool @key[use] Pool_Object;
2241 @end{Example}
2242
2243 @begin{WideAbove}
2244 @Leading@;Another access type may be added to an existing storage pool, via:
2245 @end{WideAbove}
2246 @begin{Example}
2247 @key[for] T2'Storage_Pool @key[use] T'Storage_Pool;
2248 @end{Example}
2249
2250 The semantics of this is implementation defined
2251 for a standard storage pool.
2252 @begin{Reason}
2253 For example, the implementation is allowed to choose a storage pool
2254 for T that takes advantage of the fact that T is of a certain size.
2255 If T2 is not of that size, then the above will probably not work.
2256 @end{Reason}
2257
2258 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
2259 As usual, a derivative of Root_Storage_Pool may define additional
2260 operations. For example, @Chg{Version=[3],New=[consider the],Old=[presuming that]}
2261 Mark_Release_Pool_Type @Chg{Version=[3],New=[defined in
2262 @RefSecNum{Storage Subpool Example}, that ],Old=[]}has
2263 two additional operations, Mark and Release,
2264 the following is a possible use:
2265 @begin{Example}
2266 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0041],ARef=[AI95-00066-01]}
2267 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
2268 @key[type] Mark_Release_Pool_Type
2269 (Pool_Size : Storage_Elements.Storage_Count@Chg{Version=[3],New=[],Old=[;
2270 Block_Size : Storage_Elements.Storage_Count]})
2271 @key[is] @key[new] @Chg{Version=[3],New=[Subpools.Root_Storage_Pool_With_Subpools],Old=[Root_Storage_Pool]} @key[with @Chg{New=[],Old=[limited ]}private];@Chg{Version=[3],New=[
2272 -- @Examcom{As defined in package MR_Pool, see @RefSecNum{Storage Subpool Example}}],Old=[]}
2273
2274 ...
2275
2276 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
2277 @Chg{Version=[3],New=[Our_Pool],Old=[MR_Pool]} : Mark_Release_Pool_Type (Pool_Size => 2000@Chg{Version=[3],New=[],Old=[,
2278 Block_Size => 100]});
2279 @Chg{Version=[3],New=[My_Mark : MR_Pool.Subpool_Handle; -- @Examcom{See @RefSecNum{Storage Subpool Example}}],Old=[]}
2280
2281 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
2282 @key[type] Acc @key[is] @key[access] ...;
2283 @key[for] Acc'Storage_Pool @key[use] @Chg{Version=[3],New=[Our_Pool],Old=[MR_Pool]};
2284 ...
2285
2286 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0111-3]}
2287 @Chg{Version=[3],New=[My_Mark := ],Old=[]}Mark(@Chg{Version=[3],New=[Our_Pool],Old=[MR_Pool]});
2288 ... --@RI{ Allocate objects using @lquotes@;@key[new] @Chg{Version=[3],New=[(My_Mark) ],Old=[]}Designated(...)@rquotes@;.}
2289 Release(@Chg{Version=[3],New=[My_Mark],Old=[MR_Pool]}); --@RI{ @Chg{Version=[3],New=[Finalize objects and reclaim],Old=[Reclaim the]} storage.}
2290 @end{Example}
2291 @end{Examples}
2292
2293 @begin{Extend83}
2294 @Defn{extensions to Ada 83}
2295 User-defined storage pools are new to Ada 95.
2296 @end{Extend83}
2297
2298 @begin{DiffWord83}
2299 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1],ARef=[AI05-0190-1]}
2300 Ada 83 @Chg{Version=[3],New=[originally introduced the],Old=[had a]}
2301 concept called a @lquotes@;collection,@rquotes@;
2302 which is similar to what we call a storage pool.
2303 All access types in the same derivation class
2304 @Chg{Version=[3],New=[share],Old=[shared]} the same collection.
2305 @Chg{Version=[3],New=[],Old=[In ]}Ada 95@Chg{Version=[3],New=[ introduces
2306 the storage pool, which is similar in that],Old=[,]} all access types in the
2307 same derivation class
2308 share the same storage pool,
2309 but other (unrelated) access types can also share the same storage pool,
2310 either by default, or as specified by the user.
2311 A collection @Chg{Version=[3],New=[is],Old=[was]} an amorphous
2312 @Chg{Version=[3],New=[grouping],Old=[collection]}
2313 of objects@Chg{Version=[3],New=[ (mainly used to describe finalization of
2314 access types)],Old=[]};
2315 a storage pool is a more concrete concept @em hence
2316 the different name.
2317
2318 RM83 states the erroneousness of reading or updating deallocated
2319 objects incorrectly by missing various cases.
2320 @end{DiffWord83}
2321
2322 @begin{Incompatible95}
2323 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00435-01]}
2324 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
2325 @b<Amendment Correction:> Storage pools (and Storage_Size)
2326 are not defined for access-to-subprogram types. The original Ada 95 wording
2327 defined the attributes, but said nothing about their values.
2328 If a program uses attributes Storage_Pool or Storage_Size on an
2329 access-to-subprogram type, it will need to be corrected for Ada 2005.
2330 That's a good thing, as such a use is a bug @em the concepts
2331 never were defined for such types.]}
2332 @end{Incompatible95}
2333
2334 @begin{Extend95}
2335 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
2336 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2337 @b[Amendment Correction:] Added @nt{pragma} Preelaborable_Initialization to
2338 type Root_Storage_Pool, so that extensions of it can be used to declare
2339 default-initialized objects in preelaborated units.]}
2340 @end{Extend95}
2341
2342
2343 @begin{DiffWord95}
2344 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
2345 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that
2346 these are representation attributes.]}
2347
2348 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00416-01]}
2349 @ChgAdded{Version=[2],Text=[Added wording to clarify that an @nt{allocator}
2350 for a coextension nested inside an outer @nt{allocator} shares
2351 the pool with the outer @nt{allocator}.]}
2352 @end{DiffWord95}
2353
2354 @begin{DiffWord2005}
2355 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1]}
2356 @ChgAdded{Version=[3],Text=[@b<Correction:> Added the missing definition
2357 of the storage pool of an @nt{allocator} for an anonymous access result type.]}
2358
2359 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0107-1]}
2360 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified when an implementation
2361 is allowed to call Allocate and Deallocate, and the requirements on such
2362 calls.]}
2363
2364 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
2365 @ChgAdded{Version=[3],Text=[Added wording to support subpools and refer to
2366 the subpool example, see @RefSecNum{Storage Subpools}.]}
2367
2368 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0116-1]}
2369 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to specify that the
2370 alignment for an @nt{allocator} with a class-wide designated type comes from
2371 the specific type that is allocated.]}
2372
2373 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0193-1]}
2374 @ChgAdded{Version=[3],Text=[Added wording to allow larger
2375 alignments for calls to Allocate made by @nt{allocator}s,
2376 up to Max_Alignment_For_Allocation. This eases implementation in some cases.]}
2377 @end{DiffWord2005}
2378
2379 @begin{DiffWord2012}
2380 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0043-1]}
2381 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Tightened up the description of
2382 the implementation-defined pool used when Storage_Size is specified. This
2383 is not intended to change any implementation.]}
2384 @end{DiffWord2012}
2385
2386
2387 @LabeledRevisedSubClause{Version=[3],New=[Storage Allocation Attributes],
2388 Old=[The Max_Size_In_Storage_Elements Attribute]}
2389
2390 @begin{Intro}
2391 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0193-1]}
2392 @redundant[The Max_Size_In_Storage_Elements @Chg{Version=[3],New=[and
2393 Max_Alignment_For_Allocation attributes may be],Old=[attribute is]}
2394 useful in writing user-defined pool types.]
2395 @end{Intro}
2396
2397 @begin{StaticSem}
2398 @Leading@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0193-1]}
2399 For @PrefixType{every subtype S},
2400 the following @Chg{Version=[3],New=[attributes are],Old=[attribute is]} defined:
2401 @begin{Description}
2402 @ChgAttribute{Version=[3],Kind=[Revised],ChginAnnex=[T],
2403 Leading=<F>, Prefix=<S>, AttrName=<Max_Size_In_Storage_Elements>,
2404 ARef=[AI95-00256-01],ARef=[AI95-00416-01],ARef=[AI05-0193-1],
2405 InitialVersion=[0], Text=<Denotes the maximum value for
2406 Size_In_Storage_Elements
2407 that @Chg{Version=[2],New=[could],Old=[will]} be requested @Chg{Version=[2],
2408 New=[by the implementation ],Old=[]}via Allocate for an access type whose
2409 designated subtype is S.@Chg{Version=[2],New=[@Chg{Version=[3],New=[],Old=[ For a type with access
2410 discriminants, if the implementation allocates space for a coextension
2411 in the same pool as that of the object having the access discriminant,
2412 then this accounts for any calls on Allocate that could be performed to
2413 provide space for such coextensions.]}],Old=[]}
2414 The value of this attribute is of type @i{universal_integer}.>}
2415 @begin{Ramification}
2416 If S is an unconstrained array subtype,
2417 or an unconstrained subtype with discriminants,
2418 S'Max_Size_In_Storage_Elements might be very large.
2419 @end{Ramification}
2420
2421 @ChgAttribute{Version=[3], Kind=[AddedNormal], ChginAnnex=[T], Leading=[F],
2422 Prefix=<S>, AttrName=<Max_Alignment_For_Allocation>, ARef=[AI05-0193-1],
2423 InitialVersion=[3], Text=<@Chg{Version=[3],New=[Denotes the maximum value for
2424 Alignment that could be requested by the implementation via Allocate for
2425 an access type whose designated subtype is S. The value of this attribute
2426 is of type @i{universal_integer}.],Old=[]}>}
2427 @EndPrefixType{}
2428 @end{Description}
2429 @end{StaticSem}
2430
2431 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0193-1]}
2432 @ChgAdded{Version=[3],Text=[For a type with access discriminants, if the
2433 implementation allocates space for a coextension in the same pool as that of the
2434 object having the access discriminant, then these attributes account for any
2435 calls on Allocate that could be performed to provide space for such
2436 coextensions.]}
2437 @begin{Reason}
2438 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0193-1]}
2439 @ChgAdded{Version=[3],Text=[The values of these attributes should reflect only
2440 the calls that might be made to the pool specified for an access type with
2441 designated type S. Thus, if the coextensions would normally be
2442 allocated from a different pool than the one used for the main object (that is,
2443 the @ImplAdviceName of @RefSecNum{Storage Management} for determining the pool
2444 of an anonymous access discriminant is not followed), then these attributes
2445 should not reflect any calls on Allocate used to allocate the coextensions.]}
2446 @end{Reason}
2447 @begin{Ramification}
2448 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0193-1]}
2449 @ChgAdded{Version=[3],Text=[Coextensions of coextensions of this type (and so on)
2450 are included in the values of these attributes if they are allocated from the
2451 same pool.]}
2452 @end{Ramification}
2453
2454 @begin{DiffWord95}
2455 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00256-01]}
2456 @ChgAdded{Version=[2],Text=[Corrected the wording so that a
2457 fortune-telling compiler that can see the future execution of the
2458 program is not required.]}
2459 @end{DiffWord95}
2460
2461 @begin{Extend2005}
2462 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0193-1]}
2463 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}The
2464 Max_Alignment_For_Allocation attribute is new.]}
2465 @end{Extend2005}
2466
2467
2468
2469 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
2470 @LabeledSubClause{Unchecked Storage Deallocation}
2471
2472 @begin{Intro}
2473 @redundant[@Defn{unchecked storage deallocation}
2474 @Defn2{Term=[storage deallocation], Sec=(unchecked)}
2475 @Defn{deallocation of storage}
2476 @Defn{reclamation of storage}
2477 @Defn{freeing storage}
2478 Unchecked storage deallocation of an object designated by a value of an
2479 access type is achieved by a call to an instance of
2480 the generic procedure Unchecked_Deallocation.]
2481 @end{Intro}
2482
2483 @begin{StaticSem}
2484 @leading@keepnext@;The following language-defined generic library procedure exists:
2485 @begin{Example}
2486 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2487 @key[generic]
2488 @key[type] Object(<>) @key[is] @key[limited] @key[private];
2489 @key[type] Name @key[is] @key[access] Object;
2490 @SubChildUnit{Parent=[Ada],Child=[Unchecked_Deallocation]}@key[procedure] Ada.Unchecked_Deallocation(X : @key[in] @key[out] Name)@Chg{Version=[3],New=[
2491 @key(with) Convention => Intrinsic;],Old=[;
2492 @key[pragma] Convention(Intrinsic, Ada.Unchecked_Deallocation);]}
2493 @key[pragma] Preelaborate(Ada.Unchecked_Deallocation);
2494 @end{Example}
2495 @begin{Reason}
2496 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2497 The @Chg{Version=[3],New=[aspect],Old=[@nt{pragma}]} Convention implies that
2498 the attribute Access is not allowed
2499 for instances of Unchecked_Deallocation.
2500 @end{Reason}
2501 @end{StaticSem}
2502
2503 @begin{Legality}
2504 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0157-1]}
2505 @ChgAdded{Version=[3],Text=[A call on an instance of Unchecked_Deallocation is
2506 illegal if the actual access type of the instance is a type for which the
2507 Storage_Size has been specified by a static expression with value zero or is
2508 defined by the language to be zero.
2509 @PDefn{generic contract issue}In addition to the places where
2510 @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
2511 this rule applies also in the private part of an instance of a generic unit.]}
2512
2513 @begin{Discussion}
2514 @ChgRef{Version=[3],Kind=[AddedNormal]}
2515 @ChgAdded{Version=[3],Text=[This rule is the same as the rule for
2516 @nt{allocator}s. We could have left the last sentence out, as a call to
2517 Unchecked_Deallocation cannot occur in a specification as it is a procedure
2518 call, but we left it for consistency and to avoid future maintenance hazards.]}
2519 @end{Discussion}
2520
2521 @end{Legality}
2522
2523 @begin{RunTime}
2524 @Leading@;Given an instance of Unchecked_Deallocation
2525 declared as follows:
2526 @begin{Example}
2527 @key[procedure] Free @key[is]
2528 @key[new] Ada.Unchecked_Deallocation(
2529 @RI[object_subtype_name], @RI[access_to_variable_subtype_name]);
2530 @end{Example}
2531
2532 @begin{WideAbove}
2533 @Leading@Keepnext@;Procedure Free has the following effect:
2534 @end{WideAbove}
2535 @begin{Enumerate}
2536 After executing Free(X), the value of X is @key{null}.
2537
2538 Free(X), when X is already equal to @key{null}, has no effect.
2539
2540 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
2541 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0107-1]}
2542 Free(X), when X is not equal to @key{null} first
2543 performs finalization@Chg{Version=[2],New=[ of the object designated by X (and
2544 any coextensions of the object @em see @RefSecNum{Operations of Access Types})],
2545 Old=[]}, as described in
2546 @Chg{Version=[2],New=[@RefSecNum{Completion and Finalization}],
2547 Old=[@RefSecNum{Assignment and Finalization}]}.
2548 It then deallocates the storage occupied by the object designated by
2549 X@Chg{Version=[2],New=[ (and any coextensions)],Old=[]}.
2550 If the storage pool is a user-defined object, then
2551 the storage is deallocated by calling Deallocate@Chg{Version=[3],New=[ as described
2552 in @RefSecNum{Storage Management}],Old=[,
2553 passing @i[access_to_@!variable_@!subtype_name]'Storage_Pool as the Pool parameter.
2554 Storage_Address is the value returned in the Storage_Address parameter of the
2555 corresponding Allocate call.
2556 Size_In_@!Storage_@!Elements and Alignment are the same values passed to the
2557 corresponding Allocate call]}.
2558 There is one exception: if the object being freed contains tasks,
2559 the object might not be deallocated.
2560 @begin{Ramification}
2561 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0107-1]}
2562 Free calls only the specified Deallocate procedure
2563 to do deallocation.@Chg{Version=[3],New=[],Old=[ For any given
2564 object deallocation, the number of calls to Free (usually one)
2565 will be equal to the number of Allocate calls it took
2566 to allocate the object.
2567 We do not define the relative order of multiple calls used to deallocate
2568 the same object @em that is, if the @nt{allocator} allocated two pieces @i{x}
2569 and @i{y}, then Free might deallocate @i{x} and then @i{y},
2570 or it might deallocate @i{y} and then @i{x}.]}
2571 @end{Ramification}
2572 @end{Enumerate}
2573
2574 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
2575 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0148-1]}
2576 @IndexSee{Term=[freed],See=(nonexistent)}
2577 @Defn{nonexistent}
2578 @PDefn2{Term=[exist],Sec=[cease to]}
2579 @PDefn2{Term=[cease to exist],Sec=[object]}
2580 After @Chg{Version=[4],New=[the finalization step of ],Old=[]}Free(X), the
2581 object designated by X, and any subcomponents
2582 @Chg{Version=[2],New=[(and coextensions) ],Old=[]}thereof, no
2583 longer exist; their storage can be reused for other purposes.
2584 @end{RunTime}
2585
2586 @begin{Bounded}
2587 @Leading@PDefn2{Term=(bounded error),Sec=(cause)}
2588 It is a bounded error to free a discriminated, unterminated
2589 task object. The possible consequences are:
2590 @begin{Reason}
2591 This is an error because the task might refer to its discriminants,
2592 and the discriminants might be deallocated by freeing the task object.
2593 @end{Reason}
2594 @begin{Itemize}
2595 No exception is raised.
2596
2597 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2598 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)}
2599 Program_Error or Tasking_Error is raised at the point of the
2600 deallocation.
2601
2602 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2603 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)}
2604 Program_Error or Tasking_Error is raised in the task the next time it
2605 references any of the discriminants.
2606 @begin{ImplNote}
2607 This last case presumes an implementation where the task references
2608 its discriminants indirectly,
2609 and the pointer is nulled out when the task object is deallocated.
2610 @end{ImplNote}
2611 @end{Itemize}
2612
2613 In the first two cases,
2614 the storage for the discriminants
2615 (and for any enclosing object if it is designated by an access
2616 discriminant of the task)
2617 is not reclaimed prior to task termination.
2618 @begin{Ramification}
2619 The storage might never be reclaimed.
2620 @end{Ramification}
2621
2622 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0148-1]}
2623 @ChgAdded{Version=[4],Text=[An access value that designates a nonexistent object is called a
2624 @i<dangling reference>.@Defn{dangling reference}@Defn2{Term=[reference],Sec=[dangling]}]}
2625
2626 @begin{Discussion}
2627 @ChgRef{Version=[4],Kind=[AddedNormal]}
2628 @ChgAdded{Version=[4],Text=[These can result from use of
2629 Unchecked_Deallocation, Unchecked_Deallocate_Subpool, and attribute
2630 Unchecked_Access. Bad results from Unchecked_Conversion and from
2631 stream-oriented attributes are abnormal by @RefSecNum{Data Validity},
2632 which is stronger and thus takes precedence.]}
2633 @end{Discussion}
2634
2635 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0148-1]}
2636 @ChgAdded{Version=[4],Text=[@Redundant[If a dangling reference is dereferenced
2637 (implicitly or explicitly), execution is erroneous (see below).] If there is
2638 no explicit or implicit dereference, then it is a bounded error
2639 @Leading@PDefn2{Term=(bounded error),Sec=(cause)}to evaluate an
2640 expression whose result is a dangling reference. If the error is detected,
2641 either Constraint_Error or Program_Error is raised.
2642 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2643 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
2644 Otherwise, execution
2645 proceeds normally, but with the possibility that the access value designates
2646 some other existing object.]}
2647
2648 @begin{Reason}
2649 @ChgRef{Version=[4],Kind=[AddedNormal]}
2650 @ChgAdded{Version=[4],Text=[If a dangling reference is compared with another
2651 access value, a result of either True or False is allowed. We need to allow
2652 this so that simple implementations of access values (for instance, as a
2653 bare address) can work if the memory in question is reused. (The formal
2654 definition of access equality is that it returns True if both access values
2655 designate the same object; that can never be True if one of the values is a
2656 dangling reference, and the other is not, but both values could refer to the
2657 same memory.) Membership tests that do not involve an implicit dereference
2658 generally do not depend on the access value at all.]}
2659
2660 @ChgRef{Version=[4],Kind=[AddedNormal]}
2661 @ChgAdded{Version=[4],Text=[We allow Constraint_Error to be raised here so
2662 that dangling reference and null pointer checks can be combined into a
2663 single check. If different exceptions are required, then the checks have to
2664 be made separately - but there's little semantic difference (neither
2665 designate a usable object).]}
2666 @end{Reason}
2667
2668 @begin{Ramification}
2669 @ChgRef{Version=[4],Kind=[AddedNormal]}
2670 @ChgAdded{Version=[4],Text=[If a dangling reference is assigned into an
2671 object, including being passed to a formal parameter, that object also
2672 contains a dangling reference afterwards.]}
2673 @end{Ramification}
2674
2675 @begin{Discussion}
2676 @ChgRef{Version=[4],Kind=[AddedNormal]}
2677 @ChgAdded{Version=[4],Text=[For equality and membership operations on
2678 composite types, this applies to any parts that are access types, as these
2679 operations are created based on the operations of the components (which
2680 triggers the bounded error). For other operations on composite types, the
2681 bounded error is not triggered. For instance, an assignment of a composite
2682 object with a subcomponent that is a dangling reference has to work
2683 normally; no exception can be raised, but the target object will have a
2684 subcomponent that is a dangling references, and a (direct) use of that
2685 subcomponent is again a bounded error. This is similar to the way that
2686 assignments of invalid subcomponents are handled (see
2687 @RefSecNum{Data Validity}).]}
2688 @end{Discussion}
2689 @end{Bounded}
2690
2691 @begin{Erron}
2692 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0033-1],ARef=[AI05-0262-1]}
2693 @Defn{nonexistent}@PDefn2{Term=(erroneous execution),Sec=(cause)}
2694 Evaluating a name that denotes a nonexistent object@Chg{Version=[3],
2695 New=[, or a protected subprogram or subprogram renaming whose
2696 associated object (if any) is nonexistent, ],Old=[]}is erroneous.
2697 The execution of a call to an instance of Unchecked_Deallocation is
2698 erroneous if the object was created other than by an @nt<allocator> for
2699 an access type whose pool is Name'Storage_Pool.
2700
2701 @begin{Reason}
2702 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1],ARef=[AI05-0262-1]}
2703 @ChgAdded{Version=[3],Text=[The part about a protected subprogram is intended
2704 to cover the case of an access-to-protected-subprogram where the associated
2705 object has been deallocated. The part about a subprogram renaming is intended
2706 to cover the case of a renaming of a prefixed view where the prefix object has
2707 been deallocated, or the case of a renaming of an entry or protected
2708 subprogram where the associated task or protected object has been
2709 deallocated.]}
2710 @end{Reason}
2711 @begin{Ramification}
2712 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0157-1]}
2713 @ChgAdded{Version=[3],Text=[This text does not cover the case of
2714 a name that contains a null access value, as @key[null] does not
2715 denote an object (rather than denoting a nonexistent object).]}
2716 @end{Ramification}
2717
2718 @end{Erron}
2719
2720 @begin{ImplAdvice}
2721 For a standard storage pool,
2722 Free should actually reclaim the storage.
2723 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
2724 Text=[For a standard storage pool, an instance of Unchecked_Deallocation
2725 should actually reclaim the storage.]}]}
2726 @begin{Ramification}
2727 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
2728 This is not a testable property,
2729 since we do not @Chg{Version=[2],New=[know ],Old=[]}how much storage is used
2730 by a given pool element, nor whether fragmentation can occur.
2731 @end{Ramification}
2732
2733 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0157-1]}
2734 @ChgAdded{Version=[3],Text=[A call on an instance of Unchecked_Deallocation with
2735 a nonnull access value should raise Program_Error if the actual access type of
2736 the instance is a type for which the Storage_Size has been specified to be zero
2737 or is defined by the language to be zero.]}
2738 @ChgImplAdvice{Version=[3],Kind=[Added],Text=[@ChgAdded{Version=[3],
2739 Text=[A call on an instance of Unchecked_Deallocation with
2740 a nonnull access value should raise Program_Error if the actual access type of
2741 the instance is a type for which the Storage_Size has been specified to be zero
2742 or is defined by the language to be zero.]}]}
2743 @begin{Discussion}
2744 @ChgAdded{Version=[3],Text=[If the call is not illegal (as in a generic body), we
2745 recommend that it raise Program_Error. Since the execution of this call is
2746 erroneous (any allocator from the pool will have raised Storage_Error, so
2747 the nonnull access value must have been allocated from a different pool or
2748 be a stack-allocated object), we can't require any behavior @em anything at
2749 all would be a legitimate implementation.]}
2750 @end{Discussion}
2751 @end{ImplAdvice}
2752
2753 @begin{Notes}
2754 The rules here that refer to Free apply to any instance
2755 of Unchecked_Deallocation.
2756
2757 Unchecked_Deallocation cannot be instantiated for an
2758 access-to-constant type.
2759 This is implied by the rules of @RefSecNum{Formal Access Types}.
2760 @end{Notes}
2761
2762 @begin{DiffWord95}
2763 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
2764 @ChgAdded{Version=[2],Text=[The rules for coextensions are clarified
2765 (mainly by adding that term). In theory, this reflects no change from
2766 Ada 95 (coextensions existed in Ada 95, they just didn't have a name).]}
2767 @end{DiffWord95}
2768
2769 @begin{DiffWord2005}
2770 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1]}
2771 @ChgAdded{Version=[3],Text=[@b<Correction:> Added a rule that using
2772 an access-to-protected-subprogram is erroneous if the associated
2773 object no longer exists. It is hard to imagine an alternative meaning here,
2774 and this has no effect on correct programs.]}
2775
2776 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0107-1]}
2777 @ChgAdded{Version=[3],Text=[@b<Correction:> Moved the requirements
2778 on an implementation-generated call to Deallocate to
2779 @RefSecNum{Storage Management}, in order to put all of the rules
2780 associated with implementation-generated calls to Allocate and Deallocate
2781 together.]}
2782
2783 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0157-1]}
2784 @ChgAdded{Version=[3],Text=[@b<Correction:> Added wording so that calling
2785 an instance of Unchecked_Deallocation is treated similarly to @nt{allocator}s
2786 for access types where @nt{allocator}s would be banned.]}
2787 @end{DiffWord2005}
2788
2789 @begin{Inconsistent2012}
2790 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0148-1]}
2791 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}
2792 @b<Corrigendum:> Defined a "dangling reference", and specified that
2793 a dangling reference might designate some other existing object.
2794 This allows simple implementations of access values and reuse of
2795 object memory after deallocation. In prior versions of Ada, "=" between
2796 a dangling reference and an access to an existing object has to return
2797 False, even if the existing object and the object designated by the
2798 dangling reference are
2799 allocated in the same memory. A program that depended upon that could break
2800 with this revised rule. However, as a practical matter, almost all Ada
2801 implementations use simple implementations of access types that do not meet
2802 that requirement. So such a program would not work (consistently) on
2803 most Ada implementations; thus the change shouldn't break any existing
2804 programs - it just aligns the Standard with actual practice.]}
2805
2806 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0148-1]}
2807 @ChgAdded{Version=[4],Text=[A side effect of this change is to allow an
2808 Ada implementation to detect dangling references in more places. This
2809 does not require any Ada implementation to change, and if the implementation
2810 does change, it just means that errors will be detected earlier.]}
2811 @end{Inconsistent2012}
2812
2813 @begin{DiffWord2012}
2814 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0148-1]}
2815 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that deallocated
2816 objects cease to exist after finalization but before Deallocate is called.
2817 This is necessary to prevent erroneous execution from being triggered by
2818 the rules in @RefSecNum{Storage Management} in the time between the end
2819 of finalization and the end of the call to the instance of
2820 Unchecked_Deallocation.]}
2821 @end{DiffWord2012}
2822
2823
2824
2825
2826 @LabeledRevisedSubClause{Version=[3],New=[Default Storage Pools],
2827 Old=[Pragma Controlled]}
2828
2829 @begin{Intro}
2830 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2831 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0003-1]}
2832 @Chg{Version=[3],New=[@Chg{Version=[4],New=[@Redundant[Pragma and aspect
2833 Default_Storage_Pool specify the storage pool that
2834 will be used in the absence of an explicit specification of a storage pool or
2835 storage size for an access type.]],Old=[]}],Old=[@Redundant[Pragma Controlled
2836 is used to prevent
2837 any automatic reclamation of storage (garbage collection) for the objects
2838 created by @nt<allocator>s of a given access type.]]}
2839 @end{Intro}
2840
2841 @begin{Syntax}
2842 @begin{SyntaxText}
2843 @Leading@Keepnext@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
2844 The form of a @nt{pragma} @Chg{Version=[3],New=[Default_Storage_Pool],Old=[Controlled]}
2845 is as follows:
2846 @end{SyntaxText}
2847
2848 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
2849 @AddedPragmaSyn<Version=[3],@Chg{Version=[3],
2850 New=[@key{pragma} @prag<Default_Storage_Pool> (@Syn2{storage_pool_indicator});],Old=[]}>
2851 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@Chg{Version=[3],New=[],
2852 Old=[@key{pragma} @prag(Controlled)(@SynI{first_subtype_}@Syn2{local_name});]}>
2853
2854 @begin{Discussion}
2855 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
2856 @ChgDeleted{Version=[3],Text=[Not to be confused with type
2857 Finalization.Controlled.]}
2858 @end{Discussion}
2859
2860 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
2861 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0003-1]}
2862 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<storage_pool_indicator>,Old=<>}>,
2863 rhs="@Chg{Version=[3],New=<@SynI{storage_pool_}@Syn2{name} | @key[null]@Chg{Version=[4],New=< | Standard>,Old=<>}>,Old=<>}"}
2864
2865 @begin{SyntaxText}
2866 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
2867 @ChgAdded{Version=[3],Text=[A @nt{pragma} Default_Storage_Pool is allowed
2868 immediately within the visible part of a @nt{package_specification}, immediately
2869 within a @nt{declarative_part}, or as a configuration pragma.]}
2870 @end{SyntaxText}
2871 @end{Syntax}
2872
2873 @begin{Resolution}
2874 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
2875 @ChgAdded{Version=[3],Text=[The @SynI{storage_pool_}@nt{name} is expected to be
2876 of type Root_Storage_Pool'Class.]}
2877 @end{Resolution}
2878
2879 @begin{Legality}
2880 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
2881 @Chg{Version=[3],New=[The @SynI{storage_pool_}@nt{name} shall denote a variable.],
2882 Old=[The @SynI{first_subtype_}@nt<local_name> of a @nt{pragma} Controlled
2883 shall denote a nonderived access subtype.]}
2884
2885 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0003-1]}
2886 @ChgAdded{Version=[4],Text=[The Standard @nt{storage_pool_indicator} is an
2887 identifier specific to a pragma (see @RefSecNum{Pragmas}) and does not denote
2888 any declaration. If the @nt{storage_pool_indicator} is Standard, then there
2889 shall not be a declaration with @nt{defining_identifier} Standard that is
2890 immediately visible at the point of the pragma, other than package Standard
2891 itself.]}
2892
2893 @begin{Reason}
2894 @ChgRef{Version=[4],Kind=[Added]}
2895 @ChgAdded{Version=[4],Text=[We considered having the Standard
2896 @nt{storage_pool_indicator} resolve to package Standard rather than
2897 being an identifier specific to a pragma. That would eliminate the need for a
2898 special check. But it would be bizarre to have something that could resolve to
2899 either an object or a (single) package, and resolving to package Standard
2900 would imply that the standard pool is an object declared in that package. A
2901 storage pool object must be a variable (see @RefSecNum{Storage Management}),
2902 yet preelaborable packages depend on package Standard, which would require
2903 implementers to implement the standard storage pool with
2904 Preelaborable_Initialization, which is an unnecessary restriction.]}
2905
2906 @ChgRef{Version=[4],Kind=[Added]}
2907 @ChgAdded{Version=[4],Text=[No declaration of Standard can ever be
2908 use-visible, as the language-defined nonoverloadable definition of
2909 Standard will hide any use-visible declarations. Thus we need only concern
2910 ourselves with eliminating any possible confusion with regard to
2911 immediately visible declarations with the @nt{defining_identifier} Standard.]}
2912 @end{Reason}
2913
2914 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
2915 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0003-1]}
2916 @ChgAdded{Version=[3],Text=[If the @nt{pragma} is used as a configuration pragma,
2917 the @nt{storage_pool_indicator} shall be@Chg{Version=[4],New=[ either],Old=[]}
2918 @key[null]@Chg{Version=[4],New=[ or Standard],Old=[]}, and it defines the
2919 @i<default pool>@Defn{default pool}@Defn2{Term=[storage pool],Sec=[default]}@Defn2{Term=[pool],Sec=[default]} to
2920 be @Chg{Version=[4],New=[the given @nt{storage_pool_indicator}],Old=[@b<null>]}
2921 within all
2922 applicable compilation units (see @RefSecNum{Pragmas and Program Units}),
2923 except within the immediate scope of
2924 another @nt{pragma} Default_Storage_Pool. Otherwise, @Redundant[the pragma
2925 occurs immediately within a sequence of declarations, and] it defines the
2926 default pool within the immediate scope of the pragma to be
2927 @Chg{Version=[4],New=[the given @nt{storage_pool_indicator}],Old=[either
2928 @key[null] or the pool denoted by the @SynI{storage_pool_}@nt{name}]}, except
2929 within the immediate scope of a later pragma Default_Storage_Pool.
2930 @Redundant[Thus, an inner pragma overrides an outer one.]]}
2931
2932 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1],ARef=[AI05-0262-1]}
2933 @ChgRef{Version=[4],Kind=[RevisedAdded]}@Comment{Just to mark the fact that the paragraph number changed}
2934 @ChgAdded{Version=[3],Text=[A @nt{pragma} Default_Storage_Pool shall not be used
2935 as a configuration pragma that applies to a compilation unit that is within the
2936 immediate scope of another @nt{pragma} Default_Storage_Pool.]}
2937
2938 @begin{Reason}
2939 @ChgRef{Version=[3],Kind=[AddedNormal]}
2940 @ChgAdded{Version=[3],Type=[Leading],Text=[This is to prevent confusion in cases like this:]}
2941 @begin{Example}
2942
2943 @ChgRef{Version=[3],Kind=[AddedNormal]}
2944 @ChgAdded{Version=[3],Text=[@key[package] Parent @key[is]
2945 pragma Default_Storage_Pool(...);
2946 ...
2947 @key[end] Parent;]}
2948
2949 @ChgRef{Version=[3],Kind=[AddedNormal]}
2950 @ChgAdded{Version=[3],Text=[@key[pragma] Default_Storage_Pool(...); --@examcom{ Illegal!}
2951 @key[package] Parent.Child @key[is]
2952 ...
2953 @key[end] Parent.Child;]}
2954 @end{Example}
2955
2956 @ChgRef{Version=[3],Kind=[AddedNormal]}
2957 @ChgAdded{Version=[3],Type=[Trailing],Text=[where the Default_Storage_Pool
2958 on Parent.Child would not (if it were legal) override the one in Parent.]}
2959 @end{Reason}
2960 @end{Legality}
2961
2962 @begin{StaticSem}
2963 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
2964 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0003-1]}
2965 @Chg{Version=[3],New=[The language-defined aspect Default_Storage_Pool may be
2966 specified for a generic instance; it defines the default pool for
2967 access types within an instance.@AspectDefn{Default_Storage_Pool}
2968 @Chg{Version=[4],New=[],Old=[The expected type for the
2969 Default_Storage_Pool aspect is Root_Storage_Pool'Class. The @nt{aspect_definition}
2970 must be a @nt{name} that denotes a variable. This aspect overrides any
2971 Default_Storage_Pool pragma that might apply to the generic unit; if the aspect
2972 is not specified, the default pool of the instance is that defined for the
2973 generic unit]}],
2974 Old=[@PDefn2{Term=[representation pragma], Sec=(Controlled)}
2975 @PDefn2{Term=[pragma, representation], Sec=(Controlled)}
2976 A @nt{pragma} Controlled is a representation pragma
2977 @PDefn2{Term=[aspect of representation], Sec=(controlled)}
2978 @Defn2{Term=[controlled], Sec=(aspect of representation)}
2979 that specifies the @i{controlled} aspect of representation]}.
2980
2981 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0003-1]}
2982 @ChgAdded{Version=[4],Text=[The Default_Storage_Pool aspect may be specified as
2983 Standard, which is an identifier specific to an aspect (see
2984 @RefSecNum{Aspect Specifications}) and defines the default pool to be
2985 Standard. In this case, there shall not be a declaration with
2986 @nt{defining_identifier} Standard that is immediately visible at the point
2987 of the aspect specification, other than package Standard itself.]}
2988
2989 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0003-1]}
2990 @ChgAdded{Version=[4],Text=[Otherwise, the expected type for the
2991 Default_Storage_Pool aspect is Root_Storage_Pool'Class and the @nt{aspect_definition}
2992 shall be a @nt{name} that denotes a variable. This aspect overrides any
2993 Default_Storage_Pool pragma that might apply to the generic unit; if the aspect
2994 is not specified, the default pool of the instance is that defined for the
2995 generic unit.]}
2996
2997 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Default_Storage_Pool],
2998 Text=[@ChgAdded{Version=[3],Text=[Default storage pool for a generic instance.]}]}
2999
3000 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0136-1]}
3001 @ChgAdded{Version=[4],Text=[The effect of specifying the aspect
3002 Default_Storage_Pool on an instance of a language-defined generic unit is
3003 implementation-defined.]}
3004
3005 @ChgImplDef{Version=[4],Kind=[Added],
3006 Text=[@ChgAdded{Version=[4],Text=[The effect of specifying aspect
3007 Default_Storage_Pool on an instance of a language-defined generic unit.]}]}
3008
3009 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
3010 @ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Conditional leading}
3011 @Chg{Version=[3],New=[For nonderived access types declared in places where the
3012 default pool is defined by the pragma or aspect, their Storage_Pool or
3013 Storage_Size attribute is determined as follows, unless Storage_Pool or
3014 Storage_Size is specified for the type:],
3015 Old=[@Defn{garbage collection}
3016 @i{Garbage collection} is a process that automatically reclaims storage,
3017 or moves objects to a different address,
3018 while the objects still exist.]}
3019
3020 @begin{Itemize}
3021 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3022 @ChgAdded{Version=[3],Text=[If the default pool is @key[null], the
3023 Storage_Size attribute is defined by the language to be zero.
3024 @Redundant[Therefore, an @nt{allocator} for such a type is illegal.]]}
3025
3026 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3027 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0003-1]}
3028 @ChgAdded{Version=[3],Text=[If the default pool is @Chg{Version=[4],New=[neither
3029 @key[null] nor Standard],Old=[nonnull]}, the Storage_Pool
3030 attribute is that pool.]}
3031
3032 @end{Itemize}
3033
3034 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3035 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0003-1]}
3036 @ChgAdded{Version=[3],Text=[Otherwise@Chg{Version=[4],New=[ (including when
3037 the default pool is specified as Standard),],Old=[, there is no
3038 default pool;]} the standard storage
3039 pool is used for the type as described in @RefSecNum{Storage Management}.]}
3040
3041 @begin{Ramification}
3042 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
3043 @Chg{Version=[3],New=[Default_Storage_Pool is the only way to specify the
3044 storage pool for an anonymous access type],
3045 Old=[Storage reclamation upon leaving a master is not considered garbage
3046 collection]}.
3047
3048 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
3049 Note that @Chg{Version=[3],New=[coextensions should be allocated in the same
3050 pool (or on the stack) as the outer object (see @RefSecNum{Storage Management});
3051 the Storage_Pool of the access discriminant
3052 (and hence the Default_Storage_Pool) is supposed to be ignored for
3053 coextensions. This matches the required finalization point for coextensions],
3054 Old=[garbage collection includes compaction of a pool (@lquotes@;moved to
3055 a different Address@rquotes@;), even if storage reclamation is not done]}.
3056
3057 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3058 @ChgAdded{Version=[3],Text=[The default storage pool for an allocator that
3059 occurs within an instance of a generic is defined by the Default_Storage_Pool
3060 aspect of the instantiation (if specified), or by the Default_Storage_Pool
3061 pragma that applied to the generic; the Default_Storage_Pool pragma that applies
3062 to the instantiation is irrelevant.]}
3063
3064 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3065 @ChgAdded{Version=[3],Text=[It is possible to specify the Default_Storage_Pool
3066 aspect for an instantiation such that allocations will fail. For example, the
3067 generic unit might be expecting a pool that supports certain sizes and
3068 alignments, and the one on the instance might be more restrictive. It is the
3069 programmer's responsibility to get this right.]}
3070
3071 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0190-1]}
3072 @ChgAdded{Version=[3],Text=[The semantics of the Default_Storage_Pool aspect are
3073 similar to passing a pool object as a generic formal, and putting pragma
3074 Default_Storage_Pool at the top of the generic's visible part, specifying that
3075 formal.]}
3076 @end{Ramification}
3077 @begin{Reason}
3078 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3079 @ChgDeleted{Version=[3],Text=[Programs that will be damaged by automatic storage
3080 reclamation are just as likely to be damaged by having objects moved to
3081 different locations in memory. A @nt{pragma} Controlled should turn off both
3082 flavors of garbage collection.]}
3083 @end{Reason}
3084 @begin{ImplNote}
3085 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3086 @ChgDeleted{Version=[3],Text=[If garbage collection reclaims the storage of
3087 a controlled object, it should first finalize it.
3088 Finalization is not done when moving an object;
3089 any self-relative pointers will have to be updated by the garbage
3090 collector.
3091 If an implementation provides garbage collection
3092 for a storage pool containing controlled objects
3093 (see @RefSecNum{Assignment and Finalization}),
3094 then it should provide a means for deferring garbage collection of
3095 those controlled objects.]}
3096 @end{ImplNote}
3097 @begin{Reason}
3098 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3099 @ChgDeleted{Version=[3],Type=[Leading],Text=[This allows the manager of a
3100 resource released by a Finalize operation to defer garbage collection during
3101 its critical regions; it is up to the author of the Finalize operation to do
3102 so. Garbage collection, at least in some systems, can happen asynchronously
3103 with respect to normal user code. Note that it is not enough to defer garbage
3104 collection during Initialize, Adjust, and Finalize, because the resource in
3105 question might be used in other situations as well. For example:]}
3106 @begin{Example}
3107 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3108 @ChgDeleted{Version=[3],Text=[@key[with] Ada.Finalization;
3109 @key[package] P @key[is]]}
3110
3111 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3112 @ChgDeleted{Version=[3],Text=[ @key[type] My_Controlled @key[is]
3113 @key[new] Ada.Finalization.Limited_Controlled @key[with] @key[private];
3114 @key[procedure] Finalize(Object : @key[in] @key[out] My_Controlled);
3115 @key[type] My_Controlled_Access @key[is] @key[access] My_Controlled;]}
3116
3117 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3118 @ChgDeleted{Version=[3],Text=[ @key[procedure] Non_Reentrant;]}
3119
3120 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3121 @ChgDeleted{Version=[3],Text=[@key[private]
3122 ...
3123 @key[end] P;]}
3124
3125 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3126 @ChgDeleted{Version=[3],Text=[@key[package] @key[body] P @key[is]
3127 X : Integer := 0;
3128 A : @key[array](Integer @key[range] 1..10) @key[of] Integer;]}
3129
3130 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3131 @ChgDeleted{Version=[3],Text=[ @key[procedure] Non_Reentrant @key[is]
3132 @key[begin]
3133 X := X + 1;
3134 --@Examcom{ If the system decides to do a garbage collection here,}
3135 --@Examcom{ then we're in trouble, because it will call Finalize on}
3136 --@Examcom{ the collected objects; we essentially have two threads}
3137 --@Examcom{ of control erroneously accessing shared variables.}
3138 --@Examcom{ The garbage collector behaves like a separate thread}
3139 --@Examcom{ of control, even though the user hasn't declared}
3140 --@Examcom{ any tasks.}
3141 A(X) := ...;
3142 @key[end] Non_Reentrant;]}
3143
3144 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3145 @ChgDeleted{Version=[3],Text=[ @key[procedure] Finalize(Object : @key[in] @key[out] My_Controlled) @key[is]
3146 @key[begin]
3147 Non_Reentrant;
3148 @key[end] Finalize;
3149 @key[end] P;]}
3150
3151 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3152 @ChgDeleted{Version=[3],Text=[@key[with] P; @key[use] P;
3153 @key[procedure] Main @key[is]
3154 @key[begin]
3155 ... @key[new] My_Controlled ... --@Examcom{ allocate some objects}
3156 ... @Examcom{ forget the pointers to some of them, so they become garbage}
3157 Non_Reentrant;
3158 @key[end] Main;]}
3159 @end{Example}
3160
3161 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3162 @ChgDeleted{Version=[3],Text=[It is the user's responsibility to protect
3163 against this sort of thing, and the implementation's responsibility to provide
3164 the necessary operations.]}
3165
3166 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
3167 @ChgDeleted{Version=[3],Text=[We do not give these operations names,
3168 nor explain their exact semantics,
3169 because different implementations of garbage collection might have
3170 different needs, and because garbage collection is not supported by
3171 most Ada implementations, so portability is not important here.
3172 Another reason not to
3173 turn off garbage collection during each entire
3174 Finalize operation is that it would create a serial bottleneck;
3175 it might be only part of the Finalize operation that conflicts with
3176 some other resource.
3177 It is the intention that the mechanisms provided be finer-grained
3178 than pragma Controlled.]}
3179 @end{Reason}
3180
3181 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]}
3182 @ChgDeleted{Version=[3],Text=[If a @nt{pragma} Controlled is specified
3183 for an access type with a standard storage pool,
3184 then garbage collection is not performed for objects in that pool.]}
3185 @begin{Ramification}
3186 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3187 @ChgDeleted{Version=[3],Text=[If Controlled is not specified,
3188 the implementation may, but need not, perform garbage
3189 collection. If Storage_Pool is specified,
3190 then a @nt{pragma} Controlled for that type is ignored.]}
3191 @end{Ramification}
3192 @begin{Reason}
3193 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
3194 @ChgDeleted{Version=[3],Text=[Controlled means that implementation-provided
3195 garbage collection is turned off;
3196 if the Storage_Pool is specified, the pool controls
3197 whether garbage collection is done.]}
3198 @end{Reason}
3199 @end{StaticSem}
3200
3201 @begin{ImplPerm}
3202 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0190-1],ARef=[AI05-0229-1]}
3203 @Chg{Version=[3],New=[An object created by an @nt{allocator} that is passed as
3204 the actual parameter to an access parameter may be allocated on the stack, and
3205 automatically reclaimed, regardless of the default pool],
3206 Old=[An implementation need not support garbage collection, in
3207 which case, a pragma Controlled has no effect]}.
3208 @begin{Discussion}
3209 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0190-1]}
3210 @ChgAdded{Version=[3],Text=[This matches the required finalization point for
3211 such an allocated object.]}
3212 @end{Discussion}
3213 @end{ImplPerm}
3214
3215 @begin{Notes}
3216 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0190-1]}
3217 @ChgAdded{Version=[3],Text=[Default_Storage_Pool may be used with restrictions No_Coextensions and
3218 No_Access_Parameter_Allocators (see @RefSecNum{High Integrity Restrictions})
3219 to ensure that all @nt{allocator}s use the default pool.]}
3220 @end{Notes}
3221
3222 @begin{DiffWord83}
3223 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]}
3224 @ChgDeleted{Version=[3],Text=[Ada 83 used the term @lquotes@;automatic storage
3225 reclamation@rquotes@; to refer to what is known traditionally as
3226 @lquotes@;garbage collection@rquotes@;. Because of the existence of storage
3227 pools (see @RefSecNum{Storage Management}), we need to distinguish this from
3228 the storage reclamation that might happen upon leaving a master. Therefore, we
3229 now use the term @lquotes@;garbage collection@rquotes@; in its normal
3230 computer-science sense. This has the additional advantage of making our
3231 terminology more accessible to people outside the Ada world.]}
3232 @end{DiffWord83}
3233
3234 @begin{Incompatible2005}
3235 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
3236 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 95}Pragma
3237 Controlled has been dropped from Ada,
3238 as it has no effect in any known Ada implementations and it seems to promise
3239 capabilities not expected in Ada implementations. This is usually not an
3240 incompatibility, as the pragma merely becomes unrecognized (with a warning)
3241 and can be implemented as an implementation-defined pragma if desired. However,
3242 it is incompatible if it is (now) implemented as an implementation-defined
3243 pragma, someone used this pragma in a unit, and they
3244 also used restriction No_Implementation_Pragmas on that unit. In that
3245 case, the pragma would now violate the restriction; but use of this pragma
3246 (which does nothing) should be very rare, so this is not a significant
3247 issue.]}
3248 @end{Incompatible2005}
3249
3250 @begin{Extend2005}
3251 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0190-1]}
3252 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
3253 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}The
3254 pragma Default_Storage_Pool @Chg{Version=[4],New=[and aspect
3255 Default_Storage_Pool are],Old=[is]} new.]}
3256 @end{Extend2005}
3257
3258 @begin{DiffWord2005}
3259 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
3260 @ChgAdded{Version=[3],Text=[The entire discussion of garbage collection
3261 (and especially that of controlled objects) is deleted. Ada 2012 provides
3262 subpools (see @RefSecNum{Storage Subpools}) for storage management of objects,
3263 including controlled objects, a mechanism which is much more predictable
3264 than garbage collection. Note that no version of Ada allows early
3265 finalization of controlled objects (other than via the use of
3266 Unchecked_Deallocation or Unchecked_Deallocate_Subpool), so that garbage
3267 collection of such objects would be ineffective in the standard mode anyway.]}
3268 @end{DiffWord2005}
3269
3270 @begin{Extend2012}
3271 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0003-1]}
3272 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:>
3273 The @nt{storage_pool_indicator} Standard is new.]}
3274 @end{Extend2012}
3275
3276 @begin{DiffWord2012}
3277 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0136-1]}
3278 @ChgAdded{Version=[4],Text=[@b{Corrigendum:} We now explicitly say that
3279 the behavior of language-defined generic units when given the
3280 Default_Storage_Pool aspect is implementation-defined. Portable code
3281 cannot rely on such a package using a particular pool implementation.]}
3282 @end{DiffWord2012}
3283
3284
3285 @LabeledAddedSubClause{Version=[3],Name=[Storage Subpools]}
3286
3287 @begin{Intro}
3288 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3289 @ChgAdded{Version=[3],Text=[This subclause defines a package to support the
3290 partitioning of a storage pool into subpools. A subpool may be specified as the
3291 default to be used for allocation from the associated storage pool, or a
3292 particular subpool may be specified as part of an @nt{allocator}
3293 (see @RefSecNum{Allocators}).]}
3294 @end{Intro}
3295
3296
3297 @begin{StaticSem}
3298 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3299 @ChgAdded{Version=[3],Text=[The following language-defined library package
3300 exists:]}
3301
3302 @begin{Example}
3303 @ChgRef{Version=[3],Kind=[AddedNormal]}
3304 @ChgAdded{Version=[3],Text=[@ChildUnit{Parent=[System.Storage_Pools],Child=[Subpools]}@key[package] System.Storage_Pools.Subpools @key[is]
3305 @key[pragma] Preelaborate (Subpools);]}
3306
3307 @ChgRef{Version=[3],Kind=[AddedNormal]}
3308 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Root_Storage_Pool_With_Subpools} @key[is]
3309 @key[abstract new] Root_Storage_Pool @key[with private];]}
3310
3311 @ChgRef{Version=[3],Kind=[AddedNormal]}
3312 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Root_Subpool} @key[is abstract tagged limited private];]}
3313
3314 @ChgRef{Version=[3],Kind=[AddedNormal]}
3315 @ChgAdded{Version=[3],Text=[ @key[type] @AdaTypeDefn{Subpool_Handle} @key[is access all] Root_Subpool'Class;
3316 @key[for] Subpool_Handle'Storage_Size @key[use] 0;]}
3317
3318 @ChgRef{Version=[3],Kind=[AddedNormal]}
3319 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Create_Subpool} (Pool : @key[in out] Root_Storage_Pool_With_Subpools)
3320 @key[return not null] Subpool_Handle @key[is abstract];]}
3321
3322 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0252-1]}
3323 @ChgAdded{Version=[3],Text=[ -- @Examcom{The following operations are intended for pool implementers:}]}
3324
3325 @ChgRef{Version=[3],Kind=[AddedNormal]}
3326 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Pool_of_Subpool} (Subpool : @key[not null] Subpool_Handle)
3327 @key[return access] Root_Storage_Pool_With_Subpools'Class;]}
3328
3329 @ChgRef{Version=[3],Kind=[AddedNormal]}
3330 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Set_Pool_of_Subpool} (
3331 Subpool : @key[in not null] Subpool_Handle;
3332 To : @key[in out] Root_Storage_Pool_With_Subpools'Class);]}
3333
3334 @ChgRef{Version=[3],Kind=[AddedNormal]}
3335 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Allocate_From_Subpool} (
3336 Pool : @key[in out] Root_Storage_Pool_With_Subpools;
3337 Storage_Address : @key[out] Address;
3338 Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count;
3339 Alignment : @key[in] Storage_Elements.Storage_Count;
3340 Subpool : @key[in not null] Subpool_Handle) @key[is abstract]
3341 @key[with] Pre'Class => Pool_of_Subpool(Subpool) = Pool'Access;]}
3342
3343 @ChgRef{Version=[3],Kind=[AddedNormal]}
3344 @ChgAdded{Version=[3],Text=[ @key[procedure] @AdaSubDefn{Deallocate_Subpool} (
3345 Pool : @key[in out] Root_Storage_Pool_With_Subpools;
3346 Subpool : @key[in out] Subpool_Handle) @key[is abstract]
3347 @key[with] Pre'Class => Pool_of_Subpool(Subpool) = Pool'Access;]}
3348
3349 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3350 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Default_Subpool_for_Pool} (
3351 Pool : @key[in out] Root_Storage_Pool_With_Subpools)
3352 @key[return not null] Subpool_Handle;]}
3353
3354 @ChgRef{Version=[3],Kind=[AddedNormal]}
3355 @ChgAdded{Version=[3],Text=[ @key[overriding]
3356 @key[procedure] @AdaSubDefn{Allocate} (
3357 Pool : @key[in out] Root_Storage_Pool_With_Subpools;
3358 Storage_Address : @key[out] Address;
3359 Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count;
3360 Alignment : @key[in] Storage_Elements.Storage_Count);]}
3361
3362 @ChgRef{Version=[3],Kind=[AddedNormal]}
3363 @ChgAdded{Version=[3],Text=[ @key[overriding]
3364 @key[procedure] @AdaSubDefn{Deallocate} (
3365 Pool : @key[in out] Root_Storage_Pool_With_Subpools;
3366 Storage_Address : @key[in] Address;
3367 Size_In_Storage_Elements : @key[in] Storage_Elements.Storage_Count;
3368 Alignment : @key[in] Storage_Elements.Storage_Count) @key[is null];]}
3369
3370 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3371 @ChgAdded{Version=[3],Text=[ @key[overriding]
3372 @key[function] @AdaSubDefn{Storage_Size} (Pool : Root_Storage_Pool_With_Subpools)
3373 @key[return] Storage_Elements.Storage_Count
3374 @key[is] (Storage_Elements.Storage_Count'Last);]}
3375
3376 @ChgRef{Version=[3],Kind=[AddedNormal]}
3377 @ChgAdded{Version=[3],Text=[private
3378 ... -- @Examcom{not specified by the language}
3379 end System.Storage_Pools.Subpools;]}
3380 @end{Example}
3381
3382 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3383 @ChgAdded{Version=[3],Text=[@Defn{subpool}@Defn2{Term=[pool],Sec={subpool}}
3384 @Defn{subpool handle}@Defn2{Term=[handle],Sec=[subpool]}
3385 @Defn{storage pool that supports subpools}A @i<subpool> is
3386 a separately reclaimable portion of a storage pool, identified by
3387 an object of type Subpool_Handle (a @i<subpool handle>). A subpool handle also
3388 identifies the enclosing storage pool, a @i<storage pool that supports subpools>,
3389 which is a storage pool whose type is descended from
3390 Root_Storage_Pool_With_Subpools. A subpool is created by calling Create_Subpool
3391 or a similar constructor; the constructor returns the subpool handle.]}
3392
3393 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3],ARef=[AI05-0269-1]}
3394 @ChgAdded{Version=[3],Text=[A @i<subpool object> is an object of a type
3395 descended from Root_Subpool. @Redundant[Typically, subpool objects are
3396 managed by the containing storage pool; only the handles need be exposed to
3397 clients of the storage pool. Subpool objects are designated by subpool handles,
3398 and are the run-time representation of a subpool.]]}
3399
3400 @begin{TheProof}
3401 @ChgRef{Version=[3],Kind=[AddedNormal]}
3402 @ChgAdded{Version=[3],Text=[We know that subpool handles designate
3403 subpool objects because the declaration of Subpool_Handle says so.]}
3404 @end{TheProof}
3405
3406 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3407 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI05-0145-1]}
3408 @ChgAdded{Version=[3],Text=[Each subpool @i<belongs>@Defn2{Term=[belongs],Sec=[subpool to a pool]}
3409 to a single storage pool @Redundant[(which will always be a pool
3410 that supports subpools)]. An access to the pool that a subpool belongs to can
3411 be obtained by calling Pool_of_Subpool with the subpool handle.
3412 Set_Pool_of_Subpool causes the subpool of the subpool handle to belong to the
3413 given pool@Redundant[; this is intended to be called from subpool constructors
3414 like Create_Subpool.] Set_Pool_of_Subpool propagates Program_Error if the
3415 subpool already belongs to a pool.@Chg{Version=[4],New=[ If Set_Pool_of_Subpool
3416 has not yet been called for a subpool, Pool_of_Subpool returns
3417 @Key[null].],Old=[]}]}
3418
3419 @begin{Discussion}
3420 @ChgRef{Version=[3],Kind=[AddedNormal]}
3421 @ChgAdded{Version=[3],Text=[Pool_of_Subpool and Set_Pool_of_Subpool are
3422 provided by the Ada implementation and typically will not be overridden by the
3423 pool implementer.]}
3424 @end{Discussion}
3425
3426 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3427 @ChgAdded{Version=[3],Text=[When an @nt{allocator} for a type whose storage pool
3428 supports subpools is evaluated, a call is made on Allocate_From_Subpool passing
3429 in a Subpool_Handle, in addition to the parameters as defined for calls on
3430 Allocate (see @RefSecNum{Storage Management}). The subpool designated by the
3431 @Syni{subpool_handle_}@nt{name} is used, if specified in an @nt{allocator}.
3432 Otherwise, Default_Subpool_for_Pool of the Pool is used to provide a subpool
3433 handle. All requirements on the Allocate procedure also apply to
3434 Allocate_from_Subpool.]}
3435
3436 @begin{Discussion}
3437 @ChgRef{Version=[3],Kind=[AddedNormal]}
3438 @ChgAdded{Version=[3],Text=[Deallocate_Subpool is expected to do whatever is
3439 needed to deallocate all of the objects contained in the subpool; it is called
3440 from Unchecked_Deallocate_Subpool (see @RefSecNum{Subpool Reclamation}).]}
3441
3442 @ChgRef{Version=[3],Kind=[AddedNormal]}
3443 @ChgAdded{Version=[3],Text=[Typically, the pool implementer will not override
3444 Allocate. In the canonical definition of the language, it will never be called
3445 for a pool that supports subpools (there is an @ImplPermName below that allows
3446 it to be called in certain rare cases).]}
3447 @end{Discussion}
3448
3449 @end{StaticSem}
3450
3451 @begin{Legality}
3452
3453 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3454 @ChgAdded{Version=[3],Text=[If a storage pool that supports subpools is specified as the Storage_Pool for
3455 an access type, the access type is called a
3456 @i<subpool access type>.@Defn{subpool access type}@Defn2{Term=[access type],Sec=[subpool]}
3457 A subpool access type shall be a pool-specific access type.]}
3458
3459 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3],ARef=[AI05-0252-1]}
3460 @ChgAdded{Version=[3],Text=[The accessibility level of a subpool access type
3461 shall not be statically deeper than that of the storage pool object.
3462 If the specified storage pool object is a storage pool that supports subpools,
3463 then the @nt{name} that denotes the object shall not denote part of a formal
3464 parameter, nor shall it denote part of a dereference of a value of a
3465 non-library-level general access type.
3466 @PDefn{generic contract issue}In addition to the places where
3467 @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
3468 these rules also apply in the private part of an instance of a generic unit.]}
3469 @end{Legality}
3470
3471 @begin{Runtime}
3472
3473 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3],ARef=[AI05-0252-1]}
3474 @ChgAdded{Version=[3],Type=[Leading],Text=[When an access type with a specified
3475 storage pool is frozen (see @RefSecNum{Freezing Rules}), if the tag of the
3476 storage pool object identifies a storage pool that supports subpools, the
3477 following checks are made:]}
3478
3479 @begin{Itemize}
3480 @ChgRef{Version=[3],Kind=[AddedNormal]}
3481 @ChgAdded{Version=[3],Text=[the @nt{name} used to specify the storage pool
3482 object does not denote part of a formal parameter nor part of a dereference of
3483 a value of a non-library-level general access type; and@IndexCheck{Accessibility_Check}]}
3484
3485 @ChgRef{Version=[3],Kind=[AddedNormal]}
3486 @ChgAdded{Version=[3],Text=[the accessibility level of the access type is not
3487 deeper than that of the storage pool object.@IndexCheck{Accessibility_Check}]}
3488 @end{Itemize}
3489
3490 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0252-1]}
3491 @ChgAdded{Version=[3],Type=[Trailing],Text=[Program_Error is raised if either
3492 of these checks
3493 fail.@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}]}
3494
3495 @begin{Reason}
3496 @ChgRef{Version=[3],Kind=[AddedNormal]}
3497 @ChgAdded{Version=[3],Text=[This check (and its static counterpart) ensures
3498 that the type of the allocated objects exists at least as long as the storage
3499 pool object, so that the subpools are finalized (which finalizes any remaining
3500 allocated objects) before the type of the objects ceases to exist. The access
3501 type itself (and the associated collection) will cease to exist before the
3502 storage pool ceases to exist.]}
3503
3504 @ChgRef{Version=[3],Kind=[AddedNormal]}
3505 @ChgAdded{Version=[3],Text=[We also disallow the use of formal parameters and
3506 dereferences of non-library-level general access types when specifying a
3507 storage pool object if it supports subpools, because the "apparent"
3508 accessibility level is potentially deeper than that of the underlying object.
3509 Neither of these cases is very likely to occur in practice.]}
3510 @end{Reason}
3511
3512 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3513 @ChgAdded{Version=[3],Type=[Leading],Text=[A call to Subpools.Allocate(P, Addr, Size, Align) does the following:]}
3514
3515 @begin{Example}
3516 @ChgRef{Version=[3],Kind=[AddedNormal]}
3517 @ChgAdded{Version=[3],Text=[Allocate_From_Subpool
3518 (Root_Storage_Pool_With_Subpools'Class(P),
3519 Addr, Size, Align,
3520 Subpool => Default_Subpool_for_Pool
3521 (Root_Storage_Pool_With_Subpools'Class(P)));]}
3522 @end{Example}
3523
3524
3525 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3526 @ChgAdded{Version=[3],Text=[An @nt{allocator} that allocates in a subpool raises
3527 Program_Error if the allocated object has task
3528 parts.@IndexCheck{Allocation_Check}@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}]}
3529
3530 @begin{Reason}
3531 @ChgRef{Version=[3],Kind=[AddedNormal]}
3532 @ChgAdded{Version=[3],Text=[This is to ease implementation. We envision
3533 relaxing this restriction in a future version of Ada, once implementation
3534 experience has been gained. At this time, we are unable to come up with a set
3535 of rules for task termination that is both useful, and surely feasible to
3536 implement.]}
3537 @end{Reason}
3538
3539 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3540 @ChgAdded{Version=[3],Text=[Unless overridden, Default_Subpool_for_Pool
3541 propagates Program_Error.]}
3542
3543 @end{Runtime}
3544
3545 @begin{Erron}
3546 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0142-1]}
3547 @PDefn2{Term=(erroneous execution),Sec=(cause)}
3548 @ChgAdded{Version=[4],Text=[If Allocate_From_Subpool does not meet one or more
3549 of the requirements on the Allocate procedure as given in the Erroneous
3550 Execution rules of @RefSecNum{Storage Management}, then the program execution
3551 is erroneous.]}
3552 @end{Erron}
3553
3554 @begin{ImplPerm}
3555
3556 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3557 @ChgAdded{Version=[3],Text=[When an allocator for a type whose storage pool is
3558 of type Root_Storage_Pool'Class is evaluated, but supports subpools, the
3559 implementation may call Allocate rather than Allocate_From_Subpool.
3560 @Redundant[This will have the same effect, so long as Allocate has not been
3561 overridden.]]}
3562
3563 @begin{Reason}
3564 @ChgRef{Version=[3],Kind=[AddedNormal]}
3565 @ChgAdded{Version=[3],Type=[Leading],Text=[This ensures either of two implementation models
3566 are possible for an @nt{allocator} with no @nt{subpool_specification}.
3567 Note that the "supports subpools" property is not known at compile time for a
3568 pool of the class-wide type.]}
3569
3570 @begin{Itemize}
3571 @ChgRef{Version=[3],Kind=[AddedNormal]}
3572 @ChgAdded{Version=[3],Text=[The implementation can dispatch to
3573 Storage_Pools.Allocate. If the pool supports subpools, this will call
3574 Allocate_From_Subpool with the default subpool so long as Allocate has not
3575 been overridden.]}
3576
3577 @ChgRef{Version=[3],Kind=[AddedNormal]}
3578 @ChgAdded{Version=[3],Text=[The implementation can declare
3579 Allocate_From_Subpool as a primitive of Root_Storage_Pool in the private
3580 part of Storage_Pools. This means that the Allocate_From_Subpool for
3581 Root_Storage_Pool_With_Subpools overrides that private one. The
3582 implementation can thus call the private one, which will call Allocate for
3583 non-subpool-supporting pools. The effect of this implementation does not
3584 change if Allocate is overridden for a pool that supports subpools.]}
3585 @end{Itemize}
3586 @end{Reason}
3587
3588 @end{ImplPerm}
3589
3590 @begin{Notes}
3591
3592 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3593 @ChgAdded{Version=[3],Text=[A user-defined storage pool type that supports
3594 subpools can be implemented by extending the Root_Storage_Pool_With_Subpools
3595 type, and overriding the primitive subprograms Create_Subpool,
3596 Allocate_From_Subpool, and Deallocate_Subpool. Create_Subpool should call
3597 Set_Pool_Of_Subpool before returning the subpool handle. To make use of such a
3598 pool, a user would declare an object of the type extension, use it to define the
3599 Storage_Pool attribute of one or more access types, and then call Create_Subpool
3600 to obtain subpool handles associated with the pool.]}
3601
3602 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3603 @ChgAdded{Version=[3],Text=[A user-defined storage pool type that supports
3604 subpools may define additional subpool constructors similar to Create_Subpool
3605 (these typically will have additional parameters).]}
3606
3607 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3608 @ChgAdded{Version=[3],Text=[The pool implementor should override
3609 Default_Subpool_For_Pool if the pool is to support a default subpool for the
3610 pool. The implementor can override Deallocate if individual object reclamation
3611 is to be supported, and can override Storage_Size if there is some limit on the
3612 total size of the storage pool. The implementor can override Initialize and
3613 Finalize if there is any need for nontrivial initialization and finalization
3614 for the pool as a whole. For example, Finalize might reclaim blocks of storage
3615 that are allocated over and above the space occupied by the pool object itself.
3616 The pool implementor may extend the Root_Subpool type as necessary to carry
3617 additional information with each subpool provided by Create_Subpool.]}
3618
3619 @end{Notes}
3620
3621 @begin{Extend2005}
3622 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3],ARef=[AI05-0252-1]}
3623 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Subpools and the
3624 package System.Storage_Pools.Subpools are new.]}
3625 @end{Extend2005}
3626
3627 @begin{Diffword2012}
3628 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0142-1]}
3629 @ChgAdded{Version=[4],Text=[@b<Corrigendum>: Clarified that an incorrect
3630 implementation of Allocate_From_Subpool causes execution to become erroneous.
3631 The wording already said that the requirements of Allocate apply to
3632 Allocate_From_Subpool, so we're just confirming the consequences of violating
3633 those requirements also apply.]}
3634
3635 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0145-1]}
3636 @ChgAdded{Version=[4],Text=[@b<Corrigendum>: Clarified that Pool_of_Subpool
3637 returns @key[null] if Set_Pool_of_Subpool has not been called. As that can
3638 be inferred from the definition, and all known existing implementations
3639 return @key[null] in this case, we document this as a wording change rather
3640 than a possible inconsistency.]}
3641 @end{Diffword2012}
3642
3643
3644 @LabeledAddedSubClause{Version=[3],Name=[Subpool Reclamation]}
3645
3646 @begin{Intro}
3647 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3648 @ChgAdded{Version=[3],Text=[A subpool may be explicitly deallocated using
3649 Unchecked_Deallocate_Subpool.]}
3650 @end{Intro}
3651
3652 @begin{StaticSem}
3653 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3654 @ChgAdded{Version=[3],Type=[Leading],Text=[The following language-defined
3655 library procedure exists:]}
3656
3657 @begin{Example}
3658 @ChgRef{Version=[3],Kind=[AddedNormal]}
3659 @ChgAdded{Version=[3],Text=[@key[with] System.Storage_Pools.Subpools;
3660 @SubChildUnit{Parent=[Ada],Child=[Ada.Unchecked_Deallocate_Subpool]}@key[procedure] Ada.Unchecked_Deallocate_Subpool
3661 (Subpool : @key[in out] System.Storage_Pools.Subpools.Subpool_Handle);]}
3662 @end{Example}
3663
3664 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3665 @ChgAdded{Version=[3],Text=[If Subpool is @key[null], a call on
3666 Unchecked_Deallocate_Subpool has no effect. Otherwise, the subpool is
3667 finalized, and Subpool is set to @key[null].]}
3668
3669 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3670 @ChgAdded{Version=[3],Type=[Leading],Text=[Finalization of a subpool has the
3671 following effects:]}
3672
3673 @begin{Itemize}
3674 @ChgRef{Version=[3],Kind=[AddedNormal]}
3675 @ChgAdded{Version=[3],Text=[The subpool no longer belongs to any pool;]}
3676
3677 @ChgRef{Version=[3],Kind=[AddedNormal]}
3678 @ChgAdded{Version=[3],Text=[Any of the objects allocated from the subpool that
3679 still exist are finalized in an arbitrary order;@PDefn2{Term=[arbitrary order],Sec=[allowed]}]}
3680
3681 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0148-1]}
3682 @ChgAdded{Version=[4],Text=[All of the objects allocated from the subpool
3683 cease to exist;@PDefn2{Term=[exist],Sec=[cease to]}]}
3684
3685 @ChgRef{Version=[3],Kind=[AddedNormal]}
3686 @ChgAdded{Version=[3],Type=[Leading],Text=[The following @Redundant[dispatching] call is then made:]}
3687 @begin{Example}
3688 @ChgRef{Version=[3],Kind=[AddedNormal]}
3689 @ChgAdded{Version=[3],NoPrefix=[T],Text=[ Deallocate_Subpool(Pool_of_Subpool(Subpool).@key[all], Subpool);]}
3690 @end{Example}
3691 @end{Itemize}
3692
3693 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3694 @ChgAdded{Version=[3],Text=[Finalization of a Root_Storage_Pool_With_Subpools
3695 object finalizes all subpools that belong to that pool that have not yet been
3696 finalized.]}
3697
3698 @begin{Discussion}
3699
3700 @ChgRef{Version=[3],Kind=[AddedNormal]}
3701 @ChgAdded{Version=[3],Text=[There is no need to call Unchecked_Deallocation on
3702 an object allocated in a subpool. Such objects are deallocated all at once, when
3703 Unchecked_Deallocate_Subpool is called.]}
3704
3705 @ChgRef{Version=[3],Kind=[AddedNormal]}
3706 @ChgAdded{Version=[3],Text=[If Unchecked_Deallocation is called, the object is
3707 finalized, and then Deallocate is called on the Pool, which typically will do
3708 nothing. If it wants to free memory, it will need some way to get from the
3709 address of the object to the subpool.]}
3710
3711 @ChgRef{Version=[3],Kind=[AddedNormal]}
3712 @ChgAdded{Version=[3],Text=[There is no Deallocate_From_Subpool. There is
3713 no efficient way for the implementation to determine the subpool for
3714 an arbitrary object, and if the pool implementer can determinate that,
3715 they can use that as part of the implementation of Deallocate.]}
3716
3717 @ChgRef{Version=[3],Kind=[AddedNormal]}
3718 @ChgAdded{Version=[3],Text=[If Unchecked_Deallocation is not called (the usual
3719 case), the object will be finalized when Unchecked_Deallocate_Subpool is
3720 called.]}
3721
3722 @ChgRef{Version=[3],Kind=[AddedNormal]}
3723 @ChgAdded{Version=[3],Text=[If that's never called, then the object will be
3724 finalized when the Pool_With_Subpools is finalized (by permission @em it might
3725 happen when the collection of the access type is finalized).]}
3726
3727 @end{Discussion}
3728
3729 @end{StaticSem}
3730
3731 @begin{Extend2005}
3732 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3733 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Unchecked_Deallocate_Subpool is new.]}
3734 @end{Extend2005}
3735
3736 @begin{DiffWord2012}
3737 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0148-1]}
3738 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Added missing wording to state
3739 that the objects cease to exist after the completion of finalization.
3740 This is formally an inconsistency (it would be possible to depend on the
3741 fact that objects finalized by Unchecked_Deallocate_Subpool still exist),
3742 but that violates every sane expectation for a procedure called
3743 "Deallocate" something.]}
3744 @end{DiffWord2012}
3745
3746
3747 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
3748 @LabeledAddedSubClause{Version=[3],Name=[Storage Subpool Example]}
3749
3750 @begin{Examples}
3751
3752 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3753 @ChgAdded{Version=[3],Type=[Leading],Text=[The following example is a simple but
3754 complete implementation of the classic Mark/Release pool using subpools:]}
3755
3756 @begin{Example}
3757
3758 @ChgRef{Version=[3],Kind=[AddedNormal]}
3759 @ChgAdded{Version=[3],Text=[@key[with] System.Storage_Pools.Subpools;
3760 @key[with] System.Storage_Elements;
3761 @key[with] Ada.Unchecked_Deallocate_Subpool;
3762 @key[package] MR_Pool @key[is]]}
3763
3764 @ChgRef{Version=[3],Kind=[AddedNormal]}
3765 @ChgAdded{Version=[3],Text=[ @key[use] System.Storage_Pools;
3766 -- @Examcom{For uses of Subpools.}
3767 @key[use] System.Storage_Elements;
3768 -- @Examcom{For uses of Storage_Count and Storage_Array.}]}
3769
3770 @ChgRef{Version=[3],Kind=[AddedNormal]}
3771 @ChgAdded{Version=[3],Text=[ -- @Examcom{Mark and Release work in a stack fashion, and allocations are not allowed}
3772 -- @Examcom{from a subpool other than the one at the top of the stack. This is also}
3773 -- @Examcom{the default pool.}]}
3774
3775 @ChgRef{Version=[3],Kind=[AddedNormal]}
3776 @ChgAdded{Version=[3],Text=[ @key[subtype] Subpool_Handle @key[is] Subpools.Subpool_Handle;]}
3777
3778 @ChgRef{Version=[3],Kind=[AddedNormal]}
3779 @ChgAdded{Version=[3],Text=[ @key[type] Mark_Release_Pool_Type (Pool_Size : Storage_Count) @key[is new]
3780 Subpools.Root_Storage_Pool_With_Subpools @key[with private];]}
3781
3782 @ChgRef{Version=[3],Kind=[AddedNormal]}
3783 @ChgAdded{Version=[3],Text=[ @key[function] Mark (Pool : @key[in out] Mark_Release_Pool_Type)
3784 @key[return not null] Subpool_Handle;]}
3785
3786 @ChgRef{Version=[3],Kind=[AddedNormal]}
3787 @ChgAdded{Version=[3],Text=[ @key[procedure] Release (Subpool : @key[in out] Subpool_Handle) @key[renames]
3788 Ada.Unchecked_Deallocate_Subpool;]}
3789
3790 @ChgRef{Version=[3],Kind=[AddedNormal]}
3791 @ChgAdded{Version=[3],Keepnext=[T],Text=[@key[private]]}
3792
3793 @ChgRef{Version=[3],Kind=[AddedNormal]}
3794 @ChgAdded{Version=[3],Text=[ @key[type] MR_Subpool @key[is new] Subpools.Root_Subpool @key[with record]
3795 Start : Storage_Count;
3796 @key[end record];
3797 @key[subtype] Subpool_Indexes @key[is] Positive @key[range] 1 .. 10;
3798 @key[type] Subpool_Array @key[is array] (Subpool_Indexes) @key[of aliased] MR_Subpool;]}
3799
3800 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3801 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0134-1]}
3802 @ChgAdded{Version=[3],Text=[ @key[type] Mark_Release_Pool_Type (Pool_Size : Storage_Count) @key[is new]
3803 Subpools.Root_Storage_Pool_With_Subpools @key[with record]
3804 Storage : Storage_Array (0 .. Pool_Size@Chg{Version=[4],New=[],Old=[-1]});
3805 Next_Allocation : Storage_Count := 0;
3806 Markers : Subpool_Array;
3807 Current_Pool : Subpool_Indexes := 1;
3808 @key[end record];]}
3809
3810 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3811 @ChgAdded{Version=[3],Text=[ @key[overriding]
3812 @key[function] Create_Subpool (Pool : @key[in out] Mark_Release_Pool_Type)
3813 @key[return not null] Subpool_Handle;]}
3814
3815 @ChgRef{Version=[3],Kind=[AddedNormal]}
3816 @ChgAdded{Version=[3],Text=[ @key[function] Mark (Pool : @key[in out] Mark_Release_Pool_Type)
3817 @key[return not null] Subpool_Handle @key[renames] Create_Subpool;]}
3818
3819 @ChgRef{Version=[3],Kind=[AddedNormal]}
3820 @ChgAdded{Version=[3],Text=[ @key[overriding]
3821 @key[procedure] Allocate_From_Subpool (
3822 Pool : @key[in out] Mark_Release_Pool_Type;
3823 Storage_Address : @key[out] System.Address;
3824 Size_In_Storage_Elements : @key[in] Storage_Count;
3825 Alignment : @key[in] Storage_Count;
3826 Subpool : @key[not null] Subpool_Handle);]}
3827
3828 @ChgRef{Version=[3],Kind=[AddedNormal]}
3829 @ChgAdded{Version=[3],Text=[ @key[overriding]
3830 @key[procedure] Deallocate_Subpool (
3831 Pool : @key[in out] Mark_Release_Pool_Type;
3832 Subpool : @key[in out] Subpool_Handle);]}
3833
3834 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3835 @ChgAdded{Version=[3],Text=[ @key[overriding]
3836 @key[function] Default_Subpool_for_Pool (Pool : @key[in out] Mark_Release_Pool_Type)
3837 @key[return not null] Subpool_Handle;]}
3838
3839 @ChgRef{Version=[3],Kind=[AddedNormal]}
3840 @ChgAdded{Version=[3],Text=[ @key[overriding]
3841 @key[procedure] Initialize (Pool : @key[in out] Mark_Release_Pool_Type);]}
3842
3843 @ChgRef{Version=[3],Kind=[AddedNormal]}
3844 @ChgAdded{Version=[3],Text=[ -- @Examcom{We don't need Finalize.}]}
3845
3846 @ChgRef{Version=[3],Kind=[AddedNormal]}
3847 @ChgAdded{Version=[3],Text=[@key[end] MR_Pool;]}
3848
3849 @ChgRef{Version=[3],Kind=[AddedNormal]}
3850 @ChgAdded{Version=[3],Keepnext=[T],Text=[@key[package body] MR_Pool @key[is]]}
3851
3852 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3853 @ChgAdded{Version=[3],Text=[ @key[use type] Subpool_Handle;]}
3854
3855 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3856 @ChgAdded{Version=[3],Text=[ @key[procedure] Initialize (Pool : @key[in out] Mark_Release_Pool_Type) @key[is]
3857 -- @Examcom{Initialize the first default subpool.}
3858 @key[begin]
3859 Pool.Markers(1).Start := 1;
3860 Subpools.Set_Pool_of_Subpool
3861 (Pool.Markers(1)'Unchecked_Access, Pool);
3862 @key[end] Initialize;]}
3863
3864 @ChgRef{Version=[3],Kind=[AddedNormal]}
3865 @ChgAdded{Version=[3],Text=[ @key[function] Create_Subpool (Pool : @key[in out] Mark_Release_Pool_Type)
3866 @key[return not null] Subpool_Handle @key[is]
3867 -- @Examcom{Mark the current allocation location.}
3868 @key[begin]
3869 @key[if] Pool.Current_Pool = Subpool_Indexes'Last @key[then]
3870 @key[raise] Storage_Error; -- @Examcom{No more subpools.}
3871 @key[end if];
3872 Pool.Current_Pool := Pool.Current_Pool + 1; -- @Examcom{Move to the next subpool}]}
3873
3874 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3875 @ChgAdded{Version=[3],Text=[ @key[return] Result : @key[constant not null] Subpool_Handle :=
3876 Pool.Markers(Pool.Current_Pool)'Unchecked_Access
3877 @key[do]
3878 Pool.Markers(Pool.Current_Pool).Start := Pool.Next_Allocation;
3879 Subpools.Set_Pool_of_Subpool (Result, Pool);
3880 @key[end return];
3881 @key[end] Create_Subpool;]}
3882
3883 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3884 @ChgAdded{Version=[3],Text=[ @key[procedure] Deallocate_Subpool (
3885 Pool : @key[in out] Mark_Release_Pool_Type;
3886 Subpool : @key[in out] Subpool_Handle) @key[is]
3887 @key[begin]
3888 @key[if] Subpool /= Pool.Markers(Pool.Current_Pool)'Unchecked_Access @key[then]
3889 @key[raise] Program_Error; -- @Examcom{Only the last marked subpool can be released.}
3890 @key[end if];
3891 @key[if] Pool.Current_Pool /= 1 @key[then]
3892 Pool.Next_Allocation := Pool.Markers(Pool.Current_Pool).Start;
3893 Pool.Current_Pool := Pool.Current_Pool - 1; -- @Examcom{Move to the previous subpool}
3894 @key[else] -- @Examcom{Reinitialize the default subpool:}
3895 Pool.Next_Allocation := 1;
3896 Subpools.Set_Pool_of_Subpool
3897 (Pool.Markers(1)'Unchecked_Access, Pool);
3898 @key[end if];
3899 @key[end] Deallocate_Subpool;]}
3900
3901 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0298-1]}
3902 @ChgAdded{Version=[3],Text=[ @key[function] Default_Subpool_for_Pool (Pool : @key[in out] Mark_Release_Pool_Type)
3903 @key[return not null] Subpool_Handle @key[is]
3904 @key[begin]
3905 @key[return] Pool.Markers(Pool.Current_Pool)'Unchecked_Access;
3906 @key[end] Default_Subpool_for_Pool;]}
3907
3908 @ChgRef{Version=[3],Kind=[AddedNormal]}
3909 @ChgAdded{Version=[3],Text=[ @key[procedure] Allocate_From_Subpool (
3910 Pool : @key[in out] Mark_Release_Pool_Type;
3911 Storage_Address : @key[out] System.Address;
3912 Size_In_Storage_Elements : @key[in] Storage_Count;
3913 Alignment : @key[in] Storage_Count;
3914 Subpool : @key[not null] Subpool_Handle) @key[is]
3915 @key[begin]
3916 @key[if] Subpool /= Pool.Markers(Pool.Current_Pool)'Unchecked_Access @key[then]
3917 @key[raise] Program_Error; -- @Examcom{Only the last marked subpool can be used for allocations.}
3918 @key[end if];]}
3919
3920 @ChgRef{Version=[3],Kind=[AddedNormal]}
3921 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0080-1]}
3922 @ChgAdded{Version=[3],Text=[@Chg{Version=[4],New=[ -- @Examcom{Check for the maximum supported alignment, which is the alignment of the storage area:}
3923 @key[if] Alignment > Pool.Storage'Alignment @key[then]
3924 @key[raise] Program_Error;
3925 @key[end if];
3926 ],Old=[]} -- @Examcom{Correct the alignment if necessary:}
3927 Pool.Next_Allocation := Pool.Next_Allocation +
3928 ((-Pool.Next_Allocation) @key[mod] Alignment);
3929 @key[if] Pool.Next_Allocation + Size_In_Storage_Elements >
3930 Pool.Pool_Size @key[then]
3931 @key[raise] Storage_Error; -- @Examcom{Out of space.}
3932 @key[end if];
3933 Storage_Address := Pool.Storage (Pool.Next_Allocation)'Address;
3934 Pool.Next_Allocation :=
3935 Pool.Next_Allocation + Size_In_Storage_Elements;
3936 @key[end] Allocate_From_Subpool;]}
3937
3938 @ChgRef{Version=[3],Kind=[AddedNormal]}
3939 @ChgAdded{Version=[3],Text=[@key[end] MR_Pool;]}
3940 @end{Example}
3941
3942 @end{Examples}
3943
3944
3945 @begin{DiffWord2005}
3946 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0111-3]}
3947 @ChgAdded{Version=[3],Text=[This example of subpools is new.]}
3948 @end{DiffWord2005}
3949
3950
3951
3952 @LabeledRevisedClause{Version=[3],New=[Pragma Restrictions and Pragma Profile],Old=[Pragma Restrictions]}
3953
3954 @begin{Intro}
3955 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0246-1]}
3956 @redundant[A @nt{pragma} Restrictions expresses the user's intent to abide by
3957 certain restrictions.@Chg{Version=[3],New=[ A @nt{pragma} Profile expresses the
3958 user's intent to abide by a set of Restrictions or other specified run-time
3959 policies.],Old=[]}
3960 @Chg{Version=[3],New=[These],Old=[This]} may facilitate the construction of
3961 simpler run-time environments.]
3962 @end{Intro}
3963
3964 @begin{Syntax}
3965 @begin{SyntaxText}
3966 @Leading@keepnext@;The form of a @nt{pragma} Restrictions is as follows:
3967 @end{SyntaxText}
3968
3969 @PragmaSyn`@key{pragma} @prag(Restrictions)(@Syn2{restriction}{, @Syn2{restriction}});'
3970
3971 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00381-01]}
3972 @Syn{lhs=(restriction), rhs="@SynI{restriction_}@Syn2{identifier}
3973 | @SynI{restriction_parameter_}@Syn2{identifier} => @Chg{Version=[2],New=[@Syn2{restriction_parameter_argument}],Old=[@Syn2{expression}]}"}
3974
3975 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00381-01]}
3976 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<restriction_parameter_argument>,Old=<>}>,
3977 rhs="@Chg{Version=[2],New=<@Syn2{name} | @Syn2{expression}>,Old=<>}"}
3978
3979 @end{Syntax}
3980
3981 @begin{Resolution}
3982 @PDefn2{Term=[expected type],
3983 Sec=(restriction parameter expression)}
3984 Unless otherwise specified for a particular restriction,
3985 the @nt{expression} is expected to be of any integer type.
3986 @end{Resolution}
3987
3988 @begin{Legality}
3989 Unless otherwise specified for a particular restriction,
3990 the @nt{expression} shall be static,
3991 and its value shall be nonnegative.
3992 @end{Legality}
3993
3994 @begin{StaticSem}
3995 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00394-01]}
3996 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0269-1]}
3997 @ChgDeleted{Version=[3],Text=[The set of
3998 @Chg{Version=[2],New=[restrictions],Old=[@ntf{restrictions}]} is
3999 implementation defined.]}
4000 @ChgImplDef{Version=[3],Kind=[Deleted],InitialVersion=[0],
4001 Text=[@ChgDeleted{Version=[3],Text=[The set of
4002 @Chg{Version=[2],New=[restrictions],Old=[@ntf{restrictions}]}
4003 allowed in a @nt{pragma} Restrictions.]}]}
4004 @end{StaticSem}
4005 @begin{NotIso}
4006 @ChgAdded{Version=[3],Noparanum=[T],Text=[@Shrink{@i<Paragraph 7 was
4007 deleted.>}]}@Comment{This message should be deleted if the paragraphs
4008 are ever renumbered.}
4009 @end{NotIso}
4010
4011 @begin{LinkTime}
4012 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0013-1]}
4013 @ChgNote{Use ChgAdded to get conditional Leading}@ChgAdded{Version=[3],
4014 Type=[Leading],Text=[]}@PDefn2{Term=[configuration pragma], Sec=(Restrictions)}
4015 @PDefn2{Term=[pragma, configuration], Sec=(Restrictions)}
4016 A @nt{pragma} Restrictions is a configuration pragma@Chg{Version=[3],
4017 New=[. If a @nt{pragma} Restrictions applies to any compilation unit included in
4018 the partition, this may impose either (or both) of two kinds of
4019 requirements, as],
4020 Old=[; unless otherwise]} specified for @Chg{Version=[3],New=[the],Old=[a]}
4021 particular restriction@Chg{Version=[3],New=[:],Old=[,
4022 a partition shall obey the restriction
4023 if a @nt{pragma} Restrictions applies to any compilation unit
4024 included in the partition.]}
4025
4026 @begin{Itemize}
4027 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0013-1]}
4028 @ChgAdded{Version=[3],Text=[A restriction may impose requirements on some or
4029 all of the units comprising the partition. Unless otherwise specified for a
4030 particular restriction, such a requirement applies to all of the units
4031 comprising the partition and is enforced via a post-compilation check.]}
4032
4033 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0013-1]}
4034 @ChgAdded{Version=[3],Text=[A restriction may impose requirements on the
4035 run-time behavior of the program, as indicated by the specification of run-time
4036 behavior associated with a violation of the requirement.]}
4037
4038 @begin{Ramification}
4039 @ChgRef{Version=[3],Kind=[Added]}
4040 @ChgAdded{Version=[3],Text=[In this latter case, there is no post-compilation
4041 check needed for the requirement.]}
4042 @end{Ramification}
4043 @end{Itemize}
4044
4045
4046 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]}
4047 @ChgAdded{Version=[1],Type=[Leading],Text=[For the purpose of checking whether
4048 a partition contains constructs that violate any restriction (unless specified
4049 otherwise for a particular restriction):]}
4050
4051 @begin{itemize}
4052 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]}
4053 @ChgAdded{Version=[1],Text=[Generic instances are logically expanded at the
4054 point of instantiation;]}
4055
4056 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]}
4057 @ChgAdded{Version=[1],Text=[If an object of a type is declared or allocated and
4058 not explicitly initialized, then all expressions appearing in the definition
4059 for the type and any of its ancestors are presumed to be used;]}
4060
4061 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]}
4062 @ChgAdded{Version=[1],Text=[A @nt{default_expression} for a formal parameter or
4063 a generic formal object is considered to be used if and only if the
4064 corresponding actual parameter is not provided in a given call or
4065 instantiation.]}
4066 @end{itemize}
4067 @end{LinkTime}
4068
4069 @begin{ImplPerm}
4070 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0269-1]}
4071 @ChgAdded{Version=[3],Text=[An implementation may provide implementation-defined
4072 restrictions; the identifier for an implementation-defined restriction
4073 shall differ from those of the language-defined restrictions.]}
4074 @ChgImplDef{Version=[3],Kind=[Added],
4075 Text=[@ChgAdded{Version=[3],Text=[Implementation-defined restrictions
4076 allowed in a @nt{pragma} Restrictions.]}]}
4077
4078 An implementation may place limitations on the values of the
4079 @nt{expression} that are supported,
4080 and limitations on the supported combinations of restrictions.
4081 The consequences of violating such limitations are
4082 implementation defined.
4083 @ImplDef{The consequences of violating limitations on
4084 Restrictions @nt{pragma}s.}
4085 @begin{Ramification}
4086 Such limitations may be enforced at compile time or at run time.
4087 Alternatively, the implementation is allowed to declare violations of
4088 the restrictions to be erroneous, and not enforce them at all.
4089 @end{Ramification}
4090
4091 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0042],ARef=[AI95-00130-01]}
4092 @ChgAdded{Version=[1],Text=[An implementation is permitted to omit restriction
4093 checks for code that is recognized at compile time to be unreachable and for
4094 which no code is generated.]}
4095
4096 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0043],ARef=[AI95-00190-01]}
4097 @ChgAdded{Version=[1],Text=[Whenever enforcement of a restriction is not
4098 required prior to execution, an implementation may nevertheless enforce the
4099 restriction prior to execution of a partition to which the restriction applies,
4100 provided that every execution of the partition would violate the restriction.]}
4101 @end{ImplPerm}
4102
4103 @begin{Syntax}
4104 @begin{SyntaxText}
4105 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-00249-01],ARef=[AI05-0246-1]}
4106 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[The form of a
4107 @nt{pragma} Profile is as follows:]}
4108 @end{SyntaxText}
4109
4110 @ChgRef{Version=[3],Kind=[AddedNormal]}
4111 @AddedPragmaSyn{Version=[3],@ChgAdded{Version=[3],
4112 Text=[@key{pragma} @prag<Profile> (@SynI{profile_}@Syn2{identifier} {, @SynI{profile_}@Syn2{pragma_argument_association}});]}}
4113
4114 @end{Syntax}
4115
4116 @begin{Legality}
4117 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-00249-01],ARef=[AI05-0246-1]}
4118 @ChgAdded{Version=[3],Text=[The @SynI{profile_}@nt{identifier} shall be the name
4119 of a usage profile. The semantics of any
4120 @SynI{profile_}@nt{pragma_@!argument_@!association}s are defined by
4121 the usage profile specified by the @SynI{profile_}@nt{identifier}.]}
4122 @end{Legality}
4123
4124 @begin{StaticSem}
4125 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-00249-01],ARef=[AI05-0246-1]}
4126 @ChgAdded{Version=[3],Text=[A profile is equivalent to the set of configuration
4127 pragmas that is defined for each usage profile.]}
4128 @end{StaticSem}
4129
4130 @begin{Linktime}
4131 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-00249-01]}
4132 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[configuration pragma], Sec=(Profile)}
4133 @PDefn2{Term=[pragma, configuration], Sec=(Profile)}
4134 A @nt{pragma} Profile is a configuration pragma.
4135 There may be more than one @nt{pragma} Profile for a partition.]}
4136 @end{Linktime}
4137
4138 @begin{ImplPerm}
4139 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0269-1]}
4140 @ChgAdded{Version=[3],Text=[An implementation may provide implementation-defined
4141 usage profiles; the identifier for an implementation-defined usage profile
4142 shall differ from those of the language-defined usage profiles.]}
4143
4144 @ChgImplDef{Version=[3],Kind=[Added],
4145 Text=[@ChgAdded{Version=[3],Text=[Implementation-defined usage profiles
4146 allowed in a @nt{pragma} Profile.]}]}
4147 @end{ImplPerm}
4148
4149 @begin{Notes}
4150 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00347-01]}
4151 Restrictions intended to facilitate the construction of
4152 efficient tasking run-time systems are defined
4153 in @RefSecNum{Tasking Restrictions}.
4154 @Chg{Version=[2],New=[Restrictions intended for use when constructing
4155 high integrity systems],Old=[Safety- and security-related
4156 restrictions]} are defined in
4157 @RefSecNum{High Integrity Restrictions}.
4158
4159 An implementation has to enforce the restrictions in cases where
4160 enforcement is required,
4161 even if it chooses not to take advantage of the restrictions in terms of
4162 efficiency.
4163 @begin{Discussion}
4164 It is not the intent that an implementation will support a different
4165 run-time system for every possible combination of restrictions.
4166 An implementation might support only two run-time systems,
4167 and document a set of restrictions that is sufficient to allow
4168 use of the more efficient and safe one.
4169 @end{Discussion}
4170 @end{Notes}
4171
4172 @begin{Extend83}
4173 @Defn{extensions to Ada 83}
4174 Pragma Restrictions is new to Ada 95.
4175 @end{Extend83}
4176
4177 @begin{Extend95}
4178 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-00249-01],ARef=[AI05-0246-1]}
4179 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4180 @nt{Pragma} Profile is new; it was moved here by Ada 2012 and renamed to
4181 a "usage profile" but was otherwise unchanged.]}
4182 @end{Extend95}
4183
4184 @begin{DiffWord95}
4185 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0042],ARef=[AI95-00130-01]}
4186 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the wording so that
4187 restrictions are checked inside of generic instantiations and in default
4188 expressions. Since not making these checks would violate the purpose of
4189 restrictions, we are not documenting this as an incompatibility.]}
4190
4191 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0043],ARef=[AI95-00190-01]}
4192 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added a permission that
4193 restrictions can be enforced at compile-time. While this is technically
4194 incompatible, documenting it as such would be unnecessarily alarming -
4195 there should not be any programs depending on the runtime failure of
4196 restrictions.]}
4197
4198 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4199 @ChgAdded{Version=[2],Text=[The syntax of a @nt{restriction_parameter_argument}
4200 has been defined to better support restriction No_Dependence (see
4201 @RefSecNum{Language-Defined Restrictions and Profiles}).]}
4202 @end{DiffWord95}
4203
4204 @begin{DiffWord2005}
4205 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0013-1]}
4206 @ChgAdded{Version=[3],Text=[@b<Correction>: When restrictions are
4207 checked has been clarified.]}
4208 @end{DiffWord2005}
4209
4210
4211 @LabeledRevisedSubClause{Version=[3],InitialVersion=[2],New=[Language-Defined Restrictions and Profiles],Old=[Language-Defined Restrictions]}
4212
4213 @begin{StaticSem}
4214
4215 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]}
4216 @ChgAdded{Version=[2],Type=[Leading],Text=[The following
4217 @SynI{restriction_}@nt{identifier}s are language defined (additional
4218 restrictions are defined in the Specialized Needs Annexes):]}
4219
4220 @begin{Description}
4221
4222 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0241-1]}
4223 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4224 Sec=(No_Implementation_Aspect_Specifications)}@Chg{Version=[3],New=[@Defn{No_Implementation_Aspect_Specifications restriction}],
4225 Old=[]}No_Implementation_Aspect_Specifications @\There
4226 are no implementation-defined aspects specified by an
4227 @nt{aspect_specification}. This restriction applies only to the current
4228 compilation or environment, not the entire partition.]}
4229 @begin{Discussion}
4230 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0241-1]}
4231 @ChgAdded{Version=[3],Text=[This restriction (as well as others below) applies
4232 only to the current compilation, because it is likely that the runtime (and
4233 possibly user-written low-level code) will need to use implementation-defined
4234 aspects. But a partition-wide restriction applies everywhere, including the
4235 runtime.]}
4236 @end{Discussion}
4237
4238 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]}
4239 @ChgAdded{Version=[2],Text=[@Defn2{Term=[restrictions],
4240 Sec=(No_Implementation_Attributes)}@Chg{Version=[3],New=[@Defn{No_Implementation_Attributes restriction}],
4241 Old=[]}No_Implementation_Attributes @\There
4242 are no implementation-defined attributes. This restriction applies
4243 only to the current compilation or environment, not the entire partition.]}
4244 @begin{Discussion}
4245 @ChgRef{Version=[2],Kind=[AddedNormal]}
4246 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0241-1]}
4247 @ChgDeleted{Version=[3],Text=[@Chg{Version=[2],New=[This restriction (as well as No_Implementation_Pragmas)
4248 only applies to the current compilation, because it is likely that the
4249 runtime (and possibly user-written low-level code) will need to use
4250 implementation-defined entities. But a partition-wide restriction applies
4251 everywhere, including the runtime.],Old=[]}]}
4252 @end{Discussion}
4253
4254 @Comment{The end part of this and the bullets are Redundant, but that would
4255 cause bad nesting, so we don't mark it}
4256 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0246-1],ARef=[AI05-0269-1]}
4257 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4258 Sec=(No_Implementation_Identifiers)}@Defn{No_Implementation_Identifiers restriction}No_Implementation_Identifiers
4259 @\There are no usage names that denote declarations with
4260 implementation-defined identifiers that occur within language-defined
4261 packages or instances of language-defined generic packages.
4262 Such identifiers can arise as follows:]}
4263 @begin{Itemize}
4264 @ChgRef{Version=[3],Kind=[Added]}
4265 @ChgAdded{Version=[3],Type=[Leading],Text=[The following language-defined
4266 packages and generic packages allow implementation-defined identifiers:]}
4267
4268 @begin{InnerItemize}
4269 @ChgRef{Version=[3],Kind=[Added]}
4270 @ChgAdded{Version=[3],Text=[package System (see
4271 @RefSecNum{The Package System});]}
4272
4273 @ChgRef{Version=[3],Kind=[Added]}
4274 @ChgAdded{Version=[3],Text=[package Standard (see
4275 @RefSecNum{The Package Standard});]}
4276
4277 @ChgRef{Version=[3],Kind=[Added]}
4278 @ChgAdded{Version=[3],Text=[package Ada.Command_Line (see
4279 @RefSecNum{The Package Command_Line});]}
4280
4281 @ChgRef{Version=[3],Kind=[Added]}
4282 @ChgAdded{Version=[3],Text=[package Interfaces.C (see
4283 @RefSecNum{Interfacing with C and C++});]}
4284
4285 @ChgRef{Version=[3],Kind=[Added]}
4286 @ChgAdded{Version=[3],Text=[package Interfaces.C.Strings (see
4287 @RefSecNum{The Package Interfaces.C.Strings});]}
4288
4289 @ChgRef{Version=[3],Kind=[Added]}
4290 @ChgAdded{Version=[3],Text=[package Interfaces.C.Pointers (see
4291 @RefSecNum{The Generic Package Interfaces.C.Pointers});]}
4292
4293 @ChgRef{Version=[3],Kind=[Added]}
4294 @ChgAdded{Version=[3],Text=[package Interfaces.COBOL (see
4295 @RefSecNum{Interfacing with COBOL});]}
4296
4297 @ChgRef{Version=[3],Kind=[Added]}
4298 @ChgAdded{Version=[3],Text=[package Interfaces.Fortran (see
4299 @RefSecNum{Interfacing with Fortran});]}
4300 @end{InnerItemize}
4301
4302 @ChgRef{Version=[3],Kind=[Added]}
4303 @ChgAdded{Version=[3],Type=[Leading],Text=[The following language-defined
4304 packages contain only implementation-defined identifiers:]}
4305
4306 @begin{InnerItemize}
4307 @ChgRef{Version=[3],Kind=[Added]}
4308 @ChgAdded{Version=[3],Text=[package System.Machine_Code (see
4309 @RefSecNum{Machine Code Insertions});]}
4310
4311 @ChgRef{Version=[3],Kind=[Added]}
4312 @ChgAdded{Version=[3],Text=[package Ada.Directories.Information (see
4313 @RefSecNum{The Package Directories});]}
4314
4315 @ChgRef{Version=[3],Kind=[Added]}
4316 @ChgAdded{Version=[3],Text=[nested Implementation packages of the Queue
4317 containers (see @RefSecNum{The Generic Package Containers.Unbounded_Synchronized_Queues}-31);]}
4318
4319 @ChgRef{Version=[3],Kind=[Added]}
4320 @ChgAdded{Version=[3],Text=[package Interfaces (see
4321 @RefSecNum{The Package Interfaces});]}
4322
4323 @ChgRef{Version=[3],Kind=[Added]}
4324 @ChgAdded{Version=[3],Text=[package Ada.Interrupts.Names (see
4325 @RefSecNum{The Package Interrupts}).]}
4326
4327 @end{InnerItemize}
4328
4329 @end{Itemize}
4330
4331 @ChgRef{Version=[3],Kind=[Added]}
4332 @ChgAdded{Version=[3],NoPrefix=[T],Text=[For package Standard,
4333 Standard.Long_Integer and Standard.Long_Float are considered language-defined
4334 identifiers, but identifiers such as Standard.Short_Short_Integer are considered
4335 implementation-defined.]}
4336
4337 @ChgRef{Version=[3],Kind=[Added]}
4338 @ChgAdded{Version=[3],NoPrefix=[T],Text=[This restriction applies only to the
4339 current compilation or environment, not the entire partition.]}
4340
4341 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01]}
4342 @ChgAdded{Version=[2],Text=[@Defn2{Term=[restrictions],
4343 Sec=(No_Implementation_Pragmas)}@Chg{Version=[3],
4344 New=[@Defn{No_Implementation_Pragmas restriction}],
4345 Old=[]}No_Implementation_Pragmas @\There are no
4346 implementation-defined pragmas or pragma arguments. This restriction applies
4347 only to the current compilation or environment, not the entire partition.]}
4348
4349 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0242-1]}
4350 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4351 Sec=(No_Implementation_Units)}@Defn{No_Implementation_Units restriction}No_Implementation_Units @\There
4352 is no mention in the @nt{context_clause} of any implementation-defined
4353 descendants of packages Ada, Interfaces, or System. This restriction applies
4354 only to the current compilation or environment, not the entire partition.]}
4355
4356 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00368-01]}
4357 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
4358 @ChgAdded{Version=[2],Text=[@Defn2{Term=[restrictions],
4359 Sec=(No_Obsolescent_Features)}@Chg{Version=[3],New=[@Defn{No_Obsolescent_Features restriction}],
4360 Old=[]}No_Obsolescent_Features @\There
4361 is no use of language features defined in Annex J. It is
4362 @Chg{Version=[3],New=[implementation defined whether],
4363 Old=[implementation-defined if]} uses of the renamings of
4364 @RefSecNum{Renamings of Library Units} @Chg{Version=[3],New=[and of the
4365 @nt{pragma}s of @RefSecNum{Aspect-related Pragmas} ],Old=[]}are detected
4366 by this restriction. This restriction applies only to the current
4367 compilation or environment, not the entire partition.]}
4368 @begin{Reason}
4369 @ChgRef{Version=[2],Kind=[AddedNormal]}
4370 @ChgAdded{Version=[2],Type=[Leading],Text=[A user could compile a rename
4371 like]}
4372 @begin{Example}
4373 @ChgRef{Version=[2],Kind=[AddedNormal]}
4374 @ChgAdded{Version=[2],Text=[@key{with} Ada.Text_IO;
4375 @key{package} Text_IO @key{renames} Ada.Text_IO;]}
4376 @end{Example}
4377 @ChgRef{Version=[2],Kind=[AddedNormal]}
4378 @ChgAdded{Version=[2],Text=[Such a rename must not be disallowed
4379 by this restriction, nor should the compilation of such a rename be
4380 restricted by an implementation. Many implementations implement the renames
4381 of @RefSecNum{Renamings of Library Units}
4382 by compiling them normally; we do not want to require implementations to use
4383 a special mechanism to implement these renames.]}
4384
4385 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
4386 @ChgAdded{Version=[3],Text=[The pragmas have the same functionality as the
4387 corresponding aspect (unlike the typical obsolescent feature), and rejecting
4388 them could be a significant portability problem for existing code.]}
4389 @end{Reason}
4390 @end{Description}
4391
4392 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4393 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0241-1]}
4394 @ChgAdded{Version=[2],Type=[Leading],Text=[The following
4395 @SynI{restriction_parameter_}@nt{identifier}@Chg{Version=[3],New=[s are],Old=[is]}
4396 language defined:]}
4397
4398 @begin{Description}
4399
4400 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4401 @ChgAdded{Version=[2],Text=[@Defn2{Term=[restrictions],Sec=(No_Dependence)}@Defn{No_Dependence restriction}No_Dependence @\Specifies
4402 a library unit on which there are no semantic dependences.]}
4403
4404 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0241-1]}
4405 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4406 Sec=(No_Specification_of_Aspect)}@Defn{No_Specification_of_Aspect restriction}No_Specification_of_Aspect
4407 @\Identifies an aspect for which no
4408 @nt{aspect_specification}, @nt{attribute_definition_clause}, or @nt{pragma}
4409 is given.]}
4410
4411 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0272-1]}
4412 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4413 Sec=(No_Use_Of_Attribute)}@Defn{No_Use_Of_Attribute restriction}No_Use_Of_Attribute
4414 @\Identifies an attribute for which no @nt{attribute_reference} or
4415 @nt{attribute_definition_clause} is given.]}
4416
4417 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0272-1]}
4418 @ChgAdded{Version=[3],Text=[@Defn2{Term=[restrictions],
4419 Sec=(No_Use_Of_Pragma)}@Defn{No_Use_Of_Pragma restriction}No_Use_Of_Pragma
4420 @\Identifies a @nt{pragma} which is not to be used.]}
4421
4422 @end{Description}
4423 @end{StaticSem}
4424
4425 @begin{Legality}
4426
4427 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4428 @ChgAdded{Version=[2],Text=[The @nt{restriction_parameter_argument} of a
4429 No_Dependence restriction shall be a @nt{name}; the @nt{name} shall have
4430 the form of a full expanded name of a library unit, but need not denote a unit
4431 present in the environment.]}
4432
4433 @begin{Ramification}
4434 @ChgRef{Version=[2],Kind=[AddedNormal]}
4435 @ChgAdded{Version=[2],Text=[This @nt{name} is not resolved.]}
4436 @end{Ramification}
4437
4438 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0241-1]}
4439 @ChgAdded{Version=[3],Text=[The @nt{restriction_parameter_argument} of a
4440 No_Specification_of_Aspect restriction shall be an @nt{identifier}; this
4441 is an identifier specific to a pragma (see @RefSecNum{Pragmas}) and
4442 does not denote any declaration.]}
4443
4444 @begin{Ramification}
4445 @ChgRef{Version=[3],Kind=[AddedNormal]}
4446 @ChgAdded{Version=[3],Text=[This @nt{restriction_parameter_argument} is not
4447 resolved as it is an identifier specific to a pragma. As
4448 for No_Dependence, there is no check that the aspect
4449 @nt{identifier} is meaningful; it might refer to an implementation-defined
4450 aspect on one implementation, but nothing at all on another implementation.]}
4451 @end{Ramification}
4452
4453 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0272-1]}
4454 @ChgAdded{Version=[3],Text=[The @nt{restriction_parameter_argument} of a
4455 No_Use_Of_Attribute restriction
4456 shall be an @nt{identifier} or one of the reserved words Access, Delta, Digits,
4457 Mod, or Range; this is an identifier specific to a pragma.]}
4458
4459 @begin{Ramification}
4460 @ChgRef{Version=[3],Kind=[AddedNormal]}
4461 @ChgAdded{Version=[3],Text=[This @nt{restriction_parameter_argument} is not
4462 resolved as it is an identifier specific to a pragma. There is no check that
4463 the attribute identifier refers to a known @nt{attribute_designator};
4464 it might refer to an implementation-defined
4465 attribute on one implementation, but nothing at all on another implementation.]}
4466 @end{Ramification}
4467
4468 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0272-1]}
4469 @ChgAdded{Version=[3],Text=[The @nt{restriction_parameter_argument} of a
4470 No_Use_Of_Pragma restriction
4471 shall be an @nt{identifier} or the reserved word Interface;
4472 this is an identifier specific to a pragma.]}
4473
4474 @begin{Ramification}
4475 @ChgRef{Version=[3],Kind=[AddedNormal]}
4476 @ChgAdded{Version=[3],Text=[This @nt{restriction_parameter_argument} is not
4477 resolved as it is an identifier specific to a pragma. There is no check that
4478 the pragma identifier refers to a known @nt{pragma};
4479 it might refer to an implementation-defined pragma on one implementation,
4480 but nothing at all on another implementation.]}
4481 @end{Ramification}
4482
4483 @end{Legality}
4484
4485 @begin{LinkTime}
4486
4487 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4488 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0241-1]}
4489 @ChgAdded{Version=[2],Text=[No compilation unit included in the partition shall
4490 depend semantically on the library unit identified by the
4491 @nt{name}@Chg{Version=[3],New=[ of a No_Dependence restriction],Old=[]}.]}
4492
4493 @begin{Ramification}
4494 @ChgRef{Version=[2],Kind=[AddedNormal]}
4495 @ChgAdded{Version=[2],Text=[There is no requirement that the library unit
4496 actually exist. One possible use of the pragma is to prevent the use of
4497 implementation-defined units; when the program is ported to a different
4498 compiler, it is perfectly reasonable that no unit with the name exist.]}
4499 @end{Ramification}
4500
4501 @end{LinkTime}
4502
4503 @begin{StaticSem}
4504 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0246-1]}
4505 @ChgAdded{Version=[3],Type=[Leading],Text=[The following
4506 @SynI{profile_}@nt{identifier} is language defined:]}
4507
4508 @begin{Description}
4509
4510 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0246-1]}
4511 @ChgAdded{Version=[3],Text=[@Defn2{Term=[profile],Sec=(No_Implementation_Extensions)}No_Implementation_Extensions @\]}
4512
4513 @end{Description}
4514
4515 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0246-1]}
4516 @ChgAdded{Version=[3],Text=[For usage profile No_Implementation_Extensions,
4517 there shall be no @SynI{profile_}@nt{pragma_argument_association}s.]}
4518
4519 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0246-1]}
4520 @ChgAdded{Version=[3],Type=[Leading],Text=[The No_Implementation_Extensions
4521 usage profile is equivalent to the following restrictions:]}
4522 @begin{Example}
4523 @ChgRef{Version=[3],Kind=[AddedNormal]}
4524 @ChgAdded{Version=[3],Text=[No_Implementation_Aspect_Specifications,
4525 No_Implementation_Attributes,
4526 No_Implementation_Identifiers,
4527 No_Implementation_Pragmas,
4528 No_Implementation_Units.]}
4529 @end{Example}
4530 @end{StaticSem}
4531
4532 @begin{Extend95}
4533 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00257-01],ARef=[AI95-00368-01]}
4534 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4535 Restrictions No_Implementation_Attributes, No_Implementation_Pragmas, and
4536 No_Obsolescent_Features are new.]}
4537
4538 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00381-01]}
4539 @ChgAdded{Version=[2],Text=[Restriction No_Dependence is new.]}
4540 @end{Extend95}
4541
4542 @begin{Extend2005}
4543 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0241-1],ARef=[AI05-0242-1],ARef=[AI05-0246-1],ARef=[AI05-0272-1]}
4544 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4545 Restrictions No_Implementation_Aspect_Specifications, No_Implementation_Identifiers,
4546 No_Implementation_Units, No_Specification_of_Aspect, No_Use_of_Attribute, and
4547 No_Use_of_Pragma are new.]}
4548
4549 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0246-1]}
4550 @ChgAdded{Version=[3],Text=[Profile No_Implementation_Extensions is new.]}
4551 @end{Extend2005}
4552
4553
4554 @LabeledClause{Streams}
4555
4556 @begin{Intro}
4557 @Defn{stream}
4558 @Defn{stream type}
4559 A @i{stream} is a sequence of elements comprising values from
4560 possibly different types and allowing sequential access to these values.
4561 A @i{stream type} is a type in the class whose root type is
4562 Streams.Root_Stream_Type.
4563 A stream type may be implemented in various ways,
4564 such as an external sequential file, an internal buffer,
4565 or a network channel.
4566 @begin{Discussion}
4567 A stream element will often be the same size as a storage element,
4568 but that is not required.
4569 @end{Discussion}
4570
4571 @ChgToGlossary{Version=[3],Kind=[Added],Term=<Stream>,
4572 Text=<@ChgAdded{Version=[3],Text=[A stream is a sequence of elements that can be
4573 used, along with the stream-oriented attributes, to support marshalling and
4574 unmarshalling of values of most types.]}>}
4575
4576 @end{Intro}
4577
4578 @begin{Extend83}
4579 @Defn{extensions to Ada 83}
4580 Streams are new in Ada 95.
4581 @end{Extend83}
4582
4583 @LabeledSubClause{The Package Streams}
4584
4585 @begin{StaticSem}
4586 The abstract type Root_Stream_Type is the root type of the class of
4587 stream types. The types in this class represent different kinds of
4588 streams. A new stream type is defined by extending the root type
4589 (or some other stream type), overriding the Read and Write
4590 operations, and optionally defining additional primitive
4591 subprograms,
4592 according to the requirements of the particular kind of stream.
4593 The predefined stream-oriented attributes like T'Read and T'Write
4594 make dispatching
4595 calls on the Read and Write procedures of the Root_Stream_Type.
4596 (User-defined T'Read and T'Write attributes can also make such calls,
4597 or can call the Read and Write attributes of other types.)
4598 @begin{example}
4599 @ChildUnit{Parent=[Ada],Child=[Streams]}@key[package] Ada.Streams @key[is]
4600 @key[pragma] Pure(Streams)@Defn{unpolluted};@Comment{This *must* be a Duff joke}
4601
4602 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]}
4603 @key[type] @AdaTypeDefn{Root_Stream_Type} @key[is] @key[abstract tagged limited private];@Chg{Version=[2],New=[
4604 @key[pragma] Preelaborable_Initialization(Root_Stream_Type);],Old=[]}
4605
4606 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0044],ARef=[AI95-00181-01]}
4607 @key[type] @AdaTypeDefn{Stream_Element} @key[is] @key[mod] @RI{implementation-defined};
4608 @key[type] @AdaTypeDefn{Stream_Element_Offset} @key[is] @key[range] @RI{implementation-defined};
4609 @key[subtype] @AdaSubtypeDefn{Name=[Stream_Element_Count],Of=[Stream_Element_Offset]} @key[is]
4610 Stream_Element_Offset @key[range] 0..Stream_Element_Offset'Last;
4611 @key[type] @AdaTypeDefn{Stream_Element_Array} @key[is]
4612 @key[array](Stream_Element_Offset @key[range] <>) @key[of]@Chg{New=[@key[ aliased]],Old=[]} Stream_Element;
4613
4614 @key[procedure] @AdaSubDefn{Read}(
4615 Stream : @key[in] @key[out] Root_Stream_Type;
4616 Item : @key[out] Stream_Element_Array;
4617 Last : @key[out] Stream_Element_Offset) @key[is abstract];
4618
4619 @key[procedure] @AdaSubDefn{Write}(
4620 Stream : @key[in] @key[out] Root_Stream_Type;
4621 Item : @key[in] Stream_Element_Array) @key[is abstract];
4622
4623 @key[private]
4624 ... -- @RI{not specified by the language}
4625 @key[end] Ada.Streams;
4626 @end{example}
4627
4628 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00227-01]}
4629 The Read operation transfers @Chg{Version=[2],New=[],Old=[Item'Length ]}stream
4630 elements from the specified stream to fill the array Item.
4631 @Chg{Version=[2],New=[Elements are transferred until Item'Length elements have
4632 been transferred, or until the end of the stream is reached. If any elements
4633 are transferred, the],Old=[The]} index of the last stream element transferred is
4634 returned in Last. @Chg{Version=[2],New=[Otherwise, Item'First - 1 is returned
4635 in Last. ],Old=[]}Last is less than Item'Last only if the end of the stream is
4636 reached.@Comment{This last sentence should be marked Redundant.}
4637
4638 The Write operation appends Item to the specified stream.
4639
4640 @begin{Discussion}
4641 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
4642 @ChgNote{This was moved from 13.7.1.}
4643 @ChgAdded{Version=[2],Text=[The index subtype of Stream_Element_Array is
4644 Stream_Element_Offset because we wish to allow maximum flexibility. Most
4645 Stream_Element_Arrays will probably have a lower bound of 0 or 1, but other
4646 lower bounds, including negative ones, make sense in some situations.]}
4647
4648 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
4649 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
4650 @ChgNote{This was moved from 13.7.1, where it was totally bogus.}
4651 @ChgAdded{Version=[2],Text=[Note that there are some language-defined
4652 subprograms that fill part of a Stream_Element_Array, and return the index of the
4653 last element filled as a Stream_Element_Offset. The Read procedures declared
4654 here, Streams.Stream_IO (see @RefSecNum{The Package Streams.Stream_IO}),
4655 and System.RPC (see @RefSecNum{Partition Communication Subsystem})
4656 behave in this manner.
4657 These will raise Constraint_Error if the resulting Last value is not in
4658 Stream_Element_Offset.
4659 This implies that the Stream_Element_Array passed to these subprograms should
4660 not have a lower bound of Stream_Element_Offset'First,
4661 because then a read of 0 elements would always raise Constraint_Error.
4662 A better choice of lower bound is @Chg{Version=[3],New=[0 or ],Old=[]}1.]}
4663 @end{Discussion}
4664
4665 @end{StaticSem}
4666
4667 @begin{ImplPerm}
4668 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0044],ARef=[AI95-00181-01]}
4669 @ChgAdded{Version=[1],Text=[If Stream_Element'Size is not a multiple of
4670 System.Storage_Unit, then the components of Stream_@!Element_@!Array need
4671 not be aliased.]}
4672 @begin{Ramification}
4673 @ChgRef{Version=[1],Kind=[Added]}
4674 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]}
4675 @ChgAdded{Version=[1],Text=[If the Stream_Element'Size is less than the size of
4676 System.Storage_Unit, then components of Stream_@!Element_@!Array need not be
4677 aliased. This is necessary as the components of type Stream_Element size might
4678 not be addressable on the target @Chg{Version=[2],New=[architecture],Old=[architechture]}.]}
4679 @end{Ramification}
4680 @end{ImplPerm}
4681
4682 @begin{Notes}
4683 See @RefSec{The Package Streams.Stream_IO} for an example of extending
4684 type Root_Stream_Type.
4685
4686 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00227-01]}
4687 @ChgAdded{Version=[2],Text=[If the end of stream has been reached, and
4688 Item'First is Stream_Element_Offset'First, Read will raise Constraint_Error.]}
4689 @begin{Ramification}
4690 @ChgRef{Version=[2],Kind=[AddedNormal]}
4691 @ChgAdded{Version=[2],Text=[Thus, Stream_Element_Arrays should start at 0 or
4692 1, not Stream_Element_Offset'First.]}
4693 @end{Ramification}
4694 @end{Notes}
4695
4696 @begin{Extend95}
4697 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
4698 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4699 @b[Amendment Correction:] Added @nt{pragma} Preelaborable_Initialization
4700 to type Root_Stream_Type.]}
4701 @end{Extend95}
4702
4703 @begin{DiffWord95}
4704 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0044],ARef=[AI95-00181-01]}
4705 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Stream elements are aliased
4706 presuming that makes sense.]}
4707
4708 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00227-01]}
4709 @ChgAdded{Version=[2],Text=[Fixed the wording for Read to properly define
4710 the result in Last when no stream elements are transfered.]}
4711 @end{DiffWord95}
4712
4713
4714 @LabeledSubClause{Stream-Oriented Attributes}
4715
4716 @begin{Intro}
4717 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
4718 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
4719 The @Chg{Version=[3],New=[type-related ],Old=[]}@Chg{New=[operational
4720 attributes ],Old=[]}Write, Read, Output, and
4721 Input @Chg{New=[],Old=[attributes ]}convert values to a
4722 stream of elements and reconstruct values from a
4723 stream.@Defn{stream-oriented attributes}@Defn2{Term=[attribute],Sec=[stream-oriented]}
4724 @end{Intro}
4725
4726 @begin{StaticSem}
4727
4728 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
4729 @ChgAdded{Version=[2],Type=[Leading],Text=[For @PrefixType{every subtype S of
4730 an elementary type @i(T)}, the following representation attribute is defined:]}
4731 @begin{Description}
4732
4733 @Comment{Originally Version=[2],Kind=[Added]}
4734 @ChgAttribute{Version=[3],Kind=[RevisedAdded],ChginAnnex=[T],
4735 Leading=<T>, Prefix=<S>, AttrName=<Stream_Size>, ARef=[AI95-00270-01], ARef=[AI05-0194-1],
4736 InitialVersion=[2], Text=[@Chg{Version=[2],New=[Denotes the number of bits
4737 @Chg{Version=[3],New=[read from or written to a stream by the
4738 default implementations of S'Read and S'Write],Old=[occupied
4739 in a stream by items of subtype S]}. Hence, the number of stream elements
4740 required per item of elementary type @i<T> is:],Old=[]}
4741
4742 @begin(Descexample)
4743 @ChgRef{Version=[2],Kind=[Added]}
4744 @ChgAdded{Version=[2],Text=[@i<T>'Stream_Size / Ada.Streams.Stream_Element'Size]}
4745 @end(Descexample)
4746
4747 @ChgRef{Version=[2],Kind=[Added]}
4748 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The value of this attribute is of
4749 type @i{universal_integer} and is a multiple of Stream_Element'Size.]}]}@Comment{end attribute Stream_Size}
4750
4751 @ChgRef{Version=[2],Kind=[Added]}
4752 @ChgAdded{Version=[2],NoPrefix=[T],Text=[Stream_Size may be specified for
4753 first subtypes via an @nt{attribute_definition_clause}; the @nt{expression}
4754 of such a clause shall be static, nonnegative, and a multiple of
4755 Stream_Element'Size.@Chg{Version=[3],New=[@AspectDefn{Stream_Size}],Old=[]}]}
4756
4757 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Stream_Size],
4758 Text=[@ChgAdded{Version=[3],Text=[Size in bits used to represent elementary
4759 objects in a stream.]}]}
4760
4761 @end{Description}
4762 @EndPrefixType{}
4763
4764 @begin{Discussion}
4765 @ChgRef{Version=[2],Kind=[AddedNormal]}
4766 @ChgAdded{Version=[2],Text=[Stream_Size is a type-related attribute (see
4767 @RefSecNum{Operational and Representation Aspects}).]}
4768 @end{Discussion}
4769
4770 @begin{Ramification}
4771 @ChgRef{Version=[3],Kind=[AddedNormal], ARef=[AI05-0194-1]}
4772 @ChgAdded{Version=[3],Text=[The value of S'Stream_Size is unaffected by the
4773 presence or absence of any @nt{attribute_definition_clause}s or
4774 @nt{aspect_specification}s specifying the Read or Write attributes of any
4775 ancestor of S. S'Stream_Size is defined in terms of the behavior of the
4776 default implementations of S'Read and S'Write even if those default
4777 implementations are overridden.]}
4778 @end{Ramification}
4779 @end{StaticSem}
4780
4781 @begin{ImplAdvice}
4782
4783 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
4784 @ChgAdded{Version=[2],Text=[If not specified, the value of Stream_Size for an
4785 elementary type should be the number of bits that corresponds to the
4786 minimum number of stream elements required by the
4787 first subtype of the type, rounded up to the nearest factor or multiple of the
4788 word size that is also a multiple of the stream element size.]}
4789 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4790 Text=[If not specified, the value of Stream_Size for an
4791 elementary type should be the number of bits that corresponds to the
4792 minimum number of stream elements required by the
4793 first subtype of the type, rounded up to the nearest factor or multiple of the
4794 word size that is also a multiple of the stream element size.]}]}
4795 @begin{Reason}
4796 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00270-01]}
4797 @ChgAdded{Version=[2],Text=[This is @ImplAdviceTitle because we want to
4798 allow implementations to remain compatible with their Ada 95 implementations,
4799 which may have a different handling of the number of stream elements. Users
4800 can always specify Stream_Size if they need a specific number of stream
4801 elements.]}
4802 @end{Reason}
4803
4804 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
4805 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[@PDefn2{Term=[recommended level of support],
4806 Sec=(Stream_Size attribute)}
4807 The recommended level of support for the Stream_Size attribute is:]}
4808 @begin{Itemize}
4809
4810 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
4811 @ChgAdded{Version=[2],Text=[A Stream_Size clause should be supported for a
4812 discrete or fixed point type @i<T> if the specified Stream_Size is a multiple
4813 of Stream_Element'Size and is no less than the size of the first subtype
4814 of @i<T>, and no greater than the size of the largest type of the same
4815 elementary class (signed integer, modular integer, enumeration,
4816 ordinary fixed point, or decimal fixed point).]}
4817 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4818 Text=[The recommended level of support for the Stream_Size attribute should be
4819 followed.]}]}
4820 @begin{Ramification}
4821 @ChgRef{Version=[2],Kind=[AddedNormal]}
4822 @ChgAdded{Version=[2],Text=[There are no requirements beyond supporting
4823 confirming Stream_Size clauses for floating point and access types.
4824 Floating point and access types usually only have a handful of defined
4825 formats, streaming anything else makes no sense for them.]}
4826
4827 @ChgRef{Version=[2],Kind=[AddedNormal]}
4828 @ChgAdded{Version=[2],Text=[For discrete and fixed point types, this
4829 may require support for sizes other than the @lquotes@;natural@rquotes
4830 ones. For instance, on a typical machine with 32-bit integers and a
4831 Stream_Element'Size of 8, setting Stream_Size to 24 must be supported.
4832 This is required as such formats can be useful for interoperability with
4833 unusual machines, and there is no difficulty with the implementation
4834 (drop extra bits on output, sign extend on input).]}
4835 @end{Ramification}
4836
4837 @end{Itemize}
4838 @end{ImplAdvice}
4839
4840 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
4841 @begin{StaticSem}
4842
4843 For @PrefixType{every subtype S of a specific type @i(T)},
4844 the following attributes are defined.
4845 @begin{Description}
4846 @AttributeLeading{Prefix=<S>, AttrName=<Write>,
4847 Text=<S'Write denotes a procedure with the following specification:
4848 @begin{DescExample}
4849 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
4850 @key(procedure) S'Write(
4851 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
4852 @RI{Item} : @key{in} @RI(T))
4853 @end{DescExample}
4854
4855 @noprefix@;S'Write writes the value of @i{Item} to @i{Stream}.>}
4856
4857 @AttributeLeading{Prefix=<S>, AttrName=<Read>,
4858 Text=<S'Read denotes a procedure with the following specification:
4859 @begin{DescExample}
4860 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
4861 @key(procedure) S'Read(
4862 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
4863 @RI{Item} : @key{out} @RI(T))
4864 @end{DescExample}
4865
4866 @noprefix@;S'Read reads the value of @i{Item} from @i{Stream}.>}
4867 @end{Description}
4868 @EndPrefixType{}
4869
4870
4871 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
4872 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00444-01]}
4873 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0192-1]}
4874 @ChgAdded{Version=[1],Text=[For @Chg{Version=[2],New=[an ],Old=[]}untagged
4875 derived @Chg{Version=[2],New=[type],Old=[types]}, the Write
4876 @Chg{Version=[2],New=[(resp.],Old=[and]}
4877 Read@Chg{Version=[2],New=[) attribute is],Old=[ attributes are]}
4878 inherited @Chg{Version=[2],New=[according to the rules given],Old=[as specified]}
4879 in @RefSecNum{Operational and Representation Aspects}@Chg{Version=[2],
4880 New=[ if the attribute is @Chg{Version=[3],New=[@Redundant[specified and] ],
4881 Old=[]}available for the parent type at the point
4882 where @i{T} is declared. For a tagged derived type, these attributes are
4883 not inherited, but rather],Old=[; otherwise,]} the default
4884 implementations @Chg{Version=[2],New=[],Old=[of these attributes ]}are
4885 used.@Chg{Version=[2],New=[],Old=[The default implementations of Write and
4886 Read attributes execute as follows:]}]}
4887
4888 @begin{TheProof}
4889 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0192-1]}
4890 @ChgAdded{Version=[3],Text=[The inheritance rules of
4891 @RefSecNum{Operational and Representation Aspects} say that only specified or
4892 inherited aspects are inherited; we mention it again here as a clarification.]}
4893 @end{TheProof}
4894
4895 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]}
4896 @ChgAdded{Version=[2],Type=[Leading],Text=[The default implementations of
4897 the Write and Read attributes, where available, execute as follows:]}
4898
4899 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]}
4900 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01],ARef=[AI95-00251-01],ARef=[AI95-00270-01]}
4901 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0139-2]}
4902 For elementary types, @Chg{Version=[2],New=[Read reads (and Write writes) the
4903 number of stream elements implied by the Stream_Size for the type @i<T>;],
4904 Old=[]} the representation @Chg{Version=[2],New=[],Old=[in terms ]}of@Chg{Version=[2],
4905 New=[ those],Old=[]} stream elements is implementation defined.
4906 For composite types, the Write or Read attribute for each component is
4907 called in @Chg{New=[],Old=[a ]}canonical order@Chg{New=[, which],
4908 Old=[. The canonical order of components]} is last dimension varying
4909 fastest for an array@Chg{Version=[3],New=[ (unless the convention of the array is
4910 Fortran, in which case it is first dimension varying fastest)],Old=[]},
4911 and positional aggregate order for a record.
4912 Bounds are not included in the stream if @i(T) is an array type.
4913 If @i(T) is a discriminated type, discriminants are included only if they have
4914 defaults. If @i(T) is a tagged type, the tag is not included.
4915 @Chg{New=[For type extensions, the Write or Read attribute for the parent type
4916 is called, followed by the Write or Read attribute of each component of the
4917 extension part, in canonical order. For a limited type extension, if the
4918 attribute of @Chg{Version=[2],New=[the parent],Old=[any ancestor]} type
4919 @Chg{Version=[2],New=[or any progenitor type ],Old=[]}of
4920 @i(T) @Chg{Version=[2],New=[is available anywhere within the immediate scope
4921 of @i<T>,],Old=[has been directly specified]} and the attribute
4922 of @Chg{Version=[2],New=[the parent type or],Old=[any ancestor type of]} the
4923 type of any of the extension components
4924 @Chg{Version=[2],New=[is not available at the freezing point of @i<T>, then],
4925 Old=[which are of a limited type has not been specified,]}
4926 the attribute of @i(T) shall be directly specified.],Old=[]}
4927
4928 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
4929 Text=[The @Chg{Version=[2],New=[contents
4930 of the stream elements read and written],Old=[representation used]} by the
4931 Read and Write attributes of elementary types@Chg{Version=[2],New=[],Old=[ in
4932 terms of stream elements]}.]}
4933
4934 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0023-1],ARef=[AI05-0264-1]}
4935 @ChgAdded{Version=[3],Text=[If @i<T> is a discriminated type and its
4936 discriminants have defaults, then
4937 S'Read first reads the discriminants from the stream without modifying
4938 @i<Item>. S'Read then creates an object of type @i<T> constrained by these
4939 discriminants. The value of this object is then converted to the subtype
4940 of @i<Item> and is assigned to @i<Item>. Finally, the Read attribute for each
4941 nondiscriminant component of @i<Item> is called in canonical
4942 order as described above. Normal default initialization and finalization
4943 take place for the created object.]}
4944
4945 @begin{Reason}
4946 A discriminant with a default value is treated simply as
4947 a component of the object. On the other hand,
4948 an array bound or a discriminant without a default value,
4949 is treated as @lquotes@;descriptor@rquotes@; or @lquotes@;dope@rquotes@;
4950 that must be provided in order to create the object and thus is logically
4951 separate from the regular components. Such @lquotes@;descriptor@rquotes@;
4952 data are written by 'Output and produced as part of the delivered result by
4953 the 'Input function, but they are not written by 'Write nor read by 'Read.
4954 A tag is like a discriminant without a default.
4955
4956 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
4957 @ChgAdded{Version=[1],Text=[For limited type extensions, we must have a
4958 definition of 'Read and 'Write if the parent type has one, as it is possible
4959 to make a dispatching call through the attributes. The rule is designed to
4960 automatically do the right thing in as many cases as possible.]}
4961
4962 @ChgRef{Version=[1],Kind=[Added],ARef=[AI95-00251-01]}
4963 @ChgAdded{Version=[1],Text=[Similarly, a type that has a progenitor
4964 with an available attribute must also have that attribute, for the
4965 same reason.]}
4966
4967 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0023-1]}
4968 @ChgAdded{Version=[3],Text=[The semantics of S'Read for a discriminated
4969 type with defaults involves an anonymous object so that the
4970 point of required initialization and finalization is well-defined,
4971 especially for objects that change shape and have controlled components.
4972 The creation of this anonymous object often can be omitted (see the
4973 @ImplPermTitle below).]}
4974 @end{Reason}
4975 @begin{Ramification}
4976 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]}
4977 For a composite object, the subprogram denoted by the
4978 Write or Read attribute of each component is called, whether it is the
4979 default or is user-specified.@Chg{Version=[2],New=[ Implementations are
4980 allowed to optimize these calls (see below), presuming the properties
4981 of the attributes are preserved.],Old=[]}
4982 @end{Ramification}
4983
4984 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00270-01]}
4985 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]}
4986 @ChgAdded{Version=[2],Text=[Constraint_Error is raised by the predefined Write
4987 attribute if the value of the elementary item is outside the range of values
4988 representable using Stream_Size bits. For a signed integer type, an enumeration
4989 type, or a fixed point type, the range is unsigned only if the integer code for
4990 the lower bound of the first subtype is nonnegative, and a (symmetric) signed
4991 range that covers all values of the first subtype would require more than
4992 Stream_Size bits; otherwise@Chg{Version=[3],New=[,],Old=[]} the range is signed.]}
4993
4994
4995 @Leading@;For @PrefixType{every subtype S'Class of a class-wide type
4996 @i(T)'Class}:
4997 @begin{Description}
4998 @AttributeLeading{Prefix=<S'Class>, AttrName=<Write>,
4999 Text=<S'Class'Write denotes a procedure with the following
5000 specification:
5001 @begin{DescExample}
5002 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5003 @key(procedure) S'Class'Write(
5004 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
5005 @RI{Item} : @key{in} @RI(T)'Class)
5006 @end{DescExample}
5007
5008 @noprefix@;Dispatches to the subprogram denoted by the Write attribute of
5009 the specific type identified by the tag of Item.>}
5010
5011 @AttributeLeading{Prefix=<S'Class>, AttrName=<Read>,
5012 Text=<S'Class'Read denotes a procedure with the following specification:
5013 @begin{DescExample}
5014 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5015 @key(procedure) S'Class'Read(
5016 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
5017 @RI{Item} : @key{out} @RI(T)'Class)
5018 @end{DescExample}
5019
5020 @noprefix@;Dispatches to the subprogram denoted by the Read attribute of
5021 the specific type identified by the tag of Item.>}
5022 @begin{Reason}
5023 It is necessary to have class-wide versions of Read and Write
5024 in order to avoid generic contract model violations;
5025 in a generic, we don't necessarily know at compile time whether a given
5026 type is specific or class-wide.
5027 @end{Reason}
5028 @end{Description}
5029 @EndPrefixType{}
5030 @end{StaticSem}
5031
5032 @begin{ImplAdvice}
5033 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00270-01]}
5034 @ChgDeleted{Version=[2],Text=[If a
5035 stream element is the same size as a storage element,
5036 then the normal in-memory representation should be used by Read and
5037 Write for scalar objects.
5038 Otherwise, Read and Write should use the smallest
5039 number of stream elements needed
5040 to represent all values in the base range of the scalar type.]}
5041 @ChgNote{We don't add an Implementation Advice tag here, as we're deleting this.}
5042 @end{ImplAdvice}
5043 @begin{NotIso}
5044 @ChgAdded{Version=[2],Noparanum=[T],Text=[@Shrink{@i<Paragraph 17 was
5045 deleted.>}]}@Comment{This message should be deleted if the paragraphs
5046 are ever renumbered.}
5047 @end{NotIso}
5048
5049 @begin{StaticSem}
5050 For @PrefixType{every subtype S of a specific type @i(T)},
5051 the following attributes are defined.
5052 @begin{Description}
5053 @AttributeLeading{Prefix=<S>, AttrName=<Output>,
5054 Text=<S'Output denotes a procedure with the following specification:
5055 @begin{DescExample}
5056 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5057 @key(procedure) S'Output(
5058 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
5059 @RI{Item} : @key{in} @RI(T))
5060 @end{DescExample}
5061
5062 @noprefix@;S'Output writes the value of @i{Item} to @i{Stream}, including
5063 any bounds or discriminants.>}
5064 @begin{Ramification}
5065 Note that the bounds are included even for an array type whose
5066 first subtype is constrained.
5067 @end{Ramification}
5068
5069 @AttributeLeading{Prefix=<S>, AttrName=<Input>,
5070 Text=<S'Input denotes a function with the following specification:
5071 @begin{DescExample}
5072 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5073 @key(function) S'Input(
5074 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class)
5075 @key(return) @RI(T)
5076 @end{DescExample}
5077
5078 @noprefix@;S'Input reads and returns one value from
5079 @i{Stream}, using any bounds or discriminants written by a corresponding
5080 S'Output to determine how much to read.>}
5081 @end{Description}
5082 @EndPrefixType{}
5083
5084 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]}
5085 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00444-01]}
5086 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0192-1]}
5087 @Chg{New=[For @Chg{Version=[2],New=[an ],Old=[]}untagged derived
5088 @Chg{Version=[2],New=[type],Old=[types]}, the Output
5089 @Chg{Version=[2],New=[(resp.],Old=[and]} Input@Chg{Version=[2],New=[) attribute
5090 is],Old=[attributes of the parent type are]}
5091 inherited @Chg{Version=[2],New=[according to the rules given],
5092 Old=[as specified]} in
5093 @RefSecNum{Operational and Representation Aspects}@Chg{Version=[2],
5094 New=[ if the attribute is @Chg{Version=[3],New=[@Redundant[specified and] ],
5095 Old=[]}available for the parent type at the point where @i{T}
5096 is declared. For a tagged derived type, these attributes are not
5097 inherited, but rather],Old=[; otherwise,]} the default
5098 implementations@Chg{Version=[2],New=[],Old=[ of these
5099 attributes]} are used.@Chg{Version=[2],New=[],Old=[ The default implementations of
5100 Output and Input attributes execute as follows:]}],
5101 Old=[Unless overridden by an @nt<attribute_definition_clause>, these
5102 subprograms execute as follows:]}
5103
5104 @begin{TheProof}
5105 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0192-1]}
5106 @ChgAdded{Version=[3],Text=[See the note following the inheritance rules for
5107 the Write attribute, above.]}
5108 @end{TheProof}
5109
5110 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00444-01]}
5111 @ChgAdded{Version=[2],Type=[Leading],Text=[The default implementations of the
5112 Output and Input attributes, where available, execute as follows:]}
5113 @begin(Itemize)
5114 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0269-1]}
5115 If @i(T) is an array type, S'Output first writes the bounds,
5116 and S'Input first reads the bounds.
5117 If @i(T) has discriminants without defaults, S'Output first writes
5118 the discriminants (using @Chg{Version=[3],New=[the Write attribute of the
5119 discriminant type],Old=[S'Write]} for each), and S'Input first
5120 reads the discriminants (using @Chg{Version=[3],New=[the Read attribute of the
5121 discriminant type],Old=[S'Read]} for each).
5122
5123 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]}
5124 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0023-1]}
5125 S'Output then calls S'Write to write the value of @i{Item} to the stream.
5126 S'Input then creates an object @Chg{Version=[3],New=[of type
5127 @i<T>, ],Old=[(]}with the bounds or @Chg{Version=[3],New=[(when without
5128 defaults) the ],Old=[]}discriminants, if any,
5129 taken from the stream@Chg{Version=[3],New=[],Old=[)]},
5130 @Chg{Version=[2],New=[passes],Old=[initializes]} it
5131 @Chg{Version=[2],New=[to],Old=[with]} S'Read, and returns
5132 the value of the object.@Chg{Version=[3],New=[ If @i<T> has discriminants, then this
5133 object is unconstrained if and only the discriminants have
5134 defaults.],Old=[]}@Chg{Version=[2],New=[ Normal default initialization
5135 and finalization take place for this object (see @RefSecNum{Object Declarations},
5136 @RefSecNum{Assignment and Finalization}, and
5137 @RefSecNum{Completion and Finalization}).],Old=[]}
5138 @end(Itemize)
5139
5140 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
5141 @ChgAdded{Version=[2],Text=[If @i<T> is an abstract type, then S'Input is
5142 an abstract function.]}
5143
5144 @begin{Ramification}
5145 @ChgRef{Version=[2],Kind=[AddedNormal]}
5146 @ChgAdded{Version=[2],Text=[For an abstract type @i<T>, S'Input can be
5147 called in a dispatching call, or passed to an abstract formal
5148 subprogram. But it cannot be used in nondispatching
5149 contexts, because we don't allow objects of abstract types to exist.
5150 The designation of this function as abstract has no
5151 impact on descendants of @i<T>, as @i<T>'Input is not inherited for
5152 tagged types, but rather recreated (and the default
5153 implementation of @i<T>'Input calls @i<T>'Read, not the parent type's
5154 @i<T>'Input). Note that @i<T>'Input cannot be specified in this case, as any
5155 function with the proper profile is necessarily abstract, and specifying
5156 abstract subprograms in an @nt{attribute_definition_clause} is illegal.]}
5157 @end{Ramification}
5158
5159 @Leading@;For @PrefixType{every subtype S'Class of a class-wide type
5160 @i(T)'Class}:
5161 @begin{Description}
5162 @AttributeLeading{Prefix=<S'Class>, AttrName=<Output>,
5163 Text=<S'Class'Output denotes a procedure with the following
5164 specification:
5165 @begin{DescExample}
5166 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5167 @key(procedure) S'Class'Output(
5168 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class;
5169 @RI{Item} : @key{in} @RI(T)'Class)
5170 @end{DescExample}
5171
5172 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00344-01]}
5173 @noprefix@;First writes the external tag of @i{Item} to @i{Stream}
5174 (by calling String'Output(@Chg{Version=[2],New=[@I{Stream}, ],Old=[]}Tags.@!External_Tag(@i{Item}'Tag)@Chg{Version=[2],New=[)],Old=[]}
5175 @em see @RefSecNum{Tagged Types and Type Extensions})
5176 and then dispatches to the subprogram denoted by the Output attribute of
5177 the specific type identified by the tag.@Chg{Version=[2],New=[ Tag_Error is
5178 raised if the tag of Item identifies a type declared at an accessibility
5179 level deeper than that of S.],Old=[]}>}@Comment{End of S'Class'Output attribute}
5180 @begin{Reason}
5181 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
5182 @ChgAdded{Version=[2],Text=[We raise Tag_Error here for nested types as
5183 such a type cannot be successfully read with S'Class'Input, and it doesn't
5184 make sense to allow writing a value that cannot be read.]}
5185 @end{Reason}
5186
5187 @AttributeLeading{Prefix=<S'Class>, AttrName=<Input>,
5188 Text=<S'Class'Input denotes a function with the following specification:
5189 @begin{DescExample}
5190 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5191 @key(function) S'Class'Input(
5192 @RI{Stream} : @key{@Chg{Version=[2],New=[not null ],Old=[]}access} Ada.Streams.Root_Stream_Type'Class)
5193 @key{return} @RI(T)'Class
5194 @end{DescExample}
5195
5196 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00279-01],ARef=[AI95-00344-01]}
5197 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0109-1]}
5198 @noprefix@;First reads the external tag from @i{Stream} and determines
5199 the corresponding internal tag
5200 (by calling Tags.@Chg{Version=[2],New=[Descendant_Tag],
5201 Old=[Internal_Tag]}(String'Input(@i{Stream})@Chg{Version=[2],New=[, S'Tag],Old=[]})
5202 @Chg{Version=[2],New=[which might raise Tag_Error ],Old=[]}@em
5203 see @RefSecNum{Tagged Types and Type Extensions})
5204 and then dispatches to the subprogram denoted by the Input attribute of
5205 the specific type identified by the internal tag;
5206 returns that result.@Chg{Version=[2],New=[ If the specific type identified
5207 by the internal tag @Chg{Version=[3],New=[],Old=[is not covered by
5208 @i<T>'Class or ]}is abstract, Constraint_Error
5209 is raised.],Old=[]}>}@Comment{End S'Class'Input attribute}
5210
5211 @begin{Ramification}
5212 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0109-1]}
5213 @ChgAdded{Version=[3],Text=[Descendant_Tag will ensure that the tag it
5214 returns is covered by T'Class; Tag_Error will be raised if it would not
5215 cover T'Class.]}
5216 @end{Ramification}
5217
5218 @end{Description}
5219 @EndPrefixType{}
5220
5221 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]}
5222 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0228-1]}
5223 @IndexCheck{Range_Check}
5224 In the default implementation of Read and Input for a composite type,
5225 for each scalar component that is a discriminant or @Chg{Version=[3],New=[that
5226 has an implicit initial value],Old=[whose
5227 @nt{component_declaration} includes a @nt{default_expression}]},
5228 a check is made that the value returned by Read for the component
5229 belongs to its subtype.
5230 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
5231 Constraint_Error is raised if this check fails.
5232 For other scalar components, no check is made.
5233 For each component that is of an access type, if the implementation can
5234 detect that the value returned by Read for the component is not
5235 a value of its subtype, Constraint_Error is raised. If the value
5236 is not a value of its subtype and this error is not detected,
5237 the component has an abnormal value, and erroneous execution
5238 can result (see @RefSecNum{Data Validity}).@Chg{Version=[2],New=[ In the
5239 default implementation of Read for a composite type with defaulted
5240 discriminants, if the actual parameter of Read is constrained, a check is made
5241 that the discriminants read from the stream are equal to those of the actual
5242 parameter. Constraint_Error is raised if this check fails.],Old=[]}
5243
5244 @begin{Reason}
5245 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0228-1]}
5246 @ChgAdded{Version=[3],Text=[The check for scalar components that have an
5247 implicit initial value is to preserve our @MetaRulesName that all objects
5248 that have an implicit initial value do not become "deinitialized".]}
5249 @end{Reason}
5250
5251 @begin{Ramification}
5252 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0228-1]}
5253 @ChgAdded{Version=[3],Text=[A scalar component can have an implicit initial
5254 value if it has a default_expression, if the component's type has the
5255 Default_Value aspect specified, or if the component is that of an array type
5256 that has the Default_Component_Value aspect specified.]}
5257 @end{Ramification}
5258
5259 @begin{Honest}
5260 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0228-1]}
5261 @ChgAdded{Version=[3],Text=[An implementation should always be able to detect
5262 the error for a null value read into a component of an access subtype with
5263 a null exclusion; the "if the implementation can detect" is intended to cover
5264 nonnull access values.]}
5265 @end{Honest}
5266
5267 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5268 @ChgAdded{Version=[2],Text=[@PDefn{unspecified}It is unspecified at which point
5269 and in which order these checks are performed. In particular, if
5270 Constraint_Error is raised due to the failure of one of these checks, it is
5271 unspecified how many stream elements have been read from the stream.]}
5272
5273 @ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0045],ARef=[AI95-00132-01]}
5274 @ChgAdded{Version=[1],Text=[@Defn2{Term=[End_Error],Sec=(raised by failure of run-time check)}
5275 In the default implementation of Read and Input for a type, End_Error
5276 is raised if the end of the stream is reached before the reading of a value of
5277 the type is completed.]}
5278
5279 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0040],ARef=[AI95-00108-01]}
5280 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01],ARef=[AI95-00251-01]}
5281 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0039-1]}
5282 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0106-1],ARef=[AI12-0121-1]}
5283 @PDefn2{Term=[specifiable], Sec=(of Read for a type)}
5284 @PDefn2{Term=[specifiable], Sec=(of Write for a type)}
5285 @PDefn2{Term=[specifiable], Sec=(of Input for a type)}
5286 @PDefn2{Term=[specifiable], Sec=(of Output for a type)}
5287 @Defn{Read clause}
5288 @Defn{Write clause}
5289 @Defn{Input clause}
5290 @Defn{Output clause}
5291 The stream-oriented attributes may be specified
5292 for any type via an @nt{attribute_definition_clause}.
5293 @Chg{Version=[4],New=[@Redundant[Alternatively, each of the
5294 specific stream-oriented attributes may be specified using an
5295 @nt{aspect_specification} on any @nt{type_declaration}, with the aspect name
5296 being the corresponding attribute name.] Each of the class-wide stream-oriented
5297 attributes may be specified using an @nt{aspect_specification} for a
5298 tagged type @i<T> using the name of the stream-oriented attribute followed
5299 by 'Class; such class-wide aspects do not
5300 apply to other descendants of @i<T>.],Old=[@Chg{Version=[2],New=[The
5301 subprogram name given in such a
5302 clause shall @Chg{Version=[3],New=[statically denote a subprogram that
5303 is not],Old=[not denote]} an abstract subprogram. Furthermore, if a
5304 stream-oriented attribute is specified for an interface type by an
5305 @nt{attribute_definition_clause}, the subprogram name given in the clause shall
5306 statically denote a null procedure.],
5307 Old=[All nonlimited types have default implementations
5308 for these operations. An @nt{attribute_reference} for one of
5309 these attributes is illegal if the type is limited,
5310 unless the attribute has been specified by an
5311 @nt{attribute_@!definition_@!clause}@Chg{New=[ or @Redundant[(for a type extension)]
5312 the attribute has been specified for an ancestor type],Old=[]}.
5313 For an @nt{attribute_@!definition_@!clause} specifying one of these
5314 attributes, the subtype of the Item parameter shall be the base subtype
5315 if scalar, and the first subtype otherwise.
5316 The same rule applies to the result of the Input function.]}]}
5317 @ChgNote{Most of the old text is moved down}
5318 @Chg{Version=[3],New=[@AspectDefn{Read}@AspectDefn{Write}@AspectDefn{Input}@AspectDefn{Output}],Old=[]}
5319 @Chg{Version=[4],New=[@AspectDefn{Read'Class}@AspectDefn{Write'Class}@AspectDefn{Input'Class}@AspectDefn{Output'Class}],Old=[]}
5320
5321 @begin{Reason}
5322 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00195-01]}
5323 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0106-1]}
5324 @Chg{Version=[4],New=[We need the last sentence to override the blanket rule
5325 given in @RefSecNum{Aspect Specifications} that aspect'Class applies to the
5326 type and all descendants.],Old=[@Chg{Version=[2],New=[],Old=[This is to simplify
5327 implementation.]}]}
5328 @end{Reason}
5329
5330 @begin{Discussion}@ChgNote{This is junk}
5331 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0040],ARef=[AI95-00108-01]}
5332 @ChgRef{Version=[2],Kind=[DeletedAdded],ARef=[AI95-00195-01]}
5333 @ChgDeleted{Version=[2],Text=[@Chg{Version=[1],New=[@lquotes@;Specified@rquotes
5334 includes inherited attributes, and default implementations are never inherited.
5335 So, for untagged limited types, the second part of the @nt{attribute_reference}
5336 rule has the same meaning as the first part. However, tagged types never inherit
5337 attributes, so the second rule is needed so that the default implementations
5338 for the attributes can be called when those are constructed from a directly
5339 specified ancestor.],Old=[]}]}
5340 @end{Discussion}
5341
5342 @begin{TheProof}
5343 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0121-1]}
5344 @ChgAdded{Version=[4],Text=[@RefSecNum{Aspect Specifications} says that all
5345 operational attributes can be specified with an aspect_specification.]}
5346 @end{TheProof}
5347
5348 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Read'Class],
5349 Text=[@ChgAdded{Version=[4],Text=[Procedure to read a value from a stream for
5350 the class-wide type associated with a given type.]}]}
5351
5352 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Write'Class],
5353 Text=[@ChgAdded{Version=[4],Text=[Procedure to write a value to a stream for a
5354 the class-wide type associated with a given type.]}]}
5355
5356 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Input'Class],
5357 Text=[@ChgAdded{Version=[4],Text=[Function to read a value from a stream for a
5358 the class-wide type associated with a given type, including
5359 any bounds and discriminants.]}]}
5360
5361 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Output'Class],
5362 Text=[@ChgAdded{Version=[4],Text=[Procedure to write a value to a stream for a
5363 the class-wide type associated with a given type, including
5364 any bounds and discriminants.]}]}
5365
5366 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0121-1]}
5367 @ChgAdded{Version=[4],Text=[The subprogram name given in such an
5368 @nt{attribute_@!definition_@!clause} or @nt{aspect_@!specification} shall
5369 statically denote a subprogram that is not an abstract subprogram. Furthermore,
5370 if a specific stream-oriented attribute is specified for an interface type, the
5371 subprogram name given in the @nt{attribute_definition_clause} or
5372 @nt{aspect_specification} shall statically denote a null procedure.]}
5373
5374 @begin{Discussion}
5375 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
5376 @ChgAdded{Version=[2],Type=[Leading],Text=[Stream attributes (other than
5377 Input) are always null procedures for interface types (they have no
5378 components). We need to allow explicit setting of the Read and Write
5379 attributes in order that the class-wide attributes like LI'Class'Input
5380 can be made available. (In that case, any descendant of the interface type
5381 would require available attributes.) But we don't allow any concrete
5382 implementation because these don't participate in extensions (unless the
5383 interface is the parent type). If we didn't ban concrete implementations,
5384 the order of declaration of a pair of interfaces would become significant.
5385 For example, if Int1 and Int2 are interfaces with concrete implementations
5386 of 'Read, then the following declarations would have different
5387 implementations for 'Read:]}
5388 @begin{Example}
5389 @ChgRef{Version=[2],Kind=[AddedNormal]}
5390 @ChgAdded{Version=[2],Text=[@key{type} Con1 @key{is new} Int1 @key{and} Int2 @key{with null record};
5391 @key{type} Con2 @key{is new} Int2 @key{and} Int1 @key{with null record};]}
5392 @end{Example}
5393 @ChgRef{Version=[2],Kind=[AddedNormal]}
5394 @ChgAdded{Version=[2],Type=[Trailing],Text=[This would violate our design
5395 principle that the order of the specification
5396 of the interfaces in a @nt{derived_type_definition} doesn't matter.]}
5397 @end{Discussion}
5398
5399 @begin{Ramification}
5400 @ChgRef{Version=[2],Kind=[AddedNormal]}
5401 @ChgAdded{Version=[2],Type=[Leading],Text=[The Input attribute cannot be
5402 specified for an interface. As it is a function, a null procedure is
5403 impossible; a concrete function is not possible anyway as any function
5404 returning an abstract type must be abstract. And we don't allow specifying
5405 stream attributes to be abstract subprograms. This has no impact, as the
5406 availability of Int'Class'Input (where Int is a limited interface) depends
5407 on whether Int'Read (not Int'Input) is specified. There is no reason to
5408 allow Int'Output to be specified, either, but there is equally no reason to
5409 disallow it, so we don't have a special rule for that.]}
5410 @end{Ramification}
5411
5412 @begin{Discussion}
5413 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5414 @ChgAdded{Version=[2],Text=[Limited types generally do not have default
5415 implementations of the stream-oriented attributes. The rules defining when
5416 a stream-oriented attribute is available (see below) determine when an
5417 attribute of a limited type is in fact well defined and usable. The rules are
5418 designed to maximize the number of cases in which the attributes are usable.
5419 For instance, when the language provides a default implementation of
5420 an attribute for a limited type based on a specified attribute for the parent
5421 type, we want to be able to call that attribute.]}
5422 @end{Discussion}
5423
5424 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Read],
5425 Text=[@ChgAdded{Version=[3],Text=[Procedure to read a value from a stream for
5426 a given type.]}]}
5427
5428 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Write],
5429 Text=[@ChgAdded{Version=[3],Text=[Procedure to write a value to a stream for a
5430 given type.]}]}
5431
5432 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Input],
5433 Text=[@ChgAdded{Version=[3],Text=[Function to read a value from a stream for a
5434 given type, including any bounds and discriminants.]}]}
5435
5436 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Output],
5437 Text=[@ChgAdded{Version=[3],Text=[Procedure to write a value to a stream for a
5438 given type, including any bounds and discriminants.]}]}
5439
5440
5441 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5442 @ChgAdded{Version=[2],Type=[Leading],Text=[A stream-oriented attribute for a
5443 subtype of a specific type @i<T> is @i<available> at places where one of the
5444 following conditions is true: @Defn2{Term=[available],Sec=[stream attribute]}]}
5445
5446 @begin{Itemize}
5447
5448 @ChgRef{Version=[2],Kind=[AddedNormal]}
5449 @ChgAdded{Version=[2],Text=[@i<T> is nonlimited.]}
5450
5451 @ChgRef{Version=[2],Kind=[AddedNormal]}
5452 @ChgAdded{Version=[2],Text=[The @nt{attribute_designator} is Read (resp. Write)
5453 and @i<T> is a limited record extension, and the attribute Read (resp. Write)
5454 is available for the parent type of @i<T> and for the types of all of the
5455 extension components.]}
5456 @begin{Reason}
5457 @ChgRef{Version=[2],Kind=[AddedNormal]}
5458 @ChgAdded{Version=[2],Text=[In this case, the language provides a
5459 well-defined default implementation, which we want to be able to call.]}
5460 @end{Reason}
5461
5462 @ChgRef{Version=[2],Kind=[AddedNormal]}
5463 @ChgAdded{Version=[2],Text=[@i{T} is a limited untagged derived type, and the
5464 attribute was inherited for the type.]}
5465 @begin{Reason}
5466 @ChgRef{Version=[2],Kind=[AddedNormal]}
5467 @ChgAdded{Version=[2],Text=[Attributes are only inherited for
5468 untagged derived types, and surely we want to be able to call
5469 inherited attributes.]}
5470 @end{Reason}
5471
5472 @ChgRef{Version=[2],Kind=[AddedNormal]}
5473 @ChgAdded{Version=[2],Text=[The @nt{attribute_designator} is Input (resp.
5474 Output), and @i<T> is a limited type, and the attribute Read (resp. Write) is
5475 available for @i<T>.]}
5476 @begin{Reason}
5477 @ChgRef{Version=[2],Kind=[AddedNormal]}
5478 @ChgAdded{Version=[2],Text=[The default implementation of Input and Output
5479 are based on Read and Write; so if the implementation of Read or Write is
5480 good, so is the matching implementation of Input or Output.]}
5481 @end{Reason}
5482
5483 @ChgRef{Version=[2],Kind=[AddedNormal]}
5484 @ChgAdded{Version=[2],Text=[The attribute has been specified via an
5485 @nt{attribute_definition_clause}, and the @nt{attribute_definition_clause}
5486 is visible.]}
5487 @begin{Reason}
5488 @ChgRef{Version=[2],Kind=[AddedNormal]}
5489 @ChgAdded{Version=[2],Text=[We always want to allow calling a specified
5490 attribute. But we don't want availability to break privacy.
5491 Therefore, only attributes whose specification can be seen count. Yes, we
5492 defined the visibility of an @nt{attribute_definition_clause}
5493 (see @RefSecNum{Visibility}).]}
5494 @end{Reason}
5495 @end{Itemize}
5496
5497 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5498 @ChgAdded{Version=[2],Type=[Leading],Text=[A stream-oriented attribute for a subtype of a class-wide type
5499 @i<T>'Class is available at places where one of the following conditions is true:]}
5500
5501 @begin{Itemize}
5502 @ChgRef{Version=[2],Kind=[AddedNormal]}
5503 @ChgAdded{Version=[2],Text=[@i<T> is nonlimited;]}
5504
5505 @ChgRef{Version=[2],Kind=[AddedNormal]}
5506 @ChgAdded{Version=[2],Text=[the attribute has been specified via an
5507 @nt{attribute_definition_clause}, and the @nt{attribute_definition_clause}
5508 is visible; or]}
5509
5510 @ChgRef{Version=[2],Kind=[AddedNormal]}
5511 @ChgAdded{Version=[2],Text=[the corresponding attribute of @i<T> is
5512 available, provided that if @i<T> has a partial view, the corresponding
5513 attribute is available at the end of the visible part where @i<T> is
5514 declared.]}
5515
5516 @end{Itemize}
5517 @begin{Reason}
5518 @ChgRef{Version=[2],Kind=[AddedNormal]}
5519 @ChgAdded{Version=[2],Text=[The rules are stricter for class-wide attributes
5520 because (for the default implementation) we must ensure that any specific
5521 attribute that might ever be dispatched to is available. Because we require
5522 specification of attributes for extensions of limited parent types with
5523 available attributes, we can in fact know this. Otherwise, we would not be
5524 able to use default class-wide attributes with limited types, a significant
5525 limitation.]}
5526 @end{Reason}
5527
5528 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5529 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0030-1]}
5530 @ChgAdded{Version=[2],Text=[An @nt{attribute_reference} for one of the
5531 stream-oriented attributes is illegal unless the attribute is available at
5532 the place of the @nt{attribute_reference}. Furthermore, an
5533 @nt{attribute_reference} for @i<T>'Input is illegal if @i<T> is an abstract
5534 type.@Chg{Version=[4],New=[@PDefn{generic contract issue} In addition to the
5535 places where @LegalityTitle normally apply (see
5536 @RefSecNum{Generic Instantiation}), these rules also apply in the private
5537 part of an instance of a generic unit.],Old=[]}]}
5538
5539 @begin{Discussion}
5540 @ChgRef{Version=[2],Kind=[AddedNormal]}
5541 @ChgAdded{Version=[2],Text=[Stream attributes always exist. It is illegal
5542 to call them in some cases. Having the attributes not be defined for
5543 some limited types would seem to be a cleaner solution, but it would lead
5544 to contract model problems for limited private types.]}
5545
5546 @ChgRef{Version=[2],Kind=[AddedNormal]}
5547 @ChgAdded{Version=[2],Text=[@i<T>'Input is available for abstract types
5548 so that @i<T>'Class'Input is available. But we certainly don't want to allow
5549 calls that could create an object of an abstract type. Remember that
5550 @i<T>'Class is never abstract, so the above legality rule doesn't apply to
5551 it. We don't have to discuss whether the attribute is specified, as it cannot
5552 be: any function returning the type would have to be abstract, and we do not
5553 allow specifying an attribute with an abstract subprogram.]}
5554 @end{Discussion}
5555
5556 @begin{Honest}
5557 @ChgRef{Version=[4],Kind=[AddedNormal],Aref=[AI12-0030-1]}
5558 @ChgAdded{Version=[4],Text=[@ldquote@;These rules apply@rdquote refers to
5559 just this paragraph and not to the rest of the rules in this section.
5560 This rule probably should have been a @LegalityName, but the word
5561 @ldquote@;illegal@rdquote should key the reader that this is a @LegalityName,
5562 no matter under what text heading it occurs.]}
5563 @end{Honest}
5564
5565 @ChgRef{Version=[4],Kind=[Added],Aref=[AI12-0030-1]}
5566 @ChgAdded{Version=[4],Text=[Unless inherited from a parent type, if any, for an
5567 untagged type having a task, protected, or explicitly limited record part, the
5568 default implementation of each of the Read, Write, Input, and Output attributes
5569 raises Program_Error and performs no other action.]}
5570
5571 @begin{Discussion}
5572 @ChgRef{Version=[4],Kind=[AddedNormal],Aref=[AI12-0030-1]}
5573 @ChgAdded{Version=[4],Text=[It might seem that there is no need to specify the
5574 behavior of the default implementation of a streaming attribute of, for
5575 example, a task type because there is no way that it can be invoked. It is
5576 possible, however, to construct an example where such a stream attribute can
5577 be invoked. This involves using a formal untagged limited derived type for
5578 which some streaming attribute is available (because it was explicitly
5579 specified for the ancestor type) and a corresponding actual type for which the
5580 attribute is unspecified (because the derivation occurred before the aspect
5581 was specified for the ancestor type and the specification was therefore not
5582 inherited).]}
5583 @end{Discussion}
5584
5585 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5586 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0192-1]}
5587 @ChgAdded{Version=[2],Text=[In the @nt{parameter_and_result_profile}s for
5588 @Chg{Version=[3],New=[the default implementations of ],Old=[]}the
5589 stream-oriented attributes, the subtype of the Item parameter is the base
5590 subtype of @i<T> if @i<T> is a scalar type, and the first subtype otherwise.
5591 The same rule applies to the result of the Input attribute.]}
5592
5593 @begin{Discussion}
5594 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0192-1]}
5595 @ChgAdded{Version=[3],Text=[An inherited stream attribute has a profile as
5596 determined by the rules for inheriting primitive subprograms (see
5597 @RefSecNum{Operational and Representation Aspects} and
5598 @RefSecNum{Derived Types and Classes}).]}
5599 @end{Discussion}
5600
5601 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5602 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0007-1]}
5603 @ChgAdded{Version=[2],Text=[For an @nt{attribute_definition_clause} specifying
5604 one of these attributes, the subtype of the
5605 @Chg{Version=[3],New=[@i<Item>],Old=[Item]} parameter shall be the
5606 @Chg{Version=[3],New=[first subtype or the ],Old=[]}base
5607 subtype if scalar, and the first subtype
5608 @Chg{Version=[3],New=[if not scalar],Old=[otherwise]}. The same rule
5609 applies to the result of the Input function.]}
5610
5611 @begin{Reason}
5612 @ChgRef{Version=[2],Kind=[AddedNormal]}
5613 @ChgAdded{Version=[2],Text=[This is to simplify implementation.]}
5614 @end{Reason}
5615 @begin{Ramification}
5616 @ChgRef{Version=[2],Kind=[AddedNormal]}
5617 @ChgRef{Version=[3],Kind=[AddedNormal]}
5618 @ChgAdded{Version=[2],Text=[The view of the type at the point of the
5619 @nt{attribute_definition_clause} determines whether the @Chg{Version=[3],
5620 New=[],Old=[first subtype or ]}base subtype is
5621 @Chg{Version=[3],New=[allowed],Old=[required]}. Thus, for a scalar
5622 type with a partial view (which is never scalar), whether the
5623 @Chg{Version=[3], New=[],Old=[first subtype or the ]} base subtype is
5624 @Chg{Version=[3], New=[allowed],Old=[required]} is
5625 determined by whether the @nt{attribute_definition_clause} occurs before or
5626 after the full definition of the scalar type.]}
5627 @end{Ramification}
5628
5629 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
5630 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0065-1]}
5631 @ChgAdded{Version=[2],Text=[@Defn{support external streaming}
5632 @Defn2{Term=[external streaming],Sec={type supports}}
5633 @Redundant[A type is said to @i{support external streaming} if Read and Write attributes
5634 are provided for sending values of such a type between active
5635 partitions, with Write marshalling the representation, and Read unmarshalling
5636 the representation.] A limited type supports external streaming only if
5637 it has available Read and Write attributes. A type with a part that is of
5638 @Chg{Version=[3],New=[a nonremote],Old=[an]}
5639 access type supports external streaming only if that access type or the type of
5640 some part that includes the access type component, has Read and Write
5641 attributes that have been specified via an @nt{attribute_definition_clause},
5642 and that @nt{attribute_definition_clause} is visible. @Redundant[An anonymous
5643 access type does not support external streaming. ]All other types
5644 @Chg{Version=[3],New=[(including remote access types,
5645 see @RefSecNum{Remote Types Library Units}) ],Old=[]}support
5646 external streaming.]}
5647
5648 @begin{Ramification}
5649 @ChgRef{Version=[2],Kind=[AddedNormal]}
5650 @ChgRef{Version=[3],Kind=[Revised]}
5651 @ChgAdded{Version=[2],Text=[A limited type with a part that is of
5652 @Chg{Version=[3],New=[a nonremote],Old=[an]} access
5653 type needs to satisfy both rules.]}
5654 @end{Ramification}
5655
5656 @end{StaticSem}
5657
5658 @begin{Erron}
5659 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01],ARef=[AI95-00344-01]}
5660 @ChgAdded{Version=[2],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
5661 If the internal tag returned by Descendant_Tag to T'Class'Input identifies a
5662 type that is not library-level and whose tag has not been created, or does not
5663 exist in the partition at the time of the call, execution is erroneous.]}
5664 @begin{Ramification}
5665 @ChgRef{Version=[2],Kind=[AddedNormal]}
5666 @ChgAdded{Version=[2],Text=[The definition of Descendant_Tag prevents such
5667 a tag from being provided to T'Class'Input if T is a library-level type.
5668 However, this rule is needed for nested tagged types.]}
5669 @end{Ramification}
5670 @end{Erron}
5671
5672 @begin{ImplReq}
5673 @ChgRef{Version=[1],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
5674 @ChgAdded{Version=[1],Text=[For every subtype @i<S> of a language-defined
5675 nonlimited specific type @i<T>, the output generated by S'Output or S'Write
5676 shall be readable by S'Input or S'Read, respectively. This rule applies
5677 across partitions if the implementation conforms to the Distributed Systems
5678 Annex.]}
5679
5680 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5681 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
5682 @ChgAdded{Version=[2],Text=[If Constraint_Error is raised during a call to
5683 Read because of failure of one the above checks, the implementation
5684 @Chg{Version=[3],New=[shall],Old=[must]} ensure that the discriminants
5685 of the actual parameter of Read are not modified.]}
5686 @end{ImplReq}
5687
5688 @begin{ImplPerm}
5689 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5690 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
5691 @ChgAdded{Version=[2],Text=[The number of calls performed by the predefined
5692 implementation of the stream-oriented attributes on the Read and Write
5693 operations of the stream type is unspecified. An implementation may take
5694 advantage of this permission to perform internal buffering. However, all the
5695 calls on the Read and Write operations of the stream type needed to implement
5696 an explicit invocation of a stream-oriented attribute
5697 @Chg{Version=[3],New=[shall],Old=[must]} take place before
5698 this invocation returns. An explicit invocation is one appearing explicitly
5699 in the program text, possibly through a generic instantiation (see
5700 @RefSecNum{Generic Instantiation}).]}
5701
5702 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0023-1],ARef=[AI05-0264-1]}
5703 @ChgAdded{Version=[3],Text=[If @i<T> is a discriminated type and its
5704 discriminants have defaults, then in two cases an execution of the default
5705 implementation of S'Read is not required to create an anonymous object of
5706 type @i<T>: If the discriminant values that are read in are equal to the
5707 corresponding discriminant values of @i<Item>, then no object of type @i<T>
5708 need be created and @i<Item> may be used instead. If they are not equal and
5709 @i<Item> is a constrained variable, then Constraint_Error may be raised at
5710 that point, before any further values are read from the stream and before
5711 the object of type @i<T> is created.]}
5712
5713 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0023-1]}
5714 @ChgAdded{Version=[3],Text=[A default implementation of S'Input that calls the default implementation
5715 of S'Read may create a constrained anonymous object with discriminants
5716 that match those in the stream.]}
5717 @begin{ImplNote}
5718 @ChgRef{Version=[3],Kind=[AddedNormal]}
5719 @ChgAdded{Version=[3],Type=[Leading],Keepnext=[T],Text=[This allows
5720 the combined executions of S'Input and S'Read to create one
5721 object of type @i<T> instead of two. If this option is exercised, then:]}
5722 @begin{Itemize}
5723 @ChgRef{Version=[3],Kind=[AddedNormal]}
5724 @ChgAdded{Version=[3],Text=[The discriminants are read from the stream by
5725 S'Input, not S'Read.]}
5726
5727 @ChgRef{Version=[3],Kind=[AddedNormal]}
5728 @ChgAdded{Version=[3],Text=[S'Input declares an object of type @i<T>
5729 constrained by the discriminants read from the stream, not an
5730 unconstrained object.]}
5731
5732 @ChgRef{Version=[3],Kind=[AddedNormal]}
5733 @ChgAdded{Version=[3],Text=[The discriminant values that S'Read would
5734 normally have read from the stream are read from Item instead.]}
5735
5736 @ChgRef{Version=[3],Kind=[AddedNormal]}
5737 @ChgAdded{Version=[3],Text=[The permissions of the preceding paragraph
5738 then apply and no object of type @i<T> need be created by the execution
5739 of S'Read.]}
5740 @end{Itemize}
5741 @end{ImplNote}
5742
5743 @end{ImplPerm}
5744
5745 @begin{Notes}
5746 For a definite subtype S of a type @i(T), only @i(T)'Write and @i(T)'Read
5747 are needed to pass
5748 an arbitrary value of the subtype through a stream.
5749 For an indefinite subtype S of a type @i(T), @i(T)'Output and @i(T)'Input
5750 will normally be needed, since @i(T)'Write and @i(T)'Read do not
5751 pass bounds, discriminants, or tags.
5752
5753 User-specified attributes of S'Class are not inherited by other
5754 class-wide types descended from S.
5755 @end{Notes}
5756
5757 @begin{Examples}
5758 @leading@keepnext@i{Example of user-defined Write attribute:}
5759 @begin{Example}
5760 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00441-01]}
5761 @key[procedure] My_Write(
5762 Stream : @key[@Chg{Version=[2],New=[not null ],Old=[]}access] Ada.Streams.Root_Stream_Type'Class;@Chg{Version=[2],New=[
5763 ],Old=[]}Item@Chg{Version=[2],New=[ ],Old=[]} : My_Integer'Base);
5764 @key(for) My_Integer'Write @key(use) My_Write;
5765 @end{Example}
5766 @begin{Discussion}
5767 @leading@keepnext@i{Example of network input/output using input output attributes:}
5768 @begin{Example}
5769 @key(with) Ada.Streams; @key(use) Ada.Streams;
5770 @key(generic)
5771 @key(type) Msg_Type(<>) @key(is private);
5772 @key(package) Network_IO @key(is)
5773 --@RI[ Connect/Disconnect are used to establish the stream]
5774 @key(procedure) Connect(...);
5775 @key(procedure) Disconnect(...);
5776
5777 --@RI[ Send/Receive transfer messages across the network]
5778 @key(procedure) Send(X : @key[in] Msg_Type);
5779 @key(function) Receive @key(return) Msg_Type;
5780 @key(private)
5781 @key(type) Network_Stream @key(is new) Root_Stream_Type @key(with) ...
5782 @key(procedure) Read(...); --@RI[ define Read/Write for Network_Stream]
5783 @key(procedure) Write(...);
5784 @key(end) Network_IO;
5785
5786 @key(with) Ada.Streams; @key(use) Ada.Streams;
5787 @key(package body) Network_IO @key(is)
5788 Current_Stream : @key(aliased) Network_Stream;
5789 . . .
5790 @key(procedure) Connect(...) @key(is) ...;
5791 @key(procedure) Disconnect(...) @key(is) ...;
5792
5793 @key(procedure) Send(X : @key[in] Msg_Type) @key(is)
5794 @key(begin)
5795 Msg_Type'Output(Current_Stream'Access, X);
5796 @key(end) Send;
5797
5798 @key(function) Receive @key(return) Msg_Type @key(is)
5799 @key(begin)
5800 @key(return) Msg_Type'Input(Current_Stream'Access);
5801 @key(end) Receive;
5802 @key(end) Network_IO;
5803 @end{Example}
5804 @end{Discussion}
5805 @end{Examples}
5806
5807 @begin{Inconsistent95}
5808 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01]}
5809 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
5810 @b<Corrigendum:> Clarified how the default
5811 implementation for stream attributes is determined (eliminating conflicting
5812 language). The new wording provides that attributes for type extensions are
5813 created by composing the parent's attribute with those for the extension
5814 components if any. If a program was written assuming that the extension
5815 components were not included in the stream (as in original Ada 95), it
5816 would fail to work in the language as corrected by the Corrigendum.]}
5817
5818 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5819 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Explicitly provided a
5820 permission that the number of calls to the underlying stream Read and Write
5821 operations may differ from the number determined by the canonical operations.
5822 If Ada 95 code somehow depended on the number of calls to Read or Write, it
5823 could fail with an Ada 2005 implementation. Such code is likely to be very
5824 rare; moreover, such code is really wrong, as the permission applies to Ada
5825 95 as well.]}
5826 @end{Inconsistent95}
5827
5828 @begin{Extend95}
5829 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00270-01]}
5830 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
5831 The Stream_Size attribute is new. It allows specifying the number of bits
5832 that will be streamed for a type. The @ImplAdviceTitle involving this
5833 also was changed; this is not incompatible because @ImplAdviceTitle does
5834 not have to be followed.]}
5835
5836 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0040],ARef=[AI95-00108-01],ARef=[AI95-00195-01],ARef=[AI95-00444-01]}
5837 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Limited types may have default
5838 constructed attributes if all of the parent and (for extensions) extension
5839 components have available attributes. Ada 2005 adds the notion of
5840 availability to patch up some holes in the Corrigendum model.]}
5841 @end{Extend95}
5842
5843 @begin{DiffWord95}
5844 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
5845 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that
5846 these are operational attributes.]}
5847
5848 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0045],ARef=[AI95-00132-01]}
5849 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that End_Error
5850 is raised by the default implementation of Read and Input if the end of
5851 the stream is reached. (The result could have been abnormal without this
5852 clarification, thus this is not an inconsistency, as the programmer could
5853 not have depended on the previous behavior.)]}
5854
5855 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5856 @ChgAdded{Version=[2],Text=[Clarified that the default implementation of
5857 S'Input does normal initialization on the object that it passes to S'Read.]}
5858
5859 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01]}
5860 @ChgAdded{Version=[2],Text=[Explicitly stated that what is read from a
5861 stream when a required check fails is unspecified.]}
5862
5863 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
5864 @ChgAdded{Version=[2],Text=[Defined availability and default implementations
5865 for types with progenitors.]}
5866
5867 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
5868 @ChgAdded{Version=[2],Text=[Specified that Constraint_Error is raised if
5869 the internal tag retrieved for S'Class'Input is for some type not covered
5870 by S'Class or is abstract. We also explicitly state that the program is
5871 erroneous if the tag has not been created or does not currently exist in
5872 the partition. (Ada 95 did not specify what happened in these
5873 cases; it's very unlikely to have provided some useful result, so this is
5874 not considered an inconsistency.)]}
5875
5876 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01]}
5877 @ChgAdded{Version=[2],Text=[Added wording to support nested type extensions.
5878 S'Input and S'Output always raise Tag_Error for such extensions, and such
5879 extensions were not permitted in Ada 95, so this is neither an extension
5880 nor an incompatibility.]}
5881
5882 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
5883 @ChgAdded{Version=[2],Text=[Defined @i<supports external streaming> to
5884 put all of the rules about @lquotes@;good@rquotes stream attributes in one
5885 place. This is used for distribution and for defining pragma Pure.]}
5886
5887 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00441-01]}
5888 @ChgAdded{Version=[2],Text=[Added the @key[not null] qualifier to the
5889 first parameter of all of the stream attributes, so that the semantics
5890 doesn't change between Ada 95 and Ada 2005. This change is compatible,
5891 because mode conformance is required for subprograms specified as
5892 stream attributes, and @nt{null_exclusion}s are not considered for
5893 mode conformance.]}
5894
5895 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00444-01]}
5896 @ChgAdded{Version=[2],Text=[Improved the wording to make it clear that
5897 we don't define the default implementations of attributes that cannot be
5898 called (that is, aren't @lquotes@;available@rquotes@;). Also clarified when
5899 inheritance takes place.]}
5900 @end{DiffWord95}
5901
5902 @begin{Incompatible2005}
5903 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0039-1]}
5904 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
5905 Added a requirement that stream
5906 attributes be specified by a static subprogram name rather than a
5907 dynamic expression. Expressions cannot provide any useful functionality
5908 because of the freezing rules, and the possibility of them complicates
5909 implementations. Only pathological programs should be affected.]}
5910 @end{Incompatible2005}
5911
5912 @begin{Extend2005}
5913 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0007-1]}
5914 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@b<Correction:>
5915 Stream attributes
5916 for scalar types can be specified with subprograms that take the first
5917 subtype as well as the base type. This eliminates confusion about which
5918 subtype is appropriate for attributes specified for partial views whose
5919 full type is a scalar type. It also eliminates a common user error
5920 (forgetting 'Base).]}
5921 @end{Extend2005}
5922
5923 @begin{DiffWord2005}
5924 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0023-1]}
5925 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the definition
5926 of the default version S'Read and S'Input to be well-defined if
5927 S is a discriminated type with defaulted discriminants and
5928 some components require initialization and/or finalizations.]}
5929
5930 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0065-1]}
5931 @ChgAdded{Version=[3],Text=[@b<Correction:> Defined remote access
5932 types to support external streaming, since that is their purpose.]}
5933
5934 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0109-1]}
5935 @ChgAdded{Version=[3],Text=[@b<Correction:> Removed a misleading phrase
5936 which implies that Constraint_Error is raised for internal tags of the
5937 wrong type, when Tag_Error should be raised for such tags.]}
5938
5939 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0139-2]}
5940 @ChgAdded{Version=[3],Text=[Clarified that arrays with convention Fortran
5941 are written in column-major order, rather then row-major order. This
5942 is necessary in order that streaming of Fortran arrays is efficient.]}
5943
5944 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0192-1]}
5945 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that the profile
5946 of an inherited stream attribute is as defined for an inherited primitive
5947 subprogram, while the default implementation of the same attribute might
5948 have a different profile.]}
5949
5950 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0194-1]}
5951 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that Stream_Size
5952 has no effect on and is not effected by user-defined stream attributes.]}
5953 @end{DiffWord2005}
5954
5955 @begin{Extend2012}
5956 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0106-1]}
5957 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:>
5958 Defined how to specify a class-wide stream-oriented attribute using an
5959 @nt{aspect_specification}. It was always intended that this was possible,
5960 but the method was not clear, as a class-wide type never has an explicit
5961 declaration.]}
5962 @end{Extend2012}
5963
5964 @begin{DiffWord2012}
5965 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0030-1]}
5966 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Defined the runtime
5967 effect of stream attributes for untagged limited types, as there
5968 is a weird corner case where they can be called. We don't specify this
5969 as an inconsistency, as it doesn't make semantic sense to stream a task,
5970 and nothing useful could have been done with that, so it should not
5971 exist in any programs.]}
5972
5973 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0106-1]}
5974 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that the same
5975 @LegalityTitle apply when a stream-oriented attribute is specified
5976 via an @nt{aspect_specification} as applied when it is specified via
5977 an @nt{attribute_definition_clause}.]}
5978 @end{DiffWord2012}
5979
5980
5981 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
5982 @LabeledClause{Freezing Rules}
5983
5984 @begin{Intro}
5985 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
5986 @redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} defines
5987 a place in the program text where each declared entity becomes
5988 @lquotes@;frozen.@rquotes@;
5989 A use of an entity, such as a reference to it by name,
5990 or (for a type) an expression of the type,
5991 causes freezing of the entity in some contexts,
5992 as described below.
5993 The @LegalityTitle forbid certain kinds of uses of an entity
5994 in the region of text where it is frozen.]
5995 @begin{Reason}
5996 This concept has two purposes: a compile-time one and a run-time one.
5997
5998 The compile-time purpose of the freezing rules comes from the fact that
5999 the evaluation of static expressions depends on overload resolution,
6000 and overload resolution sometimes depends on the value of a
6001 static expression.
6002 (The dependence of static evaluation upon overload resolution is
6003 obvious. The dependence in the other direction is more subtle.
6004 There are three rules that require static expressions in contexts that
6005 can appear in declarative places: The expression in an
6006 @nt{attribute_designator} shall be static.
6007 In a record aggregate, variant-controlling discriminants shall be static.
6008 In an array aggregate with more than one named association,
6009 the choices shall be static.
6010 The compiler needs to know the value of these expressions in order to
6011 perform overload resolution and legality checking.)
6012 We wish to allow a compiler to evaluate static expressions when it sees
6013 them in a single pass over the @nt{compilation_unit}.
6014 The freezing rules ensure that.
6015
6016 The run-time purpose of the freezing rules is called the @lquotes@;linear
6017 elaboration model.@rquotes@;
6018 This means that declarations are elaborated in the order in which they
6019 appear in the program text,
6020 and later elaborations can depend on the results of earlier ones.
6021 The elaboration of the declarations of certain entities requires run-time
6022 information about the implementation details of other entities.
6023 The freezing rules ensure that this information has been calculated by
6024 the time it is used.
6025 For example, suppose the initial value of a constant is the result of
6026 a function call that takes a parameter of type @i(T).
6027 In order to pass that parameter, the size of type @i(T) has to be known.
6028 If @i(T) is composite, that size might be known only at run time.
6029
6030 (Note that in these discussions, words like @lquotes@;before@rquotes@; and @lquotes@;after@rquotes@;
6031 generally refer to places in the program text,
6032 as opposed to times at run time.)
6033 @end{Reason}
6034 @begin{Discussion}
6035 @leading@;The @lquotes@;implementation details@rquotes@; we're talking
6036 about above are:
6037 @begin{Itemize}
6038 For a tagged type,
6039 the implementations of all the primitive subprograms of the type
6040 @em that is (in the canonical implementation model),
6041 the contents of the type descriptor, which contains pointers to the code for
6042 each primitive subprogram.
6043
6044 For a type, the full type declaration of any parts (including the type itself)
6045 that are private.
6046
6047 For a deferred constant,
6048 the full constant declaration, which gives the constant's value.
6049 (Since this information necessarily comes after the constant's type
6050 and subtype are fully
6051 known, there's no need to worry about its type or subtype.)
6052
6053 For any entity,
6054 representation information specified by the user
6055 via representation items.
6056 Most representation items are for types
6057 or subtypes; however, various other kinds of entities,
6058 such as objects and subprograms, are possible.
6059 @end{Itemize}
6060
6061 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
6062 Similar issues arise for incomplete types.
6063 However, we do not use freezing @Chg{Version=[3],
6064 New=[to prevent premature access],Old=[there]};
6065 incomplete types have different, more severe, restrictions.
6066 Similar issues also arise for subprograms, protected operations,
6067 tasks and generic units.
6068 However, we do not use freezing @Chg{Version=[3],
6069 New=[to prevent premature access for those,],Old=[there]} either;
6070 @RefSecNum{Declarative Parts} prevents problems with run-time
6071 Elaboration_Checks.@Chg{Version=[3],New=[ Even so, freezing is used for these
6072 entities to prevent giving representation items too late (that is, after uses
6073 that require representation information, such as calls).],Old=[]}
6074 @end{Discussion}
6075 @end{Intro}
6076
6077 @begin{MetaRules}
6078 An evaluable construct should freeze anything that's needed to evaluate
6079 it.
6080
6081 However, if the construct is not evaluated where it appears,
6082 let it cause freezing later, when it is evaluated.
6083 This is the case for @nt{default_expression}s and @nt{default_name}s.
6084 (Formal parameters, generic formal parameters, and components can have
6085 @nt{default_expression}s or @nt{default_name}s.)
6086
6087 The compiler should be allowed to evaluate static expressions without
6088 knowledge of their context. (I.e. there should not be any special
6089 rules for static expressions that happen to occur in a context that
6090 requires a static expression.)
6091
6092 Compilers should be allowed to evaluate static expressions (and record
6093 the results) using the run-time representation of the type.
6094 For example, suppose Color'Pos(Red) = 1, but the internal code for Red
6095 is 37.
6096 If the value of a static expression is Red,
6097 some compilers might store 1 in their symbol table,
6098 and other compilers might store 37.
6099 Either compiler design should be feasible.
6100
6101 Compilers should never be required to detect erroneousness or exceptions at
6102 compile time (although it's very nice if they do).
6103 This implies that we should not require
6104 code-generation for a nonstatic expression of type @i(T) too early,
6105 even if we can prove that that expression will be erroneous,
6106 or will raise an exception.
6107
6108 @Leading@;Here's an example (modified from AI83-00039, Example 3):
6109 @begin{example}
6110 @key[type] T @key[is]
6111 @key[record]
6112 ...
6113 @key[end] @key[record];
6114 @key[function] F @key[return] T;
6115 @key[function] G(X : T) @key[return] Boolean;
6116 Y : Boolean := G(F); --@RI{ doesn't force T in Ada 83}
6117 @key[for] T @key[use]
6118 @key[record]
6119 ...
6120 @key[end] @key[record];
6121 @end{example}
6122
6123 @Leading@;AI83-00039 says this is legal.
6124 Of course, it raises Program_Error because the function bodies aren't
6125 elaborated yet. A one-pass compiler has to generate code for an expression of
6126 type T before it knows the representation of T.
6127 Here's a similar example, which AI83-00039 also says is legal:
6128 @begin{example}
6129 @key[package] P @key[is]
6130 @key[type] T @key[is] @key[private];
6131 @key[function] F @key[return] T;
6132 @key[function] G(X : T) @key[return] Boolean;
6133 Y : Boolean := G(F); --@RI{ doesn't force T in Ada 83}
6134 @key[private]
6135 @key[type] T @key[is]
6136 @key[record]
6137 ...
6138 @key[end] @key[record];
6139 @key[end] P;
6140 @end{example}
6141
6142 If T's size were dynamic, that size would be stored in some
6143 compiler-generated dope; this dope would be initialized at the place
6144 of the full type declaration.
6145 However, the generated code for the function calls
6146 would most likely allocate a temp of the size specified by the dope
6147 @i{before} checking for Program_Error.
6148 That dope would contain uninitialized junk,
6149 resulting in disaster.
6150 To avoid doing that,
6151 the compiler would have to determine,
6152 at compile time, that the expression will raise Program_Error.
6153
6154 This is silly. If we're going to require compilers to detect the exception at
6155 compile time, we might as well formulate the rule as a legality rule.
6156
6157 Compilers should not be required to generate code to load the value
6158 of a variable before the address of the variable has been determined.
6159
6160 After an entity has been frozen, no further requirements may be
6161 placed on its representation (such as by a representation item
6162 or a @nt{full_type_declaration}).
6163 @end{MetaRules}
6164
6165 @begin{Intro}
6166 @RootDefn2{Term=[freezing], Sec=(entity)}
6167 @Defn2{Term=[freezing points], Sec=(entity)}
6168 The @i(freezing) of an entity occurs at one or more places
6169 (@i{freezing points}) in the program
6170 text where the representation for the entity has to be
6171 fully determined. Each entity is frozen from its first
6172 freezing point to the end of the program text
6173 (given the ordering of compilation units defined in
6174 @RefSecNum{The Compilation Process}).
6175 @begin{Ramification}
6176 The @lquotes@;representation@rquotes@; for a subprogram includes its calling convention
6177 and means for referencing the subprogram body, either a @lquotes@;link-name@rquotes@; or
6178 specified address. It does
6179 not include the code for the subprogram body itself, nor its
6180 address if a link-name is used to reference the body.
6181 @end{Ramification}
6182
6183 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0019-1],ARef=[AI05-0299-1]}
6184 @ChgAdded{Version=[3],Text=[@Defn2{Term=[freezing], Sec=(profile)}This subclause
6185 also defines a place in the program text where the profile of each declared
6186 callable entity becomes @i{frozen}. A use of a callable entity causes freezing
6187 of its profile in some contexts, as described below. At the place where the
6188 profile of a callable entity becomes frozen, the entity itself becomes
6189 frozen.]}
6190
6191 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0014]}
6192 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0017-1],ARef=[AI05-0019-1]}
6193 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0103-1]}
6194 @Defn2{Term=[freezing],
6195 Sec=(entity caused by the end of an enclosing construct)}
6196 The end of a @nt{declarative_part}, @nt{protected_body},
6197 or a declaration of a library package or generic library package,
6198 causes @i(freezing) of each
6199 entity @Chg{Version=[3],New=[and profile ],Old=[]}declared within it,
6200 except for incomplete types.
6201 @Defn2{Term=[freezing], Sec=(entity caused by a body)}
6202 A @Chg{Version=[4],New=[@nt{proper_body}, @nt{body_stub}, or
6203 @nt{entry_body}],Old=[noninstance body@Chg{New=[ other than a renames-as-body],Old=[]}]}
6204 causes freezing of each entity @Chg{Version=[3],New=[and profile ],Old=[]}declared
6205 before it within the same @nt{declarative_part}@Chg{Version=[3],
6206 New=[ that is not an incomplete type; it only causes
6207 freezing of an incomplete type if the body is within the immediate scope of the
6208 incomplete type],Old=[]}.
6209 @begin{Discussion}
6210 This is worded carefully to handle nested packages and private types.
6211 Entities declared in a nested @nt{package_specification}
6212 will be frozen by some containing construct.
6213
6214 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0017-1]}
6215 An incomplete type declared in the private part of
6216 a library @nt{package_specification}
6217 can be completed in the body.@Chg{Version=[3],New=[ For other
6218 incomplete types (and in the bodies of library packages),
6219 the completion of the type will be frozen at the end of
6220 the package or @nt{declarative_part}, and that will freeze the
6221 incomplete view as well.],Old=[]}
6222
6223 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0017-1]}
6224 @ChgAdded{Version=[3],Text=[The reason we have to worry about
6225 freezing of incomplete types is to prevent premature uses of
6226 the types in dispatching calls. Such uses may need access to
6227 the tag of the type, and the type has to be frozen to know
6228 where the tag is stored.]}
6229 @end{Discussion}
6230 @begin{Ramification}
6231 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6232 The part about bodies does not say @i{immediately} within.
6233 A renaming-as-body does not have this property.
6234 Nor does @Chg{Version=[3],New=[an imported body],Old=[a @nt{pragma} Import.]}
6235 @end{Ramification}
6236 @begin{Reason}
6237 The reason bodies cause freezing is because we want
6238 @ntf{proper_bodies} and @nt{body_stub}s to be interchangeable @em one
6239 should be able to move a @nt{proper_body} to a @nt{subunit}, and
6240 vice-versa, without changing the semantics.
6241 Clearly, anything that should cause freezing should do so even if
6242 it's inside a @nt{proper_body}.
6243 However, if we make it a @nt{body_stub}, then the compiler can't
6244 see that thing that should cause freezing.
6245 So we make @nt{body_stub}s cause freezing, just in case they
6246 contain something that should cause freezing.
6247 But that means we need to do the same for @ntf{proper_bodies}.
6248
6249 Another reason for bodies to cause freezing,
6250 there could be an added implementation burden if an entity
6251 declared in an enclosing @nt<declarative_part> is frozen
6252 within a nested body,
6253 since some compilers look at bodies after looking
6254 at the containing @nt{declarative_part}.
6255
6256 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]}
6257 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0103-1]}
6258 @ChgAdded{Version=[3],Text=[Note that
6259 @Chg{Version=[4],New=[],Old=[@ldquote@;body@rdquote
6260 includes ]}@nt{null_procedure_declaration}s and
6261 @nt{expression_function_declaration}s@Chg{Version=[4],New=[ (even],Old=[]}
6262 when those are used as completions@Chg{Version=[4],New=[)],Old=[]},
6263 as well as @Chg{Version=[4],New=[@nt{generic_instantiation}s and
6264 renames-as-bodies do not necessarily cause freezing; each have their
6265 own specific rules],Old=[@nt{entry_body}s (see
6266 @RefSecNum{Completions of Declarations}). These all cause freezing,
6267 along with @nt{proper_body}s and @nt{body_stub}s]}.]}
6268 @end{Reason}
6269 @begin{Ramification}
6270 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0103-1]}
6271 @ChgAdded{Version=[4],Text=[Note that the rule about proper bodies being
6272 freezing only applies in @nt{declarative_part}s. All of the kinds of bodies
6273 (see @RefSecNum{Completions of Declarations} @en keep in mind the
6274 difference from @nt{body}s) that are allowed in a package specification have
6275 their own freezing rules, so they don't need to be covered by the above rule.]}
6276 @end{Ramification}
6277
6278 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0046],ARef=[AI95-00106-01]}
6279 @Leading@RootDefn2{Term=[freezing], Sec=(entity caused by a construct)}
6280 A construct that (explicitly or implicitly) references an
6281 entity can cause the @i(freezing) of the entity, as defined by
6282 subsequent paragraphs.
6283 @PDefn2{Term=[freezing], Sec=(by a constituent of a construct)}
6284 At the place where a construct causes freezing,
6285 each @nt<name>, @Chg{New=[@nt<expression>, @nt<implicit_dereference>],
6286 Old=[expression]}@Redundant[, or @nt{range}] within the construct causes
6287 freezing:
6288 @begin{Ramification}
6289 Note that in the sense of this paragraph,
6290 a @nt{subtype_mark} @lquotes@;references@rquotes@; the denoted subtype,
6291 but not the type.
6292 @end{Ramification}
6293
6294 @begin{Itemize}
6295 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0213-1]}
6296 @PDefn2{Term=[freezing], Sec=(generic_instantiation)}
6297 The occurrence of a @nt{generic_instantiation} causes
6298 freezing@Chg{Version=[3],New=[, except that
6299 a @nt{name} which is a generic actual parameter whose corresponding
6300 generic formal parameter is a formal incomplete type
6301 (see @RefSecNum{Formal Private and Derived Types})
6302 does not cause freezing. In addition, if],Old=[;
6303 also, if]} a parameter of the instantiation is defaulted,
6304 the @nt{default_expression} or @nt{default_name} for that parameter
6305 causes freezing.
6306
6307 @begin{Ramification}
6308 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0213-1]}
6309 @ChgAdded{Version=[3],Text=[Thus, an actual parameter corresponding to a
6310 formal incomplete type parameter may denote an incomplete or private type
6311 which is not completely defined at the point of the @nt{generic_instantiation}.]}
6312 @end{Ramification}
6313
6314 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0103-1],ARef=[AI12-0157-1]}
6315 @ChgAdded{Version=[4],Text=[At the occurrence of an
6316 @nt{expression_function_declaration} that is a
6317 completion, the return expression of the expression function causes freezing.]}
6318
6319 @begin{Reason}
6320 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0103-1]}
6321 @ChgAdded{Version=[4],Text=[This rule prevents calls through access values to an expression
6322 that might have unfrozen parts. Typically, elaboration checks and other
6323 freezing rules prevent this, but in this case the completion is elaborated
6324 and since this is not a @nt{body} it does not by itself freeze
6325 anything that precedes it.]}
6326 @end{Reason}
6327
6328 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0132-1],ARef=[AI12-0157-1]}
6329 @ChgAdded{Version=[4],Text=[At the occurrence of a renames-as-body whose
6330 @SynI<callable_entity_>@nt{name} denotes an expression function, the
6331 return expression of the expression function causes freezing.]}
6332
6333 @PDefn2{Term=[freezing], Sec=(object_declaration)}
6334 The occurrence of an @nt<object_declaration> that has no corresponding
6335 completion causes freezing.
6336 @begin{Ramification}
6337 Note that this does not include a @nt{formal_object_declaration}.
6338 @end{Ramification}
6339
6340 @PDefn2{Term=[freezing], Sec=(subtype caused by a record extension)}
6341 The declaration of a record extension causes freezing of the parent
6342 subtype.
6343 @begin{Ramification}
6344 This combined with another rule specifying
6345 that primitive subprogram declarations shall precede freezing
6346 ensures that all descendants of a tagged type implement all of
6347 its dispatching operations.
6348
6349 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
6350 The declaration of a private
6351 extension does not cause freezing. The freezing is deferred
6352 until the full type declaration, which will necessarily be
6353 for a record extension@Chg{Version=[2],New=[, task, or protected type (the
6354 latter only for a limited private extension derived from an interface)],
6355 Old=[]}.
6356 @end{Ramification}
6357
6358 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
6359 @ChgAdded{Version=[2],Text=[The declaration of a record extension,
6360 interface type, task unit, or protected unit causes freezing of any
6361 progenitor types specified in the declaration.]}
6362 @begin{Reason}
6363 @ChgRef{Version=[2],Kind=[Added]}
6364 @ChgAdded{Version=[2],Text=[This rule has the same purpose as the one
6365 above: ensuring that all descendants of an interface tagged type implement all
6366 of its dispatching operations. As with the previous rule, a private extension
6367 does not freeze its progenitors; the full type declaration (which must have the
6368 same progenitors) will do that.]}
6369 @end{Reason}
6370 @begin{Ramification}
6371 @ChgRef{Version=[2],Kind=[Added]}
6372 @ChgAdded{Version=[2],Text=[An interface type can be a parent as well as a
6373 progenitor; these rules are similar so that the location of an interface
6374 in a record extension does not have an effect on the freezing of the interface
6375 type.]}
6376 @end{Ramification}
6377 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0183-1]}
6378 @ChgAdded{Version=[3],Text=[At the freezing point of the entity associated with
6379 an @nt{aspect_specification}, any @nt{expression}s or @nt{name}s within the
6380 @nt{aspect_specification} cause freezing. Any static expressions within an
6381 @nt{aspect_specification} also cause freezing
6382 at the end of the immediately enclosing declaration list.]}
6383 @end{Itemize}
6384
6385 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0046],ARef=[AI95-00106-01]}
6386 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1],ARef=[AI05-0183-1]}
6387 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI05-0157-1]}
6388 @PDefn2{Term=[freezing], Sec=(by an expression)}
6389 A static expression @Chg{Version=[3],New=[(other than within an
6390 @nt{aspect_specification}) ],Old=[]}causes freezing where it occurs.
6391 @Chg{New=[@PDefn2{Term=[freezing], Sec=(by an object name)}
6392 An object name or],Old=[A]} nonstatic expression causes freezing where it
6393 occurs, unless the @Chg{New=[name or ],Old=[]}expression is part of a
6394 @nt<default_expression>, a @nt<default_name>, @Chg{Version=[3],New=[the
6395 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
6396 of an expression function, an @nt{aspect_specification},
6397 ],Old=[]}or a per-object expression of a component's @nt{constraint}, in which
6398 case, the freezing occurs later as part of another construct@Chg{Version=[3],New=[
6399 or at the freezing point of an associated entity],Old=[]}.
6400
6401 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]}
6402 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0019-1]}
6403 @ChgAdded{Version=[1],Text=[@PDefn2{Term=[freezing], Sec=(by an implicit call)}
6404 An implicit call freezes the same
6405 entities @Chg{Version=[3],New=[and profiles ],Old=[]}that would be frozen by an
6406 explicit call. This is true even if the implicit call is removed via
6407 implementation permissions.]}
6408
6409 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]}
6410 @ChgAdded{Version=[1],Text=[@PDefn2{Term=[freezing], Sec=(subtype caused by an implicit conversion)}
6411 If an expression is implicitly converted to a type or subtype @i(T),
6412 then at the place where the expression causes freezing, @i(T) is frozen.]}
6413
6414 @Leading@;The following rules define which entities are frozen at the place where
6415 a construct causes freezing:
6416 @begin{Itemize}
6417 @Leading@PDefn2{Term=[freezing], Sec=(type caused by an expression)}
6418 At the place where an expression causes freezing,
6419 the type of the expression is frozen,
6420 unless the expression is an enumeration literal used as a
6421 @nt{discrete_choice} of the @nt{array_@!aggregate} of an
6422 @nt{enumeration_@!representation_@!clause}.
6423 @begin{Reason}
6424 We considered making enumeration literals never cause freezing,
6425 which would be more upward compatible,
6426 but examples like the variant record aggregate (Discrim => Red, ...)
6427 caused us to change our mind.
6428 Furthermore, an enumeration literal is a static expression,
6429 so the implementation should be allowed to represent it using its
6430 representation.
6431 @end{Reason}
6432 @begin{Ramification}
6433 @Leading@;The following pathological example was legal in Ada 83,
6434 but is illegal in Ada 95:
6435 @begin{Example}
6436 @key[package] P1 @key[is]
6437 @key[type] T @key[is] @key[private];
6438 @key[package] P2 @key[is]
6439 @key[type] Composite(D : Boolean) @key[is]
6440 @key[record]
6441 @key[case] D @key[is]
6442 @key[when] False => Cf : Integer;
6443 @key[when] True => Ct : T;
6444 @key[end] @key[case];
6445 @key[end] @key[record];
6446 @key[end] P2;
6447 X : Boolean := P2."="( (False,1), (False,1) );
6448 @key[private]
6449 @key[type] T @key[is] @key[array](1..Func_Call) @key[of] Integer;
6450 @key[end];
6451 @end{Example}
6452
6453 In Ada 95, the declaration of X freezes Composite
6454 (because it contains an expression of that type),
6455 which in turn freezes T (even though Ct does not exist in this
6456 particular case).
6457 But type T is not completely defined at that point,
6458 violating the rule that a type shall be completely defined before it
6459 is frozen.
6460 In Ada 83, on the other hand, there is no occurrence of the name T,
6461 hence no forcing occurrence of T.
6462 @end{Ramification}
6463
6464 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0019-1],ARef=[AI05-0177-1]}
6465 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0157-1]}
6466 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[freezing], Sec=(profile of a function call)}
6467 @PDefn2{Term=[freezing], Sec=(expression of an expression function by a call)}
6468 At the place where a function call causes freezing, the profile of the function is
6469 frozen. Furthermore, if a parameter of the call is defaulted, the
6470 @nt{default_expression} for that parameter causes freezing. If the function call
6471 is to an expression function, the
6472 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
6473 of the expression function
6474 causes freezing.]}
6475
6476 @begin{Reason}
6477 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0019-1]}
6478 @ChgAdded{Version=[3],Text=[This is the important rule for profile freezing: a
6479 call freezes the profile. That's because generating the call will need to know
6480 how the parameters are passed, and that will require knowing details of the
6481 types. Other uses of subprograms do not need to know about the parameters, and
6482 thus only freeze the subprogram, and not the profile.]}
6483
6484 @ChgRef{Version=[3],Kind=[AddedNormal]}
6485 @ChgAdded{Version=[3],Text=[Note that we don't
6486 need to consider procedure or entry calls, since a body freezes
6487 everything that precedes it, and the end of a declarative part freezes
6488 everything in the declarative part.]}
6489 @end{Reason}
6490 @begin{Ramification}
6491 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]}
6492 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0103-1],ARef=[AI12-0157-1]}
6493 @ChgAdded{Version=[3],Text=[Freezing of the
6494 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
6495 of an expression
6496 function only needs to be considered when the expression function is in the
6497 same compilation unit and there are no intervening
6498 @Chg{Version=[4],New=[@nt{body}s],Old=[bodies]}; the end of a
6499 @nt{declarative_part} or library package freezes everything in it, and
6500 a @Chg{Version=[4],New=[@nt{body}],Old=[body]} freezes everything
6501 declared before it.]}
6502 @end{Ramification}
6503
6504
6505 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0019-1],ARef=[AI05-0177-1],ARef=[AI05-0296-1]}
6506 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0157-1]}
6507 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[freezing], Sec=(profile of a callable entity by an instantiation)}
6508 @PDefn2{Term=[freezing], Sec=(expression of an expression function by an instantiation)}
6509 At the place where a @nt{generic_instantiation} causes freezing of a callable
6510 entity, the profile of that entity is frozen
6511 unless the formal subprogram corresponding to the callable entity has a
6512 parameter or result of a formal untagged incomplete type;
6513 if the callable entity is
6514 an expression function, the
6515 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
6516 of the expression function causes freezing.]}
6517
6518 @begin{Reason}
6519 @ChgRef{Version=[3],Kind=[AddedNormal]}
6520 @ChgAdded{Version=[3],Text=[Elaboration of the generic might call the actual
6521 for one of its formal subprograms, so we need to know the profile and
6522 (for an expression function) @nt{expression}.]}
6523 @end{Reason}
6524
6525 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0177-1]}
6526 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0157-1]}
6527 @ChgAdded{Version=[3],Text=[@PDefn2{Term=[freezing], Sec=(expression of an expression function by Access attribute)}
6528 At the place where a use of the Access or Unchecked_Access attribute whose
6529 @nt{prefix} denotes an expression function causes freezing, the
6530 @Chg{Version=[4],New=[return expression],Old=[@nt{expression}]}
6531 of the expression function causes freezing.]}
6532
6533 @begin{Reason}
6534 @ChgRef{Version=[3],Kind=[AddedNormal]}
6535 @ChgAdded{Version=[3],Type=[Leading],Text=[This is needed to avoid calls to
6536 unfrozen expressions. Consider:]}
6537 @begin{Example}
6538 @ChgRef{Version=[3],Kind=[AddedNormal]}
6539 @ChgAdded{Version=[3],Text=[@key[package] Pack @key[is]]}
6540
6541 @ChgRef{Version=[3],Kind=[AddedNormal]}
6542 @ChgAdded{Version=[3],Text=[ @key[type] Flub @key[is range] 0 .. 100;]}
6543
6544 @ChgRef{Version=[3],Kind=[AddedNormal]}
6545 @ChgAdded{Version=[3],Text=[ @key[function] Foo (A : @key[in] Natural) @key[return] Natural @key[is]
6546 (A + Flub'Size); -- @Examcom[The expression is not frozen here.]]}
6547
6548 @ChgRef{Version=[3],Kind=[AddedNormal]}
6549 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
6550 @ChgAdded{Version=[3],Text=[ @key[type] Bar @key[is access function] @Chg{Version=[4],New=[],Old=[Foo ]}(A : @key[in] Natural) @key[return] Natural;]}
6551
6552 @ChgRef{Version=[3],Kind=[AddedNormal]}
6553 @ChgAdded{Version=[3],Text=[ P : Bar := Foo'Access; -- @Examcom[(A)]]}
6554
6555 @ChgRef{Version=[3],Kind=[AddedNormal]}
6556 @ChgAdded{Version=[3],Text=[ Val : Natural := P.@key[all](5); -- @Examcom[(B)]]}
6557
6558 @ChgRef{Version=[3],Kind=[AddedNormal]}
6559 @ChgAdded{Version=[3],Text=[@key[end] Pack;]}
6560 @end{Example}
6561
6562 @ChgRef{Version=[3],Kind=[AddedNormal]}
6563 @ChgAdded{Version=[3],Text=[If point (A) did not freeze the expression of Foo
6564 (which freezes Flub), then the call at point (B) would be depending on the
6565 aspects of the unfrozen type Flub. That would be bad.]}
6566 @end{Reason}
6567
6568 @Leading@PDefn2{Term=[freezing], Sec=(entity caused by a name)}
6569 At the place where a @nt<name> causes freezing,
6570 the entity denoted by the @nt<name> is frozen, unless
6571 the @nt<name> is a @nt<prefix> of an expanded name;
6572 @PDefn2{Term=[freezing], Sec=(nominal subtype caused by a name)}
6573 at the place where an object @nt{name} causes freezing, the
6574 nominal subtype associated with the @nt<name> is frozen.
6575 @begin{Ramification}
6576 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6577 This only matters in the presence of deferred constants or
6578 access types; an @nt{object_declaration} other than a
6579 @Chg{Version=[2],New=[deferred constant declaration],Old=[@ntf{deferred_constant_declaration}]}
6580 causes freezing of the nominal subtype, plus all component junk.
6581
6582 @ChgRef{Version=[1],Kind=[Deleted],Ref=[8652/0046],ARef=[AI95-00106-01]}
6583 @ChgDeleted{Version=[1],Text=[@nt{Implicit_dereference}s are covered by
6584 @nt{expression}.]}
6585 @Comment{This statement is just plain wrong.}
6586 @end{Ramification}
6587
6588 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0046],ARef=[AI95-00106-01]}
6589 @ChgAdded{Version=[1],Type=[Leading],Text=[@PDefn2{Term=[freezing], Sec=(subtype caused by an implicit dereference)}
6590 At the place where an @nt{implicit_dereference} causes freezing,
6591 the nominal subtype associated with the @nt{implicit_dereference} is frozen.]}
6592
6593 @begin{Discussion}
6594 @ChgRef{Version=[2],Kind=[AddedNormal]}
6595 @ChgAdded{Version=[2],Text=[This rule ensures that X.D freezes the same
6596 entities that X.@key{all}.D does. Note that an @nt{implicit_dereference} is
6597 neither a @nt{name} nor @nt{expression} by itself, so it isn't covered by
6598 other rules.]}
6599 @end{Discussion}
6600
6601 @Leading@Redundant[@PDefn2{Term=[freezing], Sec=(type caused by a range)}
6602 At the place where a @nt{range} causes freezing, the type of the
6603 @nt<range> is frozen.]
6604 @begin{TheProof}
6605 This is consequence of the facts that expressions freeze their type,
6606 and the Range attribute is defined to be equivalent
6607 to a pair of expressions separated by @lquotes@;..@rquotes@;.}
6608 @end{TheProof}
6609
6610 @Leading@PDefn2{Term=[freezing],
6611 Sec=(designated subtype caused by an allocator)}
6612 At the place where an @nt<allocator> causes freezing,
6613 the designated subtype of its type is frozen.
6614 If the type of the @nt<allocator> is a derived type,
6615 then all ancestor types are also frozen.
6616 @begin{Ramification}
6617 @nt{Allocator}s also freeze the named subtype,
6618 as a consequence of other rules.
6619
6620 @Leading@;The ancestor types are frozen to prevent things like this:
6621 @begin{Example}
6622 @key[type] Pool_Ptr @key[is] @key[access] System.Storage_Pools.Root_Storage_Pool'Class;
6623 @key[function] F @key[return] Pool_Ptr;
6624
6625 @key[package] P @key[is]
6626 @key[type] A1 @key[is] @key[access] Boolean;
6627 @key[type] A2 @key[is] @key[new] A1;
6628 @key[type] A3 @key[is] @key[new] A2;
6629 X : A3 := @key[new] Boolean; --@RI{ Don't know what pool yet!}
6630 @key[for] A1'Storage_Pool @key[use] F.all;
6631 @key[end] P;
6632 @end{Example}
6633
6634 This is necessary because derived access types share their parent's pool.
6635 @end{Ramification}
6636
6637 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0019-1]}
6638 @Leading@PDefn2{Term=[freezing], Sec=(subtypes of the profile of a callable entity)}
6639 At the place where a @Chg{Version=[3],New=[profile],Old=[callable entity]}
6640 is frozen, each subtype of @Chg{Version=[3],New=[the],Old=[its]} profile is frozen.
6641 If the @Chg{Version=[3],New=[corresponding ],Old=[]}callable entity is
6642 a member of an entry family, the index subtype of the family is
6643 frozen.@Chg{Version=[3],New=[],Old=[
6644 @PDefn2{Term=[freezing], Sec=(function call)}
6645 At the place where a function call
6646 causes freezing, if a parameter of the call is defaulted,
6647 the @nt{default_@!expression} for that parameter causes freezing.]}
6648 @begin{Discussion}
6649 @ChgRef{Version=[3],Kind=[Deleted]}@Comment{Moved above with rule}
6650 @ChgDeleted{Version=[3],Text=[We don't worry about freezing for procedure calls
6651 or entry calls, since a body freezes everything that precedes it, and the end
6652 of a declarative part freezes everything in the declarative part.]}
6653 @end{Discussion}
6654
6655 @Leading@PDefn2{Term=[freezing],
6656 Sec=[type caused by the freezing of a subtype]}
6657 At the place where a subtype is frozen,
6658 its type is frozen.
6659 @PDefn2{Term=[freezing], Sec=(constituents of a full type definition)}
6660 @PDefn2{Term=[freezing],
6661 Sec=(first subtype caused by the freezing of the type)}
6662 At the place where a type is frozen, any expressions or @nt<name>s within
6663 the full type definition cause freezing;
6664 the first subtype, and
6665 any component subtypes,
6666 index subtypes, and parent subtype
6667 of the type are frozen as well.
6668 @PDefn2{Term=[freezing],
6669 Sec=(class-wide type caused by the freezing of the specific type)}
6670 @PDefn2{Term=[freezing],
6671 Sec=(specific type caused by the freezing of the class-wide type)}
6672 For a specific tagged type,
6673 the corresponding class-wide type is frozen as well.
6674 For a class-wide type,
6675 the corresponding specific type is frozen as well.
6676 @begin{Ramification}
6677 Freezing a type needs to freeze its first subtype in order to
6678 preserve the property that the subtype-specific aspects of statically
6679 matching subtypes are the same.
6680
6681 Freezing an access type does not freeze its designated subtype.
6682 @end{Ramification}
6683
6684 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00341-01]}
6685 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0019-1]}
6686 @ChgAdded{Version=[2],Type=[Leading],Text=[At the place where a specific
6687 tagged type is frozen, the primitive subprograms of the type are
6688 frozen.@Chg{Version=[3],New=[ At the place where a type is frozen,
6689 any subprogram named in an @nt{attribute_definition_clause} for the type
6690 is frozen.],Old=[]}]}
6691 @begin{Reason}
6692 @ChgRef{Version=[2],Kind=[AddedNormal]}
6693 @ChgAdded{Version=[2],Text=[We have a language design principle that all of
6694 the details of a specific tagged type are known at its freezing point.
6695 But that is only true if the primitive subprograms are frozen at this
6696 point as well. Late changes of Import and address clauses violate the
6697 principle.]}
6698 @end{Reason}
6699 @begin{ImplNote}
6700 @ChgRef{Version=[2],Kind=[AddedNormal]}
6701 @ChgAdded{Version=[2],Text=[This rule means that no implicit call to
6702 Initialize or Adjust can freeze a subprogram (the type and thus subprograms
6703 would have been frozen at worst at the same point).]}
6704 @end{ImplNote}
6705 @begin{Discussion}
6706 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0019-1]}
6707 @ChgAdded{Version=[3],Text=[The second sentence is the rule that makes
6708 it possible to check that only subprograms with convention Ada are
6709 specified in @nt{attribute_definition_clause}s without jumping through hoops.]}
6710 @end{Discussion}
6711 @end{Itemize}
6712
6713 @end{Intro}
6714
6715 @begin{Legality}
6716
6717 @Comment{"Leading" below is to get the last paragraph onto the page with everything else.}
6718 @Leading@Redundant[The explicit declaration of a primitive subprogram of a
6719 tagged type shall occur before the type is frozen
6720 (see @RefSecNum{Dispatching Operations of Tagged Types}).]
6721 @begin{Reason}
6722 This rule is needed
6723 because (1) we don't want people dispatching to things that haven't
6724 been declared yet, and (2) we want to allow tagged type descriptors
6725 to be static (allocated statically, and initialized to link-time-known
6726 symbols). Suppose T2 inherits primitive P from T1, and then
6727 overrides P. Suppose P is called @i{before} the declaration of the
6728 overriding P. What should it dispatch to? If the answer is the new
6729 P, we've violated the first principle above. If the answer is the
6730 old P, we've violated the second principle. (A call
6731 to the new one necessarily raises Program_Error, but that's
6732 beside the point.)
6733
6734 Note that a call upon a dispatching operation of type @i(T) will freeze @i(T).
6735
6736 We considered applying this rule to all derived types, for uniformity.
6737 However, that would be upward incompatible, so we rejected the idea.
6738 As in Ada 83, for an untagged type, the above call upon P will call the
6739 old P (which is arguably confusing).
6740 @end{Reason}
6741
6742 @begin{Honest}
6743 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0222-1]}
6744 @ChgAdded{Version=[3],Text=[This rule only applies to "original" declarations
6745 and not to the completion of a primitive subprogram, even though a completion
6746 is technically an explicit declaration, and it may declare a primitive
6747 subprogram.]}
6748 @end{Honest}
6749
6750 @Leading@Redundant[A type shall be completely defined before it is frozen
6751 (see @RefSecNum{Completions of Declarations} and
6752 @RefSecNum{Private Types and Private Extensions}).]
6753
6754 @Leading@Redundant[The completion of a deferred constant declaration shall occur
6755 before the constant is frozen
6756 (see @RefSecNum{Deferred Constants}).]
6757
6758 @begin{TheProof}
6759 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
6760 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6761 @ChgAdded{Version=[2],Text=[The above @LegalityTitle are stated
6762 @lquotes@;officially@rquotes@; in the referenced
6763 @Chg{Version=[3],New=[subclauses],Old=[clauses]}.]}
6764 @end{TheProof}
6765
6766 @Leading@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
6767 @Chg{New=[An operational or],Old=[A]} representation item that
6768 directly specifies an aspect of an entity shall appear before the entity is
6769 frozen (see @RefSecNum{Operational and Representation Aspects}).
6770 @ChgNote{A last minute change (requested by WG9) moved this rule to 13.1(9).
6771 However, the rule there only covers types and subtypes. So this rule is not
6772 redundant, and I removed the @Redundant for it. I don't have a way to mark
6773 that as a change, so it is just gone. RLB-29-08-00}
6774
6775 @begin{Discussion}
6776
6777 @comment{The following is a "fix" to keep consistent with v. 5.95;
6778 appearently 6.0 is different.
6779 @ChgRef{Version=[1],Kind=[Deleted]}
6780 @ChgDeleted{Version=[1],Text=[Old @b{Change}.]}}
6781
6782 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
6783 From RM83-13.1(7). The wording here forbids freezing
6784 within the @Chg{New=[@nt{aspect_clause}],Old=[@nt{representation_clause}]}
6785 itself, which was not true of the Ada 83 wording.
6786 The wording of this rule is carefully written to
6787 work properly for type-related representation items.
6788 For example, an @nt{enumeration_@!representation_@!clause} is illegal after the
6789 type is frozen, even though the @ntf{_clause} refers to the first subtype.
6790
6791 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00114-01]}
6792 @ChgAdded{Version=[2],Text=[The above @LegalityName is stated
6793 for types and subtypes in @RefSecNum{Operational and Representation Aspects},
6794 but the rule here covers all other entities as well.]}
6795 @end{Discussion}
6796 @begin{TheProof}
6797 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00114-01]}
6798 @ChgDeleted{Version=[2],Text=[The above @LegalityTitle
6799 are stated @lquotes@;officially@rquotes@;
6800 in the referenced clauses.]}
6801 @end{TheProof}
6802 @begin{Discussion}
6803 @Leading@;Here's an example that illustrates when freezing occurs in the
6804 presence of defaults:
6805 @begin{Example}
6806 @key[type] T @key[is] ...;
6807 @key[function] F @key[return] T;
6808 @key[type] R @key[is]
6809 @key[record]
6810 C : T := F;
6811 D : Boolean := F = F;
6812 @key[end] @key[record];
6813 X : R;
6814 @end{Example}
6815
6816 Since the elaboration of R's declaration does not allocate component C,
6817 there is no need to freeze C's subtype at that place.
6818 Similarly, since the elaboration of R does not evaluate the
6819 @nt{default_expression} @lquotes@;F = F@rquotes@;, there is no need to freeze the types
6820 involved at that point.
6821 However, the declaration of X @i{does} need to freeze these things.
6822 Note that even if component C did not exist, the elaboration of the
6823 declaration of X would still need information about T @em even though
6824 D is not of type T,
6825 its @nt{default_expression} requires that information.
6826 @end{Discussion}
6827 @begin{Ramification}
6828 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6829 Although we define freezing in terms of the program text as a whole
6830 (i.e. after applying the rules of @Chg{Version=[3],New=[Clause],Old=[Section]}
6831 @RefSecNum{Program Structure and Compilation Issues}),
6832 the freezing rules actually have no effect beyond compilation unit boundaries.
6833 @end{Ramification}
6834 @begin{Reason}
6835 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6836 That is important, because @Chg{Version=[3],New=[Clause],Old=[Section]}
6837 @RefSecNum{Program Structure and Compilation Issues} allows some
6838 implementation definedness in the order of things,
6839 and we don't want the freezing rules to be implementation defined.
6840 @end{Reason}
6841 @begin{Ramification}
6842 These rules also have no effect in @nt{statement}s @em they only apply within
6843 a single @nt{declarative_part}, @nt{package_specification},
6844 @nt{task_definition},
6845 @nt{protected_definition},
6846 or @nt{protected_body}.
6847 @end{Ramification}
6848 @begin{ImplNote}
6849 An implementation may choose to generate code for
6850 @nt{default_expression}s and @nt{default_name}s in
6851 line at the place of use.
6852 @Defn{thunk}
6853 Alternatively, an implementation may choose to generate thunks
6854 (subprograms implicitly generated by the compiler)
6855 for evaluation of defaults.
6856 Thunk generation cannot, in general, be done at the place of the
6857 declaration that includes the default.
6858 Instead, they can be generated at the first freezing point of the
6859 type(s) involved.
6860 (It is impossible to write a purely one-pass Ada compiler,
6861 for various reasons.
6862 This is one of them @em the compiler needs to store a representation of
6863 defaults in its symbol table, and then walk that representation later,
6864 no earlier than the first freezing point.)
6865
6866 In implementation terms, the linear elaboration model can be thought of
6867 as preventing uninitialized dope.
6868 For example, the implementation might generate dope to contain the size
6869 of a private type.
6870 This dope is initialized at the place where the type becomes
6871 completely defined.
6872 It cannot be initialized earlier,
6873 because of the order-of-elaboration rules.
6874 The freezing rules prevent elaboration of earlier declarations from
6875 accessing the size dope for a private type before it is initialized.
6876
6877 @RefSecNum{Pragmas} overrides the freezing rules in the case of
6878 unrecognized @nt{pragma}s.
6879
6880 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
6881 @Chg{New=[An @nt{aspect_clause}],Old=[A @nt{representation_clause}]} for
6882 an entity should most certainly @i{not} be a freezing point for the entity.
6883 @end{ImplNote}
6884 @end{Legality}
6885
6886 @begin{RunTime}
6887 @ChgNote{This is the last normative paragraph in the subclause}
6888 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
6889 @ChgAdded{Version=[2],Text=[The tag (see
6890 @RefSecNum{Tagged Types and Type Extensions}) of a tagged type T
6891 is created at the point where T is frozen.@PDefn2{Term=[creation],Sec=[of a tag]}]}
6892 @end{RunTime}
6893
6894 @begin{Incompatible83}
6895 @Defn{incompatibilities with Ada 83}
6896 RM83 defines a forcing occurrence of a type as follows:
6897 @lquotes@;A forcing occurrence is any occurrence [of the name of the type,
6898 subtypes of the type, or types or subtypes with subcomponents of the type]
6899 other than in a type or subtype
6900 declaration, a subprogram specification, an entry declaration, a deferred
6901 constant declaration, a @nt{pragma}, or a @ntf{representation_clause} for the type
6902 itself. In any case, an occurrence within an expression is always forcing.@rquotes@;
6903
6904 @Leading@;It seems like the wording allows things like this:
6905 @begin{Example}
6906 @key[type] A @key[is] @key[array](Integer @key[range] 1..10) @key[of] Boolean;
6907 @key[subtype] S @key[is] Integer @key[range] A'Range;
6908 --@RI{ not forcing for A}
6909 @end{Example}
6910
6911 Occurrences within @nt{pragma}s can cause freezing in Ada 95.
6912 (Since such @nt{pragma}s are ignored in Ada 83,
6913 this will probably fix more bugs than it causes.)
6914 @end{Incompatible83}
6915
6916 @begin{Extend83}
6917 @Leading@;@Defn{extensions to Ada 83}
6918 In Ada 95, @nt{generic_formal_parameter_declaration}s
6919 do not normally freeze the entities from which they are defined.
6920 For example:
6921 @begin{example}
6922 @key[package] Outer @key[is]
6923 @key[type] T @key[is] @key[tagged] @key[limited] @key[private];
6924 @key[generic]
6925 @key[type] T2 @key[is]
6926 @key[new] T @key[with] @key[private]; --@RI{ Does not freeze T}
6927 --@RI{ in Ada 95.}
6928 @key[package] Inner @key[is]
6929 ...
6930 @key[end] Inner;
6931 @key[private]
6932 @key[type] T @key[is] ...;
6933 @key[end] Outer;
6934 @end{example}
6935
6936 This is important for the usability of generics.
6937 The above example uses the Ada 95 feature of formal derived types.
6938 Examples using the kinds of formal parameters already allowed in
6939 Ada 83 are well known.
6940 See, for example, comments 83-00627 and 83-00688.
6941 The extensive use expected for formal derived types
6942 makes this issue even more compelling
6943 than described by those comments.
6944 Unfortunately, we are unable to solve the problem that
6945 @nt{explicit_generic_actual_parameter}s cause freezing, even though a package
6946 equivalent to the instance would not cause freezing.
6947 This is primarily because such an equivalent package would have its
6948 body in the body of the containing program unit, whereas an instance
6949 has its body right there.
6950 @end{Extend83}
6951
6952 @begin{DiffWord83}
6953 The concept of freezing is based on Ada 83's concept of @lquotes@;forcing
6954 occurrences.@rquotes@;
6955 The first freezing point of an entity
6956 corresponds roughly to the place of the first forcing occurrence, in Ada
6957 83 terms.
6958 The reason for changing the terminology is that the new rules do not
6959 refer to any particular @lquotes@;occurrence@rquotes@; of a name of an entity.
6960 Instead, we refer to @lquotes@;uses@rquotes@; of an entity,
6961 which are sometimes implicit.
6962
6963 In Ada 83, forcing occurrences were used only in rules about
6964 @ntf{representation_clause}s.
6965 We have expanded the concept to cover private types,
6966 because the rules stated in RM83-7.4.1(4) are almost identical to the
6967 forcing occurrence rules.
6968
6969 @Leading@;The Ada 83 rules are changed in Ada 95 for the following reasons:
6970 @begin{Itemize}
6971 The Ada 83 rules do not work right for subtype-specific aspects.
6972 In an earlier version of Ada 9X, we considered allowing representation
6973 items to apply to subtypes other than the first subtype.
6974 This was part of the reason for changing the Ada 83 rules.
6975 However, now that we have dropped that functionality,
6976 we still need the rules to be different from the Ada 83 rules.
6977
6978 The Ada 83 rules do not achieve the intended effect.
6979 In Ada 83, either with or without the AIs,
6980 it is possible to force the compiler to generate code that references
6981 uninitialized dope, or force it to detect erroneousness and exception
6982 raising at compile time.
6983
6984 It was a goal of Ada 83 to avoid uninitialized access values.
6985 However, in the case of deferred constants, this goal was not achieved.
6986
6987 The Ada 83 rules are not only too weak @em they are also too strong.
6988 They allow loopholes (as described above),
6989 but they also prevent certain kinds of @nt{default_expression}s that are
6990 harmless,
6991 and certain kinds of @nt{generic_declaration}s that are both harmless
6992 and very useful.
6993
6994 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6995 Ada 83 had a case where @Chg{Version=[2],New=[an @nt{aspect_clause}],
6996 Old=[a @nt{representation_clause}]} had a strong
6997 effect on the semantics of the program @em 'Small.
6998 This caused certain semantic anomalies.
6999 There are more cases in Ada 95,
7000 because the @Chg{Version=[2],New=[@nt{attribute_definition_clause}],
7001 Old=[@ntf{attribute_representation_clause}]} has been generalized.
7002 @end{Itemize}
7003 @end{DiffWord83}
7004
7005 @begin{Incompatible95}
7006 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0046],ARef=[AI95-00106-01],ARef=[AI95-00341-01]}
7007 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
7008 @b<Corrigendum:> Various freezing rules were added to fix holes in the rules.
7009 Most importantly, implicit calls are now freezing, which make some
7010 representation clauses illegal in Ada 2005 that were legal (but dubious) in
7011 Ada 95. @b[Amendment Correction:] Similarly, the primitive subprograms of a
7012 specific tagged type are frozen when the type is frozen, preventing dubious
7013 convention changes (and address clauses) after the freezing point. In both
7014 cases, the code is dubious and the workaround is easy.]}
7015 @end{Incompatible95}
7016
7017 @begin{DiffWord95}
7018 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
7019 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to specify that
7020 both operational and representation attributes must be specified before
7021 the type is frozen.]}
7022
7023 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
7024 @ChgAdded{Version=[2],Text=[Added wording that declaring a specific
7025 descendant of an interface type freezes the interface type.]}
7026
7027 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00279-01]}
7028 @ChgAdded{Version=[2],Text=[Added wording that defines when a tag is created
7029 for a type (at the freezing point of the type). This is used to specify
7030 checking for uncreated tags (see @RefSecNum{Tagged Types and Type Extensions}).]}
7031 @end{DiffWord95}
7032
7033 @begin{Incompatible2005}
7034 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0019-1]}
7035 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 95}@b<Correction:>
7036 Separated the freezing of the profile from the rest of a subprogram, in order
7037 to reduce the impact of the Ada 95 incompatibility noted above. (The effects
7038 were much more limiting than expected.)]}
7039 @end{Incompatible2005}
7040
7041 @begin{DiffWord2005}
7042 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0017-1]}
7043 @ChgAdded{Version=[3],Text=[@b<Correction:> Reworded so that
7044 incomplete types with a deferred completion aren't prematurely
7045 frozen.]}
7046
7047 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]}
7048 @ChgAdded{Version=[3],Text=[Added freezing rules for expression functions;
7049 these are frozen at the point of call, not the point of declaration, like
7050 default expressions.]}
7051
7052 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
7053 @ChgAdded{Version=[3],Text=[Added freezing rules for @nt{aspect_specification}s;
7054 these are frozen at the freezing point of the associated entity, not the
7055 point of declaration.]}
7056
7057 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0213-1]}
7058 @ChgAdded{Version=[3],Text=[Added freezing rules for formal incomplete types;
7059 the corresponding actual is not frozen.]}
7060 @end{DiffWord2005}
7061
7062 @begin{DiffWord2012}
7063 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0103-1],ARef=[AI12-0132-1]}
7064 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified when and what an
7065 @nt{expression_function_declaration} that is a completion or that is the
7066 target of a renames-as-body freezes. This is formally an incompatibility,
7067 but as all known implementations freeze expression functions more
7068 aggressively than allowed by either the old or new wording, practically this
7069 will be an extension.]}
7070 @end{DiffWord2012}
7071