Version 1.1 of acs/ac-00141.txt

Unformatted version of acs/ac-00141.txt version 1.1
Other versions for file acs/ac-00141.txt

!standard 8.3.1(5/2)          07-04-06 AC95-00141/01
!class confirmation 07-04-06
!status received no action 07-04-06
!status received 07-03-26
!subject Possible grammatical ambiguity
!summary
!appendix

!topic Possible grammatical ambiguity in 8.3.1
!reference 8.3.1(5/2)
!from Adam Beneschan 07-03-26
!discussion


While recently trying to figure out whether a certain construct is
allowed, I ran across some wording that I found maddeningly difficult,
and I couldn't figure out what it meant until I read the e-mail trail
on AI-218 (and I only *think* I've figured it out---I'm still not 100%
certain).

The clause in question is:

  "if the overriding_indicator is overriding, then the operation shall
   override a homograph at the place of the declaration or body;"

My problem is that the prepositional phrase beginning with "at" could
be read as modifying the verb "override" or the noun "homograph".  The
more natural reading is that it modifies "override", on first reading.
But here's an example from the !appendix of AI-218:

    package P is
        type T is tagged private;

        [overriding] procedure Finalize(X: in out T);
    private
        type T is new Limited_Controlled with...;
    end P;

The comments in the e-mail indicate that the overriding keyword is not
allowed here, but it would be allowed on the *body* of Finalize.  But
this does not seem to make sense when 8.3.1(5) is read in (what I
consider to be) the natural way.  In that case, the question to be
asked is, "Where does the overriding take place?"---and 8.3(10) would
seem to indicate that it takes place in the visible part of P, since
it says "An explicit declaration overrides an implicit declaration of
a primitive subprogram, regardless of which declaration comes first".
So the overriding occurs where Finalize is first declared.  It may be
possible to argue that the overriding doesn't take place until the
private part, but I don't think one can argue that the overriding
takes place where the body of P appears, since the body is a
completion and not a declaration, and 8.3(9) makes it seem that only a
declaration can override a homograph.

Eventually, after staring at this for some time, I decided that the
prepositional phrase refers to the homograph---i.e. a homograph *that*
*exists*, or *that* *is* *visible*, at the place of the declaration or
body.  I assume that something like this is what is meant, but it's
far from obvious.  I had to twist my brain in knots to figure this
out, and I had to search through the whole AI to do so.

The following would be a much better wording, except that it's wrong:

   "If the overriding_indicator is overriding, then the operation
   shall override a homograph that is visible at the place of the
   declaration or body",

except that of course it's not visible because it's been hidden by the
declaration.  But it seems to me that something like that is needed.

Or perhaps something like,

   "... then the operation shall override a homograph in whose scope
   the overriding_indicator appears".

or

   "... then the operation shall override a homograph in whose scope
   the declaration or body with the overriding_indicator appears".

I think this would make the "overriding" in the above example illegal,
since the scope of the inherited Finalize includes only things that
occur after the full definition of T, but it would make it clear that
"overriding" is legal on the body.

I realize it may be too late to change the wording, but maybe
something could be stuck in the AARM, now or the next time such
changes take place......???

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

From: Randy Brukardt
Date: Monday, March 26, 2007  9:56 PM

...
> The clause in question is:
>
>   "if the overriding_indicator is overriding, then the operation shall
>    override a homograph at the place of the declaration or body;"
>
> My problem is that the prepositional phrase beginning with "at" could
> be read as modifying the verb "override" or the noun "homograph".  The
> more natural reading is that it modifies "override", on first reading.

I don't think there is any other possible reading...

> But here's an example from the !appendix of AI-218:
>
>     package P is
>         type T is tagged private;
>
>         [overriding] procedure Finalize(X: in out T);
>     private
>         type T is new Limited_Controlled with...;
>     end P;
>
> The comments in the e-mail indicate that the overriding keyword is not
> allowed here, but it would be allowed on the *body* of Finalize.  But
> this does not seem to make sense when 8.3.1(5) is read in (what I
> consider to be) the natural way.  In that case, the question to be
> asked is, "Where does the overriding take place?"---and 8.3(10) would
> seem to indicate that it takes place in the visible part of P, since
> it says "An explicit declaration overrides an implicit declaration of
> a primitive subprogram, regardless of which declaration comes first".
> So the overriding occurs where Finalize is first declared.

I don't agree, as the implicit declaration doesn't exist at the place of the
first declaration, so it cannot override anything.

> It may be
> possible to argue that the overriding doesn't take place until the
> private part, ...

Yes, that is the way that I understand it works.

> ... but I don't think one can argue that the overriding
> takes place where the body of P appears, since the body is a
> completion and not a declaration, and 8.3(9) makes it seem that only a
> declaration can override a homograph.

Sure, but that's irrelevant. Read the rule again: it says the "operation"
shall override, not that the body shall override.

I do see that there is a possible point of confusion here, in that the
intent isn't to care about where the overriding is, only that it has already
happened. In your example, the keyword is illegal because the overriding has
not happened; in the body case, it is legal because it already has happened.
You seem to be assuming that the wording means that the overriding can only
happen at the place of the declaration, but that doesn't make sense.

Note that the AARM note talks about the "overriding state"; we're not
talking about the specific place of overriding. If you read the statement to
care about "overriding at the place", that's wrong; we care whether it is
known to be overriding at the place.

> Eventually, after staring at this for some time, I decided that the
> prepositional phrase refers to the homograph---i.e. a homograph *that*
> *exists*, or *that* *is* *visible*, at the place of the declaration or
> body.  I assume that something like this is what is meant, but it's
> far from obvious.  I had to twist my brain in knots to figure this
> out, and I had to search through the whole AI to do so.

I can't even begin to make sense of how you get this by associating with
"homograph". If you believe the wording means "only at the place", then
that's going to be true if you associate with overriding or with homograph.

...

> I realize it may be too late to change the wording, but maybe
> something could be stuck in the AARM, now or the next time such
> changes take place......???

Well, it's never too late to fix a mistake, but obviously that will be done
in the next maintenance cycle. The Amendment has been published by ISO, so
it surely isn't going to change!

Fiddling with this sort of wording requires a lot of care (as you showed by
your attempts to fix the wording, none of which work).

With your unfriendly reading, it might have been better to say:

"if the overriding_indicator is overriding, then the operation shall
   override a homograph at the place of the declaration or body, or some
   earlier place;"

But this is iffy, too, because it's not completely clear if "earlier place"
is well-defined.

Humm, really the problem is simply one of association, as you originally
stated. The meaning is simple:

"if the overriding_indicator is overriding, then at the place of the
declaration or body, the operation shall override a homograph (anywhere)."

Not sure if that really helps any. Other thoughts are welcome.

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

From: Robert A. Duff
Date: Monday, March 27, 2007  8:30 AM

> Note that the AARM note talks about the "overriding state"; we're not
> talking about the specific place of overriding. If you read the statement to
> care about "overriding at the place", that's wrong; we care whether it is
> known to be overriding at the place.

Right, I think the right way to think about these sorts of things is that
there's a region of text over which some property holds.  The rule is saying if
the decl or body is within that region, then ....

Don't focus on the place at the beginning of that region -- that's
compiler-implementation talk.

In other words, there is no "the" (one and only) place where overriding
happens.

This is the way the visibility rules and freezing rules and so forth work in
general.

If the rules need rewording, I think we should maintain this "region" style of
thinking.

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

From: Adam Beneschan
Date: Monday, March 27, 2007  11:13 AM

> > ... but I don't think one can argue that the overriding
> > takes place where the body of P appears, since the body is a
> > completion and not a declaration, and 8.3(9) makes it seem that only a
> > declaration can override a homograph.
>
> Sure, but that's irrelevant. Read the rule again: it says the "operation"
> shall override, not that the body shall override.

Right, I'm aware of that.  But the rule says, "the operation shall
override a homograph at the place of the declaration or body"; here,
I'm assuming "declaration or body" means "the declaration or body on
which the 'overriding' keyword appears".  My point was that since a
body that is a completion can't override anything, the overriding
cannot occur *at* *that* *place*.  But it appears this is addressed by
your next paragraph.


> I do see that there is a possible point of confusion here, in that the
> intent isn't to care about where the overriding is, only that it has already
> happened. In your example, the keyword is illegal because the overriding has
> not happened; in the body case, it is legal because it already has happened.
> You seem to be assuming that the wording means that the overriding can only
> happen at the place of the declaration, but that doesn't make sense.

I guess I was assuming that "at the place" means "at the place", not
"at the place or sometime later".  "At", I think, tends to refer to a
specific place, not to a range of places.


> Note that the AARM note talks about the "overriding state"

Yeah, but now it's using "overriding" as a present participle, while
the rule in 8.3(5) used "override" as a verb; I think it makes a big
difference.  Saying "override...at the place" indicates that we're
talking about the place where the action of overriding occurred;
talking about the "overriding state...at the place" could, however,
refer to a state that was caused by an action at an earlier place.

It's a little of like the difference between "I took the package to
Jim at 3:00" and "The package was in Jim's possession at 3:00".  The
second sentence is consistent with my taking Jim the package at 3:00,
2:00, the previous day, or anything beforehand, but the first sentence
is not---the "at" phrase tells you exactly when I performed the action
denoted by the verb "took".


> we're not
> talking about the specific place of overriding.

Apparently you didn't intend to---but if that was the intent, I think
the wording was incorrect, or at least deficient.

I'm not trying to be anyone's high-school English teacher, by the
way---sorry if it comes across that way.  I'm only trying to explain
how someone who has not been involved in ARG discussions and knows
only what he reads in the RM/AARM can come to the incorrect
conclusion.  The correct reading may have been obvious to those who
had long discussions about this feature already, but it wasn't obvious
to me, and I think this could trip someone else up too.  By the way,
the code snippet that led to my looking up the rule was:

    with Ada.Finalization;
    package pak1 is

       type T1 is new Ada.Finalization.Controlled with null record;

       overriding
       procedure Adjust(Object: in out T1);

    end pak1;

    package body pak1 is

       overriding        -- LEGAL?
       procedure Adjust(Object: in out T1) is
       begin
          null;
       end Adjust;

    end pak1;

At first, the RM made it seem that this was illegal, but after reading
the whole AI appendix I figured out otherwise.  By the way, I'd
recommend including a case like this, and other similar cases, in the
ACATS suite so that compiler writers who misunderstand the RM text the
way I misunderstood it will get corrected.

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



Questions? Ask the ACAA Technical Agent