GNU bug report logs -
#24863
Functions declared as side-effect-free do not generate warnings in the same file
Previous Next
Reported by: Wilfred Hughes <me <at> wilfred.me.uk>
Date: Thu, 3 Nov 2016 01:02:02 UTC
Severity: minor
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24863 in the body.
You can then email your comments to 24863 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24863
; Package
emacs
.
(Thu, 03 Nov 2016 01:02:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Wilfred Hughes <me <at> wilfred.me.uk>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 03 Nov 2016 01:02:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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.")
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24863
; Package
emacs
.
(Thu, 03 Nov 2016 23:15:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 24863 <at> debbugs.gnu.org (full text, mbox):
severity 24863 minor
quit
Wilfred Hughes <me <at> wilfred.me.uk> 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.
Severity set to 'minor' from 'normal'
Request was from
npostavs <at> users.sourceforge.net
to
control <at> debbugs.gnu.org
.
(Thu, 03 Nov 2016 23:15:03 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24863
; Package
emacs
.
(Sat, 06 Feb 2021 11:55:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 24863 <at> debbugs.gnu.org (full text, mbox):
Wilfred Hughes <me <at> wilfred.me.uk> writes:
> 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.
I tried this in Emacs 25.1-28, and I do get a warning:
Compiling file /tmp/side.el at Sat Feb 6 12:51:52 2021
Entering directory ‘/tmp/’
In foo-calls-pure:
side.el:5:8: Warning: value returned from (foo-pure 1) is unused
You didn't specify what Emacs version you were reporting the bug for,
but I'm going to go ahead and guess that this has been fixed since, and
I'm closing this bug report. If the issue persists, please respond to
the debbugs address and we'll reopen.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug closed, send any further explanations to
24863 <at> debbugs.gnu.org and Wilfred Hughes <me <at> wilfred.me.uk>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 06 Feb 2021 11:55:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 06 Mar 2021 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 23 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.