all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wilfred Hughes <me@wilfred.me.uk>
To: 24863@debbugs.gnu.org
Subject: bug#24863: Functions declared as side-effect-free do not generate warnings in the same file
Date: Wed, 2 Nov 2016 20:59:39 -0400	[thread overview]
Message-ID: <CAFXAjY4YAT_uhdSRc-LCv4ih=LEeHkRA7YEVAV-foh+d-HDmJA@mail.gmail.com> (raw)

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





             reply	other threads:[~2016-11-03  0:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03  0:59 Wilfred Hughes [this message]
2016-11-03 23:14 ` bug#24863: Functions declared as side-effect-free do not generate warnings in the same file npostavs
2021-02-06 11:54 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFXAjY4YAT_uhdSRc-LCv4ih=LEeHkRA7YEVAV-foh+d-HDmJA@mail.gmail.com' \
    --to=me@wilfred.me.uk \
    --cc=24863@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.