comp.lang.ada
 help / color / mirror / Atom feed
* Re: Generic children, instances and visibility...
  1997-04-09  0:00 ` Stephen Leake
@ 1997-04-09  0:00   ` Jon S Anthony
  1997-04-12  0:00     ` Tucker Taft
  1997-04-13  0:00     ` Jon S Anthony
  0 siblings, 2 replies; 5+ messages in thread
From: Jon S Anthony @ 1997-04-09  0:00 UTC (permalink / raw)



In article <334BA5F2.4111@gsfc.nasa.gov> Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> with Parent.Child;
> with Inst_Types;
> package Parent.PC_Inst is new Parent.Child (Inst_Types.It);
> 
> gnat says neither case allows visibility:

True.  But that may or may not be accurate (though it probably is...)


> So, hoping that a private child would have visibility, I tried a third
> variation:
> 
> with Parent.Child;
> with Inst_Types;
> private package Parent.Test is
>    type It is new Parent.T with null record;
> 
>    package PC_Inst is new Parent.Child (Inst_Types.It);

Since PC_Inst is not a child of Parent, 12.3(11) seems to say that
this can't work.  The case where the instance is a child of the parent
is the interesting one.  What is more, this case "works" (according to
gnat) if you declare the IT type in a child package of Parent:

package Parent.Inst_Types is
    type IT is new Parent.T with null record;
end Parent.Inst_Types;

with Parent.Child;
with Parent.Inst_Types;
package Parent.PC_Inst is new Parent.Child(Parent.Inst_Types.IT);

Hmmm, just checked and it also "works" if you just dump the
instantiation in Parent.Inst_Types:

with Parent.Child;
package Parent.Inst_Types is
    type IT is new Parent.T with null record;
    package PC_Inst is new Parent.Child(IT);
end Parent.Inst_Types;

Now this last case is really odd as it does not seem different (in the
relevant point - properties of IT visible at instantiation point) than
the case where Inst_Types is not a child and simply withs Parent to
derive the IT type.  Now, I _am_ beginning to think that GNAT has a
bug here somewhere.


> It would seem that no generic can see inside type It; it is a limited
> private type, period.

That may well be true (actually the limited part is irrelevant), but
as the above shows, you can't use GNAT as a verification of this
statement.  I was wondering about this from a "language lawyer" point
of view, but now am wondering if GNAT has a bug in it as well.

Tucker, Bob, Norman - any comments appreciated.

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

* Generic children, instances and visibility...
@ 1997-04-09  0:00 Jon S Anthony
  1997-04-09  0:00 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Jon S Anthony @ 1997-04-09  0:00 UTC (permalink / raw)




As we all know, certain visibility issues in Ada can make you scratch
your head a bit.  Here's one on which I would appreciate any comments.

What is the best way of thinking about the case of an instantiation of
a generic child package with a constrained generic formal tagged type?
In particular, the visibility of the body of the instance to the
generic child's parent's private part.  Fer'nstance,

Say you have a parent library package thus:

package P is
    type T is abstract tagged limited private;
...
private
    type T is abstract tagged limited record
        F : Some_Type;
    end record;
...
end P;


and then you have a generic child package of P, which requires that
it's formal be constrained to that of some type derived from T:


generic
    type Nt is new T with private;
package P.C is
...
end P.C;


Does P.C have visibility to the field F of any object of type NT??  At
first glance this seems like, "yes, of course - since C is a child of
P".  So, you might have in the body:

package body P.C is
...
    O : NT;
...
    O.F := ... -- (**)
...
end P.C;

And 12.3(11) seems to support this - for the _generic_ unit P.C.  OK,
but now consider an _instance_ of P.C (which _must_ supply a type
derived from P.T):

with P.C;
package Inst_Holder is
    type IT is new P.T with null record;
    package PC_Inst is new P.C(IT);
...
end Inst_Holder;

Does the body of PC_Inst have access to the field F, i.e., is (**)
legal in an instance?  12.3(11) together with 12.3(15) seem to say,
"No way - the properties of IT do not include visibility to F (the 15
bit) and this is checked at compile time for the instantiation (the 11
bit)."  Well, OK.  But now, suppose we make PC_Inst a _child_ of P:

with Inst_Types;
with P.C;
package P.PC_Inst is new P.C(Inst_Types.IT);

Now, 12.3(12) would seem to say that in this case, PC_Inst should have
visibility to F as it should be equivalent to a simple non generic
version and such a version will have access.

What's the scoop?


/Jon
-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

* Re: Generic children, instances and visibility...
  1997-04-09  0:00 Generic children, instances and visibility Jon S Anthony
@ 1997-04-09  0:00 ` Stephen Leake
  1997-04-09  0:00   ` Jon S Anthony
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 1997-04-09  0:00 UTC (permalink / raw)



Jon asks about visibility into a private type within a generic body. I
constructed a compilable example:

package Parent is
   type T is abstract tagged limited private;
private
   type T is abstract tagged limited record
      F : Integer;
   end record;
end Parent;

generic
   type Nt is new T with private;
package Parent.Child is

   procedure Foo (Object : in out Nt);

end Parent.Child;

package body Parent.Child is
   procedure Foo (Object : in out Nt)
   is begin
      Object.F := 1;
   end Foo;
end Parent.Child;

Jon then tries to instantiate this in two ways:

with Parent.Child;
with Inst_Types;
procedure test is
   package PC_Inst is new Parent.Child (Inst_Types.It);
begin
   null;
end test;

with Parent.Child;
with Inst_Types;
package Parent.PC_Inst is new Parent.Child (Inst_Types.It);

gnat says neither case allows visibility:

gnatmake test.adb
gcc -c test.adb
test.adb:4:04: instantiation error at parent-child.adb:4
test.adb:4:04: undefined selector for type "It" defined at
inst_types.ads:3
gnatmake: "test.adb" compilation error


gnatmake parent-pc_inst.ads
gcc -c parent-pc_inst.ads
parent-pc_inst.ads:3:01: instantiation error at parent-child.adb:4
parent-pc_inst.ads:3:01: undefined selector for type "It" defined at
inst_types.ads:3
gnatmake: "parent-pc_inst.ads" compilation error

So, hoping that a private child would have visibility, I tried a third
variation:

with Parent.Child;
with Inst_Types;
private package Parent.Test is
   type It is new Parent.T with null record;

   package PC_Inst is new Parent.Child (Inst_Types.It);

end Parent.Test;

It would seem that no generic can see inside type It; it is a limited
private type, period.
-- 
- Stephe




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

* Re: Generic children, instances and visibility...
  1997-04-09  0:00   ` Jon S Anthony
@ 1997-04-12  0:00     ` Tucker Taft
  1997-04-13  0:00     ` Jon S Anthony
  1 sibling, 0 replies; 5+ messages in thread
From: Tucker Taft @ 1997-04-12  0:00 UTC (permalink / raw)



Jon S Anthony (jsa@alexandria) wrote:

: In article <334BA5F2.4111@gsfc.nasa.gov> Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

: > with Parent.Child;
: > with Inst_Types;
: > package Parent.PC_Inst is new Parent.Child (Inst_Types.It);
: > 
: > gnat says neither case allows visibility:

: True.  But that may or may not be accurate (though it probably is...)

Since GNAT does not complain when you compile the generic,
it should not complain when you compile the instantiation.
Any error during instantiation is suspicious, given the Ada 95
generic "contract" model.  If there is an error, it must be something
that is due to a usage of the formal type in the spec of the generic,
not the body.  Hence this looks like a compiler bug (albeit a subtle one).

: ...
: Tucker, Bob, Norman - any comments appreciated.

See above.

: /Jon
: -- 
: Jon Anthony
: Organon Motives, Inc.
: Belmont, MA 02178
: 617.484.3383
: jsa@organon.com

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




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

* Re: Generic children, instances and visibility...
  1997-04-09  0:00   ` Jon S Anthony
  1997-04-12  0:00     ` Tucker Taft
@ 1997-04-13  0:00     ` Jon S Anthony
  1 sibling, 0 replies; 5+ messages in thread
From: Jon S Anthony @ 1997-04-13  0:00 UTC (permalink / raw)



In article <E8IzEL.2L1.0.-s@inmet.camb.inmet.com> stt@houdini.camb.inmet.com (Tucker Taft) writes:

> : > with Parent.Child;
> : > with Inst_Types;
> : > package Parent.PC_Inst is new Parent.Child (Inst_Types.It);
> : > 
> : > gnat says neither case allows visibility:
> 
> : True.  But that may or may not be accurate (though it probably is...)
> 
> Since GNAT does not complain when you compile the generic,
> it should not complain when you compile the instantiation.
> Any error during instantiation is suspicious, given the Ada 95
> generic "contract" model.

OK, thinking about it that way makes a good deal of sense.  What has
me puzzled a bit is the status of the instantiation in the subsystem
hierarchy.  In particular, shouldn't _only_ the above sort of
instantiation (where the instance _is_ a child of Parent) have
visibility to such private fields?  I see your point about the
contract model and that would seem to indicate that the answer to my
question is "no".  But then how does that jibe with the fact that only
children of the parent can see into its private part???


> If there is an error, it must be something that is due to a usage of
> the formal type in the spec of the generic, not the body.  Hence
> this looks like a compiler bug (albeit a subtle one).

I've convinced myself that this is a bug and your comments reinforce
that conviction.  But, in the cases given the formal type is not even
mentioned in the spec - maybe that's the "abnormal" useage???


> : Tucker, Bob, Norman - any comments appreciated.
> 
> See above.

Check.  Thanks,

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





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

end of thread, other threads:[~1997-04-13  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-09  0:00 Generic children, instances and visibility Jon S Anthony
1997-04-09  0:00 ` Stephen Leake
1997-04-09  0:00   ` Jon S Anthony
1997-04-12  0:00     ` Tucker Taft
1997-04-13  0:00     ` Jon S Anthony

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