GNU bug report logs - #8712
24.0.50; getting the "Forgot to expand macro XXXX" error - problem? solution?

Previous Next

Package: emacs;

Reported by: "Drew Adams" <drew.adams <at> oracle.com>

Date: Sat, 21 May 2011 21:02:02 UTC

Severity: normal

Found in version 24.0.50

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8712 in the body.
You can then email your comments to 8712 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Sat, 21 May 2011 21:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Drew Adams" <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 21 May 2011 21:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <bug-gnu-emacs <at> gnu.org>
Subject: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sat, 21 May 2011 14:00:49 -0700
When byte-compiling I'm getting the famous "Forgot to expand macro XXXX"
error.
 
AFAICT, the email threads about that error just said, in effect:
 
1. Stefan thinks he found a bug that caused this, and fixed it, but he
isn't sure.
 
2. Concerning Emacs sources, just do a make -k clean and then try again.
 

But I'm seeing this for my own code.  I guess I need to understand the
solution (what to do) and, preferably, the cause of the problem.
 
I put the source files in a new directory, load the file with the
defmacros, and try to byte-compile a file that uses them.  I get the
above error, with XXXX = `push'.
 
These are the files: icicles-mac.el has the macros; icicles-cmd1.el is
the file whose byte-compiling raises the error.
 
With the source files (only) in new directory foo, cd to foo,
(add-to-list 'load-path "."), then M-x load-library icicles.
Then try to byte-compile icicles-cmd1.el.
 
The files you will need are here:
http://www.emacswiki.org/cgi-bin/wiki?action=index;match=%5C.(el%7Ctar)(%5C.gz)%
3F%24
 
You will need these files, in order to load library `icicles':
 
hexrgb.el
icicles-cmd1.el
icicles-cmd2.el
icicles-face.el
icicles-fn.el
icicles-mac.el
icicles-mcmd.el
icicles-mode.el
icicles-opt.el
icicles-var.el
icicles.el
 
To reproduce, after loading those source files try to byte-compile
icicles-cmd1.el.  You'll get this error:
 
icicles-cmd1.el:3066:91:Error: Wrong type argument: listp, "Forgot to
expand macro push"
 
I really don't understand.  Please advise.  Is this an Emacs bug that
has been fixed or will be fixed?  Is there something that I need to do
to make the code compatible with lexbind?  What's the story?  Thx.
 
In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2011-05-16 on 3249CTO
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.5) --no-opt --cflags
-Ic:/build/include'
 





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Sat, 21 May 2011 21:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 8712 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <8712 <at> debbugs.gnu.org>
Subject: RE: bug#8712: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sat, 21 May 2011 14:06:37 -0700
Forgot to mention that the same problem occurs when trying to byte-compile
icicles-cmd2.el.  In that case the error message is:

icicles-cmd2.el:3033:11:Error: Wrong type argument: listp, "Forgot to expand
macro push"

So the same problem appears in icicles-cmd1.el and icicles-cmd2.el.





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Sun, 22 May 2011 18:15:02 GMT) Full text and rfc822 format available.

Message #11 received at 8712 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Drew Adams" <drew.adams <at> oracle.com>
Cc: 8712 <at> debbugs.gnu.org
Subject: Re: bug#8712: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sun, 22 May 2011 15:14:20 -0300
> icicles-cmd1.el:3066:91:Error: Wrong type argument: listp, "Forgot to
> expand macro push"

I think the patch below fixes your problem, thanks.  Please confirm.


        Stefan


=== modified file 'lisp/emacs-lisp/bytecomp.el'
--- lisp/emacs-lisp/bytecomp.el	2011-05-12 02:36:05 +0000
+++ lisp/emacs-lisp/bytecomp.el	2011-05-22 17:36:39 +0000
@@ -2892,8 +2892,8 @@
 That command is designed for interactive use only" fn))
         (if (and (fboundp (car form))
                  (eq (car-safe (symbol-function (car form))) 'macro))
-            (byte-compile-report-error
-             (format "Forgot to expand macro %s" (car form))))
+            (byte-compile-log-warning
+             (format "Forgot to expand macro %s" (car form)) nil :error))
         (if (and handler
                  ;; Make sure that function exists.  This is important
                  ;; for CL compiler macros since the symbol may be
@@ -2991,7 +2991,7 @@
     (cond
      ((<= (+ alen alen) fmax2)
       ;; Add missing &optional (or &rest) arguments.
-      (dotimes (i (- (/ (1+ fmax2) 2) alen))
+      (dotimes (_ (- (/ (1+ fmax2) 2) alen))
         (byte-compile-push-constant nil)))
      ((zerop (logand fmax2 1))
       (byte-compile-log-warning "Too many arguments for inlined function"

=== modified file 'lisp/emacs-lisp/macroexp.el'
--- lisp/emacs-lisp/macroexp.el	2011-03-12 03:32:43 +0000
+++ lisp/emacs-lisp/macroexp.el	2011-05-22 18:11:30 +0000
@@ -169,14 +169,22 @@
       ;; here, so that any code that cares about the difference will
       ;; see the same transformation.
       ;; First arg is a function:
-      (`(,(and fun (or `apply `mapcar `mapatoms `mapconcat `mapc))
+      (`(,(and fun (or `funcall `apply `mapcar `mapatoms `mapconcat `mapc))
          ',(and f `(lambda . ,_)) . ,args)
+       (byte-compile-log-warning
+        (format "%s quoted with ' rather than with #'"
+                (list 'lambda (nth 1 f) '...))
+        t)
        ;; We don't use `maybe-cons' since there's clearly a change.
        (cons fun
              (cons (macroexpand-all-1 (list 'function f))
                    (macroexpand-all-forms args))))
       ;; Second arg is a function:
       (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args)
+       (byte-compile-log-warning
+        (format "%s quoted with ' rather than with #'"
+                (list 'lambda (nth 1 f) '...))
+        t)
        ;; We don't use `maybe-cons' since there's clearly a change.
        (cons fun
              (cons (macroexpand-all-1 arg1)





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Sun, 22 May 2011 20:01:01 GMT) Full text and rfc822 format available.

Message #14 received at 8712 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: "'Stefan Monnier'" <monnier <at> iro.umontreal.ca>
Cc: 8712 <at> debbugs.gnu.org
Subject: RE: bug#8712: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sun, 22 May 2011 13:00:24 -0700
> I think the patch below fixes your problem, thanks.  Please confirm.

I patched the corresponding functions by hand, loaded their original source
files, then loaded the patched functions.  I then byte-compiled
icicles-cmd[12].el.  No byte-compilation errors, so it seems, at least on the
surface, that this is fixed.  The compilation was _very_ slow, but that's no
doubt because I used the source code rather than byte-compiled code.

Thanks for the fix.


I do have a question about the follownig warning, however (which I have not
seen/noticed before):

 (lambda (opt) ...) quoted with ' rather than with #'

That presumably comes from a defmacro that has, in effect, this:

 ` ... (let* (... (something (lambda (opt)...))))

That is, an unquoted lambda inside a backquote.  The backquote expands to (quote
(lambda...)) no doubt.

I have a few such macros, and I use them heavily.  I get this same warning
zillions of times (460 times just for icicles-cmd1.el, 30 times for
icicles-cmd2.el).  This is quite annoying.

What is the suggested/recommended way to write such code, to avoid this warning?
Do I now need to add #' in front of a lambda inside a backquote?





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Mon, 23 May 2011 01:37:02 GMT) Full text and rfc822 format available.

Message #17 received at 8712 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Drew Adams" <drew.adams <at> oracle.com>
Cc: 8712 <at> debbugs.gnu.org
Subject: Re: bug#8712: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sun, 22 May 2011 22:36:34 -0300
> I do have a question about the follownig warning, however (which I have not
> seen/noticed before):

>  (lambda (opt) ...) quoted with ' rather than with #'

> That presumably comes from a defmacro that has, in effect, this:

>  ` ... (let* (... (something (lambda (opt)...))))

This is because you pass (lambda (opt) ...) as `function' argument
to a macro that then splices it with

  `(.... ',function ....)

so the expanded code contains '(lambda (opt) ...).
Splice it with #', instead.

> That is, an unquoted lambda inside a backquote.  The backquote expands
> to (quote (lambda...)) no doubt.

No, backquote does not know you're building code, so it can't freely
decide to add `quote' symbols as it sees fit.


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8712; Package emacs. (Mon, 23 May 2011 03:56:02 GMT) Full text and rfc822 format available.

Message #20 received at 8712 <at> debbugs.gnu.org (full text, mbox):

From: "Drew Adams" <drew.adams <at> oracle.com>
To: "'Stefan Monnier'" <monnier <at> iro.umontreal.ca>
Cc: 8712 <at> debbugs.gnu.org
Subject: RE: bug#8712: 24.0.50;
	getting the "Forgot to expand macro XXXX" error - problem? solution?
Date: Sun, 22 May 2011 20:55:17 -0700
> > That presumably comes from a defmacro that has, in effect, this:
> >  ` ... (let* (... (something (lambda (opt)...))))
> 
> This is because you pass (lambda (opt) ...) as `function' argument
> to a macro that then splices it with `(.... ',function ....)
> so the expanded code contains '(lambda (opt) ...).

Oh, right; I was looking in the wrong place.  Thx.





bug closed, send any further explanations to 8712 <at> debbugs.gnu.org and "Drew Adams" <drew.adams <at> oracle.com> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 12 Jul 2011 18:50:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 10 Aug 2011 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 314 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.