unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jimmy Wong <wyuenho@gmail.com>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	63564@debbugs.gnu.org, Andrea Corallo <akrl@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	[thread overview]
Message-ID: <6c94b15b-1f97-4a33-b334-9af017519088@Spark> (raw)
In-Reply-To: <8538FA15-8814-4CE3-AD33-16E7EEF19DC1@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

Thank you so much!
On 18 May 2023 at 7:01 PM +0100, Mattias Engdegård <mattias.engdegard@gmail.com>, wrote:
> 18 maj 2023 kl. 19.45 skrev Jimmy Wong <wyuenho@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.
>

[-- Attachment #2: Type: text/html, Size: 1873 bytes --]

  reply	other threads:[~2023-05-18 18:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  2:40 bug#63564: 29.0.91; (setcdr) behaves differently between natively and byte compiled code Jimmy Yuen Ho Wong
2023-05-18  6:50 ` Eli Zaretskii
2023-05-18  7:54   ` Andrea Corallo
2023-05-18 17:45     ` Jimmy Wong
2023-05-18 18:01       ` Mattias Engdegård
2023-05-18 18:58         ` Jimmy Wong [this message]
2023-05-18 18:25       ` Eli Zaretskii
2023-05-18  7:01 ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c94b15b-1f97-4a33-b334-9af017519088@Spark \
    --to=wyuenho@gmail.com \
    --cc=63564@debbugs.gnu.org \
    --cc=akrl@sdf.org \
    --cc=eliz@gnu.org \
    --cc=mattias.engdegard@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).