comp.lang.ada
 help / color / mirror / Atom feed
From: Emmanuel Briot <briot.emmanuel@gmail.com>
Subject: Re: Calling inherited primitive operations in Ada
Date: Thu, 1 Sep 2022 07:10:03 -0700 (PDT)	[thread overview]
Message-ID: <401d6f59-2c28-4dd5-9fa6-fccf33b6d645n@googlegroups.com> (raw)
In-Reply-To: <teqci9$26ntr$1@dont-email.me>

I have seen quite a number of cases of needing the subtype like Dmitry was showing. In a small number of cases, those were actual bugs in GNAT, but most of the time the compiler was correct.
Mostly, you start to see the issue when you have generic packages that have formal generic packages.

Here is a quick example and the corresponding compiler error message. In Main, there is no way to see T. Of course, I can use Integer_Signature
directly, but this is an issue.
   - if I rename Integer_Signature then I have to change a lot of places in my code (The aliasing that Dmitry was talking about)

with Signature;
generic
   with package Sign is new Signature (<>);
package Algo is
   procedure Compute (V : Sign.T) is null;
end Algo;

with Algo;
with Signature;
package Lib is
   package Integer_Signature is new Signature (Integer);
   package Integer_Algo is new Algo (Integer_Signature);
end Lib;


with Lib;
procedure Main is
   V : Lib.Integer_Algo.Sign.T;
   --   main.adb:3:24: "Sign" is not a visible entity of "Integer_Algo"
begin
   null;
end Main;

generic
   type T is private;
package Signature is
end Signature;

There are more interesting examples, somehow this one doesn't seem that bad. So here is another one:

    generic
       type T is private;
    package Gen is
    end Gen;

    with Gen;
    generic
       type T is private;
       with package Must_Match is new Gen (T);
       with package Need_Not_Match is new Gen (<>);
    package Gen2 is
       V1 : Must_Match.T;         --  "T" is not a visible entity of "Must_Match"
       V2 : Need_Not_Match.T;  -- instance of same package, but this time T is visible
    end Gen2;

    with Gen, Gen2;
    procedure P2 is
       package G is new Gen (Integer);
       package G2 is new Gen2 (Integer, G, G);
    begin
       null;
    end P2;




I dug out the explanation that Tucker Taft once sent to the Ada-Comment mailing list (2019-11-14):

<<<
10/2
{AI95-00317-01} The visible part of a formal package includes the first list of basic_declarative_items of the package_specification. In addition, 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. If the copied declaration is for a formal type, copies of the implicit declarations of the primitive subprograms of the formal type are also included in the visible part of the formal package.
10.a/2
Ramification: {AI95-00317-01} If the formal_package_actual_part is (<>), then the declarations that occur immediately within the generic_formal_part of the template for the formal package are visible outside the formal package, and can be denoted by expanded names outside the formal package.If only some of the actual parameters are given by <>, then the declaration corresponding to those parameters (but not the others) are made visible.
10.b/3
Reason: {AI05-0005-1} We always want either the actuals or the formals of an instance to be nameable from outside, but never both. If both were nameable, one would get some funny anomalies since they denote the same entity, but, in the case of types at least, they might have different and inconsistent sets of primitive operators due to predefined operator “reemergence.” Formal derived types exacerbate the difference. We want the implicit declarations of the generic_formal_part as well as the explicit declarations, so we get operations on the formal types.  
>>>

  reply	other threads:[~2022-09-01 14:10 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31  8:15 Calling inherited primitive operations in Ada Emmanuel Briot
2022-08-31 17:11 ` DrPi
2022-08-31 19:13 ` Dmitry A. Kazakov
2022-09-01  6:56   ` Emmanuel Briot
     [not found]     ` <67b32db0-c4db-466c-ac13-e597e008c762n@googlegroups.com>
2022-09-01 10:02       ` Dmitry A. Kazakov
2022-09-01 11:59       ` Jeffrey R.Carter
2022-09-01 12:37         ` Dmitry A. Kazakov
2022-09-01 13:37           ` Jeffrey R.Carter
2022-09-01 14:10             ` Emmanuel Briot [this message]
2022-09-01 15:50               ` amo...@unizar.es
2022-09-01 16:03               ` Jeffrey R.Carter
2022-09-01 16:07                 ` Emmanuel Briot
2022-09-01 16:17                   ` Jeffrey R.Carter
2022-09-01 18:54                     ` Emmanuel Briot
2022-09-01 21:33                       ` Jeffrey R.Carter
2022-09-02  6:11                         ` Emmanuel Briot
2022-09-02 10:55                           ` Jeffrey R.Carter
2022-09-02 11:20                             ` Emmanuel Briot
2022-09-02 14:28                               ` Jeffrey R.Carter
2022-09-03  0:16                               ` Randy Brukardt
2022-09-03  0:07                           ` Randy Brukardt
2022-09-03  8:59                             ` Jeffrey R.Carter
2022-09-07  0:42                               ` Randy Brukardt
2022-09-03 19:00                             ` Simon Wright
2022-09-05  6:56                               ` Emmanuel Briot
2022-09-05  7:34                                 ` Dmitry A. Kazakov
2022-09-05  9:30                                 ` Jeffrey R.Carter
2022-09-07  0:51                                 ` Randy Brukardt
2022-09-02  8:35                         ` amo...@unizar.es
2022-09-02  8:48                           ` Dmitry A. Kazakov
     [not found]                             ` <9484a755-f55d-407e-a40b-92421b0bcafbn@googlegroups.com>
2022-09-02  9:55                               ` Dmitry A. Kazakov
2022-09-02 10:41                           ` Jeffrey R.Carter
2022-09-02 11:04                             ` Dmitry A. Kazakov
2022-09-03  0:12                               ` Randy Brukardt
2022-09-03  8:23                                 ` Dmitry A. Kazakov
2022-09-03  0:01                           ` Randy Brukardt
2022-09-05  8:53                             ` amo...@unizar.es
replies disabled

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