Debian Codegraph @

source_2005/10.mss

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