comp.lang.ada
 help / color / mirror / Atom feed
* Visibility of package parameters in child packages
@ 2009-12-15 19:28 Andrea Taverna
  2009-12-15 21:00 ` Georg Bauhaus
  2009-12-16 21:27 ` Adam Beneschan
  0 siblings, 2 replies; 13+ messages in thread
From: Andrea Taverna @ 2009-12-15 19:28 UTC (permalink / raw)


Hello everyone,

I have the following packages:


generic
	with package P is new Q (<>);
	use P;
package Parent is
...
end Parent;

generic
Parent.Child is
...
end Parent.Child;


I can see P declarations inside Parent, but in Child I need to prefix
everything with 'P.', even if I add a use-clause.
This happens with gnat-4.3.0 .
Is it normal? How can I "use" P inside Child?

thanks

Andrea



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

* Re: Visibility of package parameters in child packages
  2009-12-15 19:28 Visibility of package parameters in child packages Andrea Taverna
@ 2009-12-15 21:00 ` Georg Bauhaus
  2009-12-16 11:50   ` Andrea Taverna
  2009-12-16 21:27 ` Adam Beneschan
  1 sibling, 1 reply; 13+ messages in thread
From: Georg Bauhaus @ 2009-12-15 21:00 UTC (permalink / raw)


Andrea Taverna schrieb:

> generic
> 	with package P is new Q (<>);
> 	use P;
> package Parent is
> ...
> end Parent;
> 
> generic
> Parent.Child is
> ...
> end Parent.Child;
> 
> 
> I can see P declarations inside Parent, but in Child I need to prefix
> everything with 'P.', even if I add a use-clause.
> This happens with gnat-4.3.0 .
> Is it normal? How can I "use" P inside Child?

generic
Parent.Child is
  use P;
end Parent.Child;




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

* Re: Visibility of package parameters in child packages
  2009-12-15 21:00 ` Georg Bauhaus
@ 2009-12-16 11:50   ` Andrea Taverna
  2009-12-16 13:14     ` Georg Bauhaus
  2009-12-17  0:19     ` Randy Brukardt
  0 siblings, 2 replies; 13+ messages in thread
From: Andrea Taverna @ 2009-12-16 11:50 UTC (permalink / raw)


On 15 Dic, 22:00, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
> Andrea Taverna schrieb:
>
>
>
> > generic
> >    with package P is new Q (<>);
> >    use P;
> > package Parent is
> > ...
> > end Parent;
>
> > generic
> > Parent.Child is
> > ...
> > end Parent.Child;
>
> > I can see P declarations inside Parent, but in Child I need to prefix
> > everything with 'P.', even if I add a use-clause.
> > This happens with gnat-4.3.0 .
> > Is it normal? How can I "use" P inside Child?
>
> generic
> Parent.Child is
>   use P;
> end Parent.Child;

I compiled the following
-----%<-----%<-----%<-----%<-----%<
-- SIGNATURE PACKAGE
generic
   type T is private;
   with function F(X : T) return T;
package Q is end Q;

-- PARENT
with Q;
with Ada.Text_IO;
 generic
    with package P is new Q(<>);
    use P;
 package Parent is

    procedure A (X : T);
 end Parent;

 package body Parent is

    procedure A (X : T) is
       C : T := F(X);
    begin
       Ada.Text_IO("Hello");
    end A;

 end Parent;

-- CHILD
 generic
 package Parent.Child is
    use P;
    function B(X : T) return T;
 end Parent.Child;

 package body Parent.Child is

function B(X : T) return T is
   use P;
       D : T := F(X);
    begin
       return F(D);
    end B;
end Parent.Child;

-- INSTANTIATION
 with Parent.Child;
 with Q;

 procedure Main is
    function Incf(X : Integer) return Integer is begin  return X + 1;
end Incf;
    package R is new Q(Integer, Incf);
    package Par is new Parent(R);
    package Ch is new Par.Child;
 begin
    null;
 end Main;
-----%<-----%<-----%<-----%<-----%<

and the compiler replied

-----%<-----%<-----%<-----%<-----%<
]# gnatmake main.adb
gcc -c main.adb
main.adb:9:05: instantiation error at parent-child.adb:6
main.adb:9:05: "F" is not visible (more references follow)
main.adb:9:05: instantiation error at parent-child.adb:6
main.adb:9:05: non-visible declaration at q.ads:3
gnatmake: "main.adb" compilation error
-----%<-----%<-----%<-----%<-----%<

Am I missing something?



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

* Re: Visibility of package parameters in child packages
  2009-12-16 11:50   ` Andrea Taverna
@ 2009-12-16 13:14     ` Georg Bauhaus
  2009-12-16 14:21       ` Andrea Taverna
  2009-12-17  0:19     ` Randy Brukardt
  1 sibling, 1 reply; 13+ messages in thread
From: Georg Bauhaus @ 2009-12-16 13:14 UTC (permalink / raw)


Andrea Taverna schrieb:

> and the compiler replied
> 
> -----%<-----%<-----%<-----%<-----%<
> ]# gnatmake main.adb
> gcc -c main.adb
> main.adb:9:05: instantiation error at parent-child.adb:6
> main.adb:9:05: "F" is not visible (more references follow)
> main.adb:9:05: instantiation error at parent-child.adb:6
> main.adb:9:05: non-visible declaration at q.ads:3
> gnatmake: "main.adb" compilation error
> -----%<-----%<-----%<-----%<-----%<
> 
> Am I missing something?

It's not a "use" issue I think.  P.F is marked invisible,
too.  Can you try this:

generic
   with package P is new Q(<>);
   use P;
package Parent is

   function P_F(X : P.T) return P.T
     renames P.F;


and then call P_F in place of F.

I think it has (remotely?) to do with an issue hat Eric Hughes
had with Ada formal packages when trying C++ patterns;
IIRC, it was not reported to the producers of the compiler.
Also, there seems to have been some change in Ada 2005 LRM
12.7 from Ada 95 around the (<>) of a generic formal package,
but I don't know whether that is matters here.



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

* Re: Visibility of package parameters in child packages
  2009-12-16 13:14     ` Georg Bauhaus
@ 2009-12-16 14:21       ` Andrea Taverna
  2009-12-16 15:54         ` Georg Bauhaus
  0 siblings, 1 reply; 13+ messages in thread
From: Andrea Taverna @ 2009-12-16 14:21 UTC (permalink / raw)


On 16 Dic, 14:14, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
> Andrea Taverna schrieb:
>
> > and the compiler replied
>
> > -----%<-----%<-----%<-----%<-----%<
> > ]# gnatmake main.adb
> > gcc -c main.adb
> > main.adb:9:05: instantiation error at parent-child.adb:6
> > main.adb:9:05: "F" is not visible (more references follow)
> > main.adb:9:05: instantiation error at parent-child.adb:6
> > main.adb:9:05: non-visible declaration at q.ads:3
> > gnatmake: "main.adb" compilation error
> > -----%<-----%<-----%<-----%<-----%<
>
> > Am I missing something?
>
> It's not a "use" issue I think.  P.F is marked invisible,
> too.
I'm not sure I understand you correctly here, however P.F *is*
visible, in fact the compiler stops complaining after prefixig P's
name to F.

>  Can you try this:
>
> generic
>    with package P is new Q(<>);
>    use P;
> package Parent is
>
>    function P_F(X : P.T) return P.T
>      renames P.F;
>
> and then call P_F in place of F.

I'd rather rename P to a shorter name.

thanks,

Andrea



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

* Re: Visibility of package parameters in child packages
  2009-12-16 14:21       ` Andrea Taverna
@ 2009-12-16 15:54         ` Georg Bauhaus
  2009-12-16 16:54           ` Andrea Taverna
  0 siblings, 1 reply; 13+ messages in thread
From: Georg Bauhaus @ 2009-12-16 15:54 UTC (permalink / raw)


Andrea Taverna schrieb:
> On 16 Dic, 14:14, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
>> Andrea Taverna schrieb:
>>
>>> and the compiler replied
>>> -----%<-----%<-----%<-----%<-----%<
>>> ]# gnatmake main.adb
>>> gcc -c main.adb
>>> main.adb:9:05: instantiation error at parent-child.adb:6
>>> main.adb:9:05: "F" is not visible (more references follow)
>>> main.adb:9:05: instantiation error at parent-child.adb:6
>>> main.adb:9:05: non-visible declaration at q.ads:3
>>> gnatmake: "main.adb" compilation error
>>> -----%<-----%<-----%<-----%<-----%<
>>> Am I missing something?
>> It's not a "use" issue I think.  P.F is marked invisible,
>> too.
> I'm not sure I understand you correctly here, however P.F *is*
> visible, in fact the compiler stops complaining after prefixig P's
> name to F.

My mistake, sorry. (I had forgotton to prefix the other F.)

Is the question then whether or not "use" of a generic
formal package extends to the formal parameters of the
generic formal package (a formal package with a (<>))?

My best guess would be to start from Ada 95 12.7(10),
if that still applies, but I simply don't know, and I
don't have my other compiler handy which might give a more
detailed error message.



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

* Re: Visibility of package parameters in child packages
  2009-12-16 15:54         ` Georg Bauhaus
@ 2009-12-16 16:54           ` Andrea Taverna
  2009-12-16 18:54             ` Georg Bauhaus
  2009-12-16 21:26             ` sjw
  0 siblings, 2 replies; 13+ messages in thread
From: Andrea Taverna @ 2009-12-16 16:54 UTC (permalink / raw)


On 16 Dic, 16:54, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
> Andrea Taverna schrieb:
>
>
>
> > On 16 Dic, 14:14, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
> >> Andrea Taverna schrieb:
>
> >>> and the compiler replied
> >>> -----%<-----%<-----%<-----%<-----%<
> >>> ]# gnatmake main.adb
> >>> gcc -c main.adb
> >>> main.adb:9:05: instantiation error at parent-child.adb:6
> >>> main.adb:9:05: "F" is not visible (more references follow)
> >>> main.adb:9:05: instantiation error at parent-child.adb:6
> >>> main.adb:9:05: non-visible declaration at q.ads:3
> >>> gnatmake: "main.adb" compilation error
> >>> -----%<-----%<-----%<-----%<-----%<
> >>> Am I missing something?
> >> It's not a "use" issue I think.  P.F is marked invisible,
> >> too.
> > I'm not sure I understand you correctly here, however P.F *is*
> > visible, in fact the compiler stops complaining after prefixig P's
> > name to F.
>
> My mistake, sorry. (I had forgotton to prefix the other F.)
>
> Is the question then whether or not "use" of a generic
> formal package extends to the formal parameters of the
> generic formal package (a formal package with a (<>))?

Hmm... I know that they are already visible in Parent as soon as I add
the use-clause. The problem is whether I can "use" the generic formal
package in a child of the generic package of which is a parameter.The
fact the package itself is visible in every children of such package
would suggest that I could.

> My best guess would be to start from Ada 95 12.7(10),
> if that still applies, but I simply don't know, and I
> don't have my other compiler handy which might give a more
> detailed error message.
Please bear some patience, I'ma self-thaught newbie.
http://www.adapower.com/adapower1/rm95/arm95_187.html
In Ada95 12.7 there seems not to be anything relevant about such
problem. What does the "(10)" mean?

thanks

Andrea



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

* Re: Visibility of package parameters in child packages
  2009-12-16 16:54           ` Andrea Taverna
@ 2009-12-16 18:54             ` Georg Bauhaus
  2009-12-16 21:44               ` Adam Beneschan
  2009-12-16 21:26             ` sjw
  1 sibling, 1 reply; 13+ messages in thread
From: Georg Bauhaus @ 2009-12-16 18:54 UTC (permalink / raw)


Andrea Taverna schrieb:
> On 16 Dic, 16:54, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
>> Andrea Taverna schrieb:
>>
>>
>>
>>> On 16 Dic, 14:14, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:
>>>> Andrea Taverna schrieb:
>>>>> and the compiler replied
>>>>> -----%<-----%<-----%<-----%<-----%<
>>>>> ]# gnatmake main.adb
>>>>> gcc -c main.adb
>>>>> main.adb:9:05: instantiation error at parent-child.adb:6
>>>>> main.adb:9:05: "F" is not visible (more references follow)
>>>>> main.adb:9:05: instantiation error at parent-child.adb:6
>>>>> main.adb:9:05: non-visible declaration at q.ads:3
>>>>> gnatmake: "main.adb" compilation error
>>>>> -----%<-----%<-----%<-----%<-----%<
>>>>> Am I missing something?
>>>> It's not a "use" issue I think.  P.F is marked invisible,
>>>> too.
>>> I'm not sure I understand you correctly here, however P.F *is*
>>> visible, in fact the compiler stops complaining after prefixig P's
>>> name to F.
>> My mistake, sorry. (I had forgotton to prefix the other F.)
>>
>> Is the question then whether or not "use" of a generic
>> formal package extends to the formal parameters of the
>> generic formal package (a formal package with a (<>))?
> 
> Hmm... I know that they are already visible in Parent as soon as I add
> the use-clause. The problem is whether I can "use" the generic formal
> package in a child of the generic package of which is a parameter.The
> fact the package itself is visible in every children of such package
> would suggest that I could.

My idea, possibly confused, is that somehow the
formal parameter F of generic package Q is not made visible
in Parent.Child.

With LRM 95 12.7(10) in mind,

generic
   with package P is new Q (<>);
   ...
package Parent...

means, I think, that the parameters for which (<>) stands
are included in visibility decisions.


> http://www.adapower.com/adapower1/rm95/arm95_187.html

(The paragraph numbering on that page is a bit different from
what is normally used in the RM. (10) means the tenth paragraph
which happens to be "Static Semantics, 2nd", on adapower.com)

"The visible part of a formal package includes the first
list of basic_declarative_items of the package_specification.
In addition, if the formal_package_actual_part is (<>),
it also includes the generic_formal_part of the template
for the formal package."

P is the formal package with formal_package_actual_part (<>).
Q is the template, F is in Qs generic_format_part.
So F should be as visible as anything specified in P.
But I'm a layman, hopefully some expert can explain all this.




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

* Re: Visibility of package parameters in child packages
  2009-12-16 16:54           ` Andrea Taverna
  2009-12-16 18:54             ` Georg Bauhaus
@ 2009-12-16 21:26             ` sjw
  1 sibling, 0 replies; 13+ messages in thread
From: sjw @ 2009-12-16 21:26 UTC (permalink / raw)


On Dec 16, 4:54 pm, Andrea Taverna <a.t...@hotmail.it> wrote:

> Please bear some patience, I'ma self-thaught newbie.http://www.adapower.com/adapower1/rm95/arm95_187.html
> In Ada95 12.7 there seems not to be anything relevant about such
> problem. What does the "(10)" mean?

That's not a very good copy of the RM (I don't know where the pages
originated). A much better one is at http://www.adaic.com/standards/95lrm/html/RM-12-7.html
-- "(10)" means paragraph 10, preceded at the left with a small '10'.

I don't recall exactly why you want to 'use P;'? Personally I wouldn't
even be tempted to do so; many bad experiences with similar usages!
Even discounting compiler errors/bombs, consider:

- what happens if there's another F (with the same profile) visible?
- what happens if you change P so it no longer has an F (with a
matching profile)?



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

* Re: Visibility of package parameters in child packages
  2009-12-15 19:28 Visibility of package parameters in child packages Andrea Taverna
  2009-12-15 21:00 ` Georg Bauhaus
@ 2009-12-16 21:27 ` Adam Beneschan
  1 sibling, 0 replies; 13+ messages in thread
From: Adam Beneschan @ 2009-12-16 21:27 UTC (permalink / raw)


On Dec 15, 11:28 am, Andrea Taverna <a.t...@hotmail.it> wrote:
> Hello everyone,
>
> I have the following packages:
>
> generic
>         with package P is new Q (<>);
>         use P;
> package Parent is
> ...
> end Parent;
>
> generic
> Parent.Child is
> ...
> end Parent.Child;
>
> I can see P declarations inside Parent, but in Child I need to prefix
> everything with 'P.', even if I add a use-clause.
> This happens with gnat-4.3.0 .
> Is it normal?

It's a bug.  The scope of the "use P" is supposed to include
Parent.Child (8.1(9), 8.4(7)).

                            -- Adam



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

* Re: Visibility of package parameters in child packages
  2009-12-16 18:54             ` Georg Bauhaus
@ 2009-12-16 21:44               ` Adam Beneschan
  0 siblings, 0 replies; 13+ messages in thread
From: Adam Beneschan @ 2009-12-16 21:44 UTC (permalink / raw)


On Dec 16, 10:54 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:

> My idea, possibly confused, is that somehow the
> formal parameter F of generic package Q is not made visible
> in Parent.Child.
>
> With LRM 95 12.7(10) in mind,
>
> generic
>    with package P is new Q (<>);
>    ...
> package Parent...
>
> means, I think, that the parameters for which (<>) stands
> are included in visibility decisions.
>
> >http://www.adapower.com/adapower1/rm95/arm95_187.html
>
> (The paragraph numbering on that page is a bit different from
> what is normally used in the RM. (10) means the tenth paragraph
> which happens to be "Static Semantics, 2nd", on adapower.com)

Be careful here.  (10) is not necessarily the tenth paragraph, because
additions to the languages have caused paragraphs to be inserted,
which are then given numbers like (4.1), (5.1), etc.  In the Ada 2005
manual, 12.7(10) is actually the 18th paragraph of section 12.7.  The
RM available at www.adaic.org/standards has the official paragraph
numbers.

> "The visible part of a formal package includes the first
> list of basic_declarative_items of the package_specification.
> In addition, if the formal_package_actual_part is (<>),
> it also includes the generic_formal_part of the template
> for the formal package.">
> P is the formal package with formal_package_actual_part (<>).
> Q is the template, F is in Qs generic_format_part.
> So F should be as visible as anything specified in P.
> But I'm a layman, hopefully some expert can explain all this

You're right that F should be as visible as anything else visible in
P.  The official rule in Ada 2005 is "for each actual parameter that
is not required to match, a copy of the declaration of the
corresponding formal parameter of the template is included in the
visible part of the formal package."  Thus, in the declaration

  with package P is new Q(<>);

the formal package P will have copies of T and F in the visible part
of P, in addition to the other stuff copied from the visible part of
Q.  Thus, "use P" should make T and F directly visible just as other
declarations in the visible part of P would be directly visible.

In answer to your previous question: Ada 2005 did change this, but it
extended this by allowing generic formal packages in which some formal
parameters were required to match but others were not.  This change
didn't affect the semantics of formal packages that were legal in Ada
95.

                              -- Adam




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

* Re: Visibility of package parameters in child packages
  2009-12-16 11:50   ` Andrea Taverna
  2009-12-16 13:14     ` Georg Bauhaus
@ 2009-12-17  0:19     ` Randy Brukardt
  2009-12-17 18:50       ` Ludovic Brenta
  1 sibling, 1 reply; 13+ messages in thread
From: Randy Brukardt @ 2009-12-17  0:19 UTC (permalink / raw)


"Andrea Taverna" <a.tavs@hotmail.it> wrote in message 
news:02e4d172-0eb9-4c2a-ac0f-68e151916d59@o19g2000vbj.googlegroups.com...
...
>-----%<-----%<-----%<-----%<-----%<
>]# gnatmake main.adb
>gcc -c main.adb
>main.adb:9:05: instantiation error at parent-child.adb:6
>main.adb:9:05: "F" is not visible (more references follow)
>main.adb:9:05: instantiation error at parent-child.adb:6
>main.adb:9:05: non-visible declaration at q.ads:3
>gnatmake: "main.adb" compilation error
>-----%<-----%<-----%<-----%<-----%<

I haven't studied this code carefully, but this error message suggests to me 
that the compiler has a bug. An instantiation should never, ever be illegal 
because of something that occurs in the body of the generic. Legality rules 
don't apply to generic bodies at instantiation time (only when the generic 
unit is compiled).

It's possible that the compiler has delayed the compilation of the body to 
the point of the instantation, but even then, the error (if there is one, 
and I don't think there is) belongs to the body, not the instantiation. So 
at the very least the error message is misleading.

So I suggest reporting this to your vendor and see what they say. (And I'm 
glad I'm not your vendor in this case, 'cause I wouldn't want to have to 
debug this one. ;-)

                                   Randy.







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

* Re: Visibility of package parameters in child packages
  2009-12-17  0:19     ` Randy Brukardt
@ 2009-12-17 18:50       ` Ludovic Brenta
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Brenta @ 2009-12-17 18:50 UTC (permalink / raw)


Randy Brukardt wrote on comp.lang.ada:
> "Andrea Taverna" wrote:
> >-----%<-----%<-----%<-----%<-----%<
> >]# gnatmake main.adb
> >gcc -c main.adb
> >main.adb:9:05: instantiation error at parent-child.adb:6
> >main.adb:9:05: "F" is not visible (more references follow)
> >main.adb:9:05: instantiation error at parent-child.adb:6
> >main.adb:9:05: non-visible declaration at q.ads:3
> >gnatmake: "main.adb" compilation error
> >-----%<-----%<-----%<-----%<-----%<
>
> I haven't studied this code carefully, but this error message suggests to me
> that the compiler has a bug. An instantiation should never, ever be illegal
> because of something that occurs in the body of the generic. Legality rules
> don't apply to generic bodies at instantiation time (only when the generic
> unit is compiled).
>
> It's possible that the compiler has delayed the compilation of the body to
> the point of the instantation, but even then, the error (if there is one,
> and I don't think there is) belongs to the body, not the instantiation. So
> at the very least the error message is misleading.
>
> So I suggest reporting this to your vendor and see what they say. (And I'm
> glad I'm not your vendor in this case, 'cause I wouldn't want to have to
> debug this one. ;-)

Could it be http://gcc.gnu.org/PR16078 ? This has just been brought to
my attention.

--
Ludovic Brenta.



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

end of thread, other threads:[~2009-12-17 18:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-15 19:28 Visibility of package parameters in child packages Andrea Taverna
2009-12-15 21:00 ` Georg Bauhaus
2009-12-16 11:50   ` Andrea Taverna
2009-12-16 13:14     ` Georg Bauhaus
2009-12-16 14:21       ` Andrea Taverna
2009-12-16 15:54         ` Georg Bauhaus
2009-12-16 16:54           ` Andrea Taverna
2009-12-16 18:54             ` Georg Bauhaus
2009-12-16 21:44               ` Adam Beneschan
2009-12-16 21:26             ` sjw
2009-12-17  0:19     ` Randy Brukardt
2009-12-17 18:50       ` Ludovic Brenta
2009-12-16 21:27 ` Adam Beneschan

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