Version 1.2 of ai05s/ai05-0099-1.txt

Unformatted version of ai05s/ai05-0099-1.txt version 1.2
Other versions for file ai05s/ai05-0099-1.txt

!standard 7.6.1(7)          08-05-28 AI05-0099-1/01
!standard 7.6.1(8)
!class binding interpretation 08-05-28
!status work item 08-05-28
!status received 06-04-09
!priority Medium
!difficulty Medium
!qualifier Omission
!subject The tag, not the type, of an object determines if it is controlled
!summary
The finalization actions for an object are determined by the runtime type of an object (as identified by the tag, if any, of the object) and not by the nominal subtype of the object.
!question
When an object is finalized, 7.6.1(7) says, "If the object is of a controlled type, the Finalize procedure is called". If the phrase "The object is of type Z" is equivalent to "The object's nominal subtype is Z" for objects declared by an object_declaration, as 3.3.1(8) would seem to imply, then there's a problem if T is an interface type:
Obj : Int'Class := <expression>;
because the "specific type identified by the tag" (this is the phrase used in other places in the RM) may be a controlled or a non-controlled type; thus, when Obj is finalized, it can't be determined statically whether any Finalize routine needs to be called. But Finalize definitely needs to be called if the specific type is controlled, right? (Yes.)
!wording
Replace 7.6.1(7) by:
* If the object is of a tagged type, and the tag of the object identifies
a controlled type, the Finalize procedure of that controlled type is called.
Replace 7.6.1(8) by:
* If the object is of a protected type, or if the object is of a tagged
type and the tag of the object identifies a protected type, the the actions defined in 9.4 are performed;
Add an AARM note after 7.6.1(9.a):
To Be Honest: The components discussed here are all of the components that the actual object has, not just those component that are identified by the type of of the actual object. These can be different if the object has a classwide type.
!discussion
The rule in question is a dynamic semantics rule, so depending on a static concept like "nominal subtype" is suspicious. However, there is no clear definition of the "dynamic type" of an object. Since T'Class can include an object of any decendant of T, we surely do not want to be calling the Finalize (if any) that is statically associated with T.
Argubly, this problem could occur in other dynamic cases, but in the absense of any examples of such cases, it is not possible to craft a general solution.
In any case, the existing wording is either vague or misleading, as it doesn't make it clear which Finalize routine is called. That needs to be corrected in any case.
7.6.1(8) has a similar problem for a (tagged) protected type that inherits from a limited or synchronized interface. Thus we reword it as well.
Note that 7.6.1(9) does not need a correction, as all tagged types are composite, and thus the use of classwide types does not change this property. We add a "To Be Honest" AARM note to make it clear that we are talking about the components that the object actually has, not necessarily those that are identified statically by the type.
--!corrigendum 7.6.1(7) --!corrigendum 7.6.1(8)
!ACATS Test
We do not expect that this will change the semantics of any Ada program, so no test should be needed. There might be value to a C-Test that checks that controlled types that inherit from interfaces get finalized properly.
!appendix

!topic What does "object of type T" mean when nominal type is classwide?
!reference RM05 3.3.1(8), 7.6.1(7)
!from Adam Beneschan 08-04-09
!discussion


This is one of those nitpicky cases where I have a feeling there's no doubt
about what's supposed to happen but the RM wording may be technically ambiguous
or incorrect.

3.3.1(8) says, "The object_declaration declares an object of the type of the nominal subtype".

So in this case:

    Obj : T'Class := <expression>;

Is the type of the object T'Class, or is it the specific type given by the type
of the expression?  Or does this depend on whether we're talking about the object
itself or the view of the object?

The reason I'm asking is because I'm trying to figure out just what
7.6.1(7) means for objects like this; when an object is finalized, this clause says,
"If the object is of a controlled type, the Finalize procedure is called". If the
phrase "The object is of type Z" is equivalent to "The object's nominal type is Z",
for objects declared by an object_declaration, as 3.3.1(8) would seem to imply,
then there's a problem if T is an interface type:

    Obj : Int'Class := <expression>;

because the "specific type identified by the tag" (this is the phrase used in
other places in the RM) may be a controlled or a non-controlled type; thus,
when Obj is finalized, it can't be determined statically whether any Finalize
routine needs to be called. But Finalize definitely needs to be called if
the specific type is controlled, right?

It looks to me that when 7.6.1(7) and probably (9), refer to the type of an object,
the "type" here needs to mean the "specific type identified by the tag, if the
object is tagged". I don't know whether the current wording clearly means that,
or a change is needed. Also, I haven't yet learned anything about synchronized
interfaces, so I don't know what the effect on (8) is, but that's probably affected too. 

(Also, I'm just picking on 7.6.1(7-9) here, but there are undoubtedly other places
dealing with Adjust and Finalize that have the same issue.) 

****************************************************************

From: Tucker Taft
Sent: Wednesday, April 9, 2008  8:56 PM

This is probably a general issue of static semantics vs. dynamic semantics.
From a static semantic point of view, there is no doubt that the "type of Obj"
is T'Class.  From a dynamic point of view, a given object can be viewed as
any classwide type that covers it, so it really only makes sense to talk
about the specific type when talking about "the" type of an object.

It wouldn't hurt to make this distinction explicit.

****************************************************************

From: Randy Brukardt
Sent: Wednesday, April 9, 2008  8:56 PM

>...
> If the phrase "The object is of type Z" is  equivalent to "The 
>object's nominal type is Z", for objects declared  by an 
>object_declaration,

This in itself can't possibly be true, because there is no such thing
as a "nominal type". I suppose you actually mean "The type of the object's
nominal subtype is Z". (If you are going to be pedantic, you have to go
all the way... :-)

>... as 3.3.1(8) would seem to imply, then  there's a problem if T is an 
>interface type:
>
>     Obj : Int'Class := <expression>;
>
> because the "specific type identified by the tag" (this is the phrase 
> used in other places in the RM) may be a controlled or a 
> non-controlled type; thus, when Obj is finalized, it can't be 
> determined statically whether any Finalize routine needs to be called.  
> But Finalize definitely needs to be called if the specific type is 
> controlled, right?

Surely. But the rule in question is a dynamic semantics rule, and we don't
want to be worrying about anything statically. So I think you are right,
but for the wrong reasons: we shouldn't be talking about the type at all,
only about its tag (which has the correct dynamic semantics). The rule
probably should be something like:

      * If the object is of a tagged type, and the tag identifies
        a controlled type, the Finalize procedure is called.

> It looks to me that when 7.6.1(7) and probably (9), refer to the type 
> of an object, the "type" here needs to mean the "specific type 
> identified by the tag, if the object is tagged".

I don't think it makes sense to change (9) this way, but it suggests that
there is a very general problem with the Standard. Maybe we simply need
to define the "dynamic type" of an object, for use in dynamic rules.

Of course it is not a real problem, since class-wide types don't exist
at runtime, and these are only runtime rules. Thus I don't see how anyone
could get this wrong (and thus it fails the Duff test).

> I don't know whether
> the current wording clearly means that, or a change is needed.

If it does, I couldn't find it. It's a clear problem caused by mixing static
and dynamic concepts, because you'll always have trouble when they are different.

> (Also, I'm just picking on 7.6.1(7-9) here, but there are undoubtedly 
> other places dealing with Adjust and Finalize that have the same
> issue.)

I think it is any place that you have a dynamic semantics rule talking
about the type of an object. (It's surely not limited to controlled types.)

Hopefully Tucker will explain that this is all obvious. ;-)
[Unfortunately, he beat me to answering this by seconds, and he didn't explain
that it is obvious. - RLB]

****************************************************************


Questions? Ask the ACAA Technical Agent