comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Function result = controlled type
Date: 1998/11/19
Date: 1998-11-19T00:00:00+00:00	[thread overview]
Message-ID: <F2nF32.4L6.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 72vlur$ck$1@nnrp1.dejanews.com

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




      parent reply	other threads:[~1998-11-19  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-18  0:00 Function result = controlled type adam
1998-11-19  0:00 ` Dmitriy Anisimkov
1998-11-19  0:00   ` Ed Falis
1998-11-19  0:00   ` Tom Moran
1998-11-19  0:00 ` Tucker Taft [this message]
replies disabled

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