all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#24863: Functions declared as side-effect-free do not generate warnings in the same file
@ 2016-11-03  0:59 Wilfred Hughes
  2016-11-03 23:14 ` npostavs
  2021-02-06 11:54 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 3+ messages in thread
From: Wilfred Hughes @ 2016-11-03  0:59 UTC (permalink / raw)
  To: 24863

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.")





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-06 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-03  0:59 bug#24863: Functions declared as side-effect-free do not generate warnings in the same file Wilfred Hughes
2016-11-03 23:14 ` npostavs
2021-02-06 11:54 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.