comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: [Revisited] How to get around "access type must not be outside generic unit"
Date: Wed, 24 Jan 2007 14:50:49 -0600
Date: 2007-01-24T14:50:49-06:00	[thread overview]
Message-ID: <EMOdnZk0RPY-WyrYnZ2dnUVZ_rOqnZ2d@megapath.net> (raw)
In-Reply-To: 1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net...
...
> > That won't work in a compiler that does generic code sharing (like
> > Janus/Ada). Subprograms in a generic have an extra hidden parameter to
carry
> > the instance descriptor, and thus the profile doesn't match that of a
> > routine outside of a generic. There is absoletely no way to change this
> > inside of the generic body short of completely abandoning the code
sharing
> > model.
>
> And what Janus/Ada would do if it meets pragma Convention (C, Foo); ?

I'm not sure. Doesn't matter anyway, because you can't do anything with such
a routine (as you are finding out). 'Access ensures that the profile is
"correct"; it's got nothing to do with the Convention pragma on the
subprogram.

...
> > But in any case, the solution to your problem (as always) is to put the
> > 'Access into the private part of the specification. Do that with an
> > appropriate constant declaration. (If the parameter type of Register was
> > anonymous, there is no problem, so there must be a named type that can
be
> > used.) Doing so will force the generic to be instantiated at the library
> > level.
>
> OK, that's definitely better than Unchecked_Conversion. In Ada 95 it was
> enough to add a declaration of the subprogram to the specification, now we
> also need an access object. This is strange, at least not obvious. Why
> should it change anything?

Because it's part of the contract model. That is assume-the-best in the
visible part of the spec, and assume-the-worst in the body. (We're somewhat
confused about the private part.) Whenever we assume-the-best, there is a
required recheck in the instance.

Thus, putting such a 'Access in the spec means that it will be rechecked and
rejected if it causes trouble. In this case, that means that the generic
will be rejected if it is instantiated in a nested scope.

> I mean, if it is semantically correct, then why
> the compiler cannot deduce it? Is it semantically correct? In the case
with
> Glib above, would it be possible to instantiate a generic package in a
> local scope; call to Boxed_Type_Register_Static passing a constant as you
> described; and then leave the scope?

No, the instance will be rejected at compile-time as failing an
accessibility check.

In terms of the shared implementation, what happens is that the instance
makes a wrapper for the routine with the "correct" profile for 'access. You
can't do that in the body when sharing, because you always need the instance
descriptor parameter there. In spec, you can do it both ways to allow
calling from both the internal and external views. That's because you know
where the instance descriptor is for the particular instance, and can
include it in the wrapper call.

                               Randy.





  parent reply	other threads:[~2007-01-24 20:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-17 10:07 How to get around "access type must not be outside generic unit" Michael Erdmann
2006-12-17 12:45 ` Pascal Obry
2006-12-17 14:28   ` Michael Erdmann
2006-12-17 15:53     ` Pascal Obry
2006-12-17 20:49     ` Robert A Duff
2006-12-18  3:35   ` Brian May
2006-12-18  7:49     ` Jean-Pierre Rosen
2006-12-18 23:15       ` Brian May
2006-12-19  1:48         ` Randy Brukardt
2006-12-19  7:41         ` Jean-Pierre Rosen
2006-12-18 20:32     ` Michael Erdmann
2006-12-18 20:57       ` Randy Brukardt
2007-01-23 18:18 ` [Revisited] How to get around "access type must not be outside generic unit" (was: How to get around "access type must not be outside generic unit") Dmitry A. Kazakov
2007-01-24  0:57   ` Randy Brukardt
2007-01-24 11:42     ` [Revisited] How to get around "access type must not be outside generic unit" Dmitry A. Kazakov
2007-01-24 11:58       ` Ludovic Brenta
2007-01-24 13:46         ` Dmitry A. Kazakov
2007-01-24 20:50       ` Randy Brukardt [this message]
2007-01-25 11:07         ` Dmitry A. Kazakov
replies disabled

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