From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#46834: 28.0.50; byte-compiling the standard counter closure fails Date: Mon, 01 Mar 2021 09:34:21 -0500 Message-ID: References: <8735xf8154.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3896"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 46834@debbugs.gnu.org, Pip Cet To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 01 15:53:14 2021 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 1lGjv8-0000sq-Ea for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 15:53:14 +0100 Original-Received: from localhost ([::1]:58954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGjv6-0006VM-26 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 09:53:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGjdX-0003qr-D7 for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 09:35:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37053) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGjdW-0001Fr-4i for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 09:35:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lGjdW-00035B-0E for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 09:35: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: Mon, 01 Mar 2021 14:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46834 X-GNU-PR-Package: emacs Original-Received: via spool by 46834-submit@debbugs.gnu.org id=B46834.161460929011829 (code B ref 46834); Mon, 01 Mar 2021 14:35:01 +0000 Original-Received: (at 46834) by debbugs.gnu.org; 1 Mar 2021 14:34:50 +0000 Original-Received: from localhost ([127.0.0.1]:48599 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGjdK-00034j-2V for submit@debbugs.gnu.org; Mon, 01 Mar 2021 09:34:50 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:36007) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGjdH-00034V-UY for 46834@debbugs.gnu.org; Mon, 01 Mar 2021 09:34:48 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1CCFD441C0E; Mon, 1 Mar 2021 09:34:42 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 65E5A4401ED; Mon, 1 Mar 2021 09:34:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1614609262; bh=M5MHI3LF/UeX+NyT8yQHA9s9T/Vm3bIndC77EKnW5ww=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=BQ5rfmjqxebdqw28+1g2oZLVI7bzVkxdVtxU1UOq/esYI7JP6pah52smfsjSOpG0I X58E1jLwYzlZtaHQLEJ1XPYfr91ktETHLfWnqgqobUZGKF2qZwz2S9gVJdESqsQrLi nnpQSy2G5otXGJ7atPnpTj6XJ4XVf3vq/bit5BB29zOyuRp6CbctTnlXjf052AN9H1 PWq82hB3BbclLGcs3IiuC/r7ICyxlp5F1oejxxR6vk4nRsCDyadcAnjCp7X7jnOMix XRizIVJDhBq7z40AZKyJUsY7r3vL+aZah8+l5Mq1fGcHAZYTYiCds/inutcVu127df sdW6O2tKaNb/w== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 42C42120319; Mon, 1 Mar 2021 09:34:22 -0500 (EST) In-Reply-To: <8735xf8154.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 01 Mar 2021 14:16:39 +0100") 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" Xref: news.gmane.io gmane.emacs.bugs:201098 Archived-At: >>> (byte-compile (let ((l 0)) (lambda () (cl-incf l)))) > Huh, that's such a standard example of using closures that it's > surprising that we haven't tripped on this before... but I guess we > don't really write code like that much in Emacs. (I can confirm that > the test case doesn't work in Emacs 28.) The problem is not in the way the actual byte compiler handles such code (e.g. when you compile a whole file, which works just fine), it's just for the special case where we pass to `byte-compile` a function *value* rather than an *expression* (in which case, `byte-compile` first needs to turn this value back into a corresponding expression). This is a very special situation, whose main use case is when you do `(byte-compile 'SYMBOL)` and which we don't handle 100% correctly, anyway. E.g. (using lexical-binding, of course): M-: (let ((x 1)) (defun counter1 () (cl-incf x)) (defun counter2 () (cl-incf x))) RET then do M-x byte-compile RET counter1 RET and then try M-: (list (counter1) (counter2) (counter1) (counter2)) and notice that the counter is not shared between the two functions :-( > I've added Stefan M to the CCs; perhaps he has some comments. Thanks, Stefan