comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Will "renames" increase program size?
Date: Thu, 16 Jun 2011 18:33:49 +0200
Date: 2011-06-16T18:33:49+02:00	[thread overview]
Message-ID: <1t5j5p8gurul3$.k4cq2qnsbbjb.dlg@40tude.net> (raw)
In-Reply-To: 2e8222df-9b82-497f-9dc4-5cb0d5653550@f31g2000pri.googlegroups.com

On Thu, 16 Jun 2011 08:40:41 -0700 (PDT), Adam Beneschan wrote:

> On Jun 16, 1:59�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>>
>>> That's not correct. A renaming does not copy nor somehow create new
>>> entities, it only creates new names for the same thing. Since
>>> visibility is via names, you arrive at unresolvability issues.
>>
>> No. First, sometimes it certainly copies, e.g. when the function's result
>> is renamed, the result (temporary object) is copied. The compiler might
>> optimize the temporary object away, or even mandated to do so for limited
>> results, but *semantically* it is a copy.
> 
> I don't think that's right.  The test would be:
> 
>    type T1 is new Ada.Finalization.Controlled with record
>       F1 : Integer;
>    end record;
>    overriding
>    procedure Adjust (Obj : in out T1);
> 
>    function Func (N : Integer) return T1 is
>    begin
>       return Ret : T1 do
>          T1.F1 := N;
>       end return;
>    end Func;
> 
>    procedure Proc is
>       R : T1 renames Func(3);
>    begin
>       ...
>    end Proc;
> 
> In this example, I believe that the renaming declaration cannot
> legally cause Adjust to be called.

I.e. the optimization is mandated for all tagged types in presence of
return statement. Nevertheless Func creates a new object, which is then
renamed.

> In the renaming case, as I read the RM, the extended return creates a
> return object, the function call denotes a constant view of the return
> object, and the renaming denotes a new view of the return object.
> There's no copying or assignment involved.  (Of course, the compiler
> could generate some sort of block-copy to implement this, but I think
> we're talking about Ada semantics.

Semantically returning result of a function is always copying because the
object being returned changes the scope. You have a fully constructed
object #1 within the scope of the return statement. You have a fully
constructed object #2 in the scope of the function call. These are
semantically two different objects because scopes are different. That both
objects might share the same physical memory and therefore no physical
copying is needed, looks like an implementation detail to me.

Of course an alternative point of view is also possible: the object is
rather a closure which floats from one scope to another remaining "same".
But I think that this logical model is unnatural to Ada, and does not work
with by-value types anyway.

I think this could be analogous to inlined bodies. A call is semantically a
call even though nothing is actually called.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-06-16 16:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15  2:10 Will "renames" increase program size? Adrian Hoe
2011-06-15  5:37 ` Randy Brukardt
2011-06-15  9:11   ` AdaMagica
2011-06-15 11:26     ` Yannick Duchêne (Hibou57)
2011-06-15 11:24   ` Yannick Duchêne (Hibou57)
2011-06-15 13:15     ` Dmitry A. Kazakov
2011-06-16  6:59       ` AdaMagica
2011-06-16  8:59         ` Dmitry A. Kazakov
2011-06-16 10:18           ` AdaMagica
2011-06-16 12:15             ` Dmitry A. Kazakov
2011-06-16 23:22             ` Randy Brukardt
2011-06-16 15:40           ` Adam Beneschan
2011-06-16 16:33             ` Dmitry A. Kazakov [this message]
2011-06-16 17:42               ` Adam Beneschan
2011-06-16 18:53                 ` Dmitry A. Kazakov
2011-06-16 23:39                   ` Randy Brukardt
2011-06-17  6:53                     ` Dmitry A. Kazakov
2011-06-18  0:02                       ` Randy Brukardt
2011-06-18  7:54                         ` Dmitry A. Kazakov
2011-06-18  8:58                           ` Yannick Duchêne (Hibou57)
2011-06-18 10:05                             ` Dmitry A. Kazakov
2011-06-18 12:49                               ` Yannick Duchêne (Hibou57)
2011-06-18 22:44                           ` Randy Brukardt
2011-06-22  0:56                             ` Shark8
2011-06-15 22:21 ` anon
replies disabled

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