EVAL occasionally expands macros twice

Bug #541584 reported by Richard Holcombe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Won't Fix
Low
Unassigned

Bug Description

I execute the following code:

(defvar *arglist* nil)
(defmacro test2(x)
(progn
(push x *arglist*)
`(setf ,x 7)))

(test2 y)

then *arglist* has the value (y y) when just (y) is expected. (at least (y) is what I get on all of the other lisps that I can find, and makes much more sense.)

This occurs at least on versions 1.0.33 and 1.0.36 on linux.

uname -a
Linux 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 05:23:09 UTC 2010 i686 GNU/Linux

*features*

(:ANSI-CL :COMMON-LISP :SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS
 :SB-UNICODE :SB-EVAL :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :X86 :UNIX :ELF
 :LINUX :SB-THREAD :LARGEFILE :GENCGC :STACK-GROWS-DOWNWARD-NOT-UPWARD
 :C-STACK-IS-CONTROL-STACK :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP
 :RAW-INSTANCE-INIT-VOPS :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :INLINE-CONSTANTS :LINKAGE-TABLE :OS-PROVIDES-DLOPEN
 :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T)

Changed in sbcl:
status: New → In Progress
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

Strictly speaking IIRC, macros are allowed to be expanded multiple times, what is going on here seems unintentional.

summary: - incorrect macro evaluation
+ EVAL occasionally expands macros twice
Changed in sbcl:
status: In Progress → Confirmed
Changed in sbcl:
importance: Undecided → Low
status: Confirmed → Triaged
Revision history for this message
Douglas Katzman (dougk) wrote :

This behavior is a consequence of *evaluator-mode* being :compile.
The REPL tries to use an extremely rudimentary evaluation strategy to avoid calling the compiler.
The first thing that it has to do to try interpreting a form is to macroexpand it, accounting for one call of TEST2.

For a variety of reasons the simplistic evaluator will give up, and call the compiler, which it does using the original form.
In this case it's a SETQ of an unknown variable that is not handled by the simple evaluator, so it then calls the compiler on the original form, which has to be expanded again.
If Y had been DEFVAR'ed, the simple evaluator would have done the SETQ and not called the compiler.

As Nikodemus remarked, this is permissible behavior. With *evaluator-mode* = :interpret, only one macroexpansion occurs.
Basically not a bug.

Changed in sbcl:
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.