[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Lexical byte-compilation warnings cleanup
From: |
Daniel Hackney |
Subject: |
Lexical byte-compilation warnings cleanup |
Date: |
Mon, 19 Aug 2013 19:33:00 -0400 |
I'm taking the advice Stafan gave in [1] and squashing lexical-scoping
bugs identified by the byte compiler. I've attached a patch which starts
making a dent in the warnings. There were some things which were
relatively easy, such as adding a leading underscore to `&rest _ignore',
but there were a lot what seem to be false positives. I've taken some
notes on what I've found.
- `condition-case': The byte-compiler doesn't recognize the handler
forms and so gives warnings about unused lexical arguments. Consider
the following code (adapted from `widget-sexp-validate'):
#+BEGIN_SRC emacs-lisp
;; -*- lexical-binding: t; -*-
(defun foo ()
(let (err)
(condition-case data
(skip-syntax-forward "\\s-")
(end-of-file (setq err "Unbalanced sexp")) ;; 1
(error (setq err (error-message-string data)))) ;; 2
err))
#+END_SRC
Byte-compiling that with `byte-compile-force-lexical-warnings' set
to `t' warns of "Unused lexical argument `data'". Switching lines 1
and 2 gives the warning "the function `end-of-file' is not known to
be defined." Removing line 1 makes it compile without errors. It
would seem that the byte-compiler is not treating `condition-case'
as specially as it should.
- I'm seeing a lot of "Argument foo is not a lexical variable", such as
in vc/ediff-diff.el:532:56. What does this mean and is this something
I should "fix"? In some cases, this is because `foo' is defined with
`defvar' but also used as a function argument. What should be done in
this case? For example, here is the definition of
`emerge-remote-exit':
#+BEGIN_SRC emacs-lisp
(defun emerge-remote-exit (file-out emerge-exit-func)
(emerge-write-and-delete file-out)
(kill-buffer emerge-merge-buffer)
(funcall emerge-exit-func (if emerge-prefix-argument 1 0)))
#+END_SRC
Note that `emerge-exit-func' is a `defvar'ed variable. Should it be
replaced with something like this:
#+BEGIN_SRC emacs-lisp
(defun emerge-remote-exit (file-out exit-func)
(let ((emerge-exit-func exit-func))
(emerge-write-and-delete file-out)
(kill-buffer emerge-merge-buffer)
(funcall emerge-exit-func (if emerge-prefix-argument 1 0))))
#+END_SRC
- In `emerge-revisions-with-ancestor', the variable `cmd' is let-bound,
but does not appear to be used. Could it be safely removed?
- Similarly, `cvs-fileinfo<' binds variables `subtypea' and `subtypeb'
but never uses them. Can they be removed?
- Superfluously-bound variables: In, for example,
`ange-ftp-file-attributes', the variables `host', `user', and `name'
are bound but never used. Should these be prefixed with an
underscore (to make the byte compiler shut up) or removed altogether
(since they aren't actually used)? It seems like they should just be
removed, but I don't want to trample on something needed.
[1] http://article.gmane.org/gmane.emacs.devel/162466
--
Daniel Hackney
byte-silence.patch
Description: Binary data
- Lexical byte-compilation warnings cleanup,
Daniel Hackney <=
- Re: Lexical byte-compilation warnings cleanup, Juanma Barranquero, 2013/08/19
- Re: Lexical byte-compilation warnings cleanup, Glenn Morris, 2013/08/19
- Re: Lexical byte-compilation warnings cleanup, Stefan Monnier, 2013/08/20
- RE: Lexical byte-compilation warnings cleanup, Drew Adams, 2013/08/20
- Re: Lexical byte-compilation warnings cleanup, Stefan Monnier, 2013/08/20
- RE: Lexical byte-compilation warnings cleanup, Drew Adams, 2013/08/20
- Re: Lexical byte-compilation warnings cleanup, Stefan Monnier, 2013/08/20
- RE: Lexical byte-compilation warnings cleanup, Drew Adams, 2013/08/20
- RE: Lexical byte-compilation warnings cleanup, Stephen J. Turnbull, 2013/08/20
- RE: Lexical byte-compilation warnings cleanup, Drew Adams, 2013/08/20