comp.lang.ada
 help / color / mirror / Atom feed
From: "amo...@unizar.es" <amosteo@unizar.es>
Subject: Re: Calling inherited primitive operations in Ada
Date: Thu, 1 Sep 2022 08:50:21 -0700 (PDT)	[thread overview]
Message-ID: <8716804b-8041-4aae-ba48-276cecce7881n@googlegroups.com> (raw)
In-Reply-To: <401d6f59-2c28-4dd5-9fa6-fccf33b6d645n@googlegroups.com>

On Thursday, September 1, 2022 at 4:11:54 PM UTC+2, briot.e...@gmail.com wrote:
> 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. 

This matches exactly my experience. I don't have enough grasp of the details to come up with a realistic short example, but I did hit this issue pretty often in two libs were I used signature packages quite extensively:

https://github.com/mosteo/rxada
https://github.com/mosteo/iterators

Initially I was always under the impression I was hitting GNAT bugs but then it turned out there were rules about it. A couple example places (you can see the renamings at the top. I was adding them "on demand" so to say):

https://github.com/mosteo/iterators/blob/master/src/iterators-traits-containers.ads
https://github.com/mosteo/rxada/blob/master/src/priv/rx-impl-transformers.ads
 
Thanks Emmanuel for the examples and digging out Tucker explanation.

-Alex.

> 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 15:50 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
2022-09-01 15:50               ` amo...@unizar.es [this message]
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