From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: pure-fns in byte-opt.el Date: Sun, 24 Sep 2017 12:23:29 -0400 Message-ID: References: <20170725020650.GA12601@holos.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1506270236 16402 195.159.176.226 (24 Sep 2017 16:23:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 24 Sep 2017 16:23:56 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 24 18:23:43 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dw9h0-0003RB-5R for ged-emacs-devel@m.gmane.org; Sun, 24 Sep 2017 18:23:42 +0200 Original-Received: from localhost ([::1]:38722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dw9h7-0006lR-Du for ged-emacs-devel@m.gmane.org; Sun, 24 Sep 2017 12:23:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dw9h0-0006l8-V4 for emacs-devel@gnu.org; Sun, 24 Sep 2017 12:23:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dw9gx-0005Ge-S9 for emacs-devel@gnu.org; Sun, 24 Sep 2017 12:23:42 -0400 Original-Received: from [195.159.176.226] (port=43250 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dw9gx-0005G9-Ki for emacs-devel@gnu.org; Sun, 24 Sep 2017 12:23:39 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dw9gm-0002ex-Uv for emacs-devel@gnu.org; Sun, 24 Sep 2017 18:23:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 31 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:cSNcaTYvTax8SOMQMB7+OeNeVe4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:218746 Archived-At: > A side-effect-free function is one where all of the following is true: > - After exiting the function (whether normally or nonlocally), the > `match-data' are `equal' to the `match-data' before entering the function. > - After exiting the function, all dynamic variables, their default values, > their symbol cells, etc., are `eq' to the respective values before entering > the function. Exceptions are variables only used for debugging/tracing, > such as `cons-cells-consed'. > - All buffer contents, markers, point values etc. are > `equal-including-properties' to their previous values. > - The same buffers and threads still exist. I don't think we want to enumerate all the manners that side-effects can occur, since we will inevitably forget some (and the list will get out of date). I think we should define it more as something like: side-effect-free means: if the result of the function is not used, calling the function or not does not affect the behavior of the program, except that the function may signal an error. side-effect-and-error-free means: like side-effect-free but cannot signal an error. This means that the optimizer can eliminate calls to those functions if the result is not used. pure: like side-effect-free but additionally, the function always returns the same value when called with the same arguments, so the compiler can precompute the call if it knows the arguments. -- Stefan