From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a41c4a2c795dbe34 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Will "renames" increase program size? Date: Thu, 16 Jun 2011 18:33:49 +0200 Organization: cbb software GmbH Message-ID: <1t5j5p8gurul3$.k4cq2qnsbbjb.dlg@40tude.net> References: <46294109-f07d-49c0-8e81-65a369a05ced@z15g2000prn.googlegroups.com> <1ayjsy885qg2b$.13bmeo97hbau1$.dlg@40tude.net> <316ac8ed-1ded-43d0-98d1-36bb2c0221ad@f2g2000yqh.googlegroups.com> <2e8222df-9b82-497f-9dc4-5cb0d5653550@f31g2000pri.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: r4+jMptzOJ3b6T4HWw+5pg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:20848 Date: 2011-06-16T18:33:49+02:00 List-Id: On Thu, 16 Jun 2011 08:40:41 -0700 (PDT), Adam Beneschan wrote: > On Jun 16, 1:59�am, "Dmitry A. Kazakov" > 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