unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Cleaning up code
@ 2013-08-07 15:57 Stefan Monnier
  2013-08-13 15:17 ` Michael Albinus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-08-07 15:57 UTC (permalink / raw)
  To: emacs-devel

If you feel like cleaning up some code, but are not sure where to look,
try the patch below and then bootstrap Emacs.  That should give you
enough warnings to keep you busy for a while.


        Stefan


=== modified file 'lisp/Makefile.in'
--- lisp/Makefile.in	2013-07-23 22:55:38 +0000
+++ lisp/Makefile.in	2013-08-05 22:00:36 +0000
@@ -42,7 +42,8 @@
 EMACSOPT = -batch --no-site-file --no-site-lisp
 
 # Extra flags to pass to the byte compiler
-BYTE_COMPILE_EXTRA_FLAGS =
+BYTE_COMPILE_EXTRA_FLAGS = --eval '(setq byte-compile-force-lexical-warnings t)'
+
 # For example to not display the undefined function warnings you can use this:
 # BYTE_COMPILE_EXTRA_FLAGS = --eval '(setq byte-compile-warnings (quote (not unresolved)))'
 # The example above is just for developers, it should not be used by default.




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

* Re: Cleaning up code
  2013-08-07 15:57 Cleaning up code Stefan Monnier
@ 2013-08-13 15:17 ` Michael Albinus
  2013-08-13 16:30   ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2013-08-13 15:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> If you feel like cleaning up some code, but are not sure where to look,
> try the patch below and then bootstrap Emacs.  That should give you
> enough warnings to keep you busy for a while.

Yay!

However, setting `byte-compile-force-lexical-warnings' to t is too
coarse. For example, Tramp's macro `with-parsed-tramp-file-name'
let-binds several variables "just in case". They are reported as unused
then, on every invocation of that macro.

Is there a way to tell the byte compiler, that these unused declarations
are intended here? Otherwise, I would be swamped with warnings, and I
won't see the real warnings I should care.

>         Stefan

Best regards, Michael.



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

* Re: Cleaning up code
  2013-08-13 15:17 ` Michael Albinus
@ 2013-08-13 16:30   ` Stefan Monnier
  2013-08-15  8:40     ` Michael Albinus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-08-13 16:30 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

> However, setting `byte-compile-force-lexical-warnings' to t is too
> coarse. For example, Tramp's macro `with-parsed-tramp-file-name'
> let-binds several variables "just in case". They are reported as unused
> then, on every invocation of that macro.

Yup, that's one of the main problems: when a single let in the source
ends up duplicated after expansion so some expansions may use it while
others end up not using it.

We need to add some way to tell Emacs that it should check "the sum of
all uses" or something like that.  In your case, this "sum" is
open-ended, so we should instead just tell it not to check at all.


        Stefan



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

* Re: Cleaning up code
  2013-08-13 16:30   ` Stefan Monnier
@ 2013-08-15  8:40     ` Michael Albinus
  2013-08-15 14:37       ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Albinus @ 2013-08-15  8:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> However, setting `byte-compile-force-lexical-warnings' to t is too
>> coarse. For example, Tramp's macro `with-parsed-tramp-file-name'
>> let-binds several variables "just in case". They are reported as unused
>> then, on every invocation of that macro.
>
> Yup, that's one of the main problems: when a single let in the source
> ends up duplicated after expansion so some expansions may use it while
> others end up not using it.
>
> We need to add some way to tell Emacs that it should check "the sum of
> all uses" or something like that.  In your case, this "sum" is
> open-ended, so we should instead just tell it not to check at all.

Yep.

There is also another case where it doesn't work as expected. Often, I
let bind a variable for side effect, like this:

      (let ((default-directory (tramp-compat-temporary-file-directory))
            (outline-regexp tramp-debug-outline-regexp))
        (outline-mode))

And I get from the byte compiler

tramp.el:1400:1:Warning: Unused lexical variable `outline-regexp'

In Tramp, there are many such stanzas of intended side effect
bindings. Therefore, there are too many false positives, that I could
see the real warnings I should fix.

Could we have a byte-compiler option telling that such bindings are
intended? Something like this:

      (let ((byte-compile-force-lexical-warnings nil)
            (default-directory (tramp-compat-temporary-file-directory))
            (outline-regexp tramp-debug-outline-regexp))
        (outline-mode))

>         Stefan

Best regards, Michael.



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

* Re: Cleaning up code
  2013-08-15  8:40     ` Michael Albinus
@ 2013-08-15 14:37       ` Stefan Monnier
  2013-08-15 17:05         ` Michael Albinus
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-08-15 14:37 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

> There is also another case where it doesn't work as expected. Often, I
> let bind a variable for side effect, like this:

>       (let ((default-directory (tramp-compat-temporary-file-directory))
>             (outline-regexp tramp-debug-outline-regexp))
>         (outline-mode))

> And I get from the byte compiler

> tramp.el:1400:1:Warning: Unused lexical variable `outline-regexp'

That is a correct warning, telling you that it treated outline-regexp as
a lexical variable and hence that it did not generate the code you want.
IOW you need to add

   (defvar outline-regexp)


-- Stefan



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

* Re: Cleaning up code
  2013-08-15 14:37       ` Stefan Monnier
@ 2013-08-15 17:05         ` Michael Albinus
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Albinus @ 2013-08-15 17:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> IOW you need to add
>
>    (defvar outline-regexp)

Thanks. By this, I could remove some other byte compiler warnings.

> -- Stefan

Best regards, Michael.



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

end of thread, other threads:[~2013-08-15 17:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-07 15:57 Cleaning up code Stefan Monnier
2013-08-13 15:17 ` Michael Albinus
2013-08-13 16:30   ` Stefan Monnier
2013-08-15  8:40     ` Michael Albinus
2013-08-15 14:37       ` Stefan Monnier
2013-08-15 17:05         ` Michael Albinus

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