This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Make attribute functions pure


On Sun, 2004-07-25 at 22:56, Robert Dewar wrote:
> Laurent GUERBY wrote:
> 
> > Interesting, I assume GNAT is not mapping the Ada pragma Pure
> > to the same thing as the GNU C pure attribute, since Ada
> > semantics allow the compiler only to remove a call to a Pure function
> > (reusing previous call result when arguments are provably not changing),
> > not to move it around. Otherwise it's a bug.
> 
> Actually that's not clear ... it is definitely an ARG issue. If
> there are no side effects, then obviously the call can be moved
> around. The intention of the design was not to allow side effects,
> so it is not really clear what transformations are or are not
> allowed. I would guess the ARG would be inclined to be permissive,
> i.e. to allow any optimization which would be valid in the absence
> of side effects.

I find the RM 10.2.1 (18) pretty clear, what makes you
think there's room for interpretation? As written
it explicitely allows the programmer to cheat
in Pure functions (memoizing) without the compiler
playing strange games.

May be an additional pragma with other semantics
would be more appropriate.

<<
18    If a library unit is declared pure, then the implementation is permitted
to omit a call on a library-level subprogram of the library unit if the
results are not needed after the call. Similarly, it may omit such a call and
simply reuse the results produced by an earlier call on the same subprogram,
provided that none of the parameters are of a limited type, and the addresses
and values of all by-reference actual parameters, and the values of all
by-copy-in actual parameters, are the same as they were at the earlier call.
[This permission applies even if the subprogram produces other side effects
when called.]
>>

Laurent


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]