GNU bug report logs - #24863
Functions declared as side-effect-free do not generate warnings in the same file

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: minor; Reported by: Wilfred Hughes <me@HIDDEN>; dated Thu, 3 Nov 2016 01:02:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Severity set to 'minor' from 'normal' Request was from npostavs@HIDDEN to control <at> debbugs.gnu.org. Full text available.

Message received at 24863 <at> debbugs.gnu.org:


Received: (at 24863) by debbugs.gnu.org; 3 Nov 2016 23:14:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 03 19:14:09 2016
Received: from localhost ([127.0.0.1]:41985 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1c2RCz-00018V-EI
	for submit <at> debbugs.gnu.org; Thu, 03 Nov 2016 19:14:09 -0400
Received: from mail-oi0-f54.google.com ([209.85.218.54]:34945)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <npostavs@HIDDEN>)
 id 1c2RCx-00017U-89; Thu, 03 Nov 2016 19:14:07 -0400
Received: by mail-oi0-f54.google.com with SMTP id x4so117185661oix.2;
 Thu, 03 Nov 2016 16:14:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=sender:from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version;
 bh=FSgWtBB0XwTAOuptPno0Af9yhQos+OsHlHO7iqRqhZw=;
 b=N0vVOpl5SRujaAgWnjeJed2XfWkYpkVkk6iHs6uq/oV8RzEk0sOCOSlIWnaAnaejTO
 65f7BJXDmgnOC0w15gDp0M/2GHR1hJMe3fzFYlEdOhlI5jBiQ/L9ubUl+QdihDmk1l7H
 GoWxMgSzfuOfIpWsbzPrbyC1fST268eCBlGjT+5k7qJcrPXppBPHbFPmjRlKtycknBYE
 B8JgmpAJNVQ4Ay9byD1Qc9/dmy+8SuXqFzUlkm6ugpgyu6tIXgupntTChK2uJpXcfbR2
 +9gXJ6ThfXxIAtfPXJVVubDHCv+URG3cqWczHC38bF2/hZOXmfSJeJtlf6kM0PdMdkA5
 mIhw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:sender:from:to:cc:subject:references:date
 :in-reply-to:message-id:user-agent:mime-version;
 bh=FSgWtBB0XwTAOuptPno0Af9yhQos+OsHlHO7iqRqhZw=;
 b=BzW4IfMBkL71yiE0sSSd2vrHKJsFeZXWFj9yQ1LYR6gW8zwyprQsx2EAEWMD9yelw9
 arv0mmbGIXnf1yTY9Zx+Z2Z0hgRv5zhv45dQZnTL/wxuaa+x9yLF00lzoAmAOam4humH
 ItDSbzOeKYV5kjj6WhpnWVX6Q7MNAzIeBNlkWFJRG5jNFjM63F5L7tX1dyBkQBK3AXo/
 hw5y4ThHLMBIYnpwTRPwJeddfI+/x9THksgRkJyEUmj6D2NuOXFxzPDa/ymlHZb/NfKO
 MaM7qIoevC7lQWi51m0nw67x9vWD0I7XJ5UN2jzA/+cQBb0ojYRW1EifGing7MP+60Gr
 AgPQ==
X-Gm-Message-State: ABUngvd6TkHhJp7C8hZ8nqef6l7JmPdQafUyVTcRwZuDaDS3hKKPdFa3Sc5GR5g/7gSwHQ==
X-Received: by 10.107.178.148 with SMTP id b142mr10774581iof.69.1478214841415; 
 Thu, 03 Nov 2016 16:14:01 -0700 (PDT)
Received: from zony ([45.2.7.130])
 by smtp.googlemail.com with ESMTPSA id n62sm500718ith.2.2016.11.03.16.14.00
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Thu, 03 Nov 2016 16:14:01 -0700 (PDT)
From: npostavs@HIDDEN
To: Wilfred Hughes <me@HIDDEN>
Subject: Re: bug#24863: Functions declared as side-effect-free do not generate
 warnings in the same file
References: <CAFXAjY4YAT_uhdSRc-LCv4ih=LEeHkRA7YEVAV-foh+d-HDmJA@HIDDEN>
Date: Thu, 03 Nov 2016 19:14:45 -0400
In-Reply-To: <CAFXAjY4YAT_uhdSRc-LCv4ih=LEeHkRA7YEVAV-foh+d-HDmJA@HIDDEN>
 (Wilfred Hughes's message of "Wed, 2 Nov 2016 20:59:39 -0400")
Message-ID: <87fun8p34q.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: 24863
Cc: 24863 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.5 (/)

severity 24863 minor
quit

Wilfred Hughes <me@HIDDEN> writes:

>
> However, ideally this wouldn't be required. I think it's just a matter
> of changing defun-declarations-alist to:
>
>    (list 'side-effect-free
>          #'(lambda (f _args val)
>              `(eval-and-compile (function-put ',f 'side-effect-free ',val)))
>          "If non-nil, calls can be ignored if their value is unused.
> If `error-free', drop calls even if `byte-compile-delete-errors' is nil.")

Note the comment above:

   ;; We can only use backquotes inside the lambdas and not for those
   ;; properties that are used by functions loaded before backquote.el.

Since the side-effect-free lambda wasn't using backquotes, I presume it
has to stay that way.

On StackExchange you commented

    changing defun-declarations-alist in my current Emacs instance
    doesn't fix the issue

But doing

    (setf (nth 1 (assq 'side-effect-free defun-declarations-alist))
          (lambda (f _args val)
            `(eval-and-compile (function-put ',f 'side-effect-free ',val))))

in a running Emacs works for me.  By "changing" did you mean just
changing the source?  In that case, you would have to redump Emacs
before the change would take effect.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#24863; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 Nov 2016 01:01:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Nov 02 21:01:23 2016
Received: from localhost ([127.0.0.1]:41003 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1c26PC-0007iz-P6
	for submit <at> debbugs.gnu.org; Wed, 02 Nov 2016 21:01:23 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40600)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <me@HIDDEN>) id 1c26PA-0007im-Dh
 for submit <at> debbugs.gnu.org; Wed, 02 Nov 2016 21:01:20 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <me@HIDDEN>) id 1c26P4-0005JA-D3
 for submit <at> debbugs.gnu.org; Wed, 02 Nov 2016 21:01:15 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_50,RCVD_IN_SORBS_SPAM,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:58770)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <me@HIDDEN>) id 1c26P4-0005J3-AE
 for submit <at> debbugs.gnu.org; Wed, 02 Nov 2016 21:01:14 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59798)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <me@HIDDEN>) id 1c26P3-0008Ue-12
 for bug-gnu-emacs@HIDDEN; Wed, 02 Nov 2016 21:01:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <me@HIDDEN>) id 1c26Oz-0005IC-UY
 for bug-gnu-emacs@HIDDEN; Wed, 02 Nov 2016 21:01:13 -0400
Received: from mail-qk0-f170.google.com ([209.85.220.170]:33723)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <me@HIDDEN>) id 1c26Oz-0005Gn-PT
 for bug-gnu-emacs@HIDDEN; Wed, 02 Nov 2016 21:01:09 -0400
Received: by mail-qk0-f170.google.com with SMTP id x190so37835700qkb.0
 for <bug-gnu-emacs@HIDDEN>; Wed, 02 Nov 2016 18:01:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=wilfred-me-uk.20150623.gappssmtp.com; s=20150623;
 h=mime-version:from:date:message-id:subject:to;
 bh=9UeKs14Y/ZIhQHpFuQMlVYTlC618m5roV8LEZ5WmDlU=;
 b=rZS+8h71RRP0fFWYijPIfc2PTphpLvg0Py06gJrAbCQOBFV4OAsr1eK7KcFzH3ljPZ
 onU57DqRqUVK3dWLfjKNS7UfjiYCSY/EmpXvPWMbk0omWT6sIPsJW2iHa9tnPJ44Jxru
 ySEs8KQWBmThWmV+I2X3KRa6esnRsq1MOW3dnomyb7kGqX7MZ5bHVWjPYWl7WAYeaA1N
 Ur6lTxHH9ueAw7b48Dejn1ex4jkB7PUf7K0SUTNJWSkiQU3EQ/AJHWg6hxMhLn7CvJS0
 oyhGE37bV8Kq3wARR+8yrOcRu9ov21IHwUA+TfNOE8Yls2bIZ7mzNAzdY+dTrIw1rd/6
 tiHw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=9UeKs14Y/ZIhQHpFuQMlVYTlC618m5roV8LEZ5WmDlU=;
 b=b051N74H9/WilcJONJO5vBs2KRZDJ2Jmkt4yoMIC1qAqULn+hiVPjvgTw85BT9xYmh
 tsaLp54EaaUVlqPtreUr5rYj+NtJCDcO9ICcKIdXxCNxx4SszRvZnFjp8YsE/rnIX9tI
 ykLcIQyvXfm6LZQjUsB3yfHREfZo2B4+SvWBV9KkKgQzyegLaOrOcJ57xp5MIPQeFjzS
 WyyLhglefjyFFGxCz5eGeUf7d5CkZ0gn61fXgZJEd1SaObv1g8H4UnWpLRt1Vt7cmuD1
 yblCqPJ3Xou+347UQDDznUBEuXjYL0C2q7JTha+OvVX2/N/aWcGd5o9h/u6OWfoDbyFv
 UzYg==
X-Gm-Message-State: ABUngveh254KpoyBtxuDQOFdTT7bG8qncIxgOAzu6WoV5icN9HMHBhQISVKxFGk14OLeHC9+LmApeE715R9Hlg==
X-Received: by 10.55.215.220 with SMTP id t89mr5292046qkt.27.1478134799683;
 Wed, 02 Nov 2016 17:59:59 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.237.36.48 with HTTP; Wed, 2 Nov 2016 17:59:39 -0700 (PDT)
X-Originating-IP: [65.206.63.10]
From: Wilfred Hughes <me@HIDDEN>
Date: Wed, 2 Nov 2016 20:59:39 -0400
Message-ID: <CAFXAjY4YAT_uhdSRc-LCv4ih=LEeHkRA7YEVAV-foh+d-HDmJA@HIDDEN>
Subject: Functions declared as side-effect-free do not generate warnings in
 the same file
To: bug-gnu-emacs@HIDDEN
Content-Type: text/plain; charset=UTF-8
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -3.5 (---)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.5 (---)

If I declare a function as side-effect-free, I do not get warnings
when I call it for side effects:

(defun foo-pure (x)
  (declare (side-effect-free t))
  x)

(defun foo-calls-pure ()
  ;; No warning here:
  (foo-pure 1)
  12)


However, if I define foo-pure in a standalone file and byte-compile
it, I get byte-compile warnings when I define foo-calls-pure in a
second file.

As mentioned in http://emacs.stackexchange.com/a/28341/304 , the
problem is that side-effect-free is added to the function symbol plist
at the wrong time. This can be worked around with:

(eval-and-compile (function-put 'foo-pure 'side-effect-free 't))

before defining foo-calls-pure.

However, ideally this wouldn't be required. I think it's just a matter
of changing defun-declarations-alist to:

   (list 'side-effect-free
         #'(lambda (f _args val)
             `(eval-and-compile (function-put ',f 'side-effect-free ',val)))
         "If non-nil, calls can be ignored if their value is unused.
If `error-free', drop calls even if `byte-compile-delete-errors' is nil.")




Acknowledgement sent to Wilfred Hughes <me@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#24863; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 3 Nov 2016 23:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.