comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: A note on GNAT 3.05 performance
Date: 1996/06/24
Date: 1996-06-24T00:00:00+00:00	[thread overview]
Message-ID: <4qm6kg$1f7a@watnews1.watson.ibm.com> (raw)
In-Reply-To: 4qm21c$qig@mdnews.btv.ibm.com


In article <4qm21c$qig@mdnews.btv.ibm.com>, pontius@btv.ibm.com
(Dale Pontius) writes: 

|> When I first began looking at Ada, I wondered if if was 'pass by value'
|> or 'pass by reference'. The answer was, apparently, 'neither and both'.
|> It seemed to me that Ada was attempting to 'idealize' a concept by
|> using copy-in/copy-out that it shouldn't be.

Ada distinguishes the semantic model from the implementation.  The
semantic model is that all parameters are passed by copy-in/copy-out, but
the Ada rules allow this effect to be implemented for composite
parameters using pass by reference.  A pass-by-reference implementation
achieves the effect of a copy-in/copy-out semantic model as long as there
is no aliasing and as long as result parameters are not examined after a
procedure call that propagates an exception.

|> Now maintaining copy-in and copy-out will apparently have a performance
|> penalty, yet changing that aspect to pass-by-reference will not be
|> consistant with regular 'in' parameter passing.

It will be consistent with regular 'in' parameter passing as long as
programmers adhere to the sensible guidelines noted above:  Be careful
about aliasing and regard a subprogram call that propagates an exception
as leaving its out and in out parameters in an undefined state.

The reason GNAT 3.05 used a pass-by-copy IMPLEMENTATION. rather than the
pass-by-reference implementation most Ada compilers use for composites
longer than a word or two, was to be consistent with the implementation
of parameter passing that gcc uses for C.

This is not a problem unique to Ada.  Consider the following C++
declarations: 

   class T { ... };
   void f1 (T x);
   void f2 (T& x);
   void f3 (T* x);

Clearly, in the gcc C++ compiler, f1 must use the C parameter-passing
convention for passing a struct by copy and f3 must use the C
parameter-passing convention for passing a pointer-to-struct by copy.
However, f2 has the SEMANTIC MODEL of passing a struct by reference,
which is almost certainly IMPLEMENTED in the same way as f3.

This is quite close to the Ada situation.  (And the declaration

   void f2 (const T& x);

is quite similar to an Ada in parameter passed by reference.) GNAT simply
has to document that its conventions for passing a record are the same as
those for passing a C++ struct or class by reference.  Even if it were
not for Ada, this would have to be a full-fledged part of the gcc
parameter-passing scheme, even though it does not arise in C.

|> Are Ada pragmas frozen in concrete the way the rest of the language
|> is? Is it feasible to make 'pass by copy' and 'pass by reference'
|> for record parameters adjustable on a pragma basis? Is it desirable?

That was (a small) part of the motivation for access parameters.  If RT
is a record type and you are concerned about the potential inefficiency
of passing RT parameters by copy, and you don't trust your compiler to do
the right thing, you can write

   procedure P (X: access RT);

instead of

   procedure P (X: in RT);

and replace calls such as P(Actual) with P(Actual'Access).  However, this
is not a problem in practice (except momentarily, in GNAT 3.05, but
that's being fixed with alacrity).  Programmers are not encouraged to
engage in this sort of efficiency micromanagement unless there is a known
performance problem that can be shown to be attributable to parameter
passing by copy.

--
Norman H. Cohen    ncohen@watson.ibm.com




  reply	other threads:[~1996-06-24  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-20  0:00 A note on GNAT 3.05 performance Robert Dewar
1996-06-21  0:00 ` Michael F Brenner
1996-06-22  0:00   ` Robert Dewar
1996-06-22  0:00   ` Jerry van Dijk
1996-06-24  0:00     ` Robert Dewar
1996-06-28  0:00       ` progers
1996-06-28  0:00       ` Robert A Duff
1996-06-24  0:00 ` Dale Pontius
1996-06-24  0:00   ` Norman H. Cohen [this message]
1996-06-24  0:00     ` Robert Dewar
1996-06-24  0:00   ` Robert Dewar
replies disabled

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