comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent Guerby <guerby@acm.org>
Subject: Re: Right of Optimize Eager Evaluation Away
Date: 1999/11/29
Date: 1999-11-29T20:20:42+00:00	[thread overview]
Message-ID: <86iu2lvyed.fsf@ppp-105-76.villette.club-internet.fr> (raw)
In-Reply-To: wccemd9z2k5.fsf@world.std.com

Robert A Duff <bobduff@world.std.com> writes:
> > Laurent Guerby wrote:
> 
> > > Is the potential raising of an exception the only language barrier
> > > here (since as you mention the compiler is free to swap calls
> > > defeating a class of side effects)? This seams easy to fix (via a
> > > pragma), if one is interested in keeping the functional aspect of the
> > > code instead of resorting to statements of course.
> 
> I don't understand Laurent's question.

I should rephrase then ;-):

Is the potential raising of an exception the only language barrier
to allow lazy evaluation for an optimizing compiler?

It looks like to me that the Ada language more or less intend that
functions shouldn't have side effects, since by example it allows the
compiler to evaluate arguments and thus potentially calling functions
in any order, or allows only "in" parameters for the programmer.

The question is then, why stop at allowing any evaluation order and
not just allow lazy evaluation as well?

It allows some "nice" optimizations, like the one I mentionned, or
things like:

-- In some Debug package body:

   Enable_Trace : constant Boolean := True; 
   -- or set to False when compiled in "release" mode
   
   procedure Trace (M : in String) is
   begin
      if Enable_Trace then
          IO.Put (M);
      end if;
   end Trace;

-- Now you have your code full of Trace calls like:

   Trace ("index = " & Image (Index) & " value = " & Image (Value));

With the current RM, even if the compilers know that the Trace call
doesn't do anything (inlining is on, and proper unreached code
elimination has been done), it cannot suppress the calls to Image or
to "&" since they might potentially raise an exception. The only way
to do a "release"/"debug" switch that does not cause a performance
penalty for the "release" version is then to use vendor specific
pragmas like GNAT Assert or Debug, and thus is outside of the
language.

The "pragma" I was mentionning could look like:

pragma You_Can_Omit_Calls_To_This_If_The_Value_Is_Not_Needed (F);

(obviously a better name is needed ;-). If an expression involves only
calls to pragma'ed functions (the Standard and String stuff could be
in this category for example), then if the compiler finds out the
result isn't needed in some run-time paths, it can omit the evaluation
of the expression in those paths.

I don't know if I'm clearer here ;-).

> - Bob

--LG




  reply	other threads:[~1999-11-29  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-28  0:00 Right of Optimize Eager Evaluation Away Laurent Guerby
1999-11-28  0:00 ` Robert A Duff
1999-11-28  0:00   ` Laurent Guerby
1999-11-29  0:00     ` Nick Roberts
1999-11-29  0:00       ` Robert A Duff
1999-11-29  0:00         ` Laurent Guerby [this message]
1999-11-29  0:00           ` Robert A Duff
1999-11-30  0:00             ` Laurent Guerby
1999-11-29  0:00           ` Niklas Holsti
1999-11-29  0:00           ` Lutz Donnerhacke
1999-11-29  0:00 ` Jean-Pierre Rosen
replies disabled

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