From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jimmy Wong Newsgroups: gmane.emacs.bugs 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-ID: <6c94b15b-1f97-4a33-b334-9af017519088@Spark> References: <83pm6yw2tu.fsf@gnu.org> <382e9fc0-c016-49a6-8341-e7bc2c90394c@Spark> <8538FA15-8814-4CE3-AD33-16E7EEF19DC1@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="64667568_59f0b344_b973" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18313"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 63564@debbugs.gnu.org, Andrea Corallo To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 18 20:59:12 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pziqF-0004aA-Kx for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 18 May 2023 20:59:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pziq7-0007y9-9G; Thu, 18 May 2023 14:59:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pziq6-0007y0-7l for bug-gnu-emacs@gnu.org; Thu, 18 May 2023 14:59:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pziq5-0001zg-WD for bug-gnu-emacs@gnu.org; Thu, 18 May 2023 14:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pziq5-0003lH-Rs for bug-gnu-emacs@gnu.org; Thu, 18 May 2023 14:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jimmy Wong Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 May 2023 18:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63564 X-GNU-PR-Package: emacs Original-Received: via spool by 63564-submit@debbugs.gnu.org id=B63564.168443633814450 (code B ref 63564); Thu, 18 May 2023 18:59:01 +0000 Original-Received: (at 63564) by debbugs.gnu.org; 18 May 2023 18:58:58 +0000 Original-Received: from localhost ([127.0.0.1]:54615 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pziq2-0003kz-3e for submit@debbugs.gnu.org; Thu, 18 May 2023 14:58:58 -0400 Original-Received: from mail-wr1-f47.google.com ([209.85.221.47]:51366) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pzipz-0003kl-EY for 63564@debbugs.gnu.org; Thu, 18 May 2023 14:58:56 -0400 Original-Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3090408e09bso1599206f8f.2 for <63564@debbugs.gnu.org>; Thu, 18 May 2023 11:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684436329; x=1687028329; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=pNMM/UPAanodgjRklJgjDBxbJLJPFiGhbCE/t7EOink=; b=oB9py7hpKg1S98BGXzVVONzHyJcN1IXfjpnHPIeMOPl5SdhPEt7j/JwhVdVuWTsj1R bIkLGCbGyVc0YITDkX3lKo0rz03oFo4tlPVG0dy5BH8SUOMzgjhmK5rPK5IvUuDov6bZ mwk2MlTCm1T0trktNxgr/Ic2/9fzcYMeH/XtG2K7xpE7a4aRNG77j6kAEQTsy/flmXHk QOe3/n7s2pAkNQHaMf4r23C9nByYv88x0RAHia28edFUYzO9vt8QLDoSi6fHatw6tHeV lLhi4IvBJSvR+pmMxZtwYXcdKSUJjS4CPgU6x9kAWKcB+2/37cotx6BSwZ8Hq5Kl0+Il ATfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684436329; x=1687028329; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pNMM/UPAanodgjRklJgjDBxbJLJPFiGhbCE/t7EOink=; b=lg7YR5jJTTOpUoS7W+r/6LaLGH2bM3vXApe8VokQt99hMiNXE2jIitJj1Ndh9y3ZqR rz1gN9RX5o0J/ZGRcqHYnObGb/Tb/i6k2cAJURPn2R/dqqvhus/kovjyNWwi7ZImvKTY WcivbOjzlI0sIYr56GzxXCL0T2e8BwZ8fGFCYn5PMxImknn/lABTqWE5r5YqEGd4fgbp maJcP3onB7L50Tmq7S8mcWMnUryEJCX6GMjBOfZuN4t5AlWRHFVwQog3U7jm+0rz76RZ LRABp7eiVyZYipzv1Q9ZreiMq9tvza23IlitDfXBo4dKZ7I5YdD6a61l2DwBizICm8kw dT4g== X-Gm-Message-State: AC+VfDymmdjqICYr6RG9BAmj0TDO9A3sEO1HTFL9w8qJGCmakrWc+oh7 85aAgMUpvdj/Hd4ZmXJ6Zg0= X-Google-Smtp-Source: ACHHUZ714ODAy5oGIrfE4nv/pgiOVSXmkshvZue7cvZK8sUUExwimsxU5gCrhpfNmr+lYbZYnc/1TA== X-Received: by 2002:adf:f98b:0:b0:307:a075:2709 with SMTP id f11-20020adff98b000000b00307a0752709mr2066437wrr.68.1684436329269; Thu, 18 May 2023 11:58:49 -0700 (PDT) Original-Received: from [2a01:4b00:89a0:2400::ffff:ffff] ([2a01:4b00:89a0:2400:301f:207a:a22f:7653]) by smtp.gmail.com with ESMTPSA id s4-20020adfecc4000000b002fae7408544sm2946773wro.108.2023.05.18.11.58.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2023 11:58:48 -0700 (PDT) In-Reply-To: <8538FA15-8814-4CE3-AD33-16E7EEF19DC1@gmail.com> X-Readdle-Message-ID: 6c94b15b-1f97-4a33-b334-9af017519088@Spark X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:261954 Archived-At: --64667568_59f0b344_b973 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thank you so much=21 On 18 May 2023 at 7:01 PM +0100, Mattias Engdeg=C3=A5rd , wrote: > 18 maj 2023 kl. 19.45 skrev Jimmy Wong : > > > 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 behave= s differently from the byte compiled version tho. This could be good lear= ning for occasional elisp devs such as myself to know what to watch out f= or. > > 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 warn= ing is fine). > > Technically, the error likely occurred because the native compiler prop= agated 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 =3D nil > (dotimes (=5F (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 sa= fe. > --64667568_59f0b344_b973 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Thank you so much=21
On 18 May 2023 at 7:01 PM +0100, Ma= ttias Engdeg=C3=A5rd <mattias.engdegard=40gmail.com>, wrote:
18 maj 2023 kl. 19.45 skrev Jimmy Wong <wyuenho=40gmail.com&= gt;:

As Mattias has noted, this commit on markdo= wn-mode did fix the issues, it would still be nice to know why the native= ly compiled version behaves differently from the byte compiled version th= o. This could be good learning for occasional elisp devs such as myself t= o know what to watch out for.

The code was mutating a program constant (quoted list) which is a no-no i= n Elisp. As luck has it, a new warning in Emacs 30 discovered it and a ma= rkdown-mode maintainer changed the code accordingly (the commit message s= ays that he 'fixed a warning' but he really fixed broken code; the warnin= g is fine).

Technically, the error likely occurred because the native compiler propag= ated that constant to its points of use where it underwent some compile-t= ime evaluation. Essentially:

(let ((root '(nil)))
...
(let ((sibling-alist (last (cdr root)))) ; sibling-alist =3D nil
(dotimes (=5F (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 w= ell, and rightly so.
Don't mutate program constants. It's not safe, and it has never been safe= .

--64667568_59f0b344_b973--