Debian Codegraph @

source_2020/13b.mss

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