comp.lang.ada
 help / color / mirror / Atom feed
* GNAT: no visible subprogram matches the specification for "Put"
@ 2019-10-04 18:53 Vincent Marciante
  2019-10-05 10:50 ` Stephen Leake
  0 siblings, 1 reply; 11+ messages in thread
From: Vincent Marciante @ 2019-10-04 18:53 UTC (permalink / raw)


Hi all,

I think that I might be hitting a GNAT defect but am not sure.
I already have a work-around but wanted some feedback before 
I go through channels to submit this to Adacore (if actually 
a defect.)  Maybe I am missing some overloading rule but I 
think that the following should compile and run: one part that 
appears in the middle does compile and does produce the expected
output but the second to last unit does not compile useing a 
GNATPRO 19 series compiler.  That place is marked with --Builder
results.

So, should all of the following be compilable?

with Ada.Text_IO;

package Ada_Text_IO_Adaptor is

  procedure Put
           (X    : in Integer;
            Base : in Ada.Text_IO.Number_Base);

  procedure New_Line;

end Ada_Text_IO_Adaptor;

-------

with Ada.Integer_Text_IO;

package body Ada_Text_IO_Adaptor is

  procedure Put
           (X    : in Integer;
            Base : in Ada.Text_IO.Number_Base) is
  begin
    Ada.Integer_Text_IO.Put(Item=>X,Base=>Base);
  end Put;

  procedure New_Line is
  begin
    Ada.Text_IO.New_Line;
  end New_Line;

end Ada_Text_IO_Adaptor;

-------

generic

  type Number_Base is range <>;
  Default_Base : Number_Base;

  with procedure Put      (X    : in Integer;
                           Base : in Number_Base 
                                  := Default_Base) is <>;
  with procedure Put      (X    : in String) is <>;
  with procedure Put_Line (X    : in String) is <>;
  with procedure New_Line is <>;

package Signature_Package_Generic is end;

-------

with Ada.Text_IO, Ada.Integer_Text_IO, Ada_Text_IO_Adaptor;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada_Text_IO_Adaptor;

with Signature_Package_Generic;

package Signature_Package_Instance is
    new Signature_Package_Generic
                         (Number_Base  => Ada.Text_IO.Number_Base,
                          Default_Base => 10);

-------

with Signature_Package_Generic;
generic
  with package Instance is new Signature_Package_Generic(<>);
procedure Signature_Package_Instance_Test_Generic;

-------

procedure Signature_Package_Instance_Test_Generic is
begin 
  Instance.New_Line;
  Instance.Put_Line("Direct Instance Put_Line(""string"")");
  Instance.Put     ("Direct Instance Put     (""string"")");
end;

-------

with      Signature_Package_Instance;
with      Signature_Package_Instance_Test_Generic;
procedure Signature_Package_Instance_Test is 
      new Signature_Package_Instance_Test_Generic
         (Signature_Package_Instance); --compiles and runs as expected

-------

with Signature_Package_Generic;
generic
  with package Instance is new Signature_Package_Generic(<>);
package Signature_Package_Reexport_Generic is

  subtype Number_Base is Instance.Number_Base;
  Default_Base : Number_Base := Instance.Default_Base;

  procedure Put      (X    : in Integer;
                      Base : in Number_Base
                             := Default_Base) renames Instance. Put;
  procedure Put      (X    : in String)       renames Instance. Put; -- instantiation error
  procedure Put_Line (X    : in String)       renames Instance. Put_Line;
  procedure New_Line                          renames Instance. New_Line;

end Signature_Package_Reexport_Generic;

-------

with    Signature_Package_Instance;
with    Signature_Package_Reexport_Generic;
package Signature_Package_Reexport_Instance is
    new Signature_Package_Reexport_Generic
       (Signature_Package_Instance);
--Builder results
--    Signature_Package_Reexport_Instance.ads
--        108:1 instantiation error at  signature_package_reexport_generic.ads:98
--        108:1 no visible subprogram matches the specification for "Put"

-------

with      Signature_Package_Reexport_Instance;
procedure Signature_Package_Reexport_Test is
begin 
  Signature_Package_Reexport_Instance.New_Line;
  Signature_Package_Reexport_Instance.Put_Line("Reexport Put_Line(""string"")");
  Signature_Package_Reexport_Instance.Put     ("Reexport Put     (""string"")");
end;


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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-04 18:53 GNAT: no visible subprogram matches the specification for "Put" Vincent Marciante
@ 2019-10-05 10:50 ` Stephen Leake
  2019-10-06 11:45   ` marciant
  0 siblings, 1 reply; 11+ messages in thread
From: Stephen Leake @ 2019-10-05 10:50 UTC (permalink / raw)


On Friday, October 4, 2019 at 11:53:34 AM UTC-7, Vincent Marciante wrote:
> Hi all,
> 
> I think that I might be hitting a GNAT defect but am not sure.
> I already have a work-around but wanted some feedback before 
> I go through channels to submit this to Adacore (if actually 
> a defect.)  Maybe I am missing some overloading rule but I 
> think that the following should compile and run: one part that 
> appears in the middle does compile and does produce the expected
> output but the second to last unit does not compile useing a 
> GNATPRO 19 series compiler.  That place is marked with --Builder
> results.
> 
> So, should all of the following be compilable?
> 
> with Ada.Text_IO;
> 
> package Ada_Text_IO_Adaptor is
> 
>   procedure Put
>            (X    : in Integer;
>             Base : in Ada.Text_IO.Number_Base);
> 
>   procedure New_Line;
> 
> end Ada_Text_IO_Adaptor;
> 
> -------
> 
> with Ada.Integer_Text_IO;
> 
> package body Ada_Text_IO_Adaptor is
> 
>   procedure Put
>            (X    : in Integer;
>             Base : in Ada.Text_IO.Number_Base) is
>   begin
>     Ada.Integer_Text_IO.Put(Item=>X,Base=>Base);
>   end Put;
> 
>   procedure New_Line is
>   begin
>     Ada.Text_IO.New_Line;
>   end New_Line;
> 
> end Ada_Text_IO_Adaptor;
> 
> -------
> 
> generic
> 
>   type Number_Base is range <>;
>   Default_Base : Number_Base;
> 
>   with procedure Put      (X    : in Integer;
>                            Base : in Number_Base 
>                                   := Default_Base) is <>;
>   with procedure Put      (X    : in String) is <>;
>   with procedure Put_Line (X    : in String) is <>;
>   with procedure New_Line is <>;
> 
> package Signature_Package_Generic is end;
> 
> -------
> 
> with Ada.Text_IO, Ada.Integer_Text_IO, Ada_Text_IO_Adaptor;
>  use Ada.Text_IO, Ada.Integer_Text_IO, Ada_Text_IO_Adaptor;
> 
> with Signature_Package_Generic;
> 
> package Signature_Package_Instance is
>     new Signature_Package_Generic
>                          (Number_Base  => Ada.Text_IO.Number_Base,
>                           Default_Base => 10);
> 
> -------
> 
> with Signature_Package_Generic;
> generic
>   with package Instance is new Signature_Package_Generic(<>);
> procedure Signature_Package_Instance_Test_Generic;
> 
> -------
> 
> procedure Signature_Package_Instance_Test_Generic is
> begin 
>   Instance.New_Line;
>   Instance.Put_Line("Direct Instance Put_Line(""string"")");
>   Instance.Put     ("Direct Instance Put     (""string"")");
> end;
> 
> -------
> 
> with      Signature_Package_Instance;
> with      Signature_Package_Instance_Test_Generic;
> procedure Signature_Package_Instance_Test is 
>       new Signature_Package_Instance_Test_Generic
>          (Signature_Package_Instance); --compiles and runs as expected
> 
> -------
> 
> with Signature_Package_Generic;
> generic
>   with package Instance is new Signature_Package_Generic(<>);
> package Signature_Package_Reexport_Generic is
> 
>   subtype Number_Base is Instance.Number_Base;
>   Default_Base : Number_Base := Instance.Default_Base;
> 
>   procedure Put      (X    : in Integer;
>                       Base : in Number_Base
>                              := Default_Base) renames Instance. Put;
>   procedure Put      (X    : in String)       renames Instance. Put; -- instantiation error
>   procedure Put_Line (X    : in String)       renames Instance. Put_Line;
>   procedure New_Line                          renames Instance. New_Line;
> 
> end Signature_Package_Reexport_Generic;
> 
> -------
> 
> with    Signature_Package_Instance;
> with    Signature_Package_Reexport_Generic;
> package Signature_Package_Reexport_Instance is
>     new Signature_Package_Reexport_Generic
>        (Signature_Package_Instance);
> --Builder results
> --    Signature_Package_Reexport_Instance.ads
> --        108:1 instantiation error at  signature_package_reexport_generic.ads:98
> --        108:1 no visible subprogram matches the specification for "Put"
> 
> -------
> 
> with      Signature_Package_Reexport_Instance;
> procedure Signature_Package_Reexport_Test is
> begin 
>   Signature_Package_Reexport_Instance.New_Line;
>   Signature_Package_Reexport_Instance.Put_Line("Reexport Put_Line(""string"")");
>   Signature_Package_Reexport_Instance.Put     ("Reexport Put     (""string"")");
> end;

What "Put" do you think is visible at the declaration of Signature_Package_Reexport_Instance? There is no "use" clause in effect.

--  Stephe

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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-05 10:50 ` Stephen Leake
@ 2019-10-06 11:45   ` marciant
  2019-10-07 11:55     ` vincent.marciante
  2019-10-07 15:03     ` Stephen Leake
  0 siblings, 2 replies; 11+ messages in thread
From: marciant @ 2019-10-06 11:45 UTC (permalink / raw)


I think that both are: both the one that can be passed a string and the one that 
can be passed an integer.  I thing that the "test signature" procedure at least 
shows that the string one and the put_line one should be visible because it
runs as expected and the string one is the one that GNAT is complaining about.
I am thinking that GNAT's compilation - and my subsequent running - of the
Signature test program would imply that?  Do you agree?


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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-06 11:45   ` marciant
@ 2019-10-07 11:55     ` vincent.marciante
  2019-10-07 15:03     ` Stephen Leake
  1 sibling, 0 replies; 11+ messages in thread
From: vincent.marciante @ 2019-10-07 11:55 UTC (permalink / raw)


(BTW, that was me - the original poster - from my home account.)

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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-06 11:45   ` marciant
  2019-10-07 11:55     ` vincent.marciante
@ 2019-10-07 15:03     ` Stephen Leake
  2019-10-07 19:00       ` Vincent Marciante
  2019-10-07 19:01       ` briot.emmanuel
  1 sibling, 2 replies; 11+ messages in thread
From: Stephen Leake @ 2019-10-07 15:03 UTC (permalink / raw)


On Sunday, October 6, 2019 at 4:45:22 AM UTC-7, marc...@earthlink.net wrote:
> I think that both are: both the one that can be passed a string and the one that 
> can be passed an integer.  I thing that the "test signature" procedure at least 
> shows that the string one and the put_line one should be visible because it
> runs as expected and the string one is the one that GNAT is complaining about.
> I am thinking that GNAT's compilation - and my subsequent running - of the
> Signature test program would imply that?  Do you agree?

To be precise, this works as expected:

$ gnatchop marc.ada # produces individual files from above code
$ gnatmake signature_package_instance_test
$ ./signature_package_instance_test

Direct Instance Put_Line("string")
Direct Instance Put     ("string")

However, this gives a compiler error:

$ gnatmake signature_package_reexport_instance
gcc -c signature_package_reexport_instance.ads
signature_package_reexport_instance.ads:6:01: instantiation error at signature_package_reexport_generic.ads:15
signature_package_reexport_instance.ads:6:01: no visible subprogram matches the specification for "Put"
gnatmake: "signature_package_reexport_instance.ads" compilation error

signature_package_reexport_generic.ads:15 is:

  procedure Put (X: in String) renames Instance. Put; -- instantiation error

"Instance.Put" is the name of a generic parameter of "Signature_Package_Generic".

The visibility of generic formal parameters outside the generic body is problematic in GNAT. LRM 8.2 (8) says:
   
      * The visible part of a generic unit includes the
     generic_formal_part. ...

So your code should work. However, I've often had problems referring to them from outside the generic, and the problems seem to change with each version of GNAT. Note that this is not an intended use of the generic formal parameters, but it is sometimes useful (if it works).

So I agree this is (probably) a compiler bug.

The fact that signature_package_instance compiles is not relevant; it is not using the name of a generic formal parameter from outside the generic; it is only referring to them in the body of the generic, which is where they are intended to be used.

One workaround is to put a rename declaration in the generic package:

package Signature_Package_Generic is

   procedure Put_Param (X    : in String) renames Put;
end;

then use it in Signature_Package_Reexport_Generic:

  procedure Put      (X    : in String)       renames Instance. Put_Param;

This compiles.

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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-07 15:03     ` Stephen Leake
@ 2019-10-07 19:00       ` Vincent Marciante
  2019-10-07 19:01       ` briot.emmanuel
  1 sibling, 0 replies; 11+ messages in thread
From: Vincent Marciante @ 2019-10-07 19:00 UTC (permalink / raw)


On Monday, October 7, 2019 at 11:03:12 AM UTC-4, Stephen Leake wrote:

<snip>
 
> So your code should work. However, I've often had problems referring to them from outside the generic, and the problems seem to change with each version of GNAT. Note that this is not an intended use of the generic formal parameters, but it is sometimes useful (if it works).
> 
> So I agree this is (probably) a compiler bug.
> 
> The fact that signature_package_instance compiles is not relevant;

I just included the "test" of it to show the GNAT is allowing the 
problematic procedure to be visible to the test procedure but not allowing 
it to be visible to the spec of the re-exporter.  

> it is not using the name of a generic formal parameter from outside the generic; it is only referring to them in the body of the generic, which is where they are intended to be used.

> One workaround is to put a rename declaration in the generic package:

Yes renaming is the workaround that non-posted code is using.

Thanks for having given you bug/nobug opinion. It will be easier for me to
justify bug submission to Adacore now.  


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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-07 15:03     ` Stephen Leake
  2019-10-07 19:00       ` Vincent Marciante
@ 2019-10-07 19:01       ` briot.emmanuel
  2019-10-08 10:01         ` Vincent Marciante
  1 sibling, 1 reply; 11+ messages in thread
From: briot.emmanuel @ 2019-10-07 19:01 UTC (permalink / raw)


> The visibility of generic formal parameters outside the generic body is problematic in GNAT. LRM 8.2 (8) says:

I have had this problem forever too, but I was told by the GNAT and Ada
experts that this was actually expected behavior, though I can never remember
the corresponding parts of the LRM. I think it has to do with whether the user of the generic instance can see what the actual parameters were. So if you pass the signature package as a parameter in the instantiation of another generic, then you can reference the formal parameters, but if the compiler see statically what the actual parameters are, you cannot.

This is a pain point when using generics.

It would be nice if someone (Randy, Bob ?) could confirm one way or the other.


> One workaround is to put a rename declaration in the generic package:

This is indeed the proper workaround, but this is a pain because we have to invent a second name to designated the same thing.

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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-07 19:01       ` briot.emmanuel
@ 2019-10-08 10:01         ` Vincent Marciante
  2019-10-08 14:53           ` Optikos
  0 siblings, 1 reply; 11+ messages in thread
From: Vincent Marciante @ 2019-10-08 10:01 UTC (permalink / raw)


On Monday, October 7, 2019 at 3:01:42 PM UTC-4, briot....@gmail.com wrote:
<snip>
> I have had this problem forever too, but I was told by the GNAT and Ada
> experts that this was actually expected behavior, though I can never remember the corresponding parts of the LRM.

<snip>
 
> This is a pain point when using generics.

New info:  The code works with Object Ada: compiles it without error and
the executable runs as expected!

If the standard in fact requires disallowence, I wonder what "bad" thing is
being prevented/avoided by not allowing the naturally expected, non-painful
behavior.  Might changing the standard to allow it - or be clear that it is allowed - be warranted? 
 
> It would be nice if someone (Randy, Bob ?) could confirm one way or the other.

Yes. Please.


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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-08 10:01         ` Vincent Marciante
@ 2019-10-08 14:53           ` Optikos
  2019-10-08 17:48             ` Björn Lundin
  0 siblings, 1 reply; 11+ messages in thread
From: Optikos @ 2019-10-08 14:53 UTC (permalink / raw)


On Tuesday, October 8, 2019 at 5:01:56 AM UTC-5, Vincent Marciante wrote:
> On Monday, October 7, 2019 at 3:01:42 PM UTC-4, briot....@gmail.com wrote:
> <snip>
> > I have had this problem forever too, but I was told by the GNAT and Ada
> > experts that this was actually expected behavior, though I can never remember the corresponding parts of the LRM.
> 
> <snip>
>  
> > This is a pain point when using generics.
> 
> New info:  The code works with Object Ada: compiles it without error and
> the executable runs as expected!

Excellent work!

> If the standard in fact requires disallowence, I wonder what "bad" thing is
> being prevented/avoided by not allowing the naturally expected, non-painful
> behavior.  Might changing the standard to allow it - or be clear that it is allowed - be warranted? 

Because you can clearly demonstrate 2 different compiler-vendors' diametrically opposing interpretation of the AARM's current wording on this topic, you •must•* submit an AI to the ARG to clarify this.  Hopefully, they will wholeheartedly endorse the ObjectAda interpretation, unless further evidence & reasoning reveals that GNAT's apparent bug is actually the wiser interpretation for some useful purpose.

* for the good of the future Ada community

Better yet, request permission & minor funding from your employer to join the ARG to contribute user-community frustrations (as a pull for better Ada) to supplement the current well-represented population of compiler & tools vendors (as a push for better Ada).

stick:
Even better, create a open-source community of drastically stronger test cases for every word, sentence, and paragraph in the AARM.  Rosetta-stone interlanguage competitions between Ada and other languages are cute, but having an enormous treasure trove of demonstrations of every microfeature of Ada would be an educational goldmine as well as a beneficial environmental Darwinian survival-of-the-fittest stressor on every line of compiler source code at all Ada compiler vendors and on every word/phrase/sentence/paragraph/section of the AARM at ARG.  Perfection is achieved by purification by fire.

carrot:
Even better still, do whatever you can to encourage a strong well-funded competitor to GNAT to emerge (even if you must fork GNAT to do so, as a last resort).

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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-08 14:53           ` Optikos
@ 2019-10-08 17:48             ` Björn Lundin
  2019-10-08 18:47               ` Vincent Marciante
  0 siblings, 1 reply; 11+ messages in thread
From: Björn Lundin @ 2019-10-08 17:48 UTC (permalink / raw)


Den 2019-10-08 kl. 16:53, skrev Optikos:
> Because you can clearly demonstrate 2 different compiler-vendors' diametrically opposing interpretation of the AARM's current wording on this topic, you •must•* submit an AI to the ARG to clarify this.  Hopefully, they will wholeheartedly endorse the ObjectAda interpretation, unless further evidence & reasoning reveals that GNAT's apparent bug is actually the wiser interpretation for some useful purpose.

That code works with one compiler and not with another does not 
automatically mean that the working one is correct.

Migrating to gnat from ObjectaAda and Verdix compilers in 2003/2004 I 
complained to AdaCore about our processes crashing upon start with when 
compiled with gnat.
The issue was related to elaboration

As we have a support contract, the code was looked into by AdaCore,
and they said it was bad code.

Then we argued that it does work with both ObjectAda and with Verdix,
and had been working for many years.

I still remember Robert Dewar's reply.

"You are lucky it works. Your program is highly erroneous"

End of story.
We had to add some pragma Elaborate_all in order to get it working.

And I think gnat was right and the other compilers were wrong.


-- 
Björn


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

* Re: GNAT: no visible subprogram matches the specification for "Put"
  2019-10-08 17:48             ` Björn Lundin
@ 2019-10-08 18:47               ` Vincent Marciante
  0 siblings, 0 replies; 11+ messages in thread
From: Vincent Marciante @ 2019-10-08 18:47 UTC (permalink / raw)


On Tuesday, October 8, 2019 at 1:48:59 PM UTC-4, björn lundin wrote:
> Den 2019-10-08 kl. 16:53, skrev Optikos:
> > Because you can clearly demonstrate 2 different compiler-vendors' diametrically opposing interpretation of the AARM's current wording on this topic, you •must•* submit an AI to the ARG to clarify this.  Hopefully, they will wholeheartedly endorse the ObjectAda interpretation, unless further evidence & reasoning reveals that GNAT's apparent bug is actually the wiser interpretation for some useful purpose.

Agreed!

> 
> That code works with one compiler and not with another does not 
> automatically mean that the working one is correct.

Also agreed!

<snip>

> Then we argued that it does work with both ObjectAda and with Verdix,
> and had been working for many years.
> 
> I still remember Robert Dewar's reply.
> 
> "You are lucky it works. Your program is highly erroneous"
> 
> End of story.

I have also previously reported seemingly wrong behavior of GNAT
with a similar _initial_ response from RBKD - actually just the
last part "Your program is highly erroneous". ;-)
However after c.l.a discussion, he changed his opinion and did make
subsequent changes to GNAT in order accept the code in question!
So there is hope!

(Unfortunately RBKD would not be the one to do it :-(  R.I.P.)

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

end of thread, other threads:[~2019-10-08 18:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 18:53 GNAT: no visible subprogram matches the specification for "Put" Vincent Marciante
2019-10-05 10:50 ` Stephen Leake
2019-10-06 11:45   ` marciant
2019-10-07 11:55     ` vincent.marciante
2019-10-07 15:03     ` Stephen Leake
2019-10-07 19:00       ` Vincent Marciante
2019-10-07 19:01       ` briot.emmanuel
2019-10-08 10:01         ` Vincent Marciante
2019-10-08 14:53           ` Optikos
2019-10-08 17:48             ` Björn Lundin
2019-10-08 18:47               ` Vincent Marciante

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