walker:macroexpand-all and tagbody
Description
There are two problems caused by the walker not treating forms in the tagbody correctly.
-
walker:macroexpand-allexpands symbols that have a symbol-macro definition intagbodywhen they are in the tag position. -
walker:macroexpand-alldoesn't "protect" macroexpansion of the macros intagbodythat can be a tag (symbols and integers).
To Reproduce
(walker:macroexpand-all
'(symbol-macrolet ((tag (tag-expanded)))
(tagbody tag)))
; => (SYMBOL-MACROLET ((TAG (TAG-EXPANDED)))
; (TAGBODY (TAG-EXPANDED)))
(defmacro not-tag () 'tag-expanded)
(walker:macroexpand-all '(tagbody (not-tag)))
; => (TAGBODY TAG-EXPANDED)
Expected behavior
The determination of which elements of the body are tags and which are statements is made prior to any macro expansion of that element. If a statement is a macro form and its macro expansion is an atom, that atom is treated as a statement, not a tag.
-- CLHS, tagbody: https://www.lispworks.com/documentation/HyperSpec/Body/s_tagbod.htm
That means that
-
tagintagbodyshould not be expanded. -
(not-tag)expansion should be "protected" so that it doesn't become a tag, for example viaprogn.
ECL version
Provide details regarding ECL version (or preferably commit), operating system and if revelant the build options and versions of the build tools.
(format t "~&~@{~12@A ~S~%~}"
:version (lisp-implementation-version)
:vcs-id (ext:lisp-implementation-vcs-id)
:os (software-type)
:os-version (software-version)
:machine-type (machine-type)
:features *features*)
VERSION "24.5.10"
VCS-ID "UNKNOWN"
OS "Linux"
OS-VERSION "6.2.0-39-generic"
MACHINE-TYPE "x86_64"
FEATURES (:WALKER :CDR-6 :GRAY-STREAMS-MODULE :CDR-1 :CDR-5 :LINUX
:FORMATTER :CDR-7 :ECL-WEAK-HASH :LITTLE-ENDIAN
:ECL-READ-WRITE-LOCK :LONG-LONG :UINT64-T :UINT32-T :UINT16-T
:COMPLEX-FLOAT :LONG-FLOAT :UNICODE :DFFI :CLOS-STREAMS
:CMU-FORMAT :UNIX :ECL-PDE :DLOPEN :CLOS :THREADS :BOEHM-GC
:ANSI-CL :COMMON-LISP :FLOATING-POINT-EXCEPTIONS
:IEEE-FLOATING-POINT :PACKAGE-LOCAL-NICKNAMES :CDR-14
:PREFIXED-API :FFI :X86_64 :COMMON :ECL)
Additional information
This affects quite a few other implementations, see this table (two last columns): https://plaster.tymoon.eu/view/4637.