comp.lang.ada
 help / color / mirror / Atom feed
* Language lawyer question: access discriminants
@ 2010-04-06 21:17 Adam Beneschan
  2010-04-07 20:04 ` Randy Brukardt
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Beneschan @ 2010-04-06 21:17 UTC (permalink / raw)


I'm hoping someone who understands the rules about access discriminant
accessibility level can answer this definitively.  This is a reduced
example of something I found in someone else's code:

package Pack1 is
    type Rec is record
        F1 : Integer;
    end record;
    type Rec2 (D : access Rec) is limited record
        F2 : Integer;
    end record;
    function Func (Param : Integer) return Rec2;
end Pack1;

with Pack1;  use Pack1;
procedure Proc2 is
    A : access Rec;
begin
    A := Func(1).D;   -- LEGAL?
end Proc2;

I think the statement marked LEGAL? is illegal, because of rules
saying that the result of Func is an object inside a nested master
that consists of just the one assignment statement, and the
accessibility level of the access discriminant (Func(1).D) is the
accessibility level of the enclosing object (the temporary object
containing the result of Func), and therefore the accessibility level
of Func(1).D is deeper than that of A.  But the rules are pretty
complex and I'm hoping someone in the know can straighten me out if
I'm wrong.  (And I'm not interested in any replies that say "XYZ
compiler says it's legal".  I need to know what the standard says.)

                                                 -- thanks, Adam



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

* Re: Language lawyer question: access discriminants
  2010-04-06 21:17 Language lawyer question: access discriminants Adam Beneschan
@ 2010-04-07 20:04 ` Randy Brukardt
  2010-04-08  0:21   ` Adam Beneschan
  0 siblings, 1 reply; 3+ messages in thread
From: Randy Brukardt @ 2010-04-07 20:04 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> wrote in message 
news:06e780ef-c171-4037-b96e-f44788ae2bdf@g10g2000yqh.googlegroups.com...
> I'm hoping someone who understands the rules about access discriminant
> accessibility level can answer this definitively.

You're assuming such a person exists. I'm dubious. :-)

> This is a reduced
> example of something I found in someone else's code:
>
> package Pack1 is
>    type Rec is record
>        F1 : Integer;
>    end record;
>    type Rec2 (D : access Rec) is limited record
>        F2 : Integer;
>    end record;
>    function Func (Param : Integer) return Rec2;
> end Pack1;
>
> with Pack1;  use Pack1;
> procedure Proc2 is
>    A : access Rec;
> begin
>    A := Func(1).D;   -- LEGAL?
> end Proc2;

This program is depending on the accessibility of access discriminants of an 
object returned from a function. Those are not currently defined. We know 
that the rules as defined in Ada 2005 don't work (have various nasty holes). 
The rules corrections proposed by AI05-0051-1 have never been approved, and 
so far as I know, are only understood by the author (Tucker Taft).

My (lousy) understanding of the rules proposed in AI05-0051-1 is that the 
accessibility of the access discriminants of the returned object are that of 
the call site. The rules Tucker proposed would generally cause the 
accessibility of the LHS of the assignment to propagate into the function, 
and a (dynamic) check would be made at the return statement that the 
accessibility is sufficient.

The net effect is that this call is always legal, but it is very likely that 
it would fail an accessibility check at the return statement -- thus it 
would usually raise Program_Error.

> I think the statement marked LEGAL? is illegal, because of rules
> saying that the result of Func is an object inside a nested master
> that consists of just the one assignment statement, and the
> accessibility level of the access discriminant (Func(1).D) is the
> accessibility level of the enclosing object (the temporary object
> containing the result of Func), and therefore the accessibility level
> of Func(1).D is deeper than that of A.  But the rules are pretty
> complex and I'm hoping someone in the know can straighten me out if
> I'm wrong.  (And I'm not interested in any replies that say "XYZ
> compiler says it's legal".  I need to know what the standard says.)

What I can't say for sure is whether the accessibility of the LHS would be 
used or whether that of a assignment statement would be used. I'd have to go 
and read the AI again several times and even then I wouldn't really know for 
sure. I do know that type conversions get the right accessibility (so using 
a named type here and a type conversion would surely be legal).

But remember this is all based on the unapproved binding interpretation 
AI05-0051-1. What the standard says currently is garbage, and it isn't worth 
figuring out what those rules are (no one will ever try to enforce those - 
that is, no ACATS test will ever exist for the rules as currently written).

So my best advice is do whatever you want now, and plan to adjust to 
AI05-0051-1 rules when (if?) that gets finished.

                                   Randy.





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

* Re: Language lawyer question: access discriminants
  2010-04-07 20:04 ` Randy Brukardt
@ 2010-04-08  0:21   ` Adam Beneschan
  0 siblings, 0 replies; 3+ messages in thread
From: Adam Beneschan @ 2010-04-08  0:21 UTC (permalink / raw)


On Apr 7, 1:04 pm, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> So my best advice is do whatever you want now, and plan to adjust to
> AI05-0051-1 rules when (if?) that gets finished.

Thanks, Randy, this is much appreciated.  I suppose I should try
delving into this AI, although I'm nervous about it because I found,
after a quick skim of the AI, that the text has several references to
exploding brains...

                                 -- Adam



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

end of thread, other threads:[~2010-04-08  0:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-06 21:17 Language lawyer question: access discriminants Adam Beneschan
2010-04-07 20:04 ` Randy Brukardt
2010-04-08  0:21   ` Adam Beneschan

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