GNU bug report logs - #63564
29.0.91; (setcdr) behaves differently between natively and byte compiled code

Previous Next

Package: emacs;

Reported by: Jimmy Yuen Ho Wong <wyuenho <at> gmail.com>

Date: Thu, 18 May 2023 02:41:02 UTC

Severity: normal

Found in version 29.0.91

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jimmy Wong <wyuenho <at> gmail.com>
To: Mattias EngdegÄrd <mattias.engdegard <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 63564 <at> debbugs.gnu.org, Andrea Corallo <akrl <at> sdf.org>
Subject: bug#63564: 29.0.91; (setcdr) behaves differently between natively and byte compiled code
Date: Thu, 18 May 2023 19:58:41 +0100
[Message part 1 (text/plain, inline)]
Thank you so much!
On 18 May 2023 at 7:01 PM +0100, Mattias EngdegÄrd <mattias.engdegard <at> gmail.com>, wrote:
> 18 maj 2023 kl. 19.45 skrev Jimmy Wong <wyuenho <at> gmail.com>:
>
> > As Mattias has noted, this commit on markdown-mode did fix the issues, it would still be nice to know why the natively compiled version behaves differently from the byte compiled version tho. This could be good learning for occasional elisp devs such as myself to know what to watch out for.
>
> The code was mutating a program constant (quoted list) which is a no-no in Elisp. As luck has it, a new warning in Emacs 30 discovered it and a markdown-mode maintainer changed the code accordingly (the commit message says that he 'fixed a warning' but he really fixed broken code; the warning is fine).
>
> Technically, the error likely occurred because the native compiler propagated that constant to its points of use where it underwent some compile-time evaluation. Essentially:
>
> (let ((root '(nil)))
> ...
> (let ((sibling-alist (last (cdr root)))) ; sibling-alist = nil
> (dotimes (_ (1- level))
> (setq sibling-alist (last (cdar sibling-alist)))) ; still nil
> (setcdr sibling-alist alist) ; boom
>
> In Emacs 30 the byte-compiler is able to do some of that propagation as well, and rightly so.
> Don't mutate program constants. It's not safe, and it has never been safe.
>
[Message part 2 (text/html, inline)]

This bug report was last modified 2 years and 63 days ago.

Previous Next


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