From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67116: byte-compile-let: reversing the order of evaluation of the clauses CAN make a difference. Date: Sun, 12 Nov 2023 12:06:27 -0500 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29626"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67116@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 12 18:08:01 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 1r2DwG-0007UB-V2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Nov 2023 18:08:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2Dvk-0003Wm-Be; Sun, 12 Nov 2023 12:07:28 -0500 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 1r2Dvd-0003WP-EH for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2023 12:07:21 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r2Dvd-0004xH-68 for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2023 12:07:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r2DwI-0003Ye-6A for bug-gnu-emacs@gnu.org; Sun, 12 Nov 2023 12:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Nov 2023 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67116 X-GNU-PR-Package: emacs Original-Received: via spool by 67116-submit@debbugs.gnu.org id=B67116.169980884613630 (code B ref 67116); Sun, 12 Nov 2023 17:08:02 +0000 Original-Received: (at 67116) by debbugs.gnu.org; 12 Nov 2023 17:07:26 +0000 Original-Received: from localhost ([127.0.0.1]:56865 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Dve-0003Xi-NU for submit@debbugs.gnu.org; Sun, 12 Nov 2023 12:07:26 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:63794) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r2Dvc-0003XM-Ph for 67116@debbugs.gnu.org; Sun, 12 Nov 2023 12:07:21 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 55756807A7; Sun, 12 Nov 2023 12:06:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1699808788; bh=EQ9AVH5Zr6wEgG4EBBaQFgD6pzvuosPDKW0SWHItA4k=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QXEcMX3RUzDZVWmNGf3aZLm19ObJ60WR4gUu026Xdd/gn+1Pv7AaIPcrLTtUmH+Bp ghoVv7Jc2ZqFHPbc0QEOJfnSFbNmBZntuxXj+PXv+zy8tuiL8Su27tXpxk2XNP0pGn fWc1TriQ47HKL+VuIzRFrN9qoGu8KFufMuBhNskoqF9oAfQ97uePMnN3FqdfYwLSq0 fkT6HWomF+r1BPg3Veqx0eMGYWsVM+ZPRkCVwhGLPdOEECL80VkTXIsbfBqtg1pgLZ KqtRNDVtbgmYzVjfxKY9XM2CKEKvZ6z1JwYzlnhr28m3XiOTz4NL5ZHBYn0JchRGOQ QK2AmxOefXSlA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 3B4CB80578; Sun, 12 Nov 2023 12:06:28 -0500 (EST) Original-Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 12A1412044D; Sun, 12 Nov 2023 12:06:28 -0500 (EST) In-Reply-To: (Alan Mackenzie's message of "Sun, 12 Nov 2023 14:54:40 +0000") 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:274213 Archived-At: >> Sounds like a bug. Do you have some recipe to reproduce it? > Certainly! In the code fragment above in jit-lock--debug-fontify, > insert the diagnostic line as above. Byte compile this function. Then > M-x jit-lock-debug-mode. Now scrolling any (previously unfontified) > sections of a buffer will fail to fontify those sections. In *Messages* > it can be seen that the printed values of BEG and END are identical, > hence the call to jit-lock-fontify-now does nothing. Hmm, indeed, thanks. Apparently Matthias already found the problem, I'm looking forward to his explanations. >> since computing E pushes it value on the stack, so after the two >> "compute" we have the values of E1 and E2 on the stack and we can pop >> them in reverse order. > > It seems apparent that the computations are being done in reverse order, > too. That can be seen in the above *Messages* output as well as in > byte-compile-let in bytecomp.el: > > (dolist (var (if is-let (reverse clauses) clauses)) > (unless is-let > (push (byte-compile-push-binding-init var) init-lexenv)) > (let ((var (if (consp var) (car var) var))) > (if (byte-compile-bind var init-lexenv) > (pop init-lexenv)))) > > .. (reverse clauses) happens before the code for any of the value forms > gets generated. AFAICT "the code for any of the value forms" is generated by `byte-compile-push-binding-init`. When `is-let` is true, the above loop does not call it at all, it only emits the code which does the `varbind` thingies. When `is-let` is true the calls to `byte-compile-push-binding-init` are performed just before this loop (and non-reversed). Maybe having written this code I'm unable to see what it actually does instead of seeing what I want(ed) it to do, but my impression is that if it really does it in the wrong order, we'd have noticed a long time ago. My crystal ball doesn't want to talk to me today, but my hope is that it's a bug in something like our new-ish variable/constant-propagation optimization. > This is a bug in either the byte compiler or the documentation of let. > I would tend towards the first of these alternatives. +1 Stefan PS: BTW, Alan, thanks for putting me in `Cc:`; even better would have been to put me in `X-Debbugs-Cc:`.