Version 1.6 of ais/ai-00360.txt
!standard 07.06(09) 04-05-27 AI95-00360/05
!standard D.07(04)
!standard A.4.5(72)
!standard A.5.2(15)
!standard A.5.2(27)
!standard A.8.1(16)
!standard A.8.4(19)
!standard A.10.1(85)
!standard A.12.1(27)
!class binding interpretation 03-10-08
!status Amendment 200Y 04-03-24
!status ARG Approved 8-0-0 04-03-07
!status work item 03-10-08
!status received 03-10-08
!priority Medium
!difficulty Easy
!subject Types that need finalization
!summary
Some types are defined to need finalization. The restriction
No_Nested_Finalization is defined in terms of types that need finalization. A
number of language-defined types are defined to need finalization.
!question
The restriction No_Nested_Finalization is expressed in terms of controlled
types. However, there are a number of language-defined types which, while not
visibly controlled, might well be implemented using controlled types by some
implementations. Are such types affected by No_Nested_Finalization? (Yes, see
list in the wording section.) Furthermore, the definition of
No_Nested_Finalization doesn't take into account access discriminants, which
can cause nested finalization to happen. Is this intended? (No.)
!recommendation
(See summary.)
!wording
Insert after 7.6(9):
A type is said to need finalization if:
o it is a controlled type, a task type or a protected type; or
o it has a component that needs finalization; or
o it is a limited type that has an access discriminant whose designated type
needs finalization; or
o it is one of a number of language-defined types that are explicitly defined
to need finalization.
AARM Note
The fact that a type needs finalization does not require it to be implemented
with a controlled type. It just has to be recognized by the
No_Nested_Finalization restriction.
Insert after A.4.5(72):
The type Unbounded_String needs finalization (see 7.6).
Insert after A.5.2(15):
The type Generator needs finalization (see 7.6).
Insert after A.5.2(27):
The type Generator needs finalization (see 7.6) in every instantiation of Discrete_Random.
Insert after A.8.1(16):
The type File_Type needs finalization (see 7.6) in every instantiation of Sequential_IO.
Insert after A.8.4(19):
The type File_Type needs finalization (see 7.6) in every instantiation of Direct_IO.
Insert after A.10.1(85):
The type File_Type needs finalization (see 7.6).
Insert after A.12.1(27):
The type File_Type needs finalization (see 7.6).
Replace D.7(4/1) by:
No_Nested_Finalization
Objects of a type that needs finalization (see 7.6) and access types that
designate a type that needs finalization (see 7.6) shall be declared only at
library level.
Add in the Static Semantics of D.15 (AI-297):
The type Timing_Event needs finalization (see 7.6).
Add in the Static Semantics of D.14 (AI-307):
The type Timer needs finalization (see 7.6).
Add in the Static Semantics of AI-354:
The type Group_Budget needs finalization (see 7.6).
!discussion
Note that the current wording of D.7(4) doesn't take into account the case of
access discriminants designating controlled objects. For example:
with Ada.Finalization.Controlled;
package P is
type T1 is new Ada.Finalization.Controlled with null record;
type T2 (D : access T1) is limited null record;
end P;
with P;
procedure Q is
pragma Restrictions (No_Nested_Finalization);
X : P.T2 (D => new P.T1); --
begin
null;
end Q;
In this example the finalization of X causes the finalization of X.D, which is
effectively a nested finalization. However, this case is not forbidden by the
existing wording of D.7(4).
!corrigendum 7.6(09)
Insert after the paragraph:
A controlled type is a descendant of Controlled or Limited_Controlled. The
(default) implementations of Initialize, Adjust, and Finalize have no effect.
The predefined "=" operator of type Controlled always returns True, since this
operator is incorporated into the implementation of the predefined equality
operator of types derived from Controlled, as explained in 4.5.2. The type
Limited_Controlled is like Controlled, except that it is limited and it lacks
the primitive subprogram Adjust.
the new paragraphs:
A type is said to need finalization if:
- it is a controlled type, a task type or a protected type; or
- it has a component that needs finalization; or
- it is a limited type that has an access discriminant whose designated
type needs finalization; or
- it is one of a number of language-defined types that are explicitly
defined to need finalization.
!corrigendum A.4.5(72)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Strings.Unbounded;
the new paragraph:
The type Unbounded_String needs finalization (see 7.6).
!corrigendum A.5.2(15)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Numerics.Float_Random;
the new paragraph:
The type Generator needs finalization (see 7.6).
!corrigendum A.5.2(27)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Numerics.Discrete_Random;
the new paragraph:
The type Generator needs finalization (see 7.6) in every instantiation of
Discrete_Random.
!corrigendum A.8.1(16)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Sequential_IO;
the new paragraph:
The type File_Type needs finalization (see 7.6) in every instantiation of
Sequential_IO.
!corrigendum A.8.4(19)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Direct_IO;
the new paragraph:
The type File_Type needs finalization (see 7.6) in every instantiation of
Direct_IO.
!corrigendum A.10.1(85)
Insert after the paragraph:
Status_Error : exception renames IO_Exceptions.Status_Error;
Mode_Error : exception renames IO_Exceptions.Mode_Error;
Name_Error : exception renames IO_Exceptions.Name_Error;
Use_Error : exception renames IO_Exceptions.Use_Error;
Device_Error : exception renames IO_Exceptions.Device_Error;
End_Error : exception renames IO_Exceptions.End_Error;
Data_Error : exception renames IO_Exceptions.Data_Error;
Layout_Error : exception renames IO_Exceptions.Layout_Error;
private
... -- not specified by the language
end Ada.Text_IO;
the new paragraph:
The type File_Type needs finalization (see 7.6).
!corrigendum A.12.1(27)
Insert after the paragraph:
private
... -- not specified by the language
end Ada.Streams.Stream_IO;>
the new paragraph:
The type File_Type needs finalization (see 7.6).
!corrigendum D.7(4)
Replace the paragraph:
- No_Nested_Finalization
-
Objects with controlled, protected, or task parts and access types that
designate such objects, shall be declared only at library level.
by:
- No_Nested_Finalization
-
Objects of a type that needs finalization (see 7.6) and access types that
designate a type that needs finalization (see 7.6) shall be declared only at
library level.
!example
!ACATS test
!appendix
From: Tucker Taft
Sent: Wednesday, October 8, 2003 10:26 AM
"Quasi-controlled" makes me feel queasy.
How about just define the term "needs finalization"? I think that
will be easier to stomach ;-).
****************************************************************
From: Pascal Leroy
Sent: Wednesday, October 8, 2003 2:49 PM
> "Quasi-controlled" makes me feel queasy.
I knew you wouldn't like it ;-)
> How about just define the term "needs finalization"? I think that
> will be easier to stomach ;-).
Well, it's not exactly "needs finalization", because protected types and
tasks need some kind of finalization, and they are not covered by
restriction No_Nested_Finalization. What this restriction covers is
really "controlled types and their buddies". Therefore I believe that
the new term has to say "controlled" somewhere. However, I would
welcome a better name...
****************************************************************
From: Tucker Taft
Sent: Wednesday, October 8, 2003 3:52 PM
No, there you are wrong. No_Nested_Finalization *does* cover
Task and Protected types. We made that change a while ago.
So I think "needs finalization" is just about right.
****************************************************************
From: Jean-Pierre Rosen
Sent: Thursday, October 9, 2003 1:58 AM
What about "potentially controlled" ? Reminds of "potentially blocking",
and I think it grasps the idea, at least for things like Unbounded_String.
The standard does not *require* Unbounded_String to be controlled, but
we know damn well that they might be...
****************************************************************
From: Tucker Taft
Sent: Thursday, October 9, 2003 10:24 AM
As I pointed out, in Ada 2000, No_Nested_Finalization includes
no nested tasks and protected types as well. It sounds
like you folks are using outdated manuals. For shame!
****************************************************************
From: Pascal Leroy
Sent: Friday, October 10, 2003 3:44 AM
Yes, sorry, I was reading the original, obsolete RM, not the new fancy
one updated by TC1.
****************************************************************
Questions? Ask the ACAA Technical Agent