bug#43601: 27.1; Macroexpansion bug in `push'

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#43601: 27.1; Macroexpansion bug in `push'

Sean Devlin
Hi folks,

I believe I've found a macroexpansion bug in the `push' macro. Open a
new instance of Emacs and evaluate the following form in the scratch
buffer:

    (macroexpand '(push (list 'x)
                        (cdr my-list)))

The result (with some reformatting) is this:

    (let* ((v (list 'x))
           (v my-list))
      (setcdr v
              (cons v
                   (cdr v))))

Both values are bound to `v', so the former is shadowed by the latter.

Thanks!


In GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))
of 2020-08-12 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.2011
System Description:  macOS 11.0

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
(x y)
See buffer *Pp Macroexpand Output*.
You can run the command ‘pp-macroexpand-last-sexp’ with M-x p-m-l RET
See buffer *Pp Macroexpand Output*.
Making completion list...

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS JSON PDUMPER

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search time-date subr-x seq
byte-opt bytecomp byte-compile cconv mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils help-mode easymenu
cl-loaddefs cl-lib gv pp tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads kqueue cocoa ns multi-tty make-network-process emacs)

Memory information:
((conses 16 46943 7509)
(symbols 48 6030 1)
(strings 32 15598 2351)
(string-bytes 1 514024)
(vectors 16 10404)
(vector-slots 8 132291 12524)
(floats 8 28 38)
(intervals 56 218 0)
(buffers 1000 13))



Reply | Threaded
Open this post in threaded view
|

bug#43601: Acknowledgement (27.1; Macroexpansion bug in `push')

Sean Devlin
Hi folks,

Upon closer inspection, it looks like the two bindings are distinct. I guess the symbols must be created by `make-symbol’ or similar. Still, it might be nice for debugging if the symbols had distinct names.

Thanks!


Reply | Threaded
Open this post in threaded view
|

bug#43601: 27.1; Macroexpansion bug in `push'

Phil Sainty
In reply to this post by Sean Devlin
On 2020-09-25 10:54, Sean Devlin wrote:

> Hi folks,
>
> I believe I've found a macroexpansion bug in the `push' macro. Open a
> new instance of Emacs and evaluate the following form in the scratch
> buffer:
>
>     (macroexpand '(push (list 'x)
>                         (cdr my-list)))
>
> The result (with some reformatting) is this:
>
>     (let* ((v (list 'x))
>            (v my-list))
>       (setcdr v
>               (cons v
>                    (cdr v))))
>
> Both values are bound to `v', so the former is shadowed by the latter.

It's actually fine.

What you're seeing is the *printed representation* of the lisp objects,
and two completely independent symbols, each with the name "v".

(setq foo (macroexpand '(push (list 'x) (cdr my-list))))
=> (let* ((v (list 'x)) (v my-list)) (setcdr v (cons v (cdr v))))

(setq vfirst (caaadr foo))
=> v

(setq vsecond (car (cadadr foo)))
=> v

(eq vfirst vsecond)
=> nil

(cdaddr (caddr foo))
=> (v (cdr v))

(eq vfirst (car (cdaddr (caddr foo))))
=> t

(eq vsecond (cadadr (cdaddr (caddr foo))))
=> t


This is like:

(eq (make-symbol "v") (make-symbol "v"))
=> nil





Reply | Threaded
Open this post in threaded view
|

bug#43601: 27.1; Macroexpansion bug in `push'

Philipp Stephani
In reply to this post by Sean Devlin
Am Fr., 25. Sept. 2020 um 00:56 Uhr schrieb Sean Devlin <[hidden email]>:

>
> Hi folks,
>
> I believe I've found a macroexpansion bug in the `push' macro. Open a
> new instance of Emacs and evaluate the following form in the scratch
> buffer:
>
>     (macroexpand '(push (list 'x)
>                         (cdr my-list)))
>
> The result (with some reformatting) is this:
>
>     (let* ((v (list 'x))
>            (v my-list))
>       (setcdr v
>               (cons v
>                    (cdr v))))
>
> Both values are bound to `v', so the former is shadowed by the latter.


These are different uninterned symbols:

(let ((print-gensym t) (print-circle t))
  (print (macroexpand '(push (list 'x) (cdr my-list))))
  nil)

⇒ (let* ((#2=#:v (list 'x)) (#1=#:v my-list)) (setcdr #1# (cons #2# (cdr #1#))))

In general, if you see a "weird" expansion like this, bind
print-gensym to non-nil to see the uninterned symbols.



Reply | Threaded
Open this post in threaded view
|

bug#43601: 27.1; Macroexpansion bug in `push'

Lars Ingebrigtsen
Philipp Stephani <[hidden email]> writes:

> In general, if you see a "weird" expansion like this, bind
> print-gensym to non-nil to see the uninterned symbols.

True.  But we could change push to use a different name for the
gensymmed symbol to avoid confusions like this.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#43601: 27.1; Macroexpansion bug in `push'

Lars Ingebrigtsen
Lars Ingebrigtsen <[hidden email]> writes:

> Philipp Stephani <[hidden email]> writes:
>
>> In general, if you see a "weird" expansion like this, bind
>> print-gensym to non-nil to see the uninterned symbols.
>
> True.  But we could change push to use a different name for the
> gensymmed symbol to avoid confusions like this.

I've now done so in Emacs 28.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no