Subject: bug#18971: 25.0.50; incorrect warning from byte compiler

From: Stefan Monnier <[email-masked]>
Date: Thu, 06 Nov 2014 18:27:10 -0500

> I want to be able to call byte-optimize-form and was under the
> impression that byte-compile-close-variables was needed.  I'm doing this
> for a project I'm working on where it is convenient to let the byte
> compiler code macroexpand a form and do some simple optimizations on it.

Just curious: why do you need those simple optimizations performed by
byte-optimize-form?

> I guess I don't understand why this would not be a bug, though.
> Or at least it perplexes me why this happens; my only theory is that
> somehow the defvars aren't seen when byte-compiling my file.  I suppose
> if I wanted to export a macro like this, I would need it to come with
> special declarations for the variables?  Except I didn't see a way to do
> that either.

Those vars are not globally bound, i.e. they are only declared with
(defvar <var>) and this only affects the file in which they appear (or
even the scope, in case they appear within a defun body).

So the macro would need to expand to something like

   (progn
     (defvar byte-compile-free-assignments)
     ...
     (defvar byte-compile-free-references)
     (let (...) ...))

if it was meant to be used outside of bytecomp.el.

        Stefan