walker:macroexpand-all doesn't macroexpand symbol-macros passed in environment
Description
walker:macroexpand-all
doesn't expand symbol-macros when its definition is contained in the lexical environment passed (both global symbol-macros and local symbol-macros).
"Mega" test
Here is a test for 6 possible cases where macro expansion should happen:
;; utility macro
(defmacro at-compile-time ((&optional env) &body body)
(let ((capture (gensym)))
`(macrolet ((,capture (,@(when env `(&environment ,env)))
,@body))
(,capture))))
(defmacro NO-1 () ''YES-1)
(define-symbol-macro NO-4 'YES-4)
(macrolet ((NO-3 () ''YES-3))
(symbol-macrolet ((NO-6 'YES-6))
(at-compile-time (env)
`',(walker:macroexpand-all
'(macrolet ((NO-2 () ''YES-2))
(symbol-macrolet ((NO-5 'YES-5))
(values (NO-1) (NO-2) (NO-3) NO-4 NO-5 NO-6)))
env))))
The produced expansion:
(MACROLET ((NO-2 ()
''YES-2))
(SYMBOL-MACROLET ((NO-5 'YES-5))
(VALUES 'YES-1 'YES-2 'YES-3 NO-4 'YES-5 NO-6)))
Expected expansion:
(MACROLET ((NO-2 ()
''YES-2))
(SYMBOL-MACROLET ((NO-5 'YES-5))
(VALUES 'YES-1 'YES-2 'YES-3 'YES-4 'YES-5 'YES-6)))
"Mini" tests
Smaller tests for those two cases where macroexpansion doesn't happen:
(define-symbol-macro macroexpand-all-test-1 'expanded)
(walker:macroexpand-all 'macroexpand-all-test-1)
; => MACROEXPAND-ALL-TEST-1
(symbol-macrolet ((macroexpand-all-test-2 'expanded))
(macrolet ((thunk (&environment env)
`',(walker:macroexpand-all
'macroexpand-all-test-2
env)))
(thunk)))
; => MACROEXPAND-ALL-TEST-2
Additional information
Comparison of macroexpand-all
provided by different implementations (using a portability layer, trivial-macroexpand-all
): https://plaster.tymoon.eu/view/4009#4009
SBCL, CCL and ABCL expand (symbol-)macros in all 6 cases. Allegro CL, LispWorks and CLISP expand macros in 4 cases; not accepting an additional environment argument.
Desktop (please complete the following information):
- OS: Linux
- Version: 21e