From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7576 invoked by alias); 29 Apr 2002 15:22:44 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 7552 invoked from network); 29 Apr 2002 15:22:41 -0000 Received: from unknown (HELO nondot.org) (64.5.103.85) by sources.redhat.com with SMTP; 29 Apr 2002 15:22:41 -0000 Received: by nondot.org (Postfix, from userid 501) id B7BBE11883; Mon, 29 Apr 2002 10:19:51 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by nondot.org (Postfix) with ESMTP id B315F1183E; Mon, 29 Apr 2002 10:19:51 -0500 (CDT) Date: Mon, 29 Apr 2002 08:30:00 -0000 From: Chris Lattner To: Cc: , Subject: Re: pure and const functions Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-04/txt/msg01548.txt.bz2 >> a) having no effects except the return value >> b) return value depends only on the parameters >> c) return value depends on global variables >> >> Condition a) is too strong for removal of duplicate calls, since it >> eliminates considering memo functions as pure. > Yes, but I think that's okay. There are cases where duplicate calls > to a non-pure memoizing function could be removed too, but how should > the compiler determine which side-effects can be ignored? > All we say is that if condition a) is fulfilled, we are on the safe > side. There are two different issues going on here confusing things: 1. The defined semantics 2. What we actually do For #1, Robert is correct... > a) having no effects except the return value Is too strong of a statement... the problem is that it's really hard to make an accurate summary of what things really are. Perhaps "Always returns the same value for a particular set of input parameters" coupled with "makes no changes to global state that would break the program if they didn't happen" is close enough. Effectively we just need to get across the idea that a pure function _can_ be eliminated, and doing so should not affect the semantics of the program. This seems nice and simple, but #2 confuses things. As I understand it, GCC automatically trys to prove functions pure. Obviously it will not be able to figure out the structure of a memoizing function in general, so it would punt on these functions, thus not automatically marking it pure. The programmer, however, can manually add the pure attribute, so the actual _notion_ of being pure is still intact, even if the actual implementation isn't "smart enough" (and there isn't really any reasonable way to make it so). -Chris http://www.nondot.org/~sabre/os/ http://www.nondot.org/~sabre/Projects/