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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5f6509dca16a8998 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Function result = controlled type Date: 1998/11/19 Message-ID: #1/1 X-Deja-AN: 413373735 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <72vlur$ck$1@nnrp1.dejanews.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-11-19T00:00:00+00:00 List-Id: adam@irvine.com wrote: : ... : As I read the RM, the statement "return Result" causes Adjust to be called : when Result is assigned into an anonymous object (6.5(21)). Also, when : String_Together is exited, Result must be finalized, which means the string : created for Result is deallocated. This means that after creating the string, : the "return" statement copies this string to a new location and then : deallocates the old one, a waste of time. Now, I realize that someone who : cares about this wouldn't have implemented the String_Together function with : a bunch of Appends, each of which deallocates a string and reallocates a new : one. (I would have gone through Arr first to compute the length of the : result.) Still, I think the idea that "return" causes probably needless : adjusting and finalization operations to take place is a cause for some : concern. : Questions: : ... : (3) Is the compiler permitted to delete the Adjust and Finalize calls in this : case? It doesn't look like 7.6(18ff) applies here, since the assignment is : not part of an assignment_statement, and because the finalization referred : to by this part of the RM is one of the intermediate finalizations that : takes place in an assignment statement, not the finalization of an object : that goes out of scope. The intent was always that such optimizations were permitted, but the wording in 7.6 was a bit unclear. Hence, there is a new "AI" (Ada Interpretation) which explicitly permits more aggressive optimization. The basic rules are that the compiler may remove unnecessary temps and the corresponding pairs of adjusts and finalizes. The rules have been tightened a bit about whether the compiler may "move" an object without adjusting it in its new location, and finalizing it in its old location. It used to be disallowed only if the object contained aliased subcomponents. Now it is also disallowed if there might be pointers to the object as a whole which need to be adjusted. A compiler might "know" additional things about Unbounded_String which would permit further optimizations. : ... : -- thanks, Adam -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA An AverStar Company