unofficial mirror of bug-gnu-emacs@gnu.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

* bug#24863: Functions declared as side-effect-free do not generate warnings in the same file
  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
  1 sibling, 0 replies; 3+ messages in thread
From: npostavs @ 2016-11-03 23:14 UTC (permalink / raw)
  To: Wilfred Hughes; +Cc: 24863

severity 24863 minor
quit

Wilfred Hughes <me@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.





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

* bug#24863: Functions declared as side-effect-free do not generate warnings in the same file
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-06 11:54 UTC (permalink / raw)
  To: Wilfred Hughes; +Cc: 24863

Wilfred Hughes <me@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





^ 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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).