Debian Codegraph @

source_2012/10.mss

raw
1 @Part(10, Root="ada.mss")
2
3 @Comment{$Date: 2015/04/03 04:12:42 $}
4 @LabeledSection{Program Structure and Compilation Issues}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/10.mss,v $}
7 @Comment{$Revision: 1.106 $}
8 @Comment{Corrigendum changes added, 2000/04/24, RLB}
9
10 @begin{Intro}
11 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
12 @redundant[The overall structure of programs and the facilities for separate
13 compilation are described in this @Chg{Version=[3],New=[clause],Old=[section]}.
14 A @i(program) is a set of @i(partitions), each of which
15 may execute in a separate address space, possibly on a separate
16 computer.
17 @ToGlossary{Term=<Program>,
18 Text=<A @i(program) is a set of @i(partitions), each of which
19 may execute in a separate address space, possibly on a separate
20 computer.
21 A partition consists of a set of library units.>}
22 @ToGlossary{Term=<Partition>,
23 Text=<A @i(partition) is a part of a program.
24 Each partition consists of a set of library units.
25 Each partition may run in a separate address space,
26 possibly on a separate computer.
27 A program may contain just one partition.
28 A distributed program typically contains multiple partitions,
29 which can execute concurrently.>}
30
31 @Defn2{Term=[library unit],Sec=(informal introduction)}
32 @Defn2{Term=[library_item],Sec=(informal introduction)}
33 @Defn2{Term=[library],Sec=(informal introduction)}
34 As explained below,
35 a partition is constructed from @i{library units}.
36 Syntactically, the declaration of a library unit is a @nt{library_item},
37 as is the body of a library unit.
38 An implementation may support a concept of a @i{program library}
39 (or simply, a @lquotes@;library@rquotes@;),
40 which contains @nt{library_item}s
41 and their subunits.
42 @IndexSee{Term=[program library],See=(library)}
43 Library units may be organized into a hierarchy of
44 children, grandchildren, and so on.]
45
46 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
47 This @Chg{Version=[3],New=[clause],Old=[section]} has two
48 @Chg{Version=[3],New=[subclauses],Old=[clauses]}:
49 @RefSec{Separate Compilation}
50 discusses compile-time issues related to separate compilation.
51 @RefSec{Program Execution}
52 discusses issues related to what is traditionally known as @lquotes@;link time@rquotes@;
53 and @lquotes@;run time@rquotes@; @em building and executing partitions.
54
55 @end{Intro}
56
57 @begin{MetaRules}
58 @Defn{avoid overspecifying environmental issues}
59 We should avoid specifying details that are outside the domain of the
60 language itself.
61 The standard is intended (at least in part)
62 to promote portability of Ada programs at the source level.
63 It is not intended to standardize extra-language issues such as how one
64 invokes the compiler (or other tools),
65 how one's source is represented and organized,
66 version management, the format of error messages, etc.
67
68 @Defn{safe separate compilation}
69 @Defn2{Term=[separate compilation], Sec=(safe)}
70 The rules of the language should be enforced
71 even in the presence of separate compilation.
72 Using separate compilation should not make a
73 program less safe.
74
75 @Defn{legality determinable via semantic dependences}
76 It should be possible to determine the legality of a
77 compilation unit by looking only at the compilation unit itself
78 and the compilation units upon which it depends semantically.
79 As an example, it should be possible to analyze the legality of
80 two compilation units in parallel if they do not depend semantically
81 upon each other.
82
83 On the other hand, it may be necessary to look outside that set in
84 order to generate code @em this is generally true for
85 generic instantiation and inlining, for example.
86 Also on the other hand,
87 it is generally necessary to look outside that set in
88 order to check @LinkTimeName@;s.
89
90 See also the @lquotes@;generic contract model@rquotes@; @MetaRulesName of
91 @RefSec{Generic Instantiation}.
92 @end{MetaRules}
93
94 @begin{DiffWord83}
95 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
96 The @Chg{Version=[3],New=[clause],Old=[section]} organization mentioned above is
97 different from that of RM83. @end{DiffWord83}
98
99 @LabeledClause{Separate Compilation}
100
101 @begin{Intro}
102 @redundant[@Defn{separate compilation}
103 @Defn2{Term=[compilation], Sec=(separate)}
104 @ToGlossaryAlso{Term=<Program unit>,
105 Text=<A @i(program unit) is either a package, a task unit,
106 a protected unit, a protected entry, a generic unit,
107 or an explicitly declared subprogram other than an enumeration
108 literal.
109 Certain kinds of program units can be separately compiled.
110 Alternatively, they can appear physically nested within
111 other program units.>}
112
113 @ToGlossaryAlso{Term=<Compilation unit>,
114 Text=<The text of a program can be submitted to the compiler in one or
115 more @nt(compilation)s.
116 Each @nt(compilation) is a succession of @nt(compilation_unit)s.
117 A @nt(compilation_unit) contains either
118 the declaration, the body, or a renaming of a program unit.>}]
119 The representation for a @nt<compilation> is implementation-defined.
120 @ImplDef{The representation for a @nt{compilation}.}
121 @begin{Ramification}
122 Some implementations might choose to make a
123 @nt{compilation} be a source (text) file.
124 Others might allow multiple source files to be automatically
125 concatenated to form a single @nt{compilation}.
126 Others still may represent the source in a nontextual form such as a parse
127 tree.
128 Note that the RM95 does not even define the concept of a
129 source file.
130
131 Note that a protected subprogram is a subprogram,
132 and therefore a program unit.
133 An instance of a generic unit is a program unit.
134
135 A protected entry is a program unit,
136 but protected entries cannot be separately compiled.
137 @end{Ramification}
138
139 @ToGlossaryAlso{Term=<Library unit>,
140 Text=<A library unit is a separately compiled
141 program unit,
142 and is always a package, subprogram, or generic unit.
143 Library units may have other (logically nested) library units as children,
144 and may have other program units physically nested within them.
145 @Defn(subsystem)
146 A root library unit, together with its children and grandchildren
147 and so on, form a @i(subsystem).>}
148
149 @end{Intro}
150
151 @begin{ImplPerm}
152 An implementation may impose implementation-defined restrictions
153 on @nt{compilation}s that contain multiple @nt<compilation_unit>s.
154 @ImplDef{Any restrictions on @nt<compilation>s that contain
155 multiple @nt<compilation_unit>s.}
156 @begin{Discussion}
157 For example, an implementation might disallow a @nt{compilation} that
158 contains two versions of the same compilation unit, or that
159 contains the declarations for library packages P1 and P2,
160 where P1 precedes P2 in the @nt<compilation> but P1 has a
161 @nt<with_clause> that mentions P2.
162 @end{Discussion}
163 @end{ImplPerm}
164
165 @begin{DiffWord83}
166 The interactions between language issues and environmental issues
167 are left open in Ada 95. The environment concept is new.
168 In Ada 83, the concept of the program library, for example,
169 appeared to be quite concrete,
170 although the rules had no force,
171 since implementations could get around them simply by defining various
172 mappings from the concept of an Ada program library to whatever data
173 structures were actually stored in support of separate compilation.
174 Indeed, implementations were encouraged to do so.
175
176 In RM83, it was unclear which was the official definition of
177 @lquotes@;program unit.@rquotes@;
178 Definitions appeared in RM83-5, 6, 7, and 9, but not 12.
179 Placing it here seems logical,
180 since a program unit is sort of a potential compilation unit.
181 @end{DiffWord83}
182
183 @LabeledSubClause{Compilation Units - Library Units}
184
185 @begin{Intro}
186 @redundant[A @nt{library_item} is a compilation unit that is the declaration, body,
187 or renaming of a library unit.
188 Each library unit (except Standard) has a @i{parent unit},
189 which is a library package or generic library package.]
190 @Defn2{Term=[child], Sec=(of a library unit)}
191 A library unit is a @i{child} of its parent unit.
192 The @i{root} library units are the children of
193 the predefined library package Standard.
194 @begin{Ramification}
195 Standard is a library unit.
196 @end{Ramification}
197 @end{Intro}
198
199 @begin{Syntax}
200 @Syn{lhs=<compilation>,rhs="{@Syn2{compilation_unit}}"}
201
202
203 @Syn{lhs=<compilation_unit>,rhs="
204 @Syn2{context_clause} @Syn2{library_item}
205 | @Syn2{context_clause} @Syn2{subunit}"}
206
207
208 @Syn{lhs=<library_item>,rhs="[@key{private}] @Syn2{library_unit_declaration}
209 | @Syn2{library_unit_body}
210 | [@key{private}] @Syn2{library_unit_renaming_declaration}"}
211
212
213 @Syn{tabs=[P25], lhs=<library_unit_declaration>,rhs="
214 @Syn2{subprogram_declaration}@\| @Syn2{package_declaration}
215 | @Syn2{generic_declaration}@\| @Syn2{generic_instantiation}"}
216
217
218 @Syn{lhs=<library_unit_renaming_declaration>,rhs="
219 @Syn2{package_renaming_declaration}
220 | @Syn2{generic_renaming_declaration}
221 | @Syn2{subprogram_renaming_declaration}"}
222
223
224 @Syn{lhs=<library_unit_body>,rhs="@Syn2{subprogram_body} | @Syn2{package_body}"}
225
226
227 @Syn{lhs=<parent_unit_name>,rhs="@Syn2{name}"}
228
229 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
230 @ChgAdded{Version=[2],Text=[An @nt{overriding_indicator} is not allowed in a
231 @nt{subprogram_declaration}, @nt{generic_instantiation}, or
232 @nt{subprogram_renaming_declaration} that declares a library unit.]}
233
234 @begin{Reason}
235 @ChgRef{Version=[2],Kind=[Added]}
236 @ChgAdded{Version=[2],Text=[All of the listed items syntactically include
237 @nt{overriding_indicator}, but a library unit can never override anything.
238 A majority of the ARG thought that allowing @key{not overriding} in that
239 case would be confusing instead of helpful.]}
240 @end{Reason}
241 @end{Syntax}
242
243 @begin{Intro}
244 @Defn{library unit}
245 @PDefn{library}@Comment{There is a different definition of library in 10.1.4.}
246 @Seealso{Primary=[library],Other=[library level]}
247 @Seealso{Primary=[library],Other=[library unit]}
248 @Seealso{Primary=[library],Other=[library_item]}
249 A @i{library unit} is a program unit that is declared by a
250 @nt{library_item}.
251 When a program unit is a library unit,
252 the prefix @lquotes@;library@rquotes@; is used to refer to it (or @lquotes@;generic library@rquotes@;
253 if generic),
254 as well as to its declaration and body,
255 as in @lquotes@;library procedure@rquotes@;, @lquotes@;library @nt{package_body}@rquotes@;, or
256 @lquotes@;generic library package@rquotes@;.
257 @Defn{compilation unit}
258 The term @i{compilation unit} is used to refer to
259 a @nt{compilation_unit}.
260 When the meaning is clear from context,
261 the term is also used to refer to the @nt{library_item}
262 of a @nt{compilation_unit}
263 or to the @nt{proper_body} of a @nt{subunit}
264 @Redundant[(that is, the @nt{compilation_unit} without the
265 @nt{context_clause} and the @key[separate] (@nt{parent_unit_name}))].
266 @begin{Discussion}
267 @leading@keepnext@;In this example:
268 @begin{Example}
269 @key[with] Ada.Text_IO;
270 @key[package] P @key[is]
271 ...
272 @key[end] P;
273 @end{Example}
274
275 the term @lquotes@;compilation unit@rquotes@; can refer to this text: @lquotes@;@key[with] Ada.Text_IO;
276 @key[package] P @key[is] ... @key[end] P;@rquotes@; or to this text:
277 @lquotes@;@key[package] P @key[is] ... @key[end] P;@rquotes@;. We use this shorthand
278 because it corresponds to common usage.
279
280 We like to use the word @lquotes@;unit@rquotes@; for declaration-plus-body things,
281 and @lquotes@;item@rquotes@; for declaration or body separately (as in
282 @nt{declarative_item}).
283 The terms @lquotes@;@nt{compilation_unit},@rquotes@; @lquotes@;compilation unit,@rquotes@;
284 and @lquotes@;@nt{subunit}@rquotes@; are exceptions to this rule.
285 We considered changing @lquotes@;@nt{compilation_unit},@rquotes@; @lquotes@;compilation unit@rquotes@;
286 to @lquotes@;@ntf{compilation_item},@rquotes@; @lquotes@;compilation item,@rquotes@;
287 respectively, but we decided not to.
288 @end{Discussion}
289
290 @Defn2{Term=[parent declaration], Sec=(of a @nt{library_item})}
291 @Defn2{Term=[parent declaration], Sec=(of a library unit)}
292 The @i{parent declaration} of a @nt{library_item}
293 (and of the library unit) is the declaration denoted
294 by the @nt{parent_@!unit_name}, if any, of the
295 @nt{defining_@!program_@!unit_name} of the @nt<library_item>.
296 @Defn{root library unit}
297 If there is no @nt{parent_@!unit_name},
298 the parent declaration is the declaration of Standard,
299 the @nt{library_item} is a @i{root} @nt{library_item}, and
300 the library unit (renaming) is a @i{root} library
301 unit (renaming).
302 The declaration and body of Standard itself have no parent declaration.
303 @Defn2{Term=[parent unit], Sec=(of a library unit)}
304 The @i{parent unit} of a @nt{library_item} or library unit is the
305 library unit declared by its parent declaration.
306 @begin{Discussion}
307 The declaration and body of Standard are presumed to exist from
308 the beginning of time, as it were.
309 There is no way to actually write them,
310 since there is no syntactic way to indicate lack of a parent.
311 An attempt to compile a package Standard would result in
312 Standard.Standard.
313 @end{Discussion}
314 @begin{Reason}
315 Library units (other than Standard)
316 have @lquotes@;parent declarations@rquotes@; and @lquotes@;parent units@rquotes@;.
317 Subunits have @lquotes@;parent bodies@rquotes@;.
318 We didn't bother to define the other possibilities:
319 parent body of a library unit,
320 parent declaration of a subunit,
321 parent unit of a subunit.
322 These are not needed,
323 and might get in the way of a correct definition of @lquotes@;child.@rquotes@;
324 @end{Reason}
325
326 @Redundant[The children of a library unit occur immediately
327 within the declarative region of the declaration of the library unit.]
328 @Defn2{Term=[ancestor], Sec=(of a library unit)}
329 The @i{ancestors} of a library unit are itself, its parent,
330 its parent's parent, and so on.
331 @Redundant[(Standard is an ancestor of every library unit.)]
332 @Defn{descendant}
333 The @i{descendant} relation is the inverse of the ancestor relation.
334 @begin{Reason}
335 These definitions are worded carefully to avoid defining subunits as
336 children. Only library units can be children.
337
338 We use the unadorned term @lquotes@;ancestors@rquotes@; here to concisely define both
339 @lquotes@;ancestor unit@rquotes@; and @lquotes@;ancestor declaration.@rquotes@;
340 @end{Reason}
341
342 @Defn{public library unit}
343 @Defn{public declaration of a library unit}
344 @Defn{private library unit}
345 @Defn{private declaration of a library unit}
346 A @nt<library_unit_declaration>
347 or a @nt<library_@!unit_@!renaming_@!declaration> is @i{private}
348 if the declaration is immediately preceded
349 by the reserved word @key{private};
350 it is otherwise @i{public}. A library unit is private or public
351 according to its declaration.
352 @Defn2{Term=[public descendant], Sec=(of a library unit)}
353 The @i{public descendants} of a library unit are the library unit
354 itself, and the public descendants of its public children.
355 @Defn2{Term=[private descendant], Sec=(of a library unit)}
356 Its other descendants are @i{private descendants}.
357 @begin{Discussion}
358 The first concept defined here is that a @nt<library_item> is either public
359 or private (not in relation to anything else @em it's just a property of
360 the library unit).
361 The second concept is that a @nt<library_item>
362 is a public descendant or
363 private descendant @i{of a given ancestor}.
364 A given @nt<library_item> can be a
365 public descendant of one of its ancestors,
366 but a private descendant of some other ancestor.
367
368 A subprogram declared by a @nt{subprogram_body}
369 (as opposed to a @nt{subprogram_declaration})
370 is always public,
371 since the syntax rules disallow the reserved word @key[private]
372 on a body.
373
374 Note that a private library unit is a @i{public}
375 descendant of itself,
376 but a @i{private} descendant of its parent.
377 This is because it is visible outside itself @em its
378 privateness means that it is not visible outside its
379 parent.
380
381 Private children of Standard are legal, and follow the normal rules.
382 It is intended that implementations might have some method for taking an
383 existing environment, and treating it as a package to be @lquotes@;imported@rquotes@; into
384 another environment, treating children of Standard in the imported environment
385 as children of the imported package.
386 @end{Discussion}
387 @begin{Ramification}
388 @leading@;Suppose we have a public library unit A,
389 a private library unit A.B, and a public library unit A.B.C.
390 A.B.C is a public descendant of itself and of A.B,
391 but a private descendant of A;
392 since A.B is private to A, we don't allow A.B.C to escape outside A
393 either.
394 This is similar to the situation that would occur with physical
395 nesting, like this:
396 @begin{Example}
397 @key[package] A @key[is]
398 @key[private]
399 @key[package] B @key[is]
400 @key[package] C @key[is]
401 @key[end] C;
402 @key[private]
403 @key[end] B;
404 @key[end] A;
405 @end{Example}
406
407 Here, A.B.C is visible outside itself and outside A.B, but not outside A.
408 (Note that this example is intended to illustrate the visibility
409 of program units from the outside;
410 the visibility within child units is not quite identical to that of
411 physically nested units,
412 since child units are nested after their parent's declaration.)
413 @end{Ramification}
414
415 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
416 @ChgAdded{Version=[2],Text=[For each library @nt{package_declaration} in the
417 environment, there is an implicit declaration of a
418 @i{limited view} of that library package.@Defn{limited view} The
419 limited view of a package contains:]}
420
421 @begin(Itemize)
422 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
423 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0129-1],ARef=[AI05-0262-1]}
424 @ChgAdded{Version=[2],Text=[For each@Chg{Version=[3],New=[],Old=[ nested]}
425 @nt{package_declaration}@Chg{Version=[3],New=[ occurring immediately within
426 the visible part],Old=[]}, a declaration of the limited view of that package,
427 with the same @nt{defining_program_unit_name}.]}
428
429 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00326-01]}
430 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0108-1],ARef=[AI05-0129-1],ARef=[AI05-0262-1]}
431 @ChgAdded{Version=[2],Text=[For each @nt{type_declaration}
432 @Chg{Version=[3],New=[occurring immediately within],Old=[in]} the visible
433 part@Chg{Version=[3],New=[ that is not an
434 @nt{incomplete_type_declaration}],Old=[]}, an incomplete view
435 of the type@Chg{Version=[3],New=[ with no @nt{discriminant_part}],Old=[]};
436 if the @nt{type_declaration} is tagged, then the view is a
437 tagged incomplete view.]}
438 @begin{Reason}
439 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0108-1]}
440 @ChgAdded{Version=[3],Text=[The incomplete view of a type does not have
441 a discriminant_part even if the @nt{type_declaration} does have
442 one. This is necessary because semantic analysis (and the associated
443 dependence on @nt{with_clause}s) would be necessary
444 to determine the types of the discriminants.]}
445
446 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0129-1]}
447 @ChgAdded{Version=[3],Text=[No incomplete views of incomplete types are
448 included in the limited view. The rules of
449 @RefSecNum{Incomplete Type Declarations} ensure that the completion of any
450 visible incomplete type is declared in the same visible part, so such
451 an incomplete view would simply be redundant.]}
452 @end{Reason}
453 @end(Itemize)
454
455 @begin(Discussion)
456 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
457 @ChgAdded{Version=[2],Text=[The implementation model of a limited view is that it
458 can be determined solely from the syntax of the source of the unit, without
459 any semantic analysis. That allows it to be created without the semantic
460 dependences of a full unit, which is necessary for it to break mutual
461 dependences of units.]}
462 @end(Discussion)
463
464 @begin(Ramification)
465 @ChgRef{Version=[2],Kind=[Added]}
466 @ChgAdded{Version=[2],Text=[The limited view does not include package instances and
467 their contents. Semantic analysis of a unit (and dependence on its
468 @nt{with_clause}s) would be needed to determine the contents of an instance.]}
469 @end(Ramification)
470
471 @ChgRef{Version=[2],Kind=[Added]}
472 @ChgAdded{Version=[2],Text=[The limited view of a library @nt{package_declaration} is private if that
473 library @nt{package_declaration} is immediately preceded by the reserved word
474 @key{private}.]}
475
476 @ChgRef{Version=[2],Kind=[Added]}
477 @ChgAdded{Version=[2],Text=[@Redundant[There is no syntax for declaring limited
478 views of packages, because they are always implicit.] The implicit declaration
479 of a limited view of a library package @Redundant[is not the declaration of a
480 library unit (the library @nt{package_declaration} is); nonetheless, it] is a
481 @nt{library_item}. The implicit declaration of the limited view of a library
482 package forms an (implicit) compilation unit whose @nt{context_clause} is
483 empty.]}
484
485 @ChgRef{Version=[2],Kind=[Added]}
486 @ChgAdded{Version=[2],Text=[A library @nt{package_declaration} is the completion of
487 the declaration of its limited view.]}
488
489 @begin{Honest}
490 @ChgRef{Version=[2],Kind=[AddedNormal]}
491 @ChgAdded{Version=[2],Text=[This is notwithstanding the rule in
492 @RefSecNum{Completions of Declarations} that says that implicit declarations
493 don't have completions.]}
494 @end{Honest}
495 @begin{Reason}
496 @ChgRef{Version=[2],Kind=[AddedNormal]}
497 @ChgAdded{Version=[2],Text=[This rule explains where to find the completions
498 of the incomplete views defined by the limited view.]}
499 @end{Reason}
500
501 @end{Intro}
502
503 @begin{Legality}
504 The parent unit of a @nt<library_item> shall be a
505 @Redundant[library] package or generic @Redundant[library] package.
506
507 If a @nt{defining_program_unit_name} of a given
508 declaration or body has a @nt{parent_unit_name},
509 then the given declaration or body shall be a @nt<library_item>.
510 The body of a program unit shall be a @nt{library_item} if and only
511 if the declaration of the program unit is a @nt<library_item>.
512 In a @nt{library_@!unit_@!renaming_@!declaration},
513 the @Redundant[(old)] @nt{name}
514 shall denote a @nt<library_item>.
515 @begin{Discussion}
516 We could have allowed nested program units to be children
517 of other program units;
518 their semantics would make sense.
519 We disallow them to keep things simpler
520 and because they wouldn't be particularly useful.
521 @end{Discussion}
522
523 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
524 A @nt{parent_unit_name} @Redundant[(which can be used within a
525 @nt<defining_program_unit_name> of a @nt<library_item>
526 and in the @key[separate] clause of a @nt<subunit>)],
527 and each of its @nt{prefix}es,
528 shall not denote a @nt{renaming_declaration}.
529 @Redundant[On the other hand,
530 a name that denotes a @nt{library_@!unit_@!renaming_@!declaration} is allowed
531 in a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]}
532 and other places where the name of a library unit is allowed.]
533
534 If a library package is an instance of
535 a generic package, then every child of the
536 library package shall either be itself an instance or be a renaming of
537 a library unit.
538 @begin{Discussion}
539 A child of an instance of a given generic unit
540 will often be an instance of a (generic) child of the given
541 generic unit.
542 This is not required, however.
543 @end{Discussion}
544 @begin{Reason}
545 @leading@;Instances are forbidden from having noninstance children for two reasons:
546 @begin(Enumerate)
547 We want all source code that can depend on information from
548 the private part of a library unit to be inside the "subsystem"
549 rooted at the library unit.
550 If an instance of a generic unit were allowed to have a noninstance
551 as a child, the source code of that child might depend on information
552 from the private part of the generic unit, even though it is outside
553 the subsystem rooted at the generic unit.
554
555 Disallowing noninstance children simplifies the description of the
556 semantics of children of generic packages.
557 @end(Enumerate)
558 @end{Reason}
559
560 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
561 A child of a generic library package shall either be itself a generic unit
562 or be a renaming of some other child of the same generic unit.@Chg{Version=[3],
563 New=[],Old=[ The renaming of a child of a generic package shall occur
564 only within the declarative region of the generic package.]}
565
566
567 A child of a parent generic package shall be
568 instantiated or renamed only within the declarative region
569 of the parent generic.
570
571 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00331-01]}
572 For each @Chg{Version=[2],New=[child @i<C>],
573 Old=[declaration or renaming of a generic unit as a child]} of some parent
574 generic package@Chg{Version=[2],New=[ @i<P>],Old=[]}, there is
575 a corresponding declaration @Chg{Version=[2],New=[@i<C>],Old=[]} nested
576 immediately within each instance @Chg{Version=[2],New=[of @i<P>. For the
577 purposes of this rule, if a child @i<C> itself has a child @i<D>, each
578 corresponding declaration for @i<C> has a corresponding
579 child @i<D>], Old=[of the parent]}.
580 @Redundant[@Chg{Version=[2],New=[The corresponding],Old=[This]}
581 declaration @Chg{Version=[2],New=[for a child within an instance ],Old=[]}is
582 visible only within the scope of a @nt{with_clause} that
583 mentions the @Chg{Version=[2],New=[(original) ],Old=[]}child generic unit.]
584
585 @begin{ImplNote}
586 Within the child, like anything nested in a generic unit,
587 one can make up-level references to the current instance of its
588 parent, and thereby gain access to the formal parameters of the
589 parent, to the types declared in the parent, etc.
590 This @lquotes@;nesting@rquotes@; model applies even within the
591 @nt{generic_formal_part} of the child,
592 as it does for a generic child of a nongeneric unit.
593 @end{ImplNote}
594 @begin{Ramification}
595
596 Suppose P is a generic library package,
597 and P.C is a generic child of P.
598 P.C can be instantiated inside the declarative region of P.
599 Outside P, P.C can be mentioned only in a @nt{with_clause}.
600 Conceptually, an instance I of P is a package that has a nested
601 generic unit called I.C.
602 Mentioning P.C in a @nt{with_clause} allows I.C to be instantiated.
603 I need not be a library unit,
604 and the instantiation of I.C need not be a library unit.
605 If I is a library unit, and an instance of I.C is a child of I,
606 then this instance has to be called something other than C.
607
608 @end{Ramification}
609
610 A library subprogram shall not override a primitive subprogram.
611 @begin{Reason}
612 This prevents certain obscure anomalies.
613 For example, if a library subprogram were to override a subprogram
614 declared in its parent package, then in a compilation unit that depends
615 @i{in}directly on the library subprogram, the library subprogram could
616 hide the overridden operation from all visibility,
617 but the library subprogram itself would not be visible.
618
619 Note that even without this rule, such subprograms would be illegal for
620 tagged types, because of the freezing rules.
621 @end{Reason}
622
623 The defining name of a function that is a compilation unit
624 shall not be an @nt{operator_symbol}.
625 @begin{Reason}
626 Since overloading is not permitted among compilation units,
627 it seems unlikely that it would be useful to define one as
628 an operator. Note that a subunit could be renamed within its
629 parent to be an operator.
630 @end{Reason}
631
632 @end{Legality}
633
634 @begin{StaticSem}
635
636 A @nt<subprogram_renaming_declaration>
637 that is a @nt{library_@!unit_@!renaming_@!declaration} is a
638 renaming-as-declaration, not a renaming-as-body.
639
640
641
642 @leading@keepnext@redundant[There are two kinds of dependences among
643 compilation units:]
644 @begin{Itemize}
645 @redundant[The @i{semantic dependences}
646 (see below)
647 are the ones needed to check the
648 compile-time rules across compilation unit boundaries;
649 a compilation unit depends semantically on
650 the other compilation units needed to determine its legality.
651 The visibility rules are based on the semantic dependences.
652
653 The @i{elaboration dependences}
654 (see @RefSecNum{Program Execution})
655 determine the order of elaboration of @nt{library_item}s.]
656 @end{Itemize}
657 @begin{Discussion}
658 Don't confuse these kinds of dependences with the run-time
659 dependences among tasks and masters defined in
660 @RefSec{Task Dependence - Termination of Tasks}.
661 @end{Discussion}
662
663 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
664 @Defn2{Term=[semantic dependence], Sec=(of one compilation unit upon another)}
665 @Defn2{Term=[dependence], Sec=(semantic)}
666 A @nt{library_item} depends semantically upon its
667 parent declaration.
668 A subunit depends semantically upon its parent body.
669 A @nt{library_unit_body} depends semantically upon the corresponding
670 @nt{library_unit_declaration}, if any.
671 @Chg{Version=[2],New=[The declaration of the limited view of a
672 library package depends semantically upon the declaration of the
673 limited view of its parent.
674 The declaration of a library package depends semantically upon the
675 declaration of its limited view.],Old=[]}
676 A compilation unit depends semantically upon each @nt<library_item>
677 mentioned in a @nt{with_clause} of the compilation unit.
678 In addition, if a given compilation unit contains an @nt{attribute_reference}
679 of a type defined in another compilation unit,
680 then the given compilation unit depends semantically upon the
681 other compilation unit.
682 The semantic dependence relationship is transitive.
683
684 @begin{Discussion}
685 The @lquotes@;if any@rquotes@; in the third sentence is necessary
686 because library subprograms are not required to have a
687 @nt{subprogram_declaration}.
688 @end{Discussion}
689 @begin{Honest}
690 If a given compilation unit contains a
691 @nt{choice_parameter_specification},
692 then the given compilation unit depends semantically upon the
693 declaration of Ada.Exceptions.
694
695 If a given compilation unit contains a @nt{pragma} with an
696 argument of a type defined in another compilation unit,
697 then the given compilation unit depends semantically upon the
698 other compilation unit.
699 @end{Honest}
700 @begin{Discussion}
701 For example, a compilation unit containing
702 X'Address depends semantically upon the declaration of package
703 System.
704
705 For the Address attribute, this fixes a hole in Ada 83.
706 Note that in almost all cases, the dependence will need to exist
707 due to @nt{with_clause}s, even without this rule.
708 Hence, the rule has very little effect on programmers.
709
710 Note that the semantic dependence does not have the same effect as a
711 @nt{with_clause}; in order to denote a declaration in one of those
712 packages, a @nt{with_clause} will generally be needed.
713
714 Note that no special rule is needed for an
715 @nt{attribute_definition_clause}, since an expression after @key[use]
716 will require semantic dependence upon the compilation unit containing
717 the @nt{type_declaration} of interest.
718
719 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
720 @ChgAdded{Version=[2],Text=[Unlike a full view of a package, a limited view
721 does not depend semantically on units mentioned in @nt{with_clause}s of the
722 @nt{compilation_unit} that defines the package. Formally, this is
723 achieved by saying that the limited view has an empty @nt{context_clause}.
724 This is necessary so that they
725 can be useful for their intended purpose: allowing mutual dependences between
726 packages. The lack of semantic dependence limits the contents of a limited view
727 to the items that can be determined solely from the syntax of the source of the
728 package, without any semantic analysis. That allows it to be created without
729 the semantic dependences of a full package.]}
730 @end{Discussion}
731 @end{StaticSem}
732
733 @begin{RunTime}
734 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
735 @ChgAdded{Version=[2],Text=[The elaboration of the declaration of the limited
736 view of a package has no effect.]}
737 @end{RunTime}
738
739 @begin{Notes}
740 A simple program may consist of a single compilation unit.
741 A @nt{compilation} need not have any compilation units;
742 for example, its text can consist of @nt{pragma}s.
743 @begin{Ramification}
744 Such @nt{pragma}s cannot have any arguments that are @nt{name}s,
745 by a previous rule of this subclause.
746 A @nt{compilation} can even be entirely empty,
747 which is probably not useful.
748
749 Some interesting properties of the three kinds of dependence:
750 The elaboration dependences also include the semantic dependences,
751 except that subunits are taken together with their parents.
752 The semantic dependences partly determine the order in which the
753 compilation units appear in the environment at compile time.
754 At run time, the order is partly determined by the elaboration
755 dependences.
756
757 @leading@;The model whereby a child is inside its parent's declarative region,
758 after the parent's declaration,
759 as explained in @RefSecNum{Declarative Region},
760 has the following ramifications:
761 @begin(itemize)
762 The restrictions on @lquotes@;early@rquotes@; use of a private type (RM83-7.4.1(4))
763 or a deferred constant (RM83-7.4.3(2))
764 do not apply to uses in child units, because they follow
765 the full declaration.
766
767 A library subprogram is never primitive, even if its profile includes a
768 type declared immediately within the parent's @nt{package_specification},
769 because the child is not declared immediately within the same
770 @nt{package_specification} as the type (so it doesn't declare a new
771 primitive subprogram), and because the child is forbidden from overriding
772 an old primitive subprogram. It is immediately within the same declarative
773 region, but not the same @nt{package_specification}. Thus, for a tagged type,
774 it is not possible to call a child subprogram in a dispatching manner.
775 (This is also forbidden by the freezing rules.)
776 Similarly, it is not possible for the user to declare primitive
777 subprograms of the types declared in the declaration of Standard,
778 such as Integer (even if the rules were changed to allow a library unit
779 whose name is an operator symbol).
780
781 When the parent unit is @lquotes@;used@rquotes@; the simple names of the
782 with'd child units are directly visible (see @RefSec{Use Clauses}).
783
784 When a parent body with's its own child, the defining name of
785 the child is directly visible, and the parent body
786 is not allowed to
787 include a declaration of a homograph of the child unit
788 immediately within the @nt{declarative_part} of the body
789 (RM83-8.3(17)).
790 @end(itemize)
791
792 Note that @lquotes@;declaration of a library unit@rquotes@;
793 is different from @lquotes@;@nt{library_unit_declaration}@rquotes@;
794 @em the former includes @nt{subprogram_body}.
795 Also, we sometimes really mean @lquotes@;declaration of a view of a
796 library unit@rquotes@;, which includes
797 @nt{library_@!unit_@!renaming_@!declaration}s.
798
799 The visibility rules generally imply that the renamed view of a
800 @nt{library_@!unit_@!renaming_@!declaration} has to be mentioned in a
801 @nt{with_@!clause} of the @nt{library_@!unit_@!renaming_@!declaration}.
802 @end{Ramification}
803 @begin{Honest}
804 The real rule is that the renamed library unit
805 has to be visible in the @nt{library_@!unit_@!renaming_@!declaration}.
806 @end{Honest}
807 @begin{Reason}
808 In most cases, @lquotes@;has to be visible@rquotes@; means there has to be a
809 @nt{with_clause}.
810 However, it is possible in obscure cases to avoid the need for a
811 @nt{with_clause}; in particular, a compilation unit such as
812 @lquotes@;@key[package] P.Q @key[renames] P;@rquotes@;
813 is legal with no @nt{with_clause}s
814 (though not particularly interesting).
815 ASCII is physically nested in Standard,
816 and so is not a library unit,
817 and cannot be renamed as a library unit.
818 @end{Reason}
819
820 The @nt{designator} of a library function cannot be an @nt{operator_symbol},
821 but a nonlibrary @nt{renaming_declaration} is allowed to rename a library
822 function as an operator.
823 Within a partition,
824 two library subprograms are required to have distinct
825 names and hence cannot overload each other.
826 However,
827 @nt{renaming_declaration}s are allowed to define overloaded names for
828 such subprograms, and a locally declared subprogram is allowed to
829 overload a library subprogram. The expanded name Standard.L can be
830 used to denote a root library unit L (unless the declaration of
831 Standard is hidden)
832 since root library unit declarations occur immediately within the
833 declarative region of package Standard.
834 @end{Notes}
835
836 @begin{Examples}
837 @leading@keepnext@i{Examples of library units:}
838 @begin{Example}
839 @key[package] Rational_Numbers.IO @key[is] --@RI[ public child of Rational_Numbers, see @RefSecNum{Package Specifications and Declarations}]
840 @key[procedure] Put(R : @key[in] Rational);
841 @key[procedure] Get(R : @key[out] Rational);
842 @key[end] Rational_Numbers.IO;
843
844 @key[private procedure] Rational_Numbers.Reduce(R : @key[in out] Rational);
845 --@RI[ private child of Rational_Numbers]
846
847 @key[with] Rational_Numbers.Reduce; --@RI[ refer to a private child]
848 @key[package body] Rational_Numbers @key[is]
849 ...
850 @key[end] Rational_Numbers;
851
852 @key[with] Rational_Numbers.IO; @key[use] Rational_Numbers;
853 @key[with] Ada.Text_io; --@RI[ see @RefSecNum{Text Input-Output}]
854 @key[procedure] Main @key[is] --@RI[ a root library procedure]
855 R : Rational;
856 @key[begin]
857 R := 5/3; --@RI[ construct a rational number, see @RefSecNum{Package Specifications and Declarations}]
858 Ada.Text_IO.Put("The answer is: ");
859 IO.Put(R);
860 Ada.Text_IO.New_Line;
861 @key[end] Main;
862
863 @key[with] Rational_Numbers.IO;
864 @key[package] Rational_IO @key[renames] Rational_Numbers.IO;
865 --@RI[ a library unit renaming declaration]
866 @end{Example}
867
868 Each of the above @nt{library_item}s can be submitted to the compiler
869 separately.
870 @begin{Discussion}
871 @leading@keepnext@i{Example of a generic package with children:}
872
873 @begin{Example}
874 @key[generic]
875 @key[type] Element @key[is] @key[private];
876 @key[with] @key[function] Image(E : Element) @key[return] String;
877 @key[package] Generic_Bags @key[is]
878 @key[type] Bag @key[is] @key[limited] @key[private]; --@RI{ A bag of Elements.}
879 @key[procedure] Add(B : @key[in] @key[out] Bag; E : Element);
880 @key[function] Bag_Image(B : Bag) @key[return] String;
881 @key[private]
882 @key[type] Bag @key[is] ...;
883 @key[end] Generic_Bags;
884
885 @key[generic]
886 @key[package] Generic_Bags.Generic_Iterators @key[is]
887 ... --@RI{ various additional operations on Bags.}
888
889 @key[generic]
890 @key[with] @key[procedure] Use_Element(E : @key[in] Element);
891 --@RI{ Called once per bag element.}
892 @key[procedure] Iterate(B : @key[in] Bag);
893 @key[end] Generic_Bags.Generic_Iterators;
894 @end{Example}
895
896 @begin{WideAbove}
897 @leading@keepnext@;A package that instantiates the above generic units:
898 @end{WideAbove}
899 @begin{Example}
900 @key[with] Generic_Bags;
901 @key[with] Generic_Bags.Generic_Iterators;
902 @key[package] My_Abstraction @key[is]
903 @key[type] My_Type @key[is] ...;
904 @key[function] Image(X : My_Type) @key[return] String;
905 @key[package] Bags_Of_My_Type @key[is] @key[new] Generic_Bags(My_Type, Image);
906 @key[package] Iterators_Of_Bags_Of_My_Type @key[is] @key[new] Bags_Of_My_Type.Generic_Iterators;
907 @key[end] My_Abstraction;
908 @end{Example}
909
910 In the above example, Bags_Of_My_Type has a nested generic unit called
911 Generic_Iterators.
912 The second @nt{with_clause} makes that nested unit visible.
913
914 @leading@;Here we show how the generic body could depend on one of its own
915 children:
916 @begin{Example}
917 @key[with] Generic_Bags.Generic_Iterators;
918 @key[package] @key[body] Generic_Bags @key[is]
919 @key[procedure] Add(B : @key[in] @key[out] Bag; E : Element) @key[is] ... @key[end] Add;
920
921 @key[package] Iters @key[is] @key[new] Generic_Iterators;
922
923 @key[function] Bag_Image(B : Bag) @key[return] String @key[is]
924 Buffer : String(1..10_000);
925 Last : Integer := 0;
926
927 @key[procedure] Append_Image(E : @key[in] Element) @key[is]
928 Im : @key[constant] String := Image(E);
929 @key[begin]
930 @key[if] Last /= 0 @key[then] --@RI{ Insert a comma.}
931 Last := Last + 1;
932 Buffer(Last) := ',';
933 @key[end] @key[if];
934 Buffer(Last+1 .. Last+Im'Length) := Im;
935 Last := Last + Im'Length;
936 @key[end] Append_Image;
937
938 @key[procedure] Append_All @key[is] @key[new] Iters.Iterate(Append_Image);
939 @key[begin]
940 Append_All(B);
941 @key[return] Buffer(1..Last);
942 @key[end] Bag_Image;
943 @key[end] Generic_Bags;
944 @end{Example}
945
946 @end{Discussion}
947 @end{Examples}
948
949 @begin{Extend83}
950 @Defn{extensions to Ada 83}
951 The syntax rule for @nt{library_item} is modified to allow the
952 reserved word @key{private} before a @nt{library_unit_declaration}.
953
954 Children (other than children of Standard)
955 are new in Ada 95.
956
957 Library unit renaming is new in Ada 95.
958 @end{Extend83}
959
960 @begin{DiffWord83}
961 Standard is considered a library unit in Ada 95.
962 This simplifies the descriptions,
963 since it implies that the parent of each library unit is a library unit.
964 (Standard itself has no parent, of course.)
965 As in Ada 83, the language does not define any way to recompile
966 Standard, since the name given in the declaration of a library unit is
967 always interpreted in relation to Standard.
968 That is,
969 an attempt to compile a package Standard would result in
970 Standard.Standard.
971 @end{DiffWord83}
972
973 @begin{Extend95}
974 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
975 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
976 The concept of a limited view is new. Combined with @nt{limited_with_clause}s
977 (see @RefSecNum{Context Clauses - With Clauses}), they facilitate
978 construction of mutually recursive types in multiple packages.]}
979 @end{Extend95}
980
981 @begin{DiffWord95}
982 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00331-01]}
983 @ChgAdded{Version=[2],Text=[Clarified the wording so that a grandchild
984 generic unit will work as expected.]}
985 @end{DiffWord95}
986
987 @begin{DiffWord2005}
988 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0108-1],ARef=[AI05-0129-1]}
989 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified the wording so that
990 it is clear that limited views of types never have discriminants and never
991 are of incomplete types.]}
992 @end{DiffWord2005}
993
994
995 @LabeledSubClause{Context Clauses - With Clauses}
996
997 @begin{Intro}
998 @redundant[A @nt{context_clause} is used to specify
999 the @nt<library_item>s whose
1000 names are needed within a compilation unit.]
1001 @end{Intro}
1002
1003 @begin{MetaRules}
1004 @Defn{one-pass @nt{context_clause}s}
1005 The reader should be able to understand a @nt{context_clause} without
1006 looking ahead.
1007 Similarly, when compiling a @nt{context_clause},
1008 the compiler should not have to look ahead at
1009 subsequent @nt{context_item}s, nor at the compilation unit
1010 to which the @nt{context_clause} is attached.
1011 (We have not completely achieved this.)
1012
1013 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1014 @ChgAdded{Version=[2],Text=[@Defn{ripple effect}A @i<ripple effect> occurs
1015 when the legality of a compilation unit could be affected by adding or removing
1016 an otherwise unneeded @nt{with_clause} on some compilation unit on which the
1017 unit depends, directly or indirectly. We try to avoid ripple effects because
1018 they make understanding and maintenance more difficult. However, ripple effects
1019 can occur because of direct visibility (as in child units); this seems
1020 impossible to eliminate. The ripple effect for @nt{with_clause}s is somewhat
1021 similar to the Beaujolais effect (see @RefSecNum{Use Clauses}) for
1022 @nt{use_clause}s, which we also try to avoid.]}
1023 @end{MetaRules}
1024
1025 @begin{Syntax}
1026 @Syn{lhs=<context_clause>,rhs="{@Syn2{context_item}}"}
1027
1028
1029 @Syn{lhs=<context_item>,rhs="@Syn2{with_clause} | @Syn2{use_clause}"}
1030
1031 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00262-01]}
1032 @Syn{lhs=<with_clause>,rhs="@Chg{Version=[2],New=<@Syn2{limited_with_clause} | @Syn2{nonlimited_with_clause}>,Old=<@key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>}"}
1033
1034 @ChgRef{Version=[2],Kind=[Added]}
1035 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<limited_with_clause>,Old=<>}>,rhs="@Chg{Version=[2],New=<@key{limited} [@key{private}] @key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>,Old=<>}"}
1036
1037 @ChgRef{Version=[2],Kind=[Added]}
1038 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<nonlimited_with_clause>,Old=<>}>,rhs="@Chg{Version=[2],New=<[@key{private}] @key{with} @SynI{library_unit_}@Syn2{name} {, @SynI{library_unit_}@Syn2{name}};>,Old=<>}"}
1039
1040 @begin{Discussion}
1041 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1042 @ChgAdded{Version=[2],Text=[A @nt{limited_with_clause} makes a limited view
1043 of a unit visible.]}
1044
1045 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]}
1046 @ChgAdded{Version=[2],Text=[@Defn{private with_clause}A @nt{with_clause}
1047 containing the reserved word @key{private} is called a @i{private with_clause}.
1048 It can be thought of as making items visible only in the private part, although
1049 it really
1050 makes items visible everywhere except the visible part. It can be used both for
1051 documentation purposes (to say that a unit is not used in the visible part),
1052 and to allow access to private units that otherwise would be
1053 prohibited.]}
1054 @end{Discussion}
1055 @end{Syntax}
1056
1057 @begin{Resolution}
1058 @Defn2{Term=[scope], Sec=(of a @nt{with_clause})}
1059 The @i{scope} of a @nt{with_clause} that appears on a
1060 @nt{library_@!unit_@!declaration}
1061 or @nt{library_@!unit_@!renaming_@!declaration}
1062 consists of the entire declarative region of the declaration@Redundant[,
1063 which includes all children and subunits].
1064 The scope of a @nt{with_clause} that appears on a
1065 body consists of the body@Redundant[, which includes all subunits].
1066 @begin{Discussion}
1067 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]}
1068 Suppose a @Chg{Version=[2],New=[nonprivate ],Old=[]} @nt{with_clause} of a
1069 public library unit mentions one of its private siblings.
1070 (This is only allowed on the body of the public library unit.)
1071 We considered making the scope of that @nt{with_clause}
1072 not include the visible part of the public library unit.
1073 (This would only matter for a @nt{subprogram_body},
1074 since those are the only kinds of body that have a visible part,
1075 and only if the @nt{subprogram_body} completes a
1076 @nt{subprogram_declaration}, since otherwise the @nt{with_clause}
1077 would be illegal.)
1078 We did not put in such a rule for two reasons:
1079 (1) It would complicate the wording of the rules,
1080 because we would have to split each @nt{with_clause}
1081 into pieces, in order to correctly handle @lquotes@;@key[with] P, Q;@rquotes@;
1082 where P is public and Q is private.
1083 (2) The conformance rules prevent any problems.
1084 It doesn't matter if a type name in the spec of the body denotes
1085 the completion of a @nt{private_type_declaration}.
1086
1087 A @nt{with_clause} also affects visibility within subsequent
1088 @nt{use_clause}s and @nt{pragma}s of the same @nt{context_clause},
1089 even though those are not in the scope of the @nt{with_clause}.
1090 @end{Discussion}
1091
1092 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1093 @Defn2{Term=[mentioned],Sec=[in a @nt<with_clause>]}
1094 @Defn2{Term=[with_clause], Sec=(mentioned in)}
1095 A @nt<library_item> @Chg{Version=[2],New=[(and the corresponding library
1096 unit) ],Old=[]}is
1097 @Chg{Version=[2],New=[@i{named}
1098 @Defn2{Term=[named],Sec=[in a @nt<with_clause>]}
1099 @Defn2{Term=[with_clause], Sec=(named in)}],Old=[@i{mentioned} ]}in a
1100 @nt<with_clause> if it is denoted by
1101 a @i(library_unit_)@nt<name> @Chg{Version=[2],New=[],Old=[or a @nt<prefix> ]}
1102 in the @nt<with_clause>.
1103 @Chg{Version=[2],New=[A @nt{library_item} (and the corresponding library unit)
1104 is @i<mentioned> in a @nt{with_clause}
1105 if it is named in the @nt{with_clause} or if it is denoted by a @nt{prefix} in
1106 the @nt{with_clause}.],Old=[]}
1107
1108 @begin{Discussion}
1109 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1110 @nt{With_clause}s control the visibility of
1111 declarations or renamings of library units.
1112 Mentioning a root library unit in a
1113 @nt{with_clause} makes its declaration
1114 directly visible. Mentioning a nonroot library unit
1115 makes its declaration visible.
1116 See @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{Visibility Rules}
1117 for details.
1118
1119 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1120 Note that this rule implies that @lquotes@;@key{with} A.B.C;@rquotes@; is
1121 @chg{Version=[2],New=[almost ],Old=[]}equivalent to
1122 @lquotes@;@key{with} A, A.B, A.B.C;@rquotes@;@Chg{Version=[2],New=[.],Old=[]}
1123 The reason for making a @nt{with_clause} apply to all the ancestor
1124 units is to avoid @lquotes@;visibility holes@rquotes@; @em situations in which an inner
1125 program unit is visible while an outer one is not.
1126 Visibility holes would cause semantic complexity and implementation
1127 difficulty.@Chg{Version=[2],New=[ (This
1128 is not exactly equivalent because the latter @nt{with_clause} names
1129 A and A.B, while the previous one does not. Whether a unit is
1130 @ldquote@;named@rdquote does not have any effect on visibility, however,
1131 so it is equivalent for visibility purposes.)],Old=[]}
1132
1133 @end{Discussion}
1134
1135 @redundant[Outside its own declarative region,
1136 the declaration or renaming of
1137 a library unit can be visible only within the scope of a
1138 @nt{with_clause} that mentions it.
1139 The visibility of the declaration or renaming of a
1140 library unit otherwise
1141 follows from its placement in the environment.]
1142 @end{Resolution}
1143
1144 @begin{Legality}
1145 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]}
1146 If a @nt{with_clause} of a given @nt<compilation_unit> mentions
1147 a private child of some library unit,
1148 then the given @nt{compilation_unit} shall be @Chg{Version=[2],New=[one of:],
1149 Old=[either the declaration of a private descendant of that library unit
1150 or the body or subunit of a @Redundant[(public or private)] descendant of
1151 that library unit.]}
1152 @begin{Itemize}
1153 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]}
1154 @ChgAdded{Version=[2],Text=[the declaration, body, or subunit of a private
1155 descendant of that library unit;]}
1156
1157 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00220-01],ARef=[AI95-00262-01]}
1158 @ChgAdded{Version=[2],Text=[the body or subunit of a public descendant of that
1159 library unit, but not a subprogram body acting as a subprogram declaration (see
1160 @RefSecNum{The Compilation Process}); or]}
1161
1162 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]}
1163 @ChgAdded{Version=[2],Text=[the declaration of a public descendant of that
1164 library unit, in which case the @nt<with_clause> shall include the reserved word
1165 @key<private>.]}
1166 @end{Itemize}
1167
1168 @begin{Reason}
1169 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]}
1170 The purpose of this rule is to prevent a private child from being
1171 visible @Chg{Version=[2],New=[],Old=[(or even semantically depended-on) ]}from
1172 outside the subsystem rooted at its parent. @Chg{Version=[2],New=[A private
1173 child can be semantically depended-on without violating this principle if it is
1174 used in a private @nt{with_clause}.],Old=[]}
1175 @end{Reason}
1176 @begin{Discussion}
1177 This rule violates the one-pass @nt{context_clause}s
1178 @MetaRulesName. We rationalize this by saying that at least that
1179 @MetaRulesName works for legal compilation units.
1180
1181 @leading@keepnext@;Example:
1182 @begin{Example}
1183 @key[package] A @key[is]
1184 @key[end] A;
1185
1186 @key[package] A.B @key[is]
1187 @key[end] A.B;
1188
1189 @key[private] @key[package] A.B.C @key[is]
1190 @key[end] A.B.C;
1191
1192 @key[package] A.B.C.D @key[is]
1193 @key[end] A.B.C.D;
1194
1195 @key[with] A.B.C; -- @RI[(1)]
1196 @key[private] @key[package] A.B.X @key[is]
1197 @key[end] A.B.X;
1198
1199 @key[package] A.B.Y @key[is]
1200 @key[end] A.B.Y;
1201
1202 @key[with] A.B.C; -- @RI[(2)]
1203 @key[package] @key[body] A.B.Y @key[is]
1204 @key[end] A.B.Y;
1205
1206 @ChgRef{Version=[2],Kind=[Added]}@ChgAdded{Version=[2],Text=[@key[private] @key[with] A.B.C; -- @RI[(3)]
1207 @key[package] A.B.Z @key[is]
1208 @key[end] A.B.Z;]}
1209 @end{Example}
1210
1211 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]}
1212 (1) is OK because it's a private child of A.B @em it would be illegal if
1213 we made A.B.X a public child of A.B.
1214 (2) is OK because it's the body of a child of A.B.
1215 @Chg{Version=[2],New=[(3) is OK because it's a child of A.B, and it is a
1216 private @nt{with_clause}.],Old=[]}
1217 It would be illegal to say @lquotes@;@key[with] A.B.C;@rquotes@; on any
1218 @nt{library_item} whose name does not start with @lquotes@;A.B@rquotes@;.
1219 Note that mentioning A.B.C.D in a @nt{with_clause} automatically
1220 mentions A.B.C as well,
1221 so @lquotes@;@key[with] A.B.C.D;@rquotes@; is illegal in the same places as
1222 @lquotes@;@key[with] A.B.C;@rquotes@;.
1223 @end{Discussion}
1224 @begin{Honest}
1225 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0005-1]}
1226 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00262-01]}
1227 @ChgDeleted{Version=[3],Text=[For the purposes of this rule,
1228 if a @nt{subprogram_body} has no preceding @nt{subprogram_declaration},
1229 the @nt{subprogram_body} should be considered a declaration and not a body.
1230 Thus, it is illegal for such a @nt{subprogram_body} to mention one of
1231 its siblings in a @Chg{Version=[2],New=[nonprivate ],Old=[]}@nt{with_clause}
1232 if the sibling is a private library unit.]}
1233 @end{Honest}
1234
1235 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]}
1236 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0122-1]}
1237 @ChgAdded{Version=[2],Type=[Leading],Text=[A @nt<name> denoting a
1238 @Chg{Version=[3],New=[@nt{library_item} (or the corresponding declaration
1239 for a child of a generic within an instance @em see
1240 @RefSecNum{Compilation Units - Library Units}), if it],Old=[library item that]}
1241 is visible only due to being mentioned in
1242 one or more @nt<with_clause>s that include the reserved word
1243 @key<private>@Chg{Version=[3],New=[,],Old=[]} shall appear only within:]}
1244 @begin{Itemize}
1245 @ChgRef{Version=[2],Kind=[AddedNormal]}
1246 @ChgAdded{Version=[2],Text=[a private part;]}
1247
1248 @ChgRef{Version=[2],Kind=[AddedNormal]}
1249 @ChgAdded{Version=[2],Text=[a body, but not within the
1250 @nt<subprogram_specification> of a library subprogram body;]}
1251
1252 @ChgRef{Version=[2],Kind=[AddedNormal]}
1253 @ChgAdded{Version=[2],Text=[a private descendant of the unit on which one of these
1254 @nt<with_clause>s appear; or]}
1255
1256 @ChgRef{Version=[2],Kind=[AddedNormal]}
1257 @ChgAdded{Version=[2],Text=[a pragma within a context clause.]}
1258 @end{Itemize}
1259
1260 @begin{Ramification}
1261 @ChgRef{Version=[2],Kind=[AddedNormal]}
1262 @ChgAdded{Version=[2],Text=[These rules apply only if all of the
1263 @nt{with_clause}s that mention the name include the reserved word
1264 @key{private}. They do not apply if the name is mentioned in any
1265 @nt{with_clause} that does not include @key{private}.]}
1266 @end{Ramification}
1267
1268 @begin{Reason}
1269 @ChgRef{Version=[2],Kind=[AddedNormal]}
1270 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]}
1271 @ChgAdded{Version=[2],Text=[These rules make the
1272 @Chg{Version=[3],New=[@nt{library_item}],Old=[library item]}
1273 visible anywhere that
1274 is not visible outside the subsystem rooted at the @nt{compilation_unit} having
1275 the private @nt{with_clause}, including private parts of packages
1276 nested in the visible part, private parts of child packages, the visible part
1277 of private children, and context clause pragmas like Elaborate_All.]}
1278
1279 @ChgRef{Version=[2],Kind=[AddedNormal]}
1280 @ChgAdded{Version=[2],Text=[We considered having the scope of a private
1281 @nt{with_clause} not include the visible part. However, that rule would mean
1282 that moving a declaration between the visible part and the private part could
1283 change its meaning from one legal interpretation to a different legal
1284 interpretation. For example:]}
1285 @begin{Example}
1286 @ChgRef{Version=[2],Kind=[AddedNormal]}
1287 @ChgAdded{Version=[2],Text=[@key{package} A @key{is}
1288 @key{function} B @key{return} Integer;
1289 @key{end} A;]}
1290
1291 @ChgRef{Version=[2],Kind=[AddedNormal]}
1292 @ChgAdded{Version=[2],Text=[@key{function} B @key{return} Integer;]}
1293
1294 @ChgRef{Version=[2],Kind=[AddedNormal]}
1295 @ChgAdded{Version=[2],Text=[@key{with} A;
1296 @key{private} @key{with} B;
1297 @key{package} C @key{is}
1298 @key{use} A;
1299 V1 : Integer := B; -- (1)
1300 @key{private}
1301 V2 : Integer := B; -- (2)
1302 @key{end} C;]}
1303 @end{Example}
1304
1305 @ChgRef{Version=[2],Kind=[AddedNormal]}
1306 @ChgAdded{Version=[2],Text=[If we say that library subprogram B is not in scope
1307 in the visible part of C, then the B at (1) resolves to A.B, while (2)
1308 resolves to library unit B. Simply moving a declaration could silently change
1309 its meaning. With the legality rule defined above, the B at (1) is illegal.
1310 If the user really meant A.B, they still can say that.]}
1311 @end{Reason}
1312
1313 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1314 @ChgAdded{Version=[2],Text=[@Redundant[A @nt{library_item} mentioned in a
1315 @nt{limited_with_clause} shall be the implicit declaration of the limited view
1316 of a library package, not the declaration of a subprogram, generic unit,
1317 generic instance, or a renaming.]]}
1318
1319 @begin{TheProof}
1320 @ChgRef{Version=[2],Kind=[AddedNormal]}
1321 @ChgAdded{Version=[2],Text=[This is redundant because only such implicit
1322 declarations are visible in a @nt{limited_with_clause}. See
1323 @RefSecNum{Environment-Level Visibility Rules}.]}
1324 @end{TheProof}
1325
1326 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
1327 @ChgAdded{Version=[2],Text=[A @nt{limited_with_clause} shall not appear on a
1328 @nt{library_unit_body}, @nt{subunit}, or @nt{library_@!unit_@!renaming_@!declaration}.]}
1329
1330 @begin{Reason}
1331 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00412-01]}
1332 @ChgAdded{Version=[2],Text=[We don't allow a @nt{limited_with_clause} on a
1333 @nt{library_@!unit_@!renaming_@!declaration} because it would be useless and
1334 therefore probably is a mistake. A
1335 renaming cannot appear in a @nt{limited_with_clause} (by the rule prior
1336 to this one), and a renaming of a limited view cannot appear in a
1337 @nt{nonlimited_with_clause} (because the name
1338 would not be within the scope of a @nt{with_clause} denoting the package, see
1339 @RefSecNum{Package Renaming Declarations}). Nor could it be the parent of
1340 another unit. That doesn't leave anywhere that the name of such a renaming
1341 @b<could> appear, so we simply make writing it illegal.]}
1342 @end{Reason}
1343
1344 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1345 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[A
1346 @nt{limited_with_clause} that names a library package shall not appear:]}
1347
1348 @begin(Itemize)
1349 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1350 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0040-1]}
1351 @ChgAdded{Version=[2],Text=[in the @nt{context_clause} for the
1352 explicit declaration of the named library package@Chg{Version=[3],New=[ or
1353 any of its descendants],Old=[]};]}
1354
1355 @begin{Reason}
1356 @ChgRef{Version=[2],Kind=[AddedNormal]}
1357 @ChgAdded{Version=[2],Text=[We have to explicitly disallow]}
1358 @begin{Example}
1359 @ChgRef{Version=[2],Kind=[AddedNormal]}
1360 @ChgAdded{Version=[2],Text=[@key{limited} @key{with} P;
1361 @key{package} P @key{is} ...]}
1362 @end{Example}
1363 @ChgRef{Version=[2],Kind=[AddedNormal]}
1364 @ChgAdded{Version=[2],Text=[as we can't depend on the semantic dependence
1365 rules to do it for us as with regular withs. This says @lquotes@;named@rquotes
1366 and not @lquotes@;mentioned@rquotes in order that]}
1367 @begin{Example}
1368 @ChgRef{Version=[2],Kind=[AddedNormal]}
1369 @ChgAdded{Version=[2],Text=[@key{limited} @key{private} @key{with} P.Child;
1370 @key{package} P @key{is} ...]}
1371 @end{Example}
1372 @ChgRef{Version=[2],Kind=[AddedNormal]}
1373 @ChgAdded{Version=[2],Text=[can be used to allow a mutual dependence between
1374 the private part of P and the private child P.Child, which occurs in
1375 interfacing and other problems. Since the child always semantically depends
1376 on the parent, this is the only way such a dependence can be broken.]}
1377
1378 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0040-1]}
1379 @ChgAdded{Version=[3],Text=[The part about descendants catches examples like]}
1380 @begin{Example}
1381 @ChgRef{Version=[3],Kind=[AddedNormal]}
1382 @ChgAdded{Version=[3],Text=[@key{limited} @key{with} P;
1383 @key{package} P.Child @key{is} ...]}
1384 @end{Example}
1385 @end{Reason}
1386
1387 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1388 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0262-1]}
1389 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[within a], Old=[in the same]}
1390 @nt{context_clause}
1391 @Chg{Version=[3],New=[for a @nt{library_item} that is],Old=[as, or]}
1392 within the scope of@Chg{Version=[3],New=[],Old=[,]}
1393 a @nt{nonlimited_with_clause} that mentions the same library package; or]}
1394
1395 @begin{Ramification}
1396 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0077-1]}
1397 @ChgAdded{Version=[3],Text=[This applies to @nt{nonlimited_with_clause}s
1398 found in the same @nt{context_clause}, as well as @nt{nonlimited_with_clause}s
1399 found on parent units.]}
1400 @end{Ramification}
1401
1402 @begin{Reason}
1403 @ChgRef{Version=[2],Kind=[AddedNormal]}
1404 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]}
1405 @ChgAdded{Version=[2],Text=[Such a @nt{limited_with_clause} could have no
1406 effect, and would be confusing. If@Chg{Version=[3],New=[],Old=[ it is
1407 within the scope of]} a @nt{nonlimited_with_clause}@Chg{Version=[3],New=[
1408 for the same package is inherited from a parent unit or given],Old=[, or
1409 if such a clause is]} in the @nt{context_clause},
1410 the full view is available, which strictly provides more information than
1411 the limited view.]}
1412 @end{Reason}
1413
1414 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1415 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1],ARef=[AI05-0262-1]}
1416 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[within a], Old=[in the same]}
1417 @nt{context_clause}
1418 @Chg{Version=[3],New=[for a @nt{library_item} that is],Old=[as, or]}
1419 within the scope of@Chg{Version=[3],New=[],Old=[,]}
1420 a @nt{use_clause} that names an entity declared within the
1421 declarative region of the library package.]}
1422
1423 @begin{Ramification}
1424 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0077-1]}
1425 @ChgAdded{Version=[3],Text=[This applies to @nt{use_clause}s found in the
1426 same @nt{context_clause}, as well as @nt{use_clause}s found in (or on)
1427 parent units.]}
1428 @end{Ramification}
1429
1430 @begin{Reason}
1431 @ChgRef{Version=[2],Kind=[AddedNormal]}
1432 @ChgAdded{Version=[2],Text=[This prevents visibility issues, where whether an
1433 entity is an incomplete or full view depends on how the name of the entity is
1434 written. The @nt{limited_with_clause} cannot be useful, as we must have the
1435 full view available in the parent in order for the @nt{use_clause} to be
1436 legal.]}
1437 @end{Reason}
1438
1439 @end(Itemize)
1440
1441 @end{Legality}
1442
1443 @begin{Notes}
1444 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1445 A @nt<library_item> mentioned in a @Chg{Version=[2],
1446 New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]} of a compilation unit
1447 is visible within the compilation unit and hence acts
1448 just like an ordinary declaration.
1449 Thus, within a compilation unit that mentions its declaration, the name of a
1450 library package can be given in @nt{use_clause}s and can be used to
1451 form expanded names, a library subprogram can be called,
1452 and instances of a generic library unit can be declared.
1453 If a child of a parent generic package is mentioned in a
1454 @Chg{Version=[2], New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]},
1455 then the corresponding declaration nested within each visible instance
1456 is visible within the compilation unit.@Chg{Version=[2], New=[ Similarly,
1457 a @nt{library_item} mentioned in a
1458 @nt{limited_with_clause} of a compilation unit is visible within the
1459 compilation unit and thus can be used to form expanded names.],Old=[]}
1460
1461 @begin{Ramification}
1462 The rules given for @nt{with_clause}s are such that the same effect
1463 is obtained whether the name of a library unit is mentioned once or
1464 more than once by the applicable @nt{with_clause}s, or even within a
1465 given @nt{with_clause}.
1466
1467 If a @nt{with_clause} mentions a
1468 @nt{library_@!unit_@!renaming_@!declaration},
1469 it only @lquotes@;mentions@rquotes@; the @nt<prefix>es appearing explicitly
1470 in the @nt<with_clause>
1471 (and the renamed view itself);
1472 the @nt{with_clause} is not defined to mention the ancestors of the
1473 renamed entity.
1474 Thus, if X renames Y.Z, then @lquotes@;with X;@rquotes@; does not make the
1475 declarations of Y or Z visible.
1476 Note that this does not cause the dreaded visibility holes mentioned
1477 above.
1478 @end{Ramification}
1479 @end{Notes}
1480
1481 @begin{Examples}
1482
1483 @begin{Example}
1484 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1485 @ChgAdded{Version=[2],Text=[@key(package) Office @key(is)
1486 @key{end} Office;]}
1487
1488 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1489 @ChgAdded{Version=[2],Text=[@key(with) Ada.Strings.Unbounded;
1490 @key(package) Office.Locations @key(is)
1491 @key(type) Location @key(is new) Ada.Strings.Unbounded.Unbounded_String;
1492 @key(end) Office.Locations;]}
1493
1494 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1495 @ChgAdded{Version=[2],Text=[@key(limited with) Office.Departments; --@RI[ types are incomplete]
1496 @key(private with) Office.Locations; --@RI[ only visible in private part]
1497 @key(package) Office.Employees @key(is)
1498 @key(type) Employee @key(is private);]}
1499
1500 @ChgRef{Version=[2],Kind=[AddedNormal]}
1501 @ChgAdded{Version=[2],Text=[ @key(function) Dept_Of(Emp : Employee) @key(return access) Departments.Department;
1502 @key(procedure) Assign_Dept(Emp : @key(in out) Employee;
1503 Dept : @key(access) Departments.Department);]}
1504
1505 @ChgRef{Version=[2],Kind=[AddedNormal]}
1506 @ChgAdded{Version=[2],Text=[ ...
1507 @key(private
1508 type) Employee @key(is
1509 record)
1510 Dept : @key(access) Departments.Department;
1511 Loc : Locations.Location;
1512 ...
1513 @key(end record);
1514 @key(end) Office.Employees;]}
1515
1516 @ChgRef{Version=[2],Kind=[AddedNormal]}
1517 @ChgAdded{Version=[2],Text=[@key(limited with) Office.Employees;
1518 @key(package) Office.Departments @key(is)
1519 @key(type) Department @key(is private);]}
1520
1521 @ChgRef{Version=[2],Kind=[AddedNormal]}
1522 @ChgAdded{Version=[2],Text=[ @key(function) Manager_Of(Dept : Department) @key(return access) Employees.Employee;
1523 @key(procedure) Assign_Manager(Dept : @key(in out) Department;
1524 Mgr : @key(access) Employees.Employee);
1525 ...
1526 @key(end) Office.Departments;]}
1527 @end{Example}
1528
1529 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1530 @ChgAdded{Version=[2],Text=[The @nt{limited_with_clause} may be used to support
1531 mutually dependent abstractions that are split across multiple packages. In
1532 this case, an employee is assigned to a department, and a department has a
1533 manager who is an employee. If a @nt{with_clause} with the reserved word
1534 @key(private) appears on one library unit and mentions a second library unit,
1535 it provides visibility to the second library unit, but restricts that
1536 visibility to the private part and body of the first unit. The compiler checks
1537 that no use is made of the second unit in the visible part of the first unit.]}
1538
1539 @end{Examples}
1540
1541
1542
1543 @begin{Extend83}
1544 @Defn{extensions to Ada 83}
1545 The syntax rule for @nt{with_clause} is modified to allow expanded name
1546 notation.
1547
1548 A @nt<use_clause> in a @nt<context_clause> may be for
1549 a package (or type) nested in a library package.
1550 @end{Extend83}
1551
1552 @begin{DiffWord83}
1553 The syntax rule for @nt{context_clause} is modified to more closely reflect
1554 the semantics.
1555 The Ada 83 syntax rule implies that the @nt{use_clause}s that appear
1556 immediately after a particular @nt{with_clause} are somehow attached to
1557 that @nt{with_clause}, which is not true.
1558 The new syntax allows a @nt{use_clause} to appear first,
1559 but that is prevented by a textual rule that already exists in Ada 83.
1560
1561 The concept of @lquotes@;scope of a @nt{with_clause}@rquotes@; (which is a region of text)
1562 replaces RM83's notion of @lquotes@;apply to@rquotes@;
1563 (a @nt{with_clause} applies to a @nt{library_item})
1564 The visibility rules are interested in a region of text,
1565 not in a set of compilation units.
1566
1567 No need to define @lquotes@;apply to@rquotes@; for @nt{use_clause}s.
1568 Their semantics are fully covered by the @lquotes@;scope (of a @nt{use_clause})@rquotes@;
1569 definition in @RefSecNum{Use Clauses}.
1570 @end{DiffWord83}
1571
1572 @begin{Incompatible95}
1573 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00220-01]}
1574 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
1575 @b[Amendment Correction:] A subprogram body acting as a declaration cannot
1576 @key[with] a private child unit. This would allow public export of types
1577 declared in private child packages, and thus cannot be allowed. This was
1578 allowed by mistake in Ada 95; a subprogram that does this will now be
1579 illegal.]}
1580 @end{Incompatible95}
1581
1582 @begin{Extend95}
1583 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1584 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1585 @nt{limited_with_clause}s are new. They make a limited view of a package
1586 visible, where all of the types in the package are incomplete. They facilitate
1587 construction of mutually recursive types in multiple packages.]}
1588
1589 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00262-01]}
1590 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0077-1]}
1591 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1592 The syntax rules for @nt{with_clause} are modified to allow the reserved
1593 word @key{private}. Private @nt{with_clause}s do not allow the use of their
1594 @Chg{Version=[3],New=[@nt{library_item}],Old=[library item]}
1595 in the visible part of their @nt{compilation_unit}. They also
1596 allow using private units in more locations than in Ada 95.]}
1597 @end{Extend95}
1598
1599 @begin{Incompatible2005}
1600 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0040-1]}
1601 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
1602 Added missing rule that
1603 a limited with clause cannot name an ancestor unit. This is incompatible
1604 if an Ada 2005 program does this, but as this is a new Ada 2005 feature and
1605 the unintentionally allowed capability is not useful, the
1606 incompatibility is very unlikely to occur in practice.]}
1607 @end{Incompatible2005}
1608
1609 @begin{DiffWord2005}
1610 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0077-1]}
1611 @ChgAdded{Version=[3],Text=[@b<Correction:> Fixed wording so that
1612 we are not checking whether something in a @nt{context_clause}
1613 is @ldquote@;within the scope of@rdquote something, as @nt{context_clause}s
1614 are never included in anything's scope. The intended meaning is unchanged,
1615 however.]}
1616
1617 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0122-1]}
1618 @ChgAdded{Version=[3],Text=[@b<Correction:> Fixed wording so the
1619 rules for private with clauses also apply to "sprouted" generic child
1620 units.]}
1621 @end{DiffWord2005}
1622
1623
1624 @LabeledSubClause{Subunits of Compilation Units}
1625
1626 @begin{Intro}
1627 @redundant[Subunits are like child units, with these (important) differences:
1628 subunits support the separate compilation of bodies
1629 only (not declarations);
1630 the parent contains a @nt{body_stub}
1631 to indicate the existence and place of each of its subunits;
1632 declarations appearing in the parent's body
1633 can be visible within the subunits.]
1634 @end{Intro}
1635
1636 @begin{Syntax}
1637 @Syn{lhs=<body_stub>,rhs="@Syn2{subprogram_body_stub} | @Syn2{package_body_stub} | @Syn2{task_body_stub} | @Syn2{protected_body_stub}"}
1638
1639
1640 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]}
1641 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
1642 @Syn{lhs=<subprogram_body_stub>,rhs="@Chg{Version=[2],New=<
1643 [@Syn2{overriding_indicator}]
1644 >,Old=[]}@Syn2{subprogram_specification} @key{is} @key{separate}@Chg{Version=[3],New=<
1645 [@Syn2{aspect_specification}]>,Old=[]};"}
1646
1647 @begin{Discussion}
1648 Although this syntax allows a @nt{parent_unit_name},
1649 that is disallowed by @RefSec{Compilation Units - Library Units}.
1650 @end{Discussion}
1651
1652
1653 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
1654 @Syn{lhs=<package_body_stub>,rhs="@Chg{Version=[3],New=<
1655 >,Old=[]}@key{package} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=<
1656 [@Syn2{aspect_specification}]>,Old=[]};"}
1657
1658
1659 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
1660 @Syn{lhs=<task_body_stub>,rhs="@Chg{Version=[3],New=<
1661 >,Old=[]}@key{task} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=<
1662 [@Syn2{aspect_specification}]>,Old=[]};"}
1663
1664
1665 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
1666 @Syn{lhs=<protected_body_stub>,rhs="@Chg{Version=[3],New=<
1667 >,Old=[]}@key{protected} @key{body} @Syn2{defining_identifier} @key{is} @key{separate}@Chg{Version=[3],New=<
1668 [@Syn2{aspect_specification}]>,Old=[]};"}
1669
1670
1671 @Syn{lhs=<subunit>,rhs="@key{separate} (@Syn2{parent_unit_name}) @Syn2{proper_body}"}
1672 @end{Syntax}
1673
1674 @begin{Legality}
1675 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00243-01]}
1676 @Defn2{Term=[parent body], Sec=(of a subunit)}
1677 The @i{parent body} of a subunit is the body of the program unit
1678 denoted by its @nt{parent_unit_name}.
1679 @Defn{subunit} The term @i{subunit} is used to refer to
1680 a @nt{subunit} and also to the @nt{proper_body} of a @nt{subunit}.
1681 @Chg{Version=[2],New=<The @i<subunits
1682 of a program unit> include any subunit that
1683 names that program unit as its parent, as well as any subunit that
1684 names such a subunit as its parent (recursively).@Defn2{Term=[subunit],
1685 Sec=(of a program unit)}>,Old=[]}
1686 @begin{Reason}
1687 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00243-01]}
1688 @ChgAdded{Version=[2],Text=[We want any rule that applies to a subunit to apply
1689 to a subunit of a subunit as well.]}
1690 @end{Reason}
1691
1692 The parent body of a subunit shall be present in the current environment,
1693 and shall contain a corresponding @nt{body_stub}
1694 with the same @nt{defining_identifier} as the subunit.
1695 @begin{Discussion}
1696 This can't be a @ResolutionName, because a @nt{subunit} is not a
1697 complete context.
1698 @end{Discussion}
1699
1700 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
1701 A @nt{package_body_stub} shall be the completion of a
1702 @nt{package_@!declaration} or @nt{generic_@!package_@!declaration};
1703 a @nt{task_@!body_@!stub} shall be the completion of a
1704 @Chg{Version=[3],New=[task declaration],Old=[@ntf{task_@!declaration}]};
1705 a @nt{protected_@!body_stub} shall be the completion of a
1706 @Chg{Version=[3],New=[protected declaration],Old=[@ntf{protected_@!declaration}]}.
1707
1708 In contrast,
1709 a @nt{subprogram_body_stub} need not be the completion of a previous
1710 declaration,
1711 @Redundant[in which case the @ntf{_stub} declares the subprogram].
1712 If the @ntf{_stub} is a completion, it shall be the completion of a
1713 @nt{subprogram_declaration} or @nt{generic_subprogram_declaration}.
1714 The profile of a @nt{subprogram_body_stub} that completes a declaration
1715 shall conform fully to that of the declaration.
1716 @Defn2{Term=[full conformance],Sec=(required)}
1717 @begin{Discussion}
1718 The part about @nt{subprogram_body_stub}s echoes the corresponding rule
1719 for @ntf{subprogram_bodies} in @RefSec{Subprogram Bodies}.
1720 @end{Discussion}
1721
1722 A subunit that corresponds to a @nt{body_stub} shall be of
1723 the same kind
1724 (@ntf{package_}, @ntf{subprogram_}, @ntf{task_}, or @ntf{protected_})
1725 as the @nt{body_stub}.
1726 The profile of a @nt{subprogram_body}
1727 subunit shall be fully conformant to
1728 that of the corresponding @nt{body_stub}.
1729 @Defn2{Term=[full conformance],Sec=(required)}
1730
1731 A @nt{body_stub} shall appear immediately within the
1732 @nt{declarative_part} of a compilation unit body.
1733 This rule does not apply within an instance of a generic unit.
1734 @begin{Discussion}
1735 @Defn{methodological restriction}
1736 This is a methodological restriction;
1737 that is, it is not necessary for the semantics of the language to
1738 make sense.
1739 @end{Discussion}
1740
1741 The @nt{defining_identifier}s of all @nt{body_stub}s that appear
1742 immediately within a particular @nt{declarative_part} shall be
1743 distinct.
1744 @end{Legality}
1745
1746 @begin{LinkTime}
1747 For each @nt{body_stub}, there shall be a subunit containing
1748 the corresponding @nt{proper_body}.
1749 @end{LinkTime}
1750
1751 @begin{Notes}
1752 @leading@;The rules in @RefSec{The Compilation Process}
1753 say that a @nt{body_stub} is equivalent to the corresponding
1754 @nt{proper_body}. This implies:
1755 @begin{Itemize}
1756 Visibility within a subunit is the
1757 visibility that would be obtained at the place of the corresponding
1758 @nt{body_stub} (within the parent body) if the
1759 @nt{context_clause} of the subunit were appended to
1760 that of the parent body.
1761 @begin{Ramification}
1762 Recursively.
1763 Note that this transformation might make the parent illegal;
1764 hence it is not a true equivalence, but applies only to visibility
1765 within the subunit.
1766 @end{Ramification}
1767
1768 The effect of the elaboration of a @nt{body_stub} is to elaborate
1769 the subunit.
1770 @begin{Ramification}
1771 The elaboration of a subunit is part of its parent body's elaboration,
1772 whereas the elaboration of a child unit is not part of its parent
1773 declaration's elaboration.
1774 @end{Ramification}
1775 @end{Itemize}
1776 @begin{Ramification}
1777 A @nt<library_item> that is mentioned in a @nt{with_clause} of a
1778 subunit can be hidden (from direct @Chg{Version=[2],New=[visibility],
1779 Old=[visiblity]}) by a declaration (with the same
1780 @nt{identifier}) given in the subunit.
1781 Moreover, such a @nt<library_item> can even be hidden by a declaration
1782 given within the parent body since a library unit is declared in its
1783 parent's declarative region; this however does not affect the
1784 interpretation of the @nt{with_clause}s themselves, since only
1785 @nt<library_item>s
1786 are visible or directly visible
1787 in @nt{with_clause}s.
1788
1789 The body of a protected operation cannot be a subunit.
1790 This follows from the syntax rules.
1791 The body of a protected unit can be a subunit.
1792 @end{Ramification}
1793 @end{Notes}
1794
1795 @begin{Examples}
1796 @leading@keepnext@;The package Parent is first written without subunits:
1797 @begin{Example}
1798 @key[package] Parent @key[is]
1799 @key[procedure] Inner;
1800 @key[end] Parent;
1801
1802 @key[with] Ada.Text_IO;
1803 @key[package] @key[body] Parent @key[is]
1804 Variable : String := "Hello, there.";
1805 @key[procedure] Inner @key[is]
1806 @key[begin]
1807 Ada.Text_IO.Put_Line(Variable);
1808 @key[end] Inner;
1809 @key[end] Parent;
1810 @end{Example}
1811
1812 @begin{WideAbove}
1813 @leading@;The body of procedure Inner may be turned into a subunit by rewriting
1814 the package body as follows (with the declaration of Parent remaining
1815 the same):
1816 @end{WideAbove}
1817 @begin{Example}
1818 @key[package] @key[body] Parent @key[is]
1819 Variable : String := "Hello, there.";
1820 @key[procedure] Inner @key[is] @key[separate];
1821 @key[end] Parent;
1822
1823 @key[with] Ada.Text_IO;
1824 @key[separate](Parent)
1825 @key[procedure] Inner @key[is]
1826 @key[begin]
1827 Ada.Text_IO.Put_Line(Variable);
1828 @key[end] Inner;
1829 @end{Example}
1830 @end{Examples}
1831
1832 @begin{Extend83}
1833 @Defn{extensions to Ada 83}
1834 Subunits of the same ancestor library unit are no longer restricted
1835 to have distinct identifiers.
1836 Instead, we require only that the full expanded names be distinct.
1837 @end{Extend83}
1838
1839 @begin{Extend95}
1840 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1841 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1842 An @nt{overriding_indicator} (see
1843 @RefSecNum{Overriding Indicators}) is allowed on a subprogram stub.]}
1844 @end{Extend95}
1845
1846 @begin{DiffWord95}
1847 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00243-01]}
1848 @ChgAdded{Version=[2],Text=[Clarified that a subunit of a subunit is still a
1849 subunit.]}
1850 @end{DiffWord95}
1851
1852 @begin{Extend2005}
1853 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0267-1]}
1854 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1855 An optional @nt{aspect_specification} can be used in a
1856 @nt{body_stub}. This is described in @RefSecNum{Aspect Specifications}.]}
1857 @end{Extend2005}
1858
1859
1860 @LabeledSubClause{The Compilation Process}
1861
1862 @begin{Intro}
1863 @Defn{environment}
1864 @Defn{environment @nt<declarative_part>}
1865 Each compilation unit submitted to the compiler is compiled in the
1866 context of an @i{environment} @nt<declarative_part> (or simply, an
1867 @i{environment}),
1868 which is a conceptual @nt<declarative_part> that forms
1869 the outermost declarative region of the
1870 context of any @nt{compilation}.
1871 At run time, an environment forms the @nt<declarative_part> of
1872 the body of the environment task of a partition
1873 (see @RefSec{Program Execution}).
1874 @begin{Ramification}
1875 At compile time, there is no particular construct that the
1876 declarative region is considered to be nested within
1877 @em the environment is the universe.
1878 @end{Ramification}
1879 @begin{Honest}
1880 The environment is really just a portion of a @nt{declarative_part},
1881 since there might, for example, be bodies that do not yet exist.
1882 @end{Honest}
1883
1884 The @nt{declarative_item}s of the environment
1885 are @nt{library_item}s appearing in an order
1886 such that there are no forward semantic dependences.
1887 Each included subunit
1888 occurs in place of the corresponding stub.
1889 The visibility rules apply as if the environment were the outermost
1890 declarative region,
1891 except that @nt{with_@!clause}s are needed to make
1892 declarations of library units visible
1893 (see @RefSecNum{Context Clauses - With Clauses}).
1894
1895 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1896 The mechanisms for creating an environment
1897 and for adding and replacing compilation units within an environment
1898 are implementation defined.@Chg{Version=[2],New=[ The mechanisms for adding a
1899 compilation unit mentioned in a @nt{limited_with_clause} to an
1900 environment are implementation defined.],Old=[]}
1901 @ImplDef{The mechanisms for creating an environment
1902 and for adding and replacing compilation units.}
1903 @ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[The
1904 mechanisms for adding a compilation unit mentioned in a @nt{limited_with_clause}
1905 to an environment.],Old=[]}]}
1906 @begin{Ramification}
1907 The traditional model, used by most Ada 83 implementations,
1908 is that one places a compilation unit in the environment
1909 by compiling it.
1910 Other models are possible.
1911 For example, an implementation might define the environment to
1912 be a directory;
1913 that is, the compilation units in the environment are all the
1914 compilation units in the source files contained in the directory.
1915 In this model, the mechanism for replacing a compilation unit with a
1916 new one is simply to edit the source file containing that compilation
1917 unit.
1918 @end{Ramification}
1919
1920 @end{Intro}
1921
1922 @begin{Resolution}
1923 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0032],ARef=[AI95-00192-01]}
1924 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
1925 If a @nt<library_unit_body> that is a @nt<subprogram_body> is
1926 submitted to the compiler, it is interpreted only as a completion
1927 if a @nt<library_unit_declaration> @Chg{New=[], Old=[for a subprogram
1928 or a generic subprogram ]}with the same @nt<defining_program_unit_name>
1929 already exists in the environment @Chg{New=[for a subprogram other than
1930 an instance of a generic subprogram or for a generic subprogram ], Old=[]}
1931 (even if the profile of the body is not type conformant with that of the
1932 declaration); otherwise@Chg{Version=[3],New=[,],Old=[]} the
1933 @nt<subprogram_body> is
1934 interpreted as both the declaration and body of a library subprogram.
1935 @PDefn{type conformance}
1936 @begin{Ramification}
1937 The principle here is that a @nt{subprogram_body} should be
1938 interpreted as only a completion if and only if it @lquotes@;might@rquotes@;
1939 be legal as the completion of some preexisting declaration,
1940 where @lquotes@;might@rquotes@; is defined in a way that does not require overload
1941 resolution to determine.
1942
1943 Hence, if the preexisting declaration is a @nt{subprogram_declaration}
1944 or @nt{generic_subprogram_declaration}, we treat the new
1945 @nt{subprogram_body} as its completion, because it @lquotes@;might@rquotes@; be legal.
1946 If it turns out that the profiles don't fully conform,
1947 it's an error.
1948 In all other cases (the preexisting declaration is a
1949 package or a generic package,
1950 or an instance of a generic subprogram,
1951 or a renaming,
1952 or a @lquotes@;spec-less@rquotes@; subprogram,
1953 or in the case where there is no preexisting thing),
1954 the @nt{subprogram_body} declares a new subprogram.
1955
1956 See also AI83-00266/09.
1957 @end{Ramification}
1958 @end{Resolution}
1959
1960 @begin{Legality}
1961 When a compilation unit is compiled,
1962 all compilation units upon which it depends semantically
1963 shall already exist in the environment;
1964 @Defn2{Term=[consistency], Sec=(among compilation units)}
1965 the set of these compilation units shall be @i{consistent} in the
1966 sense that the new compilation unit shall not semantically depend
1967 (directly or indirectly) on two different versions of the same compilation
1968 unit, nor on an earlier version of itself.
1969 @begin{Discussion}
1970 For example, if package declarations A and B both say
1971 @lquotes@;@key[with] X;@rquotes@;, and the user compiles a compilation unit that says
1972 @lquotes@;@key[with] A, B;@rquotes@;, then the A and B have to be talking about the
1973 same version of X.
1974 @end{Discussion}
1975 @begin{Ramification}
1976 What it means to be a @lquotes@;different version@rquotes@; is not specified by the
1977 language. In some implementations, it means that the compilation
1978 unit has been recompiled. In others, it means that the
1979 source of the compilation unit has been edited in some significant way.
1980
1981 Note that an implementation cannot require the existence of
1982 compilation units upon which the given one does not semantically
1983 depend.
1984 For example, an implementation is required to be able to compile a
1985 compilation unit that says "@key{with} A;" when A's body does not
1986 exist.
1987 It has to be able to detect errors without looking at A's body.
1988
1989 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1990 Similarly, the implementation has to be able to compile a call to a
1991 subprogram for which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]}
1992 Inline has been specified without
1993 seeing the body of that subprogram @em inlining would not be
1994 achieved in this case, but the call is still legal.
1995
1996 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1997 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
1998 @ChgAdded{Version=[2],Text=[The @Chg{Version=[2],New=[consistency],
1999 Old=[second]} rule applies to limited views as well
2000 as the full view of a compilation unit. That means that an implementation needs
2001 a way to enforce consistency of limited views, not just of full views.]}
2002 @end{Ramification}
2003 @end{Legality}
2004
2005 @begin{ImplPerm}
2006 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
2007 The implementation may require that a compilation unit be legal before
2008 @Chg{Version=[2],New=[it can be mentioned in a @nt{limited_with_clause} or
2009 it can be inserted],Old=[inserting it]} into the environment.
2010
2011 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00214-01]}
2012 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2013 When a compilation unit that declares or renames a library unit
2014 is added to the environment,
2015 the implementation may remove from the environment
2016 any preexisting @nt<library_item>
2017 @Chg{Version=[2],New=[or @nt<subunit> with the same full expanded name],
2018 Old=[with the same @nt<defining_@!program_@!unit_name>]}.
2019 When a compilation unit that is a subunit or the body
2020 of a library unit is added to the environment,
2021 the implementation may remove from the environment
2022 any preexisting version of the same compilation unit.
2023 @Chg{Version=[2],New=[When a compilation unit that
2024 contains a @nt<body_stub> is added to the environment, the implementation may
2025 remove any preexisting @nt<library_item> or @nt<subunit> with the same full
2026 expanded name as the @nt<body_stub>.],Old=[]}
2027 When a given compilation unit is removed from the environment,
2028 the implementation may also remove any compilation unit that depends
2029 semantically upon the given one.
2030 If the given compilation unit contains the body of a subprogram @Chg{Version=[3],New=[for],Old=[to]}
2031 which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]} Inline @Chg{Version=[3],New=[is True],Old=[applies]},
2032 the implementation may also remove any compilation unit containing a
2033 call to that subprogram.
2034 @begin{Ramification}
2035
2036 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
2037 The permissions given in this paragraph correspond to the traditional
2038 model, where compilation units enter the environment by being
2039 compiled into it, and the compiler checks their legality at that time.
2040 @Chg{Version=[3],New=[An],Old=[A]} implementation model in which the
2041 environment consists of all source files in a given directory might not
2042 want to take advantage of these permissions.
2043 Compilation units would not be checked for
2044 legality as soon as they enter the environment; legality checking
2045 would happen later, when compilation units are compiled.
2046 In this model, compilation units might never be automatically removed
2047 from the environment;
2048 they would be removed when the user explicitly deletes a source file.
2049
2050 Note that the rule is recursive: if the above permission is used to
2051 remove a compilation unit containing an inlined subprogram call,
2052 then compilation units that depend semantically upon the removed one
2053 may also be removed, and so on.
2054
2055 Note that here we are talking about dependences among existing
2056 compilation units in the environment;
2057 it doesn't matter what @nt{with_clause}s are attached to the new
2058 compilation unit that triggered all this.
2059
2060 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2061 An implementation may have other modes in which compilation units
2062 in addition to the ones mentioned above are removed.
2063 For example, an implementation might inline subprogram calls without
2064 an explicit @Chg{Version=[3],New=[aspect],Old=[@nt{pragma}]} Inline.
2065 If so, it either has to have a mode in which that optimization is
2066 turned off, or it has to automatically regenerate code for the inlined
2067 calls without requiring the user to resubmit them to the compiler.
2068 @end{Ramification}
2069 @begin{Discussion}
2070 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0108],ARef=[AI95-00077-01]}
2071 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]}
2072 @ChgAdded{Version=[1],Text=[In the standard mode, implementations may only remove
2073 units from the environment for one of the reasons listed here, or in response
2074 to an explicit user command to modify the environment. It is not intended that
2075 the act of compiling a unit is one of the
2076 @lquotes@;@Chg{Version=[2],New=[mechanisms],Old=[mechansisms]}@rquotes for
2077 removing units other than those specified by this International Standard.]}
2078
2079 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00214-01]}
2080 @ChgAdded{Version=[2],Text=[These rules are intended to ensure that an
2081 implementation never need keep more than one compilation unit with any full
2082 expanded name. In particular, it is not necessary to be able to have a subunit
2083 and a child unit with the same name in the environment at one time.]}
2084
2085 @end{Discussion}
2086 @end{ImplPerm}
2087
2088 @begin{Notes}
2089 The rules of the language are enforced across
2090 @nt{compilation} and compilation unit boundaries,
2091 just as they are enforced within a single compilation unit.
2092 @begin{Ramification}
2093 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2094 Note that @Chg{Version=[3],New=[Clause],Old=[Section]} @RefSecNum{General}
2095 requires an implementation to detect illegal compilation units at compile time.
2096 @end{Ramification}
2097
2098 @Defn{library}
2099 An implementation may support a concept of a @i{library},
2100 which contains @nt{library_item}s.
2101 If multiple libraries are supported,
2102 the implementation has to define how a single environment is
2103 constructed when a compilation unit is submitted to the compiler.
2104 Naming conflicts between different libraries might be resolved by
2105 treating each library as the root of a hierarchy of child library
2106 units.
2107 @IndexSee{Term=[program library],See=(library)}
2108 @begin{ImplNote}
2109 Alternatively, naming conflicts could be resolved via some sort of
2110 hiding rule.
2111 @end{ImplNote}
2112 @begin{Discussion}
2113 For example, the implementation might support a command to import
2114 library Y into library X.
2115 If a root library unit called LU (that is, Standard.LU) exists in Y,
2116 then from the point of view of library X,
2117 it could be called Y.LU.
2118 X might contain library units that say, @lquotes@;@key[with] Y.LU;@rquotes@;.
2119 @end{Discussion}
2120
2121 A compilation unit containing an instantiation of a separately
2122 compiled generic unit does not semantically depend on the body
2123 of the generic unit.
2124 Therefore, replacing the generic body in the environment
2125 does not result in the removal of the compilation unit
2126 containing the instantiation.
2127 @begin{ImplNote}
2128 Therefore, implementations have to be prepared to automatically
2129 instantiate generic bodies at link-time, as needed. This might
2130 imply a complete automatic recompilation, but it is the intent
2131 of the language that generic bodies can be (re)instantiated without
2132 forcing all of the compilation units that semantically depend
2133 on the compilation unit containing the instantiation to be
2134 recompiled.
2135 @end{ImplNote}
2136 @end{Notes}
2137
2138 @begin{Extend83}
2139 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00077-01],ARef=[AI95-00114-01]}
2140 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 83}
2141 Ada 83 allowed implementations to require that the body of a generic unit
2142 be available when the instantiation is compiled; that permission is dropped
2143 in Ada 95. This isn't really an extension (it doesn't allow Ada users to
2144 write anything that they couldn't in Ada 83), but there isn't a more
2145 appropriate category, and it does allow users more flexibility when
2146 developing programs.]}
2147 @end{Extend83}
2148
2149
2150 @begin{DiffWord95}
2151 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0032],ARef=[AI95-00192-01]}
2152 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> The wording was clarified to
2153 ensure that a @nt{subprogram_body} is not considered a completion of
2154 an instance of a generic subprogram.]}
2155
2156 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00214-01]}
2157 @ChgAdded{Version=[2],Text=[The permissions to remove a unit from the
2158 environment were clarified to ensure that it is never necessary to keep
2159 multiple (sub)units with the same full expanded name in the environment.]}
2160
2161 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
2162 @ChgAdded{Version=[2],Text=[Units mentioned in a @nt{limited_with_clause}
2163 were added to several rules; limited views have the same presence in the
2164 environment as the corresponding full views.]}
2165 @end{DiffWord95}
2166
2167 @LabeledSubClause{Pragmas and Program Units}
2168
2169 @begin{Intro}
2170 @Redundant[This subclause discusses pragmas related to program units,
2171 library units, and @nt{compilation}s.]
2172 @end{Intro}
2173
2174 @begin{Resolution}
2175 @RootDefn{program unit pragma}
2176 @RootDefn{pragma, program unit}
2177 Certain @nt{pragma}s are defined to be @i{program unit pragmas}.
2178 @PDefn2{Term=[apply], Sec=(to a program unit by a program unit pragma)}
2179 A @nt{name} given as the argument of a program unit pragma shall resolve to
2180 denote the declarations or renamings of one or more program
2181 units that occur immediately within the declarative region or @nt<compilation>
2182 in which the @nt<pragma> immediately occurs, or it shall resolve to denote
2183 the declaration of the immediately enclosing program unit (if any);
2184 the @nt{pragma} applies to the denoted program
2185 unit(s).
2186 If there are no @nt{name}s given as arguments,
2187 the @nt{pragma} applies to the immediately
2188 enclosing program unit.
2189 @begin{Ramification}
2190 The fact that this is a @ResolutionName means that the @nt{pragma}
2191 will not apply to declarations from outer declarative regions.
2192 @end{Ramification}
2193
2194 @end{Resolution}
2195
2196 @begin{Legality}
2197 @leading@keepnext@;A program unit pragma shall appear in one of these places:
2198 @begin{Itemize}
2199 At the place of a @nt{compilation_unit},
2200 in which case the @nt<pragma>
2201 shall immediately follow in the same @nt<compilation> (except for
2202 other @nt{pragma}s)
2203 a @nt{library_@!unit_@!declaration} that is a @nt<subprogram_@!declaration>,
2204 @nt<generic_@!subprogram_@!declaration>, or @nt<generic_@!instantiation>, and
2205 the @nt<pragma> shall have an argument that is a @nt<name> denoting
2206 that declaration.
2207 @begin{Ramification}
2208 The @nt{name} has to denote the immediately preceding
2209 @nt{library_unit_declaration}.
2210 @end{Ramification}
2211
2212 @ChgRef{Version=[1], Kind=[Revised], Ref=[8652/0033], ARef=[AI95-00136-01]}
2213 Immediately within the @Chg{New=[visible part],Old=[declaration]} of a
2214 program unit and before any nested declaration@Chg{New=[ (but not within a
2215 generic formal part)], Old=[]}, in which case the argument,
2216 if any, shall be a @nt{direct_name}
2217 that denotes the immediately enclosing program unit declaration.
2218 @begin{Ramification}
2219 The argument is optional in this case.
2220 @end{Ramification}
2221
2222 At the place of a declaration
2223 other than the first,
2224 of a @nt{declarative_part} or program unit declaration,
2225 in which case the @nt{pragma} shall have an argument,
2226 which shall be a @nt{direct_name}
2227 that denotes one or more of the following (and nothing else):
2228 a @nt{subprogram_@!declaration}, a @nt{generic_@!subprogram_@!declaration},
2229 or a @nt{generic_@!instantiation}, of the same @nt<declarative_@!part> or
2230 program unit declaration.
2231 @begin{Ramification}
2232 If you want to denote a @nt<subprogram_body> that is not a
2233 completion, or a
2234 @nt{package_declaration}, for example, you have to put the @nt{pragma}
2235 inside.
2236 @end{Ramification}
2237 @end{Itemize}
2238
2239 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0132-1]}
2240 @RootDefn{library unit pragma}
2241 @RootDefn{pragma, library unit}
2242 @PDefn2{Term=[program unit pragma], Sec=(library unit pragmas)}
2243 @PDefn2{Term=[pragma, program unit], Sec=(library unit pragmas)}
2244 Certain program unit pragmas are defined to be
2245 @i{library unit pragmas}.
2246 @Chg{Version=[3],New=[If a library unit pragma applies to a program unit,
2247 the program unit shall be],Old=[The @nt{name}, if
2248 any, in a library unit pragma shall denote the declaration of]} a library unit.
2249 @begin{Ramification}
2250 This, together with the rules for program unit pragmas above,
2251 implies that if a library unit pragma applies to a @nt{subprogram_declaration}
2252 (and similar things), it has to appear immediately after the
2253 @nt{compilation_unit}, whereas if the @nt{pragma} applies to a
2254 @nt{package_declaration}, a @nt{subprogram_body} that is not a
2255 completion (and similar things), it has to appear inside, as the first
2256 @nt{declarative_item}.
2257 @end{Ramification}
2258 @end{Legality}
2259
2260 @begin{StaticSem}
2261 @ChgRef{Version=[1], Kind=[Added], Ref=[8652/0034], ARef=[AI95-00041-01]}
2262 @ChgAdded{Version=[1],Text=[A library unit pragma that applies to a generic
2263 unit does not apply to its instances, unless a specific rule for the pragma
2264 specifies the contrary.]}
2265 @end{StaticSem}
2266
2267 @begin{LinkTime}
2268 @RootDefn{configuration pragma}
2269 @RootDefn{pragma, configuration}
2270 Certain @nt{pragma}s are defined to be @i{configuration pragmas};
2271 they shall appear before the first @nt{compilation_unit}
2272 of a @nt{compilation}.
2273 @Redundant[They are generally used to select a partition-wide
2274 or system-wide option.]
2275 The @nt<pragma> applies to all @nt{compilation_unit}s
2276 appearing in the @nt{compilation},
2277 unless there are none, in which case it applies to all future
2278 @nt{compilation_unit}s compiled into the same environment.
2279 @end{LinkTime}
2280
2281 @begin{ImplPerm}
2282 @ChgRef{Version=[2], Kind=[Revised], ARef=[AI95-00212-01]}
2283 An implementation may @Chg{Version=[2], New=[require that configuration
2284 pragmas that select partition-wide or system-wide options be compiled],
2285 Old=[place restrictions on
2286 configuration pragmas, so long as it allows them]} when the environment
2287 contains no @nt{library_item}s other than those of the predefined environment.
2288 @Chg{Version=[2], New=[In this case, the implementation shall still accept
2289 configuration pragmas in individual compilations that confirm the initially
2290 selected partition-wide or system-wide options.],Old=[]}
2291
2292 @end{ImplPerm}
2293
2294 @begin{ImplAdvice}
2295 @ChgRef{Version=[1], Kind=[AddedNormal], Ref=[8652/0034], ARef=[AI95-00041-01]}
2296 @ChgAdded{Version=[1],Text=[When applied to a generic unit, a program unit pragma that
2297 is not a library unit pragma should apply to each instance of the generic unit
2298 for which there is not an overriding pragma applied directly to the instance.]}
2299 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2300 Text=[When applied to a generic unit, a program unit pragma that
2301 is not a library unit pragma should apply to each instance of the generic unit
2302 for which there is not an overriding pragma applied directly to the instance.]}]}
2303 @end{ImplAdvice}
2304
2305
2306 @begin{DiffWord95}
2307 @ChgRef{Version=[2], Kind=[AddedNormal], Ref=[8652/0033], ARef=[AI95-00136-01]}
2308 @ChgAdded{Version=[2], Text=[@B<Corrigendum:> The wording was corrected to
2309 ensure that a program unit pragma cannot appear in private parts or
2310 generic formal parts.]}
2311
2312 @ChgRef{Version=[2], Kind=[AddedNormal], Ref=[8652/0034],
2313 ARef=[AI95-00041-01]} @ChgAdded{Version=[2], Text=[@B<Corrigendum:> The
2314 wording was clarified to explain the meaning of program unit and library unit
2315 pragmas in generic units.]}
2316
2317 @ChgRef{Version=[2], Kind=[AddedNormal]}
2318 @ChgAdded{Version=[2], Text=[The Implementation Advice added by the
2319 Corrigendum was moved, as it was not in the normal order. (This changes the
2320 paragraph number.) It originally was directly after the new Static Semantics
2321 rule.]}
2322
2323 @ChgRef{Version=[2], Kind=[AddedNormal], ARef=[AI95-00212-01]}
2324 @ChgAdded{Version=[2], Type=[Leading],Keepnext=[T],Text=[The permission to
2325 place restrictions was clarified to:]}
2326 @begin{itemize}
2327 @ChgRef{Version=[2], Kind=[AddedNormal]}
2328 @ChgAdded{Version=[2], Text=[Ensure that it applies only to partition-wide
2329 configuration pragmas, not ones like Assertion_Policy (see
2330 @RefSecNum{Pragmas Assert and Assertion_Policy}), which can be different
2331 in different units; and]}
2332
2333 @ChgRef{Version=[2], Kind=[AddedNormal]}
2334 @ChgAdded{Version=[2], Text=[Ensure that confirming pragmas are always allowed.]}
2335 @end{itemize}
2336 @end{DiffWord95}
2337
2338 @begin{DiffWord2005}
2339 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0132-1]}
2340 @ChgAdded{Version=[3], Text=[@b<Correction:> A library unit pragma must
2341 apply directly to a library unit, even if no name is given in the pragma.]}
2342 @end{DiffWord2005}
2343
2344
2345 @LabeledSubClause{Environment-Level Visibility Rules}
2346
2347 @begin{Intro}
2348 @Redundant[The normal visibility rules do not apply within a
2349 @nt{parent_unit_name} or a @nt{context_clause},
2350 nor within a @nt{pragma} that appears at the place of a compilation unit.
2351 The special visibility rules for those contexts
2352 are given here.]
2353 @end{Intro}
2354
2355 @begin{StaticSem}
2356 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00312-01]}
2357 @PDefn2{Term=[directly visible], Sec=(within the
2358 @nt{parent_unit_name} of a library unit)}
2359 @PDefn2{Term=[visible], Sec=(within the
2360 @nt{parent_unit_name} of a library unit)}
2361 @PDefn2{Term=[directly visible], Sec=(within a @nt{with_clause})}
2362 @PDefn2{Term=[visible], Sec=(within a @nt{with_clause})}
2363 Within the @nt{parent_unit_name} at the beginning of
2364 @Chg{Version=[2],New=[an explicit],Old=[a]} @nt{library_item},
2365 and within a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}],
2366 Old=[@nt{with_clause}]}, the only declarations
2367 that are visible are those that are@Chg{Version=[2],New=[ explicit],Old=[]}
2368 @nt<library_item>s of the environment,
2369 and the only declarations that are directly visible are those that
2370 are@Chg{Version=[2],New=[ explicit],Old=[]} root @nt<library_item>s
2371 of the environment.
2372 @Chg{Version=[2],New=[Within a @nt{limited_with_clause}, the only declarations
2373 that are visible are those that are the implicit declaration of the
2374 limited view of a library package of the environment, and the only
2375 declarations that are directly visible are those that are the
2376 implicit declaration of the limited view of a root library package.],
2377 Old=[@Defn{notwithstanding}
2378 Notwithstanding the rules of @RefSecNum(Selected Components),
2379 an expanded name in a @nt{with_clause} may consist of a
2380 @nt<prefix> that denotes a generic package and a @nt<selector_name> that
2381 denotes a child of that generic package.
2382 @Redundant[(The child is necessarily a generic unit;
2383 see @RefSecNum{Compilation Units - Library Units}.)]]}
2384
2385 @begin{Ramification}
2386 In @lquotes@;@key{package} P.Q.R @key{is} ... @key{end} P.Q.R;@rquotes@;,
2387 this rule requires P to be a root library unit,
2388 and Q to be a library unit
2389 (because those are the things that are directly visible and visible).
2390 Note that visibility does not apply between the @lquotes@;@key{end}@rquotes@;
2391 and the @lquotes@;;@rquotes@;.
2392
2393 Physically nested declarations are not visible at these places.
2394
2395 @ChgNote{Changed the classification of this note from Reason to Ramification,
2396 as it certainly isn't a "reason". Besides, there were two reasons, which was
2397 goofy.}
2398 Although Standard is visible at these places,
2399 it is impossible to name it,
2400 since it is not directly visible,
2401 and it has no parent.
2402
2403 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
2404 @ChgAdded{Version=[2],Text=[Only compilation units defining limited views
2405 can be mentioned in a @nt{limited_with_clause}, while only compilation
2406 units defining full views (that is, the explicit declarations) can be mentioned
2407 in a @nt{nonlimited_with_clause}. This resolves the conflict inherent in having
2408 two compilation units with the same defining name.]}
2409 @end{Ramification}
2410 @begin{Reason}
2411 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00312-01]}
2412 @ChgDeleted{Version=[2],Text=[The @lquotes@;notwithstanding@rquotes@; part
2413 allows @lquotes@;@key[with] A.B;@rquotes@;
2414 where A is a generic library package and B is one of its
2415 (generic) children.
2416 This is necessary because it is not normally legal to use an expanded
2417 name to reach inside a generic package.]}
2418 @end{Reason}
2419
2420 @PDefn2{Term=[directly visible], Sec=(within a @nt{use_clause} in a @nt{context_clause})}
2421 @PDefn2{Term=[visible], Sec=(within a @nt{use_clause} in a @nt{context_clause})}
2422 @PDefn2{Term=[directly visible], Sec=(within a @nt{pragma} in a @nt{context_clause})}
2423 @PDefn2{Term=[visible], Sec=(within a @nt{pragma} in a @nt{context_clause})}
2424 Within a @nt{use_clause} or @nt{pragma}
2425 that is within a @nt{context_clause},
2426 each @nt<library_item> mentioned in a previous
2427 @nt{with_clause} of the same @nt{context_clause} is visible,
2428 and each root @nt<library_item> so mentioned is directly visible.
2429 In addition,
2430 within such a @nt{use_clause},
2431 if a given declaration is visible or directly
2432 visible,
2433 each declaration that occurs immediately within the given declaration's
2434 visible part is also visible.
2435 No other declarations are visible or directly visible.
2436 @begin{Discussion}
2437 Note the word @lquotes@;same@rquotes@;.
2438 For example, if a @nt{with_clause} on a declaration mentions X,
2439 this does not make X visible in @nt{use_clause}s and @nt{pragma}s
2440 that are on the body.
2441 The reason for this rule is
2442 the one-pass @nt{context_clause}s @MetaRulesName.
2443
2444 Note that the second part of the rule does not
2445 mention @nt{pragma}s.
2446 @end{Discussion}
2447
2448 @PDefn2{Term=[directly visible], Sec=(within the
2449 @nt{parent_unit_name} of a subunit)}
2450 @PDefn2{Term=[visible], Sec=(within the
2451 @nt{parent_unit_name} of a subunit)}
2452 Within the @nt{parent_unit_name} of a subunit, @nt<library_item>s
2453 are visible as they are in
2454 the @nt{parent_unit_name} of a @nt{library_item};
2455 in addition, the declaration corresponding to each
2456 @nt{body_stub} in the environment
2457 is also visible.
2458 @begin{Ramification}
2459 For a subprogram without a separate @nt<subprogram_declaration>,
2460 the @nt<body_stub> itself is the declaration.
2461 @end{Ramification}
2462
2463 @PDefn2{Term=[directly visible], Sec=(within a @nt{pragma}
2464 that appears at the place of a compilation unit)}
2465 @PDefn2{Term=[visible], Sec=(within a @nt{pragma}
2466 that appears at the place of a compilation unit)}
2467 Within a @nt{pragma} that appears at the place of a compilation unit,
2468 the immediately preceding @nt<library_item> and each of its
2469 ancestors is visible.
2470 The ancestor root @nt<library_item> is directly visible.
2471
2472 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00312-01]}
2473 @ChgAdded{Version=[2],Text=[@Defn{notwithstanding}
2474 Notwithstanding the rules of @RefSecNum(Selected Components),
2475 an expanded name in a @nt{with_clause}, a @nt{pragma} in a @nt{context_clause},
2476 or a @nt{pragma} that appears at the place of a compilation unit
2477 may consist of a @nt{prefix} that denotes a generic package and
2478 a @nt<selector_name> that denotes a child of that generic package.
2479 @Redundant[(The child is necessarily a generic unit;
2480 see @RefSecNum{Compilation Units - Library Units}.)]]}
2481 @begin{Reason}
2482 @ChgRef{Version=[2],Kind=[AddedNormal]}
2483 @ChgAdded{Version=[2],Text=[This rule allows @key[with] A.B; and
2484 @key[pragma] Elaborate(A.B); where A is a
2485 generic library package and B is one of its (generic) children. This is
2486 necessary because it is not normally legal to use an expanded
2487 name to reach inside a generic package.]}
2488 @end{Reason}
2489
2490 @end{StaticSem}
2491
2492 @begin{DiffWord83}
2493 The special visibility rules that apply within a
2494 @nt{parent_unit_name} or a @nt{context_clause},
2495 and within a @nt{pragma} that appears at the place of a
2496 @nt{compilation_unit} are clarified.
2497
2498 Note that a @nt{context_clause} is not part of any declarative region.
2499
2500 We considered making the visibility rules within
2501 @nt{parent_unit_name}s and @nt{context_clause}s follow from the
2502 context of compilation.
2503 However, this attempt failed for various reasons.
2504 For example, it would require @nt{use_clause}s in
2505 @nt{context_clause}s to be within the declarative region of Standard,
2506 which sounds suspiciously like a kludge.
2507 And we would still need a special rule to prevent seeing things
2508 (in our own @nt{context_clause})
2509 that were with-ed by our parent, etc.
2510 @end{DiffWord83}
2511
2512 @begin{DiffWord95}
2513 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
2514 @ChgAdded{Version=[2],Text=[Added separate visibility rules for
2515 @nt{limited_with_clause}s; the existing rules apply only to
2516 @nt{nonlimited_with_clause}s.]}
2517
2518 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00312-01]}
2519 @ChgAdded{Version=[2],Text=[Clarified that the name of a generic child unit
2520 may appear in a @nt{pragma} in a @nt{context_clause}.]}
2521 @end{DiffWord95}
2522
2523
2524 @LabeledClause{Program Execution}
2525
2526 @begin{Intro}
2527 @Defn{program}
2528 @Defn{program execution}
2529 @IndexSee{Term=[running a program],See=(program execution)}
2530 An Ada @i{program} consists
2531 of a set of @i{partitions}@Redundant[,
2532 which can execute in parallel with one another,
2533 possibly in a separate address space,
2534 and possibly on a separate computer.]
2535 @end{Intro}
2536
2537 @begin{LinkTime}
2538
2539 @RootDefn{partition}
2540 @Defn{partition building}
2541 A partition is a program or part of a program
2542 that can be invoked from outside
2543 the Ada implementation.
2544 @Redundant[For example, on many systems,
2545 a partition might be an executable file
2546 generated by the system linker.]
2547 @Defn{explicitly assign}
2548 The user can @i{explicitly assign} library units to a partition.
2549 The assignment is done in an implementation-defined manner.
2550 The compilation units included in a partition are
2551 those of the explicitly assigned library units,
2552 as well as other compilation units @i{needed by} those library units.
2553 The compilation units needed by a given compilation unit are determined
2554 as follows
2555 (unless specified otherwise via an implementation-defined @nt{pragma},
2556 or by some other implementation-defined means):
2557 @IndexSee{Term=[linking],See=(partition building)}
2558 @RootDefn2{Term=[compilation units needed], Sec=(by a compilation unit)}
2559 @RootDefn2{Term=[needed], Sec=(of a compilation unit by another)}
2560 @begin{Discussion}
2561 From a run-time point of view,
2562 an Ada 95 partition is identical to an Ada 83 program
2563 @em implementations were always allowed to provide inter-program
2564 communication mechanisms.
2565 The additional semantics of partitions is that interfaces between
2566 them can be defined to obey normal language rules
2567 (as is done in @RefSec{Distributed Systems}),
2568 whereas interfaces between separate programs had no particular
2569 semantics.
2570 @end{Discussion}
2571 @ImplDef{The manner of explicitly assigning library units to a partition.}
2572 @ImplDef{The implementation-defined means, if any, of specifying which
2573 compilation units are needed by a given compilation unit.}
2574 @begin{Discussion}
2575 There are no pragmas that @lquotes@;specify otherwise@rquotes@; defined by the
2576 core language. However, an implementation is allowed to provide such
2577 pragmas, and in fact @RefSec{Distributed Systems} defines some
2578 pragmas whose semantics includes reducing the set of
2579 compilation units described here.
2580 @end{Discussion}
2581 @begin{Itemize}
2582 A compilation unit needs itself;
2583
2584 If a compilation unit is needed, then so are any compilation units
2585 upon which it depends semantically;
2586
2587 If a @nt{library_unit_declaration} is needed,
2588 then so is any corresponding
2589 @nt{library_unit_body};
2590
2591 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
2592 If a compilation unit with stubs is needed,
2593 then so are any corresponding subunits@Chg{Version=[2],New=[;],Old=[.]}
2594
2595 @begin{Discussion}
2596 Note that in the environment, the stubs are replaced with the
2597 corresponding @ntf{proper_bodies}.
2598 @end{Discussion}
2599
2600 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
2601 @ChgAdded{Version=[2],Text=[If the (implicit) declaration of the limited view
2602 of a library package is needed, then so is the explicit declaration of the
2603 library package.]}
2604
2605 @end{Itemize}
2606 @begin{Discussion}
2607 Note that a child unit is not included
2608 just because its parent is included @em to include a child,
2609 mention it in a @nt{with_clause}.
2610
2611 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
2612 @ChgAdded{Version=[2],Text=[A package is included in a partition even if the
2613 only reference to it is in a @nt{limited_with_clause}. While this isn't
2614 strictly necessary (no objects of types imported from such a unit can be
2615 created), it ensures that all incomplete types are eventually completed, and
2616 is the least surprising option.]}
2617 @end{Discussion}
2618
2619 @Defn2{Term=[main subprogram], Sec=(for a partition)}
2620 The user can optionally designate
2621 (in an implementation-defined manner)
2622 one subprogram as the @i{main subprogram} for the partition.
2623 A main subprogram, if specified, shall be a subprogram.
2624 @begin{Discussion}
2625 This may seem superfluous,
2626 since it follows from the definition.
2627 But we would like to have every error message that might be generated
2628 (before run time) by an implementation correspond to some
2629 explicitly stated @lquotes@;shall@rquotes@; rule.
2630
2631 Of course, this does not mean that the @lquotes@;shall@rquotes@; rules correspond
2632 one-to-one with an implementation's error messages. For example,
2633 the rule that says overload resolution @lquotes@;shall@rquotes@; succeed in producing a
2634 single interpretation would correspond to many error messages in a good
2635 implementation @em the implementation would want to explain to the user
2636 exactly why overload resolution failed.
2637 This is especially true for the syntax rules @em they are considered
2638 part of overload resolution, but in most cases, one would expect an
2639 error message based on the particular syntax rule that was violated.
2640 @end{Discussion}
2641 @ImplDef{The manner of designating the main subprogram of a partition.}
2642 @begin{Ramification}
2643 An implementation cannot require the user to specify, say, all of the
2644 library units to be included.
2645 It has to support, for example, perhaps the most typical case,
2646 where the user specifies just one library unit,
2647 the main program.
2648 The implementation has to do the work of tracking down all the other ones.
2649 @end{Ramification}
2650
2651 @Defn{environment task}
2652 Each partition has an anonymous @i{environment task}@Redundant[,
2653 which is an implicit outermost task whose execution
2654 elaborates the @nt{library_item}s of the environment
2655 @nt{declarative_part}, and then calls the main subprogram,
2656 if there is one.
2657 A partition's execution is that of its tasks.]
2658 @begin{Ramification}
2659 An environment task has no master;
2660 all nonenvironment tasks have masters.
2661
2662 An implementation is allowed to support
2663 multiple concurrent executions of the same partition.
2664 @end{Ramification}
2665
2666 @Redundant[The order of elaboration of library units is determined
2667 primarily by the @i{elaboration dependences}.]
2668 @Defn2{Term=[elaboration dependence], Sec=(library_item on another)}
2669 @Defn2{Term=[dependence], Sec=(elaboration)}
2670 There is an elaboration dependence of a given @nt{library_item} upon
2671 another if the given @nt{library_item} or any of its subunits depends
2672 semantically on the other @nt{library_item}.
2673 In addition, if a given @nt{library_item} or any of its subunits
2674 has a @nt{pragma} Elaborate or Elaborate_All that
2675 @Chg{Version=[2],New=[names],Old=[mentions]} another library unit,
2676 then there is an elaboration dependence of the given
2677 @nt{library_item} upon the body of the other library unit,
2678 and, for Elaborate_All only, upon
2679 each @nt{library_item} needed by
2680 the declaration of the other library unit.
2681 @begin{Discussion}
2682 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0107],ARef=[AI95-00180-01]}
2683 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00256-01]}
2684 @ChgAdded{Version=[1],Text=[@Lquotes@;Mentions@rquotes
2685 @Chg{Version=[2],New=[was],Old=[is]}
2686 used informally in the above rule; it @Chg{Version=[2],New=[was],Old=[is]}
2687 not intended to refer to the definition of @i{mentions} in
2688 @RefSecNum{Context Clauses - With Clauses}.
2689 @Chg{Version=[2],New=[It was changed to @Lquotes@;names@rquotes to make this clear.],
2690 Old=[It would have been better to use
2691 @Lquotes@;names@rquotes instead of @Lquotes@;mentions@rquotes above.]}]}
2692
2693 See above for a definition of which @nt{library_item}s are @lquotes@;needed by@rquotes@;
2694 a given declaration.
2695
2696 Note that elaboration dependences are among @nt{library_item}s,
2697 whereas the other two forms of dependence are among compilation units.
2698 Note that elaboration dependence includes semantic dependence.
2699 It's a little bit sad that pragma Elaborate_Body can't be folded into
2700 this mechanism.
2701 It follows from the definition that the elaboration dependence
2702 relationship is transitive.
2703 Note that the wording of the rule does not need to take into account
2704 a semantic dependence of a @nt{library_item} or one of its subunits
2705 upon a subunit of a different library unit,
2706 because that can never happen.
2707 @end{Discussion}
2708
2709 @leading@keepnext@;The environment task for a partition has the following
2710 structure:
2711 @begin{Example}
2712 @key[task] @RI{Environment_Task};
2713
2714 @key[task] @key[body] @RI{Environment_Task} @key[is]
2715 ... (1) --@RI{ The environment }@nt{declarative_part}
2716 --@RI{ (that is, the sequence of }@nt{library_item}@RI{s) goes here.}
2717 @key[begin]
2718 ... (2) --@RI{ Call the main subprogram, if there is one.}
2719 @key[end] @RI{Environment_Task};
2720 @end{Example}
2721 @begin{Ramification}
2722 The name of the environment task is written in italics here to indicate
2723 that this task is anonymous.
2724 @end{Ramification}
2725 @begin{Discussion}
2726 The model is different for a @lquotes@;passive partition@rquotes@;
2727 (see @RefSecNum{Partitions}).
2728 Either there is no environment task, or its @nt<sequence_of_statements>
2729 is an infinite loop rather than a call on a main subprogram.
2730 @end{Discussion}
2731
2732 @leading@PDefn2{Term=[environment @nt<declarative_part>], Sec=(for the
2733 environment task of a partition)}
2734 The environment @nt{declarative_part} at (1) is a sequence of
2735 @nt{declarative_item}s consisting of copies of
2736 the @nt{library_item}s included in the partition@Redundant[.
2737 The order of elaboration of @nt{library_item}s is
2738 the order in which they appear in the environment
2739 @nt{declarative_part}]:
2740 @begin{Itemize}
2741 The order of all included @nt<library_item>s
2742 is such that there are no forward elaboration
2743 dependences.
2744 @begin{Ramification}
2745 This rule is written so that if a @nt{library_item}
2746 depends on itself, we don't require it to be elaborated
2747 before itself. See AI83-00113/12.
2748 This can happen only in pathological circumstances.
2749 For example, if a library @nt{subprogram_body}
2750 has no corresponding @nt{subprogram_declaration},
2751 and one of the subunits of the @nt{subprogram_body}
2752 mentions the @nt{subprogram_body} in a @nt{with_clause},
2753 the @nt{subprogram_body} will depend on itself.
2754 For another example, if a @nt{library_unit_body}
2755 applies a @nt{pragma} Elaborate_All to its own declaration,
2756 then the @nt{library_unit_body} will depend on itself.
2757 @end{Ramification}
2758
2759 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
2760 Any included @nt{library_unit_declaration} @Chg{Version=[3],New=[for],Old=[to]}
2761 which @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]}
2762 Elaborate_Body @Chg{Version=[3],New=[is True @Redundant[(including when a
2763 @nt{pragma} Elaborate_Body applies)]],Old=[applies]}
2764 is immediately followed by its @nt{library_unit_body},
2765 if included.
2766 @begin{Discussion}
2767 This implies that the body of such a library unit
2768 shall not @lquotes@;with@rquotes@; any of its own children,
2769 or anything else that depends semantically upon
2770 the declaration of the library unit.
2771 @end{Discussion}
2772 @begin{TheProof}
2773 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2774 @ChgAdded{Version=[3],Text=[@nt{Pragma} Elaborate_Body sets
2775 aspect Elaborate_Body, see @RefSecNum{Elaboration Control}.]}
2776 @end{TheProof}
2777
2778 All @nt{library_item}s declared pure occur before any
2779 that are not declared pure.
2780
2781 All preelaborated @nt<library_item>s occur before any
2782 that are not preelaborated.
2783 @end{Itemize}
2784 @begin{Discussion}
2785 Normally, if two partitions contain the same compilation unit,
2786 they each contain a separate @i{copy} of that
2787 compilation unit.
2788 See @RefSec{Distributed Systems} for cases where two partitions share
2789 the same copy of something.
2790
2791 There is no requirement that the main subprogram be elaborated last.
2792 In fact, it is possible to write a partition in which the main
2793 subprogram cannot be elaborated last.
2794 @end{Discussion}
2795 @begin{Ramification}
2796 This @nt{declarative_part} has the properties required of all
2797 environments (see @RefSecNum{The Compilation Process}).
2798 However, the environment @nt{declarative_part} of a partition will
2799 typically contain fewer compilation units than the environment
2800 @nt{declarative_part} used at compile time @em only the @lquotes@;needed@rquotes@;
2801 ones are included in the partition.
2802 @end{Ramification}
2803
2804 There shall be a total order of the @nt{library_item}s that obeys the
2805 above rules.
2806 The order is otherwise implementation defined.
2807 @begin{Discussion}
2808 The only way to violate this rule is to have
2809 Elaborate, Elaborate_All, or Elaborate_Body @nt{pragma}s that cause circular ordering
2810 requirements, thus preventing an order that has no forward
2811 elaboration dependences.
2812 @end{Discussion}
2813 @ImplDef{The order of elaboration of @nt{library_item}s.}
2814 @begin{Honest}
2815 @PDefn2{Term=[requires a completion], Sec=(library_unit_declaration)}
2816 @Defn{notwithstanding}
2817 Notwithstanding what the RM95 says elsewhere,
2818 each rule that requires a declaration to have a corresponding
2819 completion is considered to be a @LinkTimeName
2820 when the declaration is that of a library unit.
2821 @end{Honest}
2822 @begin{Discussion}
2823 Such rules may be checked at @lquotes@;link time,@rquotes@; for example.
2824 Rules requiring the completion to have certain properties,
2825 on the other hand, are checked at compile time of the completion.
2826 @end{Discussion}
2827
2828
2829 The full expanded names of the library units and subunits included in a
2830 given partition shall be distinct.
2831
2832 @begin{Reason}
2833 This is a @LinkTimeName because making it a @LegalityName
2834 would violate the @MetaRulesName labeled
2835 @lquotes@;legality determinable via semantic dependences.@rquotes@;
2836 @end{Reason}
2837
2838 @leading@;The @nt{sequence_of_statements} of the environment task (see (2)
2839 above) consists of either:
2840 @begin{Itemize}
2841 A call to the main subprogram,
2842 if the partition has one.
2843 If the main subprogram has parameters, they are passed;
2844 where the actuals come from is implementation defined.
2845 What happens to the result of a main function is also
2846 implementation defined.
2847 @ImplDef{Parameter passing and function return for the main
2848 subprogram.}
2849 @end{Itemize}
2850
2851 @leading@keepnext@;or:
2852 @begin{Itemize}
2853 A @nt{null_statement}, if there is no main subprogram.
2854 @begin{Discussion}
2855 For a passive partition, either there is no environment task,
2856 or its @nt<sequence_of_statements> is an infinite loop.
2857 See @RefSecNum{Partitions}.
2858 @end{Discussion}
2859 @end{Itemize}
2860
2861 The mechanisms for building and running partitions are implementation
2862 defined.
2863 @Redundant[These might be combined into one operation,
2864 as, for example, in dynamic linking, or @lquotes@;load-and-go@rquotes@; systems.]
2865 @ImplDef{The mechanisms for building and running partitions.}
2866 @end{LinkTime}
2867
2868 @begin{RunTime}
2869 @PDefn2{Term=[execution], Sec=(program)}
2870 The execution of a program consists of the execution of a set of
2871 partitions. Further details are implementation defined.
2872 @PDefn2{Term=[execution], Sec=(partition)}
2873 The execution of a partition starts with the execution
2874 of its environment task,
2875 ends when the environment task terminates,
2876 and includes the executions of all tasks of the partition.
2877 @Redundant[The execution of the (implicit) @nt<task_body> of the
2878 environment task acts as a master
2879 for all other tasks created as part of the execution of the partition.
2880 When the environment task completes (normally or abnormally),
2881 it waits for the termination of all such tasks,
2882 and then finalizes any remaining objects of the partition.]
2883 @begin{Ramification}
2884 The @lquotes@;further details@rquotes@; mentioned above include,
2885 for example, program termination @em it
2886 is implementation defined.
2887 There is no need to define it here;
2888 it's entirely up to the implementation whether it wants
2889 to consider the program as a whole to exist beyond the existence of
2890 individual partitions.
2891 @end{Ramification}
2892 @ImplDef{The details of program execution,
2893 including program termination.}
2894 @begin{Honest}
2895 @PDefn2{Term=[termination], Sec=(of a partition)}
2896 @PDefn2{Term=[normal termination], Sec=(of a partition)}
2897 @PDefn2{Term=[termination], Sec=(normal)}
2898 @PDefn2{Term=[abnormal termination], Sec=(of a partition)}
2899 @PDefn2{Term=[termination], Sec=(abnormal)}
2900 The execution of the partition terminates (normally or abnormally) when the
2901 environment task terminates (normally or abnormally, respectively).
2902 @end{Honest}
2903
2904 @end{RunTime}
2905
2906 @begin{Bounded}
2907 @PDefn2{Term=(bounded error),Sec=(cause)}
2908 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2909 Once the environment task has awaited the termination of all other
2910 tasks of the partition, any further attempt to create a task
2911 (during finalization) is a bounded error, and may result in
2912 the raising of Program_Error either upon creation or activation
2913 of the task.
2914 @PDefn{unspecified}
2915 If such a task is activated, it is not specified
2916 whether the task is awaited prior to termination of the
2917 environment task.
2918 @end{Bounded}
2919
2920 @begin{ImplReq}
2921 @Leading@;The implementation shall ensure that all compilation units
2922 included in a partition are consistent with one another,
2923 and are legal according to the rules of the language.
2924 @begin{Discussion}
2925 The consistency requirement implies that
2926 a partition cannot contain two versions of the same compilation unit.
2927 That is,
2928 a partition cannot contain two different library units with the
2929 same full expanded name, nor two different bodies for the same
2930 program unit.
2931 For example, suppose we compile the following:
2932 @begin{Example}
2933 @key[package] A @key[is] --@RI{ Version 1.}
2934 ...
2935 @key[end] A;
2936
2937 @key[with] A;
2938 @key[package] B @key[is]
2939 @key[end] B;
2940
2941 @key[package] A @key[is] --@RI{ Version 2.}
2942 ...
2943 @key[end] A;
2944
2945 @key[with] A;
2946 @key[package] C @key[is]
2947 @key[end] C;
2948 @end{Example}
2949
2950 It would be wrong for a partition containing B and C to contain both
2951 versions of A.
2952 Typically, the implementation would require the use of Version 2 of A,
2953 which might require the recompilation of B.
2954 Alternatively, the implementation might automatically recompile B
2955 when the partition is built.
2956 A third alternative would be an incremental compiler that,
2957 when Version 2 of A is compiled,
2958 automatically patches the object code for B to reflect the changes to
2959 A (if there are any relevant changes @em there might not be any).
2960
2961 An implementation that supported fancy version management
2962 might allow the use of Version 1 in some circumstances.
2963 In no case can the implementation allow the use of both versions in
2964 the same partition
2965 (unless, of course, it can prove that the two versions are
2966 semantically identical).
2967
2968 The core language says nothing about inter-partition
2969 consistency; see also @RefSec{Distributed Systems}.
2970 @end{Discussion}
2971 @end{ImplReq}
2972
2973 @begin{ImplPerm}
2974 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2975 @Defn{active partition}
2976 The kind of partition described in this @Chg{Version=[3],New=[subclause],Old=[clause]}
2977 is known as an @i{active} partition.
2978 An implementation is allowed to support other kinds of partitions,
2979 with implementation-defined semantics.
2980 @ImplDef{The semantics of any nonactive partitions supported by the
2981 implementation.}
2982 @begin{Discussion}
2983 @RefSec{Distributed Systems} defines the concept of passive partitions;
2984 they may be thought of as a partition without an environment task,
2985 or as one with a particularly simple form of environment task,
2986 having an infinite loop rather than a call on a main subprogram
2987 as its @nt<sequence_of_statements>.
2988 @end{Discussion}
2989
2990 An implementation may restrict the kinds of subprograms it supports
2991 as main subprograms.
2992 However, an implementation is required to support all main
2993 subprograms that are public parameterless library procedures.
2994 @begin{Ramification}
2995 The implementation is required to support main subprograms that are
2996 procedures declared by @nt{generic_instantiation}s,
2997 as well as those
2998 that are children of library units other than Standard.
2999 Generic units are, of course, not allowed to be main subprograms,
3000 since they are not subprograms.
3001
3002 Note that renamings are irrelevant to this rule.
3003 This rules says which subprograms (not views)
3004 have to be supported.
3005 The implementation can choose any way it wants for the
3006 user to indicate which subprogram should be the main subprogram.
3007 An implementation might allow any name of any view,
3008 including those declared by renamings.
3009 Another implementation might require it to be the original name.
3010 Another implementation still might use the name of the source file or
3011 some such thing.
3012 @end{Ramification}
3013
3014 If the environment task completes abnormally,
3015 the implementation may abort any dependent tasks.
3016 @begin{Reason}
3017 If the implementation does not take advantage of this permission,
3018 the normal action takes place @em the environment task awaits those
3019 tasks.
3020
3021 The possibility of aborting them
3022 is not shown in the @i{Environment_Task} code above,
3023 because there is nowhere to put an @nt{exception_handler} that can
3024 handle exceptions raised in both the environment @nt{declarative_part}
3025 and the main subprogram,
3026 such that the dependent tasks can be aborted.
3027 If we put an @nt{exception_handler} in the body of the environment
3028 task, then it won't handle exceptions that occur during elaboration of
3029 the environment @nt{declarative_part}.
3030 If we were to move those things into a nested @nt{block_statement},
3031 with the @nt{exception_handler} outside that,
3032 then the @nt{block_statement} would await the library tasks we are
3033 trying to abort.
3034
3035 Furthermore, this is merely a permission, and is not fundamental to the
3036 model, so it is probably better to state it separately anyway.
3037
3038 Note that implementations (and tools like debuggers)
3039 can have modes that provide other behaviors in addition.
3040 @end{Reason}
3041 @end{ImplPerm}
3042
3043 @begin{Notes}
3044 An implementation may provide inter-partition
3045 communication mechanism(s) via special packages and pragmas.
3046 Standard pragmas for distribution and methods for specifying
3047 inter-partition communication are defined in @RefSec{Distributed Systems}.
3048 If no such mechanisms are provided, then each partition is isolated from all
3049 others, and behaves as a program in and of itself.
3050 @begin{Ramification}
3051 Not providing such mechanisms is equivalent to disallowing multi-partition
3052 programs.
3053
3054 An implementation may provide mechanisms to facilitate checking the
3055 consistency of library units elaborated in different partitions;
3056 @RefSec{Distributed Systems} does so.
3057 @end{Ramification}
3058
3059 Partitions are not required to run in separate address spaces.
3060 For example, an implementation might support dynamic linking
3061 via the partition concept.
3062
3063 An order of elaboration of @nt{library_item}s that is consistent with
3064 the partial ordering defined above does not always ensure that each
3065 @nt{library_unit_body} is elaborated before any other compilation unit
3066 whose elaboration necessitates that the @nt{library_unit_body} be
3067 already elaborated.
3068 (In particular, there is no requirement that the body of a library unit
3069 be elaborated as soon as possible after the
3070 @nt{library_unit_declaration} is elaborated,
3071 unless the pragmas in subclause @RefSecNum{Elaboration Control} are
3072 used.)
3073
3074 A partition (active or otherwise) need not have a main subprogram.
3075 In such a case, all the work done by the partition would be done by
3076 elaboration of various @nt{library_item}s, and by tasks created by that
3077 elaboration.
3078 Passive partitions, which cannot have main subprograms,
3079 are defined in @RefSec{Distributed Systems}.
3080 @begin{Ramification}
3081 The environment task is the outermost semantic level
3082 defined by the language.
3083
3084 Standard has no private part.
3085 This prevents strange implementation-dependences involving private
3086 children of Standard having visibility upon Standard's private part.
3087 It doesn't matter where the body of Standard appears in the environment,
3088 since it doesn't do anything.
3089 See @RefSec{Predefined Language Environment}.
3090
3091 Note that elaboration dependence is carefully defined in such a way that
3092 if (say) the body of something doesn't exist yet,
3093 then there is no elaboration dependence upon the nonexistent body.
3094 (This follows from the fact that @lquotes@;needed by@rquotes@; is defined that way,
3095 and the elaboration dependences caused by a @nt{pragma} Elaborate or
3096 Elaborate_All are defined in terms of @lquotes@;needed by@rquotes@;.)
3097 This property allows us to use the environment concept both at compile
3098 time and at partition-construction time/run time.
3099 @end{Ramification}
3100 @end{Notes}
3101
3102 @begin{Extend83}
3103 @Defn{extensions to Ada 83}
3104 The concept of partitions is new to Ada 95.
3105
3106 A main subprogram is now optional.
3107 The language-defined restrictions on main subprograms are relaxed.
3108 @end{Extend83}
3109
3110 @begin{DiffWord83}
3111 Ada 95 uses the term @lquotes@;main subprogram@rquotes@; instead of Ada 83's @lquotes@;main
3112 program@rquotes@; (which was inherited from Pascal).
3113 This is done to avoid confusion @em a main subprogram is a subprogram, not a
3114 program.
3115 The program as a whole is an entirely different thing.
3116 @end{DiffWord83}
3117
3118 @begin{DiffWord95}
3119 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00256-01]}
3120 @ChgAdded{Version=[2],Text=[The mistaken use of @lquotes@;mentions@rquotes@;
3121 in the elaboration dependence rule was fixed.]}
3122
3123 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
3124 @ChgAdded{Version=[2],Text=[The @i<needs> relationship was extended to
3125 include limited views.]}
3126 @end{DiffWord95}
3127
3128 @LabeledSubClause{Elaboration Control}
3129
3130 @begin{Intro}
3131 @Redundant[@Defn{elaboration control}
3132 This subclause defines pragmas that help control
3133 the elaboration order of @nt{library_item}s.]
3134 @end{Intro}
3135
3136 @begin{MetaRules}
3137 The rules governing preelaboration are designed to allow
3138 it to be done largely by bulk initialization of statically
3139 allocated storage from information in a @lquotes@;load module@rquotes@; created by a linker.
3140 Some implementations may require run-time code to be executed in some
3141 cases, but we consider these cases rare enough that we need not
3142 further complicate the rules.
3143
3144 It is important that programs be able to declare data structures that
3145 are link-time initialized with @nt{aggregate}s, @nt{string_literal}s,
3146 and concatenations thereof.
3147 It is important to be able to write link-time evaluated expressions
3148 involving the First, Last, and Length attributes of such data structures
3149 (including variables), because they might be initialized with positional
3150 @nt{aggregate}s or @nt{string_literal}s, and we don't want the user to
3151 have to count the elements.
3152 There is no corresponding need for accessing discriminants,
3153 since they can be initialized with a static constant,
3154 and then the constant can be referred to elsewhere.
3155 It is important to allow link-time initialized data structures
3156 involving discriminant-dependent components.
3157 It is important to be able to write link-time evaluated expressions
3158 involving pointers (both access values and addresses)
3159 to the above-mentioned data structures.
3160
3161 The rules also ensure that no Elaboration_Check need be performed
3162 for calls on library-level subprograms declared within
3163 a preelaborated package.
3164 This is true also of the Elaboration_Check on task activation
3165 for library level task types declared in a preelaborated package.
3166 However, it is not true of the Elaboration_Check on instantiations.
3167
3168 A static expression should never prevent a library unit from being
3169 preelaborable.
3170
3171
3172 @end{MetaRules}
3173
3174 @begin{Syntax}
3175 @begin{SyntaxText}
3176 @Leading@Keepnext@;The form of a @nt{pragma} Preelaborate is as follows:
3177 @end{SyntaxText}
3178
3179 @PragmaSyn`@key{pragma} @prag(Preelaborate)[(@SynI{library_unit_}@Syn2{name})];'
3180
3181 @begin{SyntaxText}
3182 @PDefn2{Term=[library unit pragma], Sec=(Preelaborate)}
3183 @PDefn2{Term=[pragma, library unit], Sec=(Preelaborate)}
3184 A @nt{pragma} Preelaborate is a library unit pragma.
3185 @end{SyntaxText}
3186
3187 @begin{SyntaxText}
3188 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
3189 @ChgAdded{Version=[2],Type=[Leading],KeepNext=[T],Text=[The form of a
3190 @nt{pragma} Preelaborable_Initialization is as follows:]}
3191 @end{SyntaxText}
3192 @ChgRef{Version=[2],Kind=[Added]}
3193 @AddedPragmaSyn{Version=[2],@ChgAdded{Version=[2],
3194 Text=<@key{pragma} @prag<Preelaborable_Initialization>(@Syn2{direct_name});>}}
3195 @end{Syntax}
3196
3197 @begin{Legality}
3198 @Leading@RootDefn2{Term=[preelaborable], Sec=(of an elaborable construct)}
3199 An elaborable construct is preelaborable unless its
3200 elaboration performs any of the following actions:
3201 @begin{Ramification}
3202 A @i{preelaborable} construct can be elaborated
3203 without using any information that is available only at run time.
3204 Note that we don't try to prevent exceptions in preelaborable
3205 constructs; if the implementation wishes to generate code to
3206 raise an exception, that's OK.
3207
3208 Because there is no flow of control and there are no calls
3209 (other than to predefined subprograms),
3210 these run-time properties can actually be detected at compile
3211 time.
3212 This is necessary in order to require compile-time enforcement of the
3213 rules.
3214 @end{Ramification}
3215 @begin{Itemize}
3216 The execution of a @nt{statement} other than a @nt{null_statement}.
3217 @begin{Ramification}
3218 A preelaborable construct can contain @nt{label}s and
3219 @nt{null_statement}s.
3220 @end{Ramification}
3221
3222 A call to a subprogram other than a static function.
3223
3224 The evaluation of a @nt{primary} that is a @nt{name}
3225 of an object, unless the @nt{name} is a static expression,
3226 or statically denotes a discriminant of an enclosing type.
3227 @begin{Ramification}
3228 One can evaluate such a @nt{name}, but not as a @nt{primary}.
3229 For example, one can evaluate an attribute of the object.
3230 One can evaluate an @nt{attribute_reference},
3231 so long as it does not denote an object,
3232 and its @nt{prefix} does not disobey any of these rules.
3233 For example, Obj'Access, Obj'Unchecked_Access,
3234 and Obj'Address are generally legal in preelaborated library
3235 units.
3236 @end{Ramification}
3237
3238 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00161-01]}
3239 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0028-1]}
3240 The creation of @Chg{Version=[2],New=[an object @Redundant[(including a
3241 component)] @Chg{Version=[3],New=[that is initialized by default, if
3242 its],Old=[of a]} type @Chg{Version=[3],New=[],Old=[that ]}does not have
3243 preelaborable initialization. Similarly,],
3244 Old=[a default-initialized object @Redundant[(including
3245 a component)] of a descendant of a private type,
3246 private extension, controlled type,
3247 task type, or protected type with
3248 @nt{entry_@!declaration}s; similarly]} the evaluation of
3249 an @nt<extension_@!aggregate> with
3250 an ancestor @nt<subtype_@!mark> denoting a subtype of such a type.
3251
3252 @begin{Ramification}
3253 One can declare these kinds of types,
3254 but one cannot create objects of those types.
3255
3256 It is also nonpreelaborable to create an object if that will cause the
3257 evaluation of a default expression that will call a user-defined
3258 function.
3259 This follows from the rule above forbidding nonnull statements.
3260 @end{Ramification}
3261 @begin{Reason}
3262 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00161-01]}
3263 @ChgDeleted{Version=[2],Text=[Controlled objects are disallowed because most
3264 implementations will have to take some run-time action during initialization,
3265 even if the Initialize procedure is null.]}
3266 @end{Reason}
3267 @end{Itemize}
3268
3269 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00403-01]}
3270 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Phony addition to get conditional leading}
3271 A generic body is
3272 preelaborable only if elaboration of a corresponding
3273 instance body would not perform any such actions,
3274 presuming that@Chg{Version=[2],New=[:],Old=[ the actual for each formal
3275 private type (or extension) is
3276 a private type (or extension), and the actual for each
3277 formal subprogram is a user-defined subprogram.]}
3278 @Defn{generic contract issue}
3279 @begin{Itemize}
3280 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]}
3281 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI95-0028-1]}
3282 @ChgAdded{Version=[2],Text=[the actual for each@Chg{Version=[3],
3283 New=[ discriminated formal derived type,],Old=[]} formal private
3284 type@Chg{Version=[3],New=[, ],Old=[ (]}or
3285 @Chg{Version=[3],New=[formal private ],Old=[]}extension@Chg{Version=[3],New=[],Old=[)]}
3286 declared within the formal part of the generic unit is
3287 a @Chg{Version=[3],New=[],Old=[private ]}type@Chg{Version=[3],New=[],Old=[ (or extension)]}
3288 that does not have preelaborable initialization@Chg{Version=[3],
3289 New=[, unless @nt<pragma>
3290 Preelaborable_Initialization has been applied to the formal type],Old=[]};]}
3291
3292 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]}
3293 @ChgAdded{Version=[2],Text=[the actual for each formal type is nonstatic;]}
3294
3295 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]}
3296 @ChgAdded{Version=[2],Text=[the actual for each formal object is nonstatic; and]}
3297
3298 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]}
3299 @ChgAdded{Version=[2],Text=[the actual for each formal subprogram is a
3300 user-defined subprogram.]}
3301 @end{Itemize}
3302 @begin{Discussion}
3303 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00403-01]}
3304 @ChgAdded{Version=[2],Text=[This is an @lquotes@;assume-the-worst@rquotes
3305 rule. The elaboration of a generic unit doesn't perform any of the actions
3306 listed above, because its sole effect is to establish that the generic can
3307 from now on be instantiated. So the elaboration of the generic itself is not
3308 the interesting part when it comes to preelaboration rules. The interesting
3309 part is what happens when you elaborate @lquotes@;any instantiation@rquotes
3310 of the generic. For instance, declaring an object of a limited formal private
3311 type might well start tasks, call functions, and do all sorts of
3312 nonpreelaborable things. We prevent these situations by assuming that the
3313 actual parameters are as badly behaved as possible.]}
3314 @end{Discussion}
3315 @begin{Reason}
3316 Without this rule about generics, we would have to forbid
3317 instantiations in preelaborated library units,
3318 which would significantly reduce their usefulness.
3319 @end{Reason}
3320
3321 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]}
3322 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0034-1],ARef=[AI05-0243-1]}
3323 @PDefn{preelaborated}
3324 @Chg{Version=[3],New=[A],Old=[If a]} @nt{pragma} Preelaborate (or
3325 @nt<pragma> Pure @em see below) @Chg{Version=[3],New=[is used to specify that],
3326 Old=[applies to]}
3327 a library unit@Chg{Version=[3],New=[],Old=[, then it]} is
3328 @i{preelaborated}@Chg{Version=[3],New=[, namely that the Preelaborate
3329 aspect@AspectDefn{Preelaborate} of the library unit is True; all
3330 compilation units of the
3331 library unit are preelaborated],Old=[]}.
3332 @Chg{Version=[3],New=[],Old=[@Redundant[
3333 @RootDefn{preelaborated}
3334 If a library unit is preelaborated, then its declaration, if any,
3335 and body, if any, are elaborated
3336 prior to all nonpreelaborated @nt{library_item}s of the partition.]
3337 ]}@Chg{New=[The declaration and body of a preelaborated library
3338 unit, and all subunits that are elaborated as part of elaborating the library
3339 unit,], Old=[All compilation units of a preelaborated
3340 library unit]} shall be preelaborable.@Chg{Version=[3],New=[
3341 All
3342 compilation units of a preelaborated library unit shall depend semantically only
3343 on declared pure or preelaborated @nt{library_item}s.],Old=[]}
3344 @PDefn{generic contract issue}
3345 In addition to the places where @LegalityTitle normally apply
3346 (see @RefSecNum{Generic Instantiation}),
3347 @Chg{Version=[3],New=[these rules also apply],Old=[this rule applies also]}
3348 in the private part of an instance of a generic unit.
3349 @Chg{Version=[3],New=[@Redundant[
3350 @RootDefn{preelaborated}
3351 If a library unit is preelaborated, then its declaration, if any,
3352 and body, if any, are elaborated
3353 prior to all nonpreelaborated @nt{library_item}s of the partition.]],
3354 Old=[In addition, all compilation units of a preelaborated library unit
3355 shall depend semantically only on
3356 compilation units of other preelaborated library units.]}
3357 @begin{Ramification}
3358 In a generic body, we assume the worst about
3359 formal private types and extensions.
3360
3361 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0035],ARef=[AI95-00002-01]}
3362 @ChgAdded{Version=[1],Text=[Subunits of a preelaborated subprogram unit
3363 do not need
3364 to be preelaborable. This is needed in order to be consistent with units
3365 nested in a subprogram body, which do not need to be preelaborable even if
3366 the subprogram is preelaborated. However, such subunits cannot depend
3367 semantically on nonpreelaborated units, which is also consistent with
3368 nested units.]}
3369 @end{Ramification}
3370
3371 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Preelaborate],
3372 Text=[@ChgAdded{Version=[3],Text=[Code execution during elaboration is
3373 avoided for a given package.]}]}
3374
3375 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
3376 @ChgAdded{Version=[2],Text=[@defn{preelaborable initialization}The following rules
3377 specify which entities have @i{preelaborable initialization}:]}
3378
3379 @begin{Itemize}
3380 @ChgRef{Version=[2],Kind=[Added]}
3381 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1]}
3382 @ChgAdded{Version=[2],Text=[The partial view
3383 of a private type or private extension, a protected type without
3384 @nt<entry_declaration>s, a generic formal private type, or a generic formal
3385 derived type, @Chg{Version=[3],New=[has],Old=[have]} preelaborable
3386 initialization if and only if the @nt<pragma> Preelaborable_Initialization has
3387 been applied to them. @Redundant[A protected type with @nt{entry_declaration}s
3388 or a task type never has preelaborable initialization.]]}
3389
3390 @ChgRef{Version=[2],Kind=[Added]}
3391 @ChgAdded{Version=[2],Text=[A component (including a discriminant) of a record or
3392 protected type has preelaborable initialization if its declaration includes a
3393 @nt<default_expression> whose execution does not perform any actions prohibited
3394 in preelaborable constructs as described above, or if its declaration does not
3395 include a default expression and its type has preelaborable
3396 initialization.]}
3397
3398 @ChgRef{Version=[2],Kind=[Added]}
3399 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1],ARef=[AI05-0221-1]}
3400 @ChgAdded{Version=[2],Text=[A derived type has preelaborable initialization
3401 if its parent type has preelaborable initialization and
3402 @Chg{Version=[3],New=[],Old=[(in the case of a
3403 derived record extension) ]}if the noninherited components all have
3404 preelaborable initialization. However, a @Chg{Version=[3],New=[],
3405 Old=[user-defined ]}controlled type with an
3406 @Chg{Version=[3],New=[],Old=[overriding ]}Initialize procedure
3407 @Chg{Version=[3],New=[that is not a null procedure ],Old=[]}does not
3408 have preelaborable initialization.]}
3409
3410 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01],ARef=[AI95-00345-01]}
3411 @ChgAdded{Version=[2],Text=[A view of a type has preelaborable initialization if it
3412 is an elementary type, an array type whose component type has preelaborable
3413 initialization, a record type whose components all have preelaborable
3414 initialization, or an interface type.]}
3415 @end{Itemize}
3416
3417 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
3418 @ChgAdded{Version=[2],Text=[A @nt<pragma> Preelaborable_Initialization specifies that a type has
3419 preelaborable initialization. This pragma shall appear in the visible part
3420 of a package or generic package.]}
3421
3422 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01],ARef=[AI95-00345-01]}
3423 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0028-1]}
3424 @ChgAdded{Version=[2],Text=[If the pragma appears in the first list of
3425 @nt{basic_declarative_item}s of a
3426 @nt<package_specification>, then the @nt<direct_name> shall denote the first
3427 subtype of a @Chg{Version=[3],New=[composite],Old=[private]}
3428 type@Chg{Version=[3],New=[],Old=[, private extension, or protected type that is not
3429 an interface type and is without
3430 @nt<entry_declaration>s]}, and the type shall be declared immediately within
3431 the same package
3432 as the @nt<pragma>. If the @nt<pragma> is applied to a private type or a
3433 private extension, the full view of the type shall have preelaborable
3434 initialization. If the @nt<pragma> is applied to a protected type,
3435 @Chg{Version=[3],New=[the protected type shall not have
3436 entries, and ],Old=[]}each
3437 component of the protected type shall have preelaborable initialization.
3438 @Chg{Version=[3],New=[For any other composite type, the type shall have
3439 preelaborable initialization. ],Old=[]}@PDefn{generic contract issue}In
3440 addition to the places where @LegalityTitle normally apply
3441 (see @RefSecNum{Generic Instantiation}), these rules apply
3442 also in the private part of an instance of a generic unit.]}
3443
3444 @begin{Reason}
3445 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1]}
3446 @ChgAdded{Version=[3],Text=[The reason why we need the pragma for private
3447 types, private extensions, and protected types is fairly clear: the
3448 properties of the full view determine whether the type has preelaborable
3449 initialization or not; in order to preserve privacy we need a way to express
3450 on the partial view that the full view is well-behaved. The reason why we
3451 need the pragma for other composite types is more subtle: a nonnull override
3452 for Initialize might occur in the private part, even for a nonprivate type;
3453 in order to preserve privacy, we need a way to express on a type declared in
3454 a visible part that the private part does not contain any nasty override of
3455 Initialize.]}
3456 @end{Reason}
3457
3458 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
3459 @ChgAdded{Version=[2],Text=[If the @nt<pragma> appears in a @nt<generic_formal_part>, then the
3460 @nt<direct_name> shall denote a generic formal private type or a generic formal
3461 derived type declared in the same @nt<generic_formal_part> as the @nt<pragma>.
3462 In a @nt<generic_instantiation> the corresponding actual type shall have
3463 preelaborable initialization.]}
3464
3465 @begin{Ramification}
3466 @ChgRef{Version=[2],Kind=[AddedNormal]}
3467 @ChgAdded{Version=[2],Text=[Not only do protected types with
3468 @nt{entry_declaration}s
3469 and task types not have preelaborable initialization, but they cannot have
3470 pragma Preelaborable_Initialization applied to them.]}
3471 @end{Ramification}
3472 @end{Legality}
3473
3474 @begin{ImplAdvice}
3475 In an implementation, a type declared in a preelaborated package
3476 should have the same representation in every elaboration
3477 of a given version of the package,
3478 whether the elaborations occur in distinct executions of
3479 the same program, or in executions of distinct programs or partitions
3480 that include the given version.
3481 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3482 Text=[A type declared in a preelaborated package
3483 should have the same representation in every elaboration
3484 of a given version of the package.]}]}
3485 @end{ImplAdvice}
3486
3487 @begin{Syntax}
3488 @begin{SyntaxText}
3489 @leading@keepnext@;The form of a @nt{pragma} Pure is as follows:
3490 @end{SyntaxText}
3491
3492 @PragmaSyn`@key{pragma} @prag(Pure)[(@SynI{library_unit_}@Syn2{name})];'
3493
3494 @begin{SyntaxText}
3495 @PDefn2{Term=[library unit pragma], Sec=(Pure)}
3496 @PDefn2{Term=[pragma, library unit], Sec=(Pure)}
3497 A @nt{pragma} Pure is a library unit pragma.
3498 @end{SyntaxText}
3499 @end{Syntax}
3500
3501 @begin{StaticSem}
3502
3503 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00366-01]}
3504 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]}
3505 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{pure}
3506 A @i{pure} @Chg{Version=[3],New=[compilation unit],Old=[@nt{library_item}]}
3507 is a preelaborable @Chg{Version=[3],New=[compilation unit],Old=[@nt{library_item}]} whose
3508 elaboration does not perform any of the following actions:]}
3509
3510 @begin{Itemize}
3511 @ChgRef{Version=[2],Kind=[Added]}
3512 @ChgAdded{Version=[2],Text=[the elaboration of a variable declaration;]}
3513
3514 @ChgRef{Version=[2],Kind=[Added]}
3515 @ChgAdded{Version=[2],Text=[the evaluation of an @nt{allocator} of an
3516 access-to-variable type; for the purposes of this rule, the partial view of a
3517 type is presumed to have nonvisible components whose default initialization
3518 evaluates such an @nt{allocator};]}
3519
3520 @begin{Reason}
3521 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0004-1]}
3522 @ChgAdded{Version=[3],Type=[Leading],Text=[Such an @nt{allocator} would
3523 provide a backdoor way to get a global variable into a pure unit, so it is
3524 prohibited. Most such @nt{allocator}s are illegal anyway, as their type is
3525 required to have Storage_Size = 0 (see the next two rules). But access
3526 parameters and access discriminants don't necessarily disallow @nt{allocator}s.
3527 However, a call is also illegal here (by the preelaboration rules), so access
3528 parameters cannot cause trouble. So this rule is really about prohibiting
3529 allocators in discriminant constraints:]}
3530
3531 @begin{Example}
3532 @ChgRef{Version=[3],Kind=[Added]}
3533 @ChgAdded{Version=[3],Text=[@key[type] Rec (Acc : @key[access] Integer) @key[is record]
3534 C : Character;
3535 @key[end record];]}
3536
3537 @ChgRef{Version=[3],Kind=[Added]}
3538 @ChgAdded{Version=[3],Text=[Not_Const : @key[constant] Rec (Acc => @key[new] Integer'(2)); -- @RI{Illegal in a pure unit}.]}
3539 @end{Example}
3540
3541 @ChgRef{Version=[2],Kind=[AddedNormal]}
3542 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0004-1]}
3543 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[The second half of the],Old=[This]}
3544 rule is needed because aggregates can specify the default initialization
3545 of a private type or extension using <> or the ancestor subtype of an
3546 extension aggregate. The
3547 subtype of a component could use an @nt{allocator} to initialize an access
3548 discriminant; the type still could have a pragma Preelaborable_Initialization
3549 given. Ada 95 did not allow such private types to have preelaborable
3550 initialization, so such a default initialization could not have occurred.
3551 Thus this rule is not incompatible with Ada 95.]}
3552 @end{Reason}
3553
3554 @ChgRef{Version=[2],Kind=[Added]}
3555 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]}
3556 @ChgAdded{Version=[2],Text=[the elaboration of the declaration of a
3557 @Chg{Version=[3],New=[nonderived ],Old=[]}named
3558 access-to-variable type unless the Storage_Size of the type
3559 has been specified by a static expression with value zero or
3560 is defined by the language to be zero;]}
3561
3562 @begin{Discussion}
3563 @ChgRef{Version=[2],Kind=[AddedNormal]}
3564 @ChgAdded{Version=[2],Text=[A remote access-to-class-wide type
3565 (see @RefSecNum{Remote Types Library Units}) has its Storage_Size defined to
3566 be zero.]}
3567 @end{Discussion}
3568 @begin{Reason}
3569 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
3570 @ChgAdded{Version=[2],Text=[We disallow most named access-to-object types
3571 because an @nt{allocator} has a side effect; the pool constitutes variable
3572 data. We allow access-to-subprogram types because they
3573 don't have @nt{allocator}s. We even allow named access-to-object types if
3574 they have an empty predefined pool (they can't have a user-defined pool as
3575 System.Storage_Pools is not pure). In this case, most attempts to use an
3576 @nt{allocator} are illegal, and any others (in a generic body) will raise
3577 Storage_Error.]}
3578 @end{Reason}
3579
3580 @ChgRef{Version=[2],Kind=[Added]}
3581 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0035-1]}
3582 @ChgAdded{Version=[2],Text=[the elaboration of the declaration of a
3583 @Chg{Version=[3],New=[nonderived ],Old=[]}named
3584 access-to-constant type for which the Storage_Size has been specified by an
3585 expression other than a static expression with value zero.]}
3586
3587 @begin{Discussion}
3588 @ChgRef{Version=[2],Kind=[AddedNormal]}
3589 @ChgAdded{Version=[2],Text=[We allow access-to-constant types so long as
3590 there is no user-specified nonzero Storage_Size; if there were a
3591 user-specified nonzero Storage_Size restricting the size of the storage
3592 pool, allocators would be problematic since the package is supposedly
3593 @lquote@;stateless@rquote, and the allocated size count for the storage pool
3594 would represent state.]}
3595 @end{Discussion}
3596
3597 @end{Itemize}
3598
3599 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0035-1]}
3600 @ChgAdded{Version=[3],Text=[A generic body is pure only if elaboration of a
3601 corresponding instance body would not perform any such actions presuming any
3602 composite formal types have nonvisible components whose default initialization
3603 evaluates an @nt{allocator} of an access-to-variable type.]}
3604
3605 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00366-01]}
3606 @ChgAdded{Version=[2],Text=[The Storage_Size for an anonymous
3607 access-to-variable type declared at library level in a library unit that is
3608 declared pure is defined to be zero.]}
3609
3610 @begin{Ramification}
3611 @ChgRef{Version=[2],Kind=[AddedNormal]}
3612 @ChgAdded{Version=[2],Text=[This makes @nt{allocator}s illegal for such types
3613 (see @RefSecNum{Allocators}), making a storage pool unnecessary for these
3614 types. A storage pool would represent state.]}
3615
3616 @ChgRef{Version=[2],Kind=[AddedNormal]}
3617 @ChgAdded{Version=[2],Text=[Note that access discriminants and access
3618 parameters are never library-level, even when they are declared in a
3619 type or subprogram declared at library-level. That's because they have their
3620 own special accessibility rules (see @RefSecNum{Operations of Access Types}).]}
3621 @end{Ramification}
3622
3623 @end{StaticSem}
3624
3625
3626 @begin{Legality}
3627 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00366-01]}
3628 @ChgDeleted{Version=[2],Text=[@Defn{pure}
3629 A @i{pure} @nt{library_item} is a preelaborable @nt{library_item}
3630 that does not contain the declaration of any
3631 variable or named access within a
3632 subprogram, generic
3633 subprogram,
3634 task unit, or protected unit.]}
3635
3636 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
3637 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0034-1],ARef=[AI05-0035-1],ARef=[AI05-0243-1]}
3638 @Defn{declared pure}
3639 A @nt{pragma} Pure is used to @Chg{Version=[3],New=[specify],Old=[declare]}
3640 that a library unit is @Chg{Version=[3],New=[@i{declared pure}, namely
3641 that the Pure aspect@AspectDefn{Pure} of the library unit is True; all
3642 compilation units of the library unit are declared ],Old=[]}pure.
3643 @Chg{Version=[3],New=[In addition, the limited view
3644 of any library package is declared pure. The declaration and
3645 body of a declared pure library unit, and all subunits that are
3646 elaborated as part of elaborating the library unit, shall be pure.
3647 All],Old=[If a @nt{pragma} Pure applies to a library unit,
3648 then its]} compilation units @Chg{Version=[3],New=[of a declared pure
3649 library unit],Old=[shall be pure, and they]} shall depend semantically
3650 only on @Chg{Version=[3],New=[],Old=[compilation units of other library units
3651 that are ]}declared pure@Chg{Version=[3],New=[ @nt{library_item}s],
3652 Old=[]}.@Chg{Version=[3],New=[ @PDefn{generic contract issue}
3653 In addition to the places where @LegalityTitle normally apply
3654 (see @RefSecNum{Generic Instantiation}), these rules also
3655 apply in the private part of an instance of a generic unit.],
3656 Old=[]}@Chg{Version=[2],New=[ Furthermore, the full view of any
3657 partial view declared in the visible part of @Chg{Version=[3],New=[a declared
3658 pure],Old=[the]} library unit that has
3659 any available stream attributes shall support external streaming
3660 (see @RefSecNum{Stream-Oriented Attributes}).],Old=[]}
3661 @begin{Honest}
3662 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0243-1]}@ChgNote{This is now described normatively}
3663 @ChgDeleted{Version=[3],Text=[A @i{declared-pure} library unit is one to
3664 which a @nt{pragma} Pure applies.
3665 Its declaration and body are also said to be declared pure.]}
3666 @end{Honest}
3667 @begin{Discussion}
3668 A declared-pure package is useful for defining types to be shared
3669 between partitions with no common address space.
3670 @end{Discussion}
3671 @begin{Reason}
3672 Note that generic packages are not mentioned
3673 in the list of things that can contain variable declarations.
3674 Note that the Ada 95 rules for deferred constants make them
3675 allowable in library units that are declared pure;
3676 that isn't true of Ada 83's deferred constants.
3677 @end{Reason}
3678 @begin{Ramification}
3679 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
3680 Anonymous access types
3681 @Chg{Version=[2],New=[],Old=[(that is, access discriminants and
3682 access parameters) ]}are allowed.
3683
3684 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0243-1]}
3685 @ChgAdded{Version=[3],Text=[A limited view is not a library unit, so any rule
3686 that starts @ldquote@;declared pure library unit@rdquote does not apply to a
3687 limited view. In particular, the 3rd and last sentences never apply to limited
3688 views. However, a limited view is a @nt{library_item}, so rules that discuss
3689 @ldquote@;declared pure @nt{library_item}s@rdquote do include limited views.]}
3690 @end{Ramification}
3691 @begin{Reason}
3692 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
3693 @Chg{Version=[2],New=[Ada 95 didn't allow any access types as],
3694 Old=[The primary reason for disallowing named
3695 access types is that an @nt{allocator} has a side effect;
3696 the pool constitutes variable data. We considered somehow allowing
3697 @nt{allocator}-less access types. However,]} these
3698 (including access-to-subprogram types)
3699 @Chg{Version=[2],New=[],Old=[would ]}cause trouble
3700 for @RefSec{Distributed Systems}, because such types @Chg{Version=[2],New=[],
3701 Old=[would ]} allow access values in a shared passive
3702 partition to designate objects in an active partition,
3703 thus allowing inter-address space references.@Chg{Version=[2],New=[ We decided
3704 to disallow such uses in the relatively rare cases where they cause problems,
3705 rather than making life harder for the majority of users. Types declared
3706 in a pure package can be used in remote operations only if they are externally
3707 streamable. That simply means that there is a means to transport values of the
3708 type; that's automatically true for nonlimited types that don't have an
3709 access part. The only tricky part about this is to avoid privacy leakage; that
3710 was handled by ensuring that any private types (and private
3711 extensions) declared in a pure package that have available stream attributes
3712 (which include all nonlimited types by definition) have to be externally
3713 streamable.],
3714 Old=[Furthermore, a named access-to-object type without a pool would be a new
3715 concept, adding complexity from the user's point of view. Finally, the
3716 prevention of @nt{allocator}s would have to be
3717 a run-time check, in order to avoid violations of the generic contract
3718 model.]}
3719 @end{Reason}
3720
3721 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pure],
3722 Text=[@ChgAdded{Version=[3],Text=[Side effects are avoided in the
3723 subprograms of a given package.]}]}
3724
3725 @end{Legality}
3726
3727 @begin{Erron}
3728 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0076-1]}
3729 @ChgAdded{Version=[4],Text=[Execution is erroneous if some operation (other
3730 than the initialization or finalization of the object) modifies the value of a
3731 constant object declared at library-level in a pure package.]}
3732
3733 @begin{Discussion}
3734 @ChgRef{Version=[4],Kind=[AddedNormal]}
3735 @ChgAdded{Version=[4],Text=[This could be accomplished via a
3736 self-referencing pointer or via squirrelling a writable pointer to a
3737 controlled object.]}
3738 @end{Discussion}
3739 @end{Erron}
3740
3741 @begin{ImplPerm}
3742 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
3743 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0219-1]}
3744 If a library unit is declared pure, then the implementation
3745 is permitted to omit a call on a library-level
3746 subprogram of the library unit if the
3747 results are not needed after the call. @Chg{Version=[2],New=[In addition,
3748 the implementation],Old=[Similarly, it]} may omit @Chg{Version=[2],New=[],
3749 Old=[such ]}a call@Chg{Version=[2],New=[ on such a subprogram],Old=[]} and
3750 simply reuse the results produced by an earlier call on
3751 the same subprogram, provided that none of the
3752 parameters @Chg{Version=[2],New=[nor any object accessible via access
3753 values from the parameters ],Old=[]}@Chg{Version=[3],New=[have any part that
3754 is of a type whose full type is an immutably],Old=[are of
3755 a]} limited type, and the addresses and values of all by-reference
3756 actual parameters, @Chg{Version=[2],New=[],Old=[and ]}the values of all
3757 by-copy-in actual parameters, @Chg{Version=[2],New=[and the values of all
3758 objects accessible via access values from the parameters, ],Old=[]}are
3759 the same as they were at the earlier call.
3760 @Redundant[This permission applies even if the subprogram
3761 produces other side effects when called.]
3762 @begin{Discussion}
3763 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
3764 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1],ARef=[AI05-0299-1]}
3765 A declared-pure @nt{library_item} has no variable state.
3766 Hence, a call on one of its (nonnested) subprograms cannot
3767 @Chg{Version=[2],New=[normally],Old=[@lquotes@;normally@rquotes]}
3768 have side effects. @Chg{Version=[3],New=[Side effects are still possible
3769 via dispatching calls and via indirect calls through access-to-subprogram
3770 values. Other mechanisms that might be used to modify variable state
3771 include],Old=[The only possible side effects from such a call would be
3772 through]}
3773 machine code insertions,@Chg{Version=[2],New=[ imported subprograms,
3774 @Chg{Version=[3],New=[ and ],Old=[]}],Old=[]}unchecked conversion to an access type declared within the
3775 subprogram@Chg{Version=[3],New=[; this list is not exhaustive],Old=[, and
3776 similar features]}.@Chg{Version=[3],New=[ Thus, the permissions described
3777 in this subclause may apply to a subprogram whose execution has
3778 side effects.],Old=[]} The compiler may omit a call to such a subprogram
3779 even if @Chg{Version=[3],New=[],Old=[such]} side effects exist, so the
3780 writer of such a subprogram has to keep this in mind.
3781 @end{Discussion}
3782
3783 @end{ImplPerm}
3784
3785 @begin{Syntax}
3786 @begin{SyntaxText}
3787 @Leading@Keepnext@;The form of a @nt{pragma} Elaborate, Elaborate_All, or
3788 Elaborate_Body is as follows:
3789 @end{SyntaxText}
3790
3791 @PragmaSyn`@key{pragma} @prag(Elaborate)(@SynI{library_unit_}@Syn2{name}{, @SynI{library_unit_}@Syn2{name}});'
3792
3793 @PragmaSyn`@key{pragma} @prag(Elaborate_All)(@SynI{library_unit_}@Syn2{name}{, @SynI{library_unit_}@Syn2{name}});'
3794
3795 @PragmaSyn`@key{pragma} @prag(Elaborate_Body)[(@SynI{library_unit_}@Syn2{name})];'
3796
3797 @begin{SyntaxText}
3798 A @nt{pragma} Elaborate or Elaborate_All is only allowed within a
3799 @nt{context_clause}.
3800 @begin{Ramification}
3801 @lquotes@;Within a @nt{context_clause}@rquotes@; allows it to be the last
3802 item in the @nt{context_clause}.
3803 It can't be first, because the @nt{name} has to denote something
3804 mentioned earlier.
3805 @end{Ramification}
3806
3807 @PDefn2{Term=[library unit pragma], Sec=(Elaborate_Body)}
3808 @PDefn2{Term=[pragma, library unit], Sec=(Elaborate_Body)}
3809 A @nt{pragma} Elaborate_Body is a library unit pragma.
3810 @end{SyntaxText}
3811 @begin{Discussion}
3812 Hence, a @nt{pragma} Elaborate or Elaborate_All is not
3813 elaborated, not that it makes any practical difference.
3814
3815 Note that a @nt{pragma} Elaborate or Elaborate_All is neither a program unit
3816 pragma, nor a library unit pragma.
3817
3818 @end{Discussion}
3819 @end{Syntax}
3820
3821 @begin{Legality}
3822 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3823 @PDefn2{Term=[requires a completion], Sec=(declaration to which a @nt{pragma} Elaborate_Body applies)}
3824 If @Chg{Version=[3],New=[the aspect],Old=[a @nt{pragma}]} Elaborate_Body
3825 @Chg{Version=[3],New=[is True for],Old=[applies to]} a
3826 declaration@Chg{Version=[3],New=[ @Redundant[(including when @nt{pragma}
3827 Elaborate_Body applies)]],Old=[]},
3828 then the declaration requires a completion @Redundant[(a
3829 body)].@Chg{Version=[3],New=[@PDefn2{Term=[requires a completion],
3830 Sec=(declaration for which aspect Elaborate_Body is True)}],Old=[]}
3831
3832 @begin{TheProof}
3833 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
3834 @ChgAdded{Version=[3],Text=[@nt{Pragma} Elaborate_Body sets the
3835 aspect (see below).]}
3836 @end{TheProof}
3837
3838 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
3839 @ChgAdded{Version=[2],Text=[The @SynI{library_unit_}@nt{name} of a
3840 @nt{pragma} Elaborate or Elaborate_All shall denote a nonlimited view
3841 of a library unit.]}
3842 @begin{Reason}
3843 @ChgRef{Version=[2],Kind=[AddedNormal]}
3844 @ChgAdded{Version=[2],Text=[These @nt{pragma}s are intended to prevent
3845 elaboration check failures. But a limited view does not make anything visible
3846 that has an elaboration check, so the @nt{pragma}s cannot do anything useful.
3847 Moreover, the @nt{pragma}s would probably reintroduce
3848 the circularity that the @nt{limited_with_clause} was intended to break.
3849 So we make such uses illegal.]}
3850 @end{Reason}
3851
3852 @end{Legality}
3853
3854 @begin{StaticSem}
3855 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3856 @redundant[A @nt{pragma} Elaborate specifies that the body of the named library
3857 unit is elaborated before the current @nt{library_item}.
3858 A @nt{pragma} Elaborate_All specifies that each @nt{library_item} that is
3859 needed by the named library unit declaration
3860 is elaborated before the current @nt{library_item}.@Chg{Version=[3],New=[],Old=[
3861 A @nt{pragma} Elaborate_Body specifies that the body
3862 of the library unit is elaborated immediately after its declaration.]}]
3863
3864 @begin{TheProof}
3865 The official statement of the semantics of these @nt{pragma}s is given in
3866 @RefSecNum{Program Execution}.
3867 @end{TheProof}
3868
3869 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
3870 @ChgAdded{Version=[3],Text=[A @nt{pragma} Elaborate_Body sets the Elaborate_Body
3871 representation aspect of the library unit to which it applies to the value True.
3872 @Redundant[If the Elaborate_Body aspect of a library unit is True, the body of the library
3873 unit is elaborated immediately after its declaration.@AspectDefn{Elaborate_Body}]]}
3874
3875 @begin{TheProof}
3876 @ChgRef{Version=[3],Kind=[Added]}
3877 @ChgAdded{Version=[3],Text=[The official statement of the semantics of this
3878 aspect is given in @RefSecNum{Program Execution}.]}
3879 @end{TheProof}
3880 @begin{ImplNote}
3881 The presence of a @nt{pragma} Elaborate_Body simplifies the removal of
3882 unnecessary Elaboration_Checks.
3883 For a subprogram declared immediately within a library unit to which
3884 a @nt{pragma} Elaborate_Body applies, the only calls that can fail the
3885 Elaboration_Check are those that occur in the library unit itself,
3886 between the declaration and body of the called subprogram;
3887 if there are no such calls
3888 (which can easily be detected at compile time
3889 if there are no @ntf{stub}s),
3890 then no Elaboration_Checks are needed for that subprogram.
3891 The same is true for Elaboration_Checks on task activations and
3892 instantiations, and for library subprograms and generic units.
3893 @end{ImplNote}
3894 @begin{Ramification}
3895 The fact that the unit of elaboration is the @nt{library_item}
3896 means that if a @nt{subprogram_body} is not a completion, it is
3897 impossible for any @nt{library_item} to be elaborated between the
3898 declaration and the body of such a subprogram.
3899 Therefore, it is impossible for a call to such a subprogram to fail its
3900 Elaboration_Check.
3901 @end{Ramification}
3902 @begin{Discussion}
3903 The visibility rules imply that
3904 each @i{library_unit_}@nt{name} of a @nt{pragma} Elaborate
3905 or Elaborate_All has to denote a library unit mentioned by a
3906 previous @nt{with_clause} of the same @nt{context_clause}.
3907 @end{Discussion}
3908
3909 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Elaborate_Body],
3910 Text=[@ChgAdded{Version=[3],Text=[A given package must have a body, and that
3911 body is elaborated immediately after the declaration.]}]}
3912
3913 @end{StaticSem}
3914
3915 @begin{Notes}
3916 A preelaborated library unit is allowed to have nonpreelaborable
3917 children.
3918 @begin{Ramification}
3919 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]}
3920 But @Chg{New=[generally ], Old=[]}not nonpreelaborated subunits.
3921 @Chg{New=[(Nonpreelaborated subunits of subprograms are allowed as
3922 discussed above.)], Old=[]}
3923 @end{Ramification}
3924
3925 A library unit that is declared pure is allowed to have impure
3926 children.
3927 @begin{Ramification}
3928 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0035],ARef=[AI95-00002-01]}
3929 But @Chg{New=[generally ], Old=[]}not impure subunits.
3930 @Chg{New=[(Impure subunits of subprograms are allowed as discussed above.)],
3931 Old=[]}
3932 @end{Ramification}
3933 @begin{Ramification}
3934 Pragma Elaborate is mainly for closely related library units,
3935 such as when two package bodies 'with' each other's declarations.
3936 In such cases, Elaborate_All sometimes won't work.
3937 @end{Ramification}
3938 @end{Notes}
3939
3940 @begin{Extend83}
3941 @Defn{extensions to Ada 83}
3942 The concepts of preelaborability
3943 and purity are new to Ada 95.
3944 The Elaborate_All, Elaborate_Body, Preelaborate,
3945 and Pure @nt{pragma}s are new to Ada 95.
3946
3947 Pragmas Elaborate are allowed to be mixed in with the other
3948 things in the @nt{context_clause} @em in Ada 83, they were
3949 required to appear last.
3950 @end{Extend83}
3951
3952 @begin{Incompatible95}
3953 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
3954 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
3955 The requirement that a partial view with available stream attributes
3956 be externally streamable can cause an incompatibility in rare cases.
3957 If there is a limited tagged
3958 type declared in a pure package with available attributes, and that
3959 type is used to declare a private extension in another pure package,
3960 and the full type for the private extension has a component of an
3961 explicitly limited record type, a protected type, or a type with
3962 access discriminants, then the stream attributes will have to be
3963 user-specified in the visible part of the package. That is not a requirement
3964 for Ada 95, but this combination seems very unlikely in pure packages.
3965 Note that this cannot be an incompatibility for a nonlimited type,
3966 as all of the types that are allowed in Ada 95 that would require
3967 explicitly defined stream attributes are limited (and thus cannot be used
3968 as components in a nonlimited type).]}
3969
3970 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00403-01]}
3971 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Added wording
3972 to cover missing cases for preelaborated generic units. This is
3973 incompatible as a preelaborated unit could have used a formal
3974 object to initialize a library-level object; that isn't allowed in Ada 2005. But such a unit wouldn't really
3975 be preelaborable, and Ada 95 compilers can reject such units (as this
3976 is a Binding Interpretation), so such units should be very rare.]}
3977 @end{Incompatible95}
3978
3979 @begin{Extend95}
3980 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
3981 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3982 @b[Amendment Correction:] The concept of preelaborable initialization and
3983 @nt{pragma} Preelaborable_Initialization are new. These allow more types
3984 of objects to be created in preelaborable units, and fix holes in the
3985 old rules.]}
3986
3987 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
3988 @ChgAdded{Version=[2],Text=[Access-to-subprogram types and access-to-object
3989 types with a Storage_Size of 0 are allowed in pure units. The permission
3990 to omit calls was adjusted accordingly (which also fixes a hole in Ada 95, as
3991 access parameters are allowed, and changes in the values accessed by them
3992 must be taken into account).]}
3993 @end{Extend95}
3994
3995 @begin{DiffWord95}
3996 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00002-01]}
3997 @ChgAdded{Version=[2],Text=[@B<Corrigendum:> The wording was changed so that
3998 subunits of a preelaborated subprogram are also preelaborated.]}
3999
4000 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
4001 @ChgAdded{Version=[2],Text=[Disallowed pragma Elaborate and Elaborate_All
4002 for packages that are mentioned in a @nt{limited_with_clause}.]}
4003 @end{DiffWord95}
4004
4005 @begin{Incompatible2005}
4006 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1]}
4007 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@B<Correction:>
4008 Corrected a serious
4009 unintended incompatibility with Ada 95 in the new preelaboration wording
4010 @em explicit initialization of objects of types that don't have
4011 preelaborable initialization was not allowed. Ada 2012 switches
4012 back to the Ada 95 rule in these cases. This is unlikely to
4013 occur in practice, as it is unlikely that a compiler would have
4014 implemented the more restrictive rule (it would fail many ACATS tests
4015 if it did).]}
4016
4017 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]}
4018 @ChgAdded{Version=[3],Text=[@B<Correction:> Added an assume-the-worst
4019 rule for generic bodies (else they would never be checked for purity)
4020 and added the boilerplate so that the entire generic specification is
4021 rechecked. Also fixed wording to have consistent handling for subunits
4022 for Pure and Preelaborate. An Ada 95 program could have depended on
4023 marking a generic pure that was not really pure, although this
4024 would defeat the purpose of the categorization and likely cause
4025 problems with distributed programs.]}
4026 @end{Incompatible2005}
4027
4028 @begin{Extend2005}
4029 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]}
4030 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}@B<Correction:>
4031 Adjusted wording so that a subunit can be pure (it is not a
4032 @nt<library_item>, but it is a compilation unit).]}
4033
4034 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0035-1]}
4035 @ChgAdded{Version=[3],Text=[@B<Correction:> Adjusted wording so
4036 that the rules for access types only apply to nonderived types
4037 (derived types share their storage pool with their parent, so if
4038 the parent access type is legal, so is any derived type.)]}
4039
4040 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
4041 @ChgAdded{Version=[3],Text=[Elaborate_Body is now an aspect,
4042 so it can be specified by an @nt{aspect_specification} @em
4043 although the pragma is still preferred by the Standard.]}
4044
4045 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0243-1]}
4046 @ChgAdded{Version=[3],Text=[Pure and Preelaborate are now aspects,
4047 so they can be specified by an @nt{aspect_specification} @em
4048 although the pragmas are still preferred by the Standard.]}
4049 @end{Extend2005}
4050
4051 @begin{DiffWord2005}
4052 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0034-1]}
4053 @ChgAdded{Version=[3],Text=[@B<Correction:> Added wording so that
4054 a limited view is always treated as pure, no matter what categorization
4055 is used for the originating unit. This was undefined in Ada 2005.]}
4056
4057 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0028-1],ARef=[AI05-0221-1]}
4058 @ChgAdded{Version=[3],Text=[@B<Correction:> Fixed minor issues with
4059 preelaborable initialization (PI): null Initialize procedures do not make
4060 a type non-PI; formal types with pragma PI can be assumed to have PI;
4061 formal extensions are assumed to not have PI; all composite types
4062 can have pragma PI (so that the possibility of hidden Initialize routines
4063 can be handled); added discriminants of a derived type are not considered
4064 in calculating PI.]}
4065
4066 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0219-1]}
4067 @ChgAdded{Version=[3],Text=[@B<Correction:> Clarified that the implementation
4068 permission to omit pure subprogram calls does not apply if any part of the
4069 parameters or any designated object has a part that is immutably limited.
4070 The old wording just said "limited type", which can change via visibility
4071 and thus isn't appropriate for dynamic semantics permissions.]}
4072 @end{DiffWord2005}
4073
4074 @begin{DiffWord2012}
4075 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0076-1]}
4076 @ChgAdded{Version=[4],Text=[@B<Corrigendum:> Explicitly stated that modifying
4077 a library-level constant in a pure package is erroneous. We don't document
4078 this as inconsistent as implementations certainly can still do whatever they
4079 were previously doing (no change is required); moreover, this case (and many
4080 more) were erroneous in Ada 2005 and before, so we're just restoring the
4081 previous semantics.]}
4082 @end{DiffWord2012}
4083