From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar. Date: Tue, 8 Nov 2022 11:01:17 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38308"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59057@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 08 12:02:16 2022 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 1osMMx-0009qt-TC for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Nov 2022 12:02:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osMMn-0000nd-Dp; Tue, 08 Nov 2022 06:02:05 -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 1osMMl-0000ja-1g for bug-gnu-emacs@gnu.org; Tue, 08 Nov 2022 06:02:03 -0500 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 1osMMk-0002eQ-P9 for bug-gnu-emacs@gnu.org; Tue, 08 Nov 2022 06:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1osMMk-0004XP-9m for bug-gnu-emacs@gnu.org; Tue, 08 Nov 2022 06:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Nov 2022 11:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59057 X-GNU-PR-Package: emacs Original-Received: via spool by 59057-submit@debbugs.gnu.org id=B59057.166790528717401 (code B ref 59057); Tue, 08 Nov 2022 11:02:02 +0000 Original-Received: (at 59057) by debbugs.gnu.org; 8 Nov 2022 11:01:27 +0000 Original-Received: from localhost ([127.0.0.1]:36418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1osMMB-0004Wb-8v for submit@debbugs.gnu.org; Tue, 08 Nov 2022 06:01:27 -0500 Original-Received: from mx3.muc.de ([193.149.48.5]:64375) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1osMM9-0004WN-6N for 59057@debbugs.gnu.org; Tue, 08 Nov 2022 06:01:26 -0500 Original-Received: (qmail 93465 invoked by uid 3782); 8 Nov 2022 12:01:18 +0100 Original-Received: from acm.muc.de (p4fe1541b.dip0.t-ipconnect.de [79.225.84.27]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 08 Nov 2022 12:01:17 +0100 Original-Received: (qmail 6008 invoked by uid 1000); 8 Nov 2022 11:01:17 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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:247322 Archived-At: Hello, Stefan. On Mon, Nov 07, 2022 at 16:29:15 -0500, Stefan Monnier wrote: > >> (defvar VAR) does not "create a variable". > > According to both its doc string and the Elisp manual it does. > Where? I'm talking specifically about (defvar VAR) not about > `defvar` in general. The entry in the Elisp manual starts off: This special form defines SYMBOL as a variable. Note that SYMBOL is not evaluated; the symbol to be defined should appear explicitly in the `defvar' form. The variable is marked as "special", meaning that it should always be dynamically bound (see Variable Scoping). "This special form defines SYMBOL as a variable.". There are no ifs, buts, whens, or whenevers in that sentence. This is, at best, somewhat confusing. Note also: "... that it should ALWAYS be dynamically bound ...". I suppose you're now going to say that "defining" a variable is different from "creating" it. And that you're going to say "always" doesn't mean always. >From defvar's doc string: The `defvar' form also declares the variable as "special", so that it is ALWAYS dynamically bound even if `lexical-binding' is t. Here, again, you're going to say that "always" only means "sometimes", I think. > >> It just "locally" declares that this identifier should use dynamic > >> scoping when binding a variable. > > Why "locally"? There's just one obarray involved, which is global. > No, we want to allow `defvar` to have a lexically-local effect. Why? What's the use case? This, again, is contradictory: a defvar with a value has global effect, but without a value has only lexical scope. This doesn't make sense. Why should dynamically bound variables have lexical scope? Could it be the enthusiasm for lexical binding has burst beyond its natural limits? > >> But the better way to write the above code is: > >> (defmacro acm-defvar (var) > >> `(progn > >> (defvar ,var) > >> (eval-when-compile > >> (when (version-check) > >> (setq ,var emacs-major-version))))) > > There are workarounds, yes. But surely it would be better to fix the > > bug. > It's not a workaround. It's how the programmers say whether they want > the (defvar ,var) declaration to affect all the rest of the code or only > the code within the `when`. I think programmers just want defvar to behave sensibly and consistently, and in accordance with the documentation. The recently introduced special handling of defvar without a value is not welcome. Why should anybody want a dynamic variable later to be a lexically scoped variable?. > Why put the (defvar ,var) within the `when` if not to limit > its scope? To limit when it will create the variable, according to the value of the enclosing `if' form. Just like if you do a (setq my-global some-value), that has effect outside of the lexical scope. In my test program, l-s-p is created with a dynamic binding, but later on it got a confusing warning about it being unused as a lexically bound variable. Nobody wants this, surely? > Stefan -- Alan Mackenzie (Nuremberg, Germany).