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#51982: Erroneous handling of local variables in byte-compiled nested lambdas Date: Wed, 01 Dec 2021 13:34:01 -0500 Message-ID: References: <87y25jo2q1.fsf@web.de> <29C3A3F8-CD9F-4AF2-A731-3304FC30E380@acm.org> <87wnl23pnd.fsf@web.de> <59A729EF-C4D4-47EB-9ADC-19FE8EBE7F10@acm.org> <877dd0bi17.fsf@web.de> 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="15933"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Michael Heerdegen , Paul Pogonyshev , 51982@debbugs.gnu.org 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 Wed Dec 01 19:35:54 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 1msUSQ-0003sV-Hl for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Dec 2021 19:35:54 +0100 Original-Received: from localhost ([::1]:32984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1msUSM-0001GX-NJ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Dec 2021 13:35:51 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msURf-0001GM-5o for bug-gnu-emacs@gnu.org; Wed, 01 Dec 2021 13:35:09 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1msURa-0006Ol-Vl for bug-gnu-emacs@gnu.org; Wed, 01 Dec 2021 13:35:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1msURa-0005ds-Gk for bug-gnu-emacs@gnu.org; Wed, 01 Dec 2021 13: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: Wed, 01 Dec 2021 18:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51982 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51982-submit@debbugs.gnu.org id=B51982.163838365221621 (code B ref 51982); Wed, 01 Dec 2021 18:35:02 +0000 Original-Received: (at 51982) by debbugs.gnu.org; 1 Dec 2021 18:34:12 +0000 Original-Received: from localhost ([127.0.0.1]:45601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1msUQm-0005ce-Dg for submit@debbugs.gnu.org; Wed, 01 Dec 2021 13:34:12 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49505) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1msUQk-0005cR-SI for 51982@debbugs.gnu.org; Wed, 01 Dec 2021 13:34:11 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A07EF4413E9; Wed, 1 Dec 2021 13:34:04 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D51984413D8; Wed, 1 Dec 2021 13:34:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1638383642; bh=gWcGXHoXNByaNMtXJj0XsN7V8JBTUgFZoCckbjg3Xy8=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=CK/qdKAT/7GRGBQz8WpBsy64BFGOHW+Wb9oFozpm+7o4TOKlnC7YWN6SL1LxeuaZM ULNvsYYIbT+GUlGXom9KoLa+4ZgYnCGKg5mBlMsv350PVHQ0jZGMJi9Xgk1EhXVR8v jwnwm2LcGe+KuhW7S/DatcYtH31Z6XS76uKsbQQZdx7PHg7w5gq5Gz7iaYEk9ppppq jIKBg5Fmb4AMimLfjK5ZplRtUSomTxzC8MqrkTBmQC2hPIFnmCO/a4JZ5f1gqzKNkK WxzVJ0WNmzpjN5siFrRVjN6JGSnFc9a/x54vSv8LsxLVMw9TWR+2ishXi4OCpgqwfO t3TVuZOBUh/pw== Original-Received: from alfajor (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B0FC91209CF; Wed, 1 Dec 2021 13:34:02 -0500 (EST) In-Reply-To: ("Mattias =?UTF-8?Q?Engdeg=C3=A5rd?="'s message of "Wed, 1 Dec 2021 17:04:44 +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:221220 Archived-At: >> BTW, have you checked the impact on byte-code quality? > With respect to these patches? No I meant w.r.t removing `let*` (or `let` as the case may be). > Yes: the B patch gives slightly better code because materialising the > accessor (internal-get-closed-var N) is as cheap or cheaper than even > a stack variable access. But the difference is small and since the > case is rare it's probably insignificant. I'm not worried at all about the performance of this corner-case. >> Also, If mapping is of the form (car-safe SYMBOL) is `var` really the >> correct answer? Shouldn't it still be (cadr mapping)? > Can there ever be a difference? There's a big philosophical difference, yes. >> Side note: I don't understand why we `(cons closedsym`, since that >> `closedsym` can never appear in another binding (since it's fresh). > Maybe it's to satisfy the invariant checked by the assertion at the top? I don't think so because this one just checks that the `cconv--remap-llv` was called where needed and did its job. ... [ goes and removes that `(cons closedsym` ] ... ... [ `make` ] ... Oh, you're right! >> I don't much like this `symbolp` test (which fundamentally seems to >> be trying to recover the information about which branch of the `pcase` >> we're coming from in `cconv--lifted-arg`). > That's precisely what it is trying to do and no, I don't like it much either. I think another way to do the patch B would be to replace `var` with `lifted` right when we construct the (apply-partially ...) thingy (i.e. in the :lambda-candidate part of the function), so those vars that get remapped to `internal-get-closed-var` wouldn't even make their way to `extend`. > I don't see any alternative that is obviously better so I'm applying patch > A. We can still go with B later on if we want; the changes are minor. Good. > Good comments, thank you very much! [ I resent this implicit suggestion that I could ever write something less than a good comment. ] Stefan