comp.lang.ada
 help / color / mirror / Atom feed
* Ada 95 and Class attribute for none-tagged incomplete type
@ 2009-08-02  6:55 Hibou57 (Yannick Duchêne)
  2009-08-03 15:26 ` Adam Beneschan
  0 siblings, 1 reply; 11+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-08-02  6:55 UTC (permalink / raw)


Hello,

I've learned something mostly surprising today : in Ada 95, this was
allowed to use the Class attribute with a prefix which was an
incomplete type.... even not tagged.

I've learned about it here :

http://www.adaic.org/standards/05rat/html/Rat-1-3-3.html
>> ------------------
The introduction of tagged incomplete types clarifies the ability to
write
type T_Ptr is access all T'Class;
This was allowed in Ada 95 even though we had not declared T as tagged
at this point. Of course it implied that T would be tagged. In Ada
2005 this is frowned upon since we should now declare that T is tagged
incomplete if we wish to declare a class wide access type. For
compatibility the old feature has been retained but banished to Annex
J for obsolescent features.
>> ------------------

The part of the mentionned annex J
>> ------------------
For the first subtype S of a type T declared by an
incomplete_type_declaration that is not tagged, the following
attribute is defined:
S'Class
Denotes the first subtype of the incomplete class-wide type rooted at
T. The completion of T shall declare a tagged type. Such an attribute
reference shall occur in the same library unit as the
incomplete_type_declaration.
>> ------------------

But why was it allowed ?
There was no way to declare an incomplete tagged ?
So why to allow reference to a Class attribute in such circumstances ?

This seems weird ... to allow to make reference to a class attribute
of a none-tagged type (even if the complete view is tagged)

Was this a design error or were there some reasons or is there
something I did not understand ?



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-02  6:55 Ada 95 and Class attribute for none-tagged incomplete type Hibou57 (Yannick Duchêne)
@ 2009-08-03 15:26 ` Adam Beneschan
  2009-08-03 18:45   ` Dmitry A. Kazakov
  2009-08-13  1:50   ` Randy Brukardt
  0 siblings, 2 replies; 11+ messages in thread
From: Adam Beneschan @ 2009-08-03 15:26 UTC (permalink / raw)


On Aug 1, 11:55 pm, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> wrote:
> Hello,
>
> I've learned something mostly surprising today : in Ada 95, this was
> allowed to use the Class attribute with a prefix which was an
> incomplete type.... even not tagged.
>
> I've learned about it here :
>
> http://www.adaic.org/standards/05rat/html/Rat-1-3-3.html>> ------------------
>
> The introduction of tagged incomplete types clarifies the ability to
> write
> type T_Ptr is access all T'Class;
> This was allowed in Ada 95 even though we had not declared T as tagged
> at this point. Of course it implied that T would be tagged. In Ada
> 2005 this is frowned upon since we should now declare that T is tagged
> incomplete if we wish to declare a class wide access type. For
> compatibility the old feature has been retained but banished to Annex
> J for obsolescent features.
>
> >> ------------------
>
> The part of the mentionned annex J>> ------------------
>
> For the first subtype S of a type T declared by an
> incomplete_type_declaration that is not tagged, the following
> attribute is defined:
> S'Class
> Denotes the first subtype of the incomplete class-wide type rooted at
> T. The completion of T shall declare a tagged type. Such an attribute
> reference shall occur in the same library unit as the
> incomplete_type_declaration.
>
> >> ------------------
>
> But why was it allowed ?
> There was no way to declare an incomplete tagged ?

Correct.  This just wasn't in the syntax.

> So why to allow reference to a Class attribute in such circumstances ?

You could do that if you knew that the type was going to be declared
as tagged when you got around to declaring the full type.

Keep in mind that this isn't a privacy issue.  The main reason for
incomplete types is so that you can declare linked lists and things
like that.  Allowing a 'Class reference to a type not yet declared as
tagged allowed things like this:

   type Rec;
   type Rec_Acc is access all Rec'Class;
   type Rec is tagged record
       ...
       Next : Rec_Acc;
   end record;

so that you could have a heterogeneous list of records.


> This seems weird ... to allow to make reference to a class attribute
> of a none-tagged type (even if the complete view is tagged)

It doesn't seem so weird to me; from a programmer's point of view, the
main purpose of incomplete types is so that you can define and refer
to the type's name ahead of time; therefore, there really isn't any
reason (for a programmer) to look at the type as an untagged type at
all.  It's a little different where private types are concerned,
because there are two views of the type---the partial view, which is
for packages that can't see inside the private part and thus can't see
the full declaration of the type; and the full view, for places that
*can* see the private part.  It's possible for the partial view to be
untagged and the full view to be tagged, so allowing 'Class in a place
where only the partial view is visible would be wrong.  But the "two
views" doesn't really apply to incomplete types.  (From the compiler's
standpoint, it does; but I'm talking from a programmer's standpoint
here.)

There is one exception to all of the above, and that's the case where
an incomplete type in the private part of a package is completed in
the package *body*.  Not having "tagged incomplete" types prevented
certain useful uses of the type, so the "is tagged;" syntax was
added.  I think that being able to use this in my Rec example above,
so that you can now declare an incomplete type as tagged before
applying 'Class, was more of a side benefit.  (AI95-326)


> Was this a design error or were there some reasons or is there
> something I did not understand ?

You could call it a small design error, but only a small one since the
cases where it made a difference were pretty obscure.

                                         -- Adam





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-03 15:26 ` Adam Beneschan
@ 2009-08-03 18:45   ` Dmitry A. Kazakov
  2009-08-13  1:50   ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2009-08-03 18:45 UTC (permalink / raw)


On Mon, 3 Aug 2009 08:26:24 -0700 (PDT), Adam Beneschan wrote:

> Keep in mind that this isn't a privacy issue.  The main reason for
> incomplete types is so that you can declare linked lists and things
> like that.  Allowing a 'Class reference to a type not yet declared as
> tagged allowed things like this:
> 
>    type Rec;
>    type Rec_Acc is access all Rec'Class;
>    type Rec is tagged record
>        ...
>        Next : Rec_Acc;
>    end record;
> 
> so that you could have a heterogeneous list of records.

Well, I would argue that logically the above could be rather:

   type Rec;
   type Rec_Acc is access all Rec;
   type Rec'Root is tagged record
       ...
      Next : Rec_Acc;
   end record;

Here 'Root is defined so that T'Class'Root = T. So Rec is class-wide.

Of course, from the stand point that any type has a class rooted in it,
Rec'Class is fully OK. But if we wanted further to pretend that some types
are more "classy" than others, we could maintain such distinction in a way
like above.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-03 15:26 ` Adam Beneschan
  2009-08-03 18:45   ` Dmitry A. Kazakov
@ 2009-08-13  1:50   ` Randy Brukardt
  2009-08-13  8:18     ` Niklas Holsti
  1 sibling, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2009-08-13  1:50 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

"Adam Beneschan" <adam@irvine.com> wrote in message 
news:17b5de2e-74df-414a-b214-677344dc697e@x25g2000prf.googlegroups.com...
>On Aug 1, 11:55 pm, Hibou57 (Yannick Duch�ne) <yannick_duch...@yahoo.fr> 
>wrote:
>> Hello,
>>
>> I've learned something mostly surprising today : in Ada 95, this was
>> allowed to use the Class attribute with a prefix which was an
>> incomplete type.... even not tagged.

Gee, guys, that's pretty boring. If you want something mind blowing in this 
area, look into 7.3.1(8-9) 
(http://www.adaic.org/standards/05rm/html/RM-7-3-1.html).

More than 90% of the ARG (that is, everyone other than Tucker, and he only 
had a vague recollection of it) was unaware of this rule when I stumbled 
across it updating notes. And no one can remember why we would want such a 
rule - it seems completely privacy breaking, and for no good reason. But 
there is an ACATS test for it, so it probably will work in your favorite 
compiler...and thus we were unwilling to take it out (somebody probably 
depends on it, and forcing a switch to a tagged private type would have 
other consequences making it not necessarily a trivial work-around).

A quick example:

package P is
   type Priv is private;
   type Acc is access all Priv'Class; -- Legal!!!!!!
private
   type Priv is tagged null record;
end P;

                                   Randy.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-13  1:50   ` Randy Brukardt
@ 2009-08-13  8:18     ` Niklas Holsti
  2009-08-13 13:16       ` Robert A Duff
  2009-08-14  4:17       ` Randy Brukardt
  0 siblings, 2 replies; 11+ messages in thread
From: Niklas Holsti @ 2009-08-13  8:18 UTC (permalink / raw)


Randy Brukardt wrote:
> "Adam Beneschan" <adam@irvine.com> wrote in message 
> news:17b5de2e-74df-414a-b214-677344dc697e@x25g2000prf.googlegroups.com...
>> On Aug 1, 11:55 pm, Hibou57 (Yannick Duch�ne) <yannick_duch...@yahoo.fr> 
>> wrote:
>>> Hello,
>>>
>>> I've learned something mostly surprising today : in Ada 95, this was
>>> allowed to use the Class attribute with a prefix which was an
>>> incomplete type.... even not tagged.
> 
> Gee, guys, that's pretty boring. If you want something mind blowing in this 
> area, look into 7.3.1(8-9) 
> (http://www.adaic.org/standards/05rm/html/RM-7-3-1.html).
> 
> More than 90% of the ARG (that is, everyone other than Tucker, and he only 
> had a vague recollection of it) was unaware of this rule when I stumbled 
> across it updating notes. And no one can remember why we would want such a 
> rule - it seems completely privacy breaking, and for no good reason.

I don't understand -- 7.3.1(9) says (both in RM 95 and RM 05) that the 
'Class attribute is "allowed only from the beginning of the private part 
in which the full view is declared..."

> A quick example:
> 
> package P is
>    type Priv is private;
>    type Acc is access all Priv'Class; -- Legal!!!!!!
> private
>    type Priv is tagged null record;
> end P;

This conflicts with 7.3.1(9) because Priv'Class is used before the 
private part. Gnat (Debian Lenny) says:

p.ads:3:27: tagged type required, found private type "Priv" defined at 
line 2

If the declaration of type Acc is moved below "private", Gnat accepts 
the code, as it should by 7.3.1(8-9).

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-13  8:18     ` Niklas Holsti
@ 2009-08-13 13:16       ` Robert A Duff
  2009-08-14  4:21         ` Randy Brukardt
  2009-08-14  4:17       ` Randy Brukardt
  1 sibling, 1 reply; 11+ messages in thread
From: Robert A Duff @ 2009-08-13 13:16 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> Randy Brukardt wrote:
>> A quick example:
>> package P is
>>    type Priv is private;
>>    type Acc is access all Priv'Class; -- Legal!!!!!!
>> private
>>    type Priv is tagged null record;
>> end P;
>
> This conflicts with 7.3.1(9) because Priv'Class is used before the
> private part. Gnat (Debian Lenny) says:
>
> p.ads:3:27: tagged type required, found private type "Priv" defined at
> line 2
>
> If the declaration of type Acc is moved below "private", Gnat accepts
> the code, as it should by 7.3.1(8-9).

I agree with Niklas.  The above is illegal.

The purpose of the rule is so you can create recursive types, as in:

package P is
   type Priv is private;
private
   type Acc is access all Priv'Class; -- Legal!!!!!!
   type Priv is tagged
        record
            Next : Acc;
            ... --etc.
        end record;
end P;

without exposing the taggedness to clients.  Note that Acc is in the
private part, so there's no privacy-breaking going on.

- Bob



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-13  8:18     ` Niklas Holsti
  2009-08-13 13:16       ` Robert A Duff
@ 2009-08-14  4:17       ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2009-08-14  4:17 UTC (permalink / raw)


"Niklas Holsti" <niklas.holsti@tidorum.invalid> wrote in message 
news:4a83cc73$0$6272$4f793bc4@news.tdc.fi...
> Randy Brukardt wrote:
...
> This conflicts with 7.3.1(9) because Priv'Class is used before the private 
> part. Gnat (Debian Lenny) says:

Yes, obviously wrote too fast. Just move the declaration down.

                               Randy.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-13 13:16       ` Robert A Duff
@ 2009-08-14  4:21         ` Randy Brukardt
  2009-08-14 19:01           ` Robert A Duff
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2009-08-14  4:21 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcc7hx7onv6.fsf@shell01.TheWorld.com...
...
> The purpose of the rule is so you can create recursive types, as in:
>
> package P is
>   type Priv is private;
> private
>   type Acc is access all Priv'Class; -- Legal!!!!!!
>   type Priv is tagged
>        record
>            Next : Acc;
>            ... --etc.
>        end record;
> end P;
>
> without exposing the taggedness to clients.  Note that Acc is in the
> private part, so there's no privacy-breaking going on.

Another example of why you ought to come to meetings more often. I don't 
recall anyone figuring that out per-se (although it is obvious that you can 
use it in this way). All this special rule eliminates is the need to declare 
an incomplete type in this one unusual case (the private type in cases like 
this is best declared as tagged, so this shouldn't happen very often). Seems 
like a pile of work for an implementation and for the language just to 
eliminate one line in a private part.

                                            Randy.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-14  4:21         ` Randy Brukardt
@ 2009-08-14 19:01           ` Robert A Duff
  2009-08-14 23:41             ` Randy Brukardt
  0 siblings, 1 reply; 11+ messages in thread
From: Robert A Duff @ 2009-08-14 19:01 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

>...All this special rule eliminates is the need to declare 
> an incomplete type in this one unusual case (the private type in cases like 
> this is best declared as tagged, so this shouldn't happen very often). Seems 
> like a pile of work for an implementation and for the language just to 
> eliminate one line in a private part.

The problem is that declaring that incomplete type is illegal.
Eliminating the need for one _illegal_ line isn't such a bad thing.  ;-)

package P is
   type Priv is private;
private
   type Priv is tagged; -- Illegal!
   type Acc is access all Priv'Class;
   type Priv is tagged
      record
         Next : Acc;
      end record;
end P;

We could have made it legal, I suppose.  But having three views of a
type might make more trouble for the compiler than the existing
rules.

On the third hand, compilers have to deal with:

package P is
   type Priv is private;
private
   task type Priv is ...;
end P;

package body P is
   task body Priv is separate;
end P;

separate (P)
task body Priv is ...;

where there are four things called Priv, which are all really the same
thing.

- Bob




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-14 19:01           ` Robert A Duff
@ 2009-08-14 23:41             ` Randy Brukardt
  2009-08-15 14:33               ` Robert A Duff
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2009-08-14 23:41 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcc3a7uusn8.fsf@shell01.TheWorld.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>>...All this special rule eliminates is the need to declare
>> an incomplete type in this one unusual case (the private type in cases 
>> like
>> this is best declared as tagged, so this shouldn't happen very often). 
>> Seems
>> like a pile of work for an implementation and for the language just to
>> eliminate one line in a private part.
>
> The problem is that declaring that incomplete type is illegal.
> Eliminating the need for one _illegal_ line isn't such a bad thing.  ;-)

Why is it illegal? Doesn't seem like it ought to be on the face of it.

...

> We could have made it legal, I suppose.  But having three views of a
> type might make more trouble for the compiler than the existing
> rules.

Apparently, you haven't thought to hard about the semantics of limited 
views. :-) *Every* private type that can be used in a limited view has (at 
least) three views (the incomplete view from the limited view being the 
third).

I believe we (Tucker and I? On the ARG list? I don't remember) were 
discussing eliminating some of the restrictions on the declaration and 
completion of incomplete types in order to make the use of "incomplete 
instances" or "intgregated packages" or whatever we end up with more useful. 
(Many of the "derivation" problems go away if you can simply declare an 
incomplete type ahead of time to introduce the proper name for the type.)

                            Randy.







^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Ada 95 and Class attribute for none-tagged incomplete type
  2009-08-14 23:41             ` Randy Brukardt
@ 2009-08-15 14:33               ` Robert A Duff
  0 siblings, 0 replies; 11+ messages in thread
From: Robert A Duff @ 2009-08-15 14:33 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
> news:wcc3a7uusn8.fsf@shell01.TheWorld.com...
>> "Randy Brukardt" <randy@rrsoftware.com> writes:
>>
>>>...All this special rule eliminates is the need to declare
>>> an incomplete type in this one unusual case (the private type in cases 
>>> like
>>> this is best declared as tagged, so this shouldn't happen very often). 
>>> Seems
>>> like a pile of work for an implementation and for the language just to
>>> eliminate one line in a private part.
>>
>> The problem is that declaring that incomplete type is illegal.
>> Eliminating the need for one _illegal_ line isn't such a bad thing.  ;-)
>
> Why is it illegal? Doesn't seem like it ought to be on the face of it.

Umm... Because the RM says so?  7.3(4).  So why does the RM say so?
Because Jean Ichbiah wanted it that way, I guess, and nobody thought
it desirable or important enough to change during Ada 9X
or Ada 0X projects.

> Apparently, you haven't thought to hard about the semantics of limited 
> views. :-) *Every* private type that can be used in a limited view has (at 
> least) three views (the incomplete view from the limited view being the 
> third).

Good point, although at the time the rule we're talking about (allowing
Private_Type'Class before the full type) was invented, there were no
such things as limited views.

> I believe we (Tucker and I? On the ARG list? I don't remember) 

We discussed it in a telephone meeting.  No doubt also on ARG list.

>...were 
> discussing eliminating some of the restrictions on the declaration and 
> completion of incomplete types in order to make the use of "incomplete 
> instances" or "intgregated packages" or whatever we end up with more useful. 
> (Many of the "derivation" problems go away if you can simply declare an 
> incomplete type ahead of time to introduce the proper name for the type.)

Yes, I think that's a good direction to go, if we can make it work.
A language design goal should be: Never require the use of pointers,
except when reference semantics is desired.  Ada violates this principle
in several ways, and removing one of them one be a good thing.
(C violates this principle even more, and Java more still.)

- Bob



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-08-15 14:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-02  6:55 Ada 95 and Class attribute for none-tagged incomplete type Hibou57 (Yannick Duchêne)
2009-08-03 15:26 ` Adam Beneschan
2009-08-03 18:45   ` Dmitry A. Kazakov
2009-08-13  1:50   ` Randy Brukardt
2009-08-13  8:18     ` Niklas Holsti
2009-08-13 13:16       ` Robert A Duff
2009-08-14  4:21         ` Randy Brukardt
2009-08-14 19:01           ` Robert A Duff
2009-08-14 23:41             ` Randy Brukardt
2009-08-15 14:33               ` Robert A Duff
2009-08-14  4:17       ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox