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#31641: 26.1; iter-do variable not left unused warning Date: Thu, 04 Feb 2021 11:36:27 -0500 Message-ID: References: <20180529131230.kijx2bkcvcqsyhgg@nullprogram.com> <87in76cdpd.fsf@gmail.com> <87czxgtafv.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22010"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Christopher Wellons , 31641@debbugs.gnu.org, Noam Postavsky To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 04 17:54:52 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 1l7hu7-0005c5-Sk for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Feb 2021 17:54:51 +0100 Original-Received: from localhost ([::1]:45970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7hu6-0000ss-PR for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Feb 2021 11:54:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7hcs-0004z3-SJ for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 11:37:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7hcr-00039F-TX for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 11:37:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l7hcr-0000FU-QE for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 11:37:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Feb 2021 16:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31641 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 31641-submit@debbugs.gnu.org id=B31641.1612456601929 (code B ref 31641); Thu, 04 Feb 2021 16:37:01 +0000 Original-Received: (at 31641) by debbugs.gnu.org; 4 Feb 2021 16:36:41 +0000 Original-Received: from localhost ([127.0.0.1]:42123 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7hcW-0000Eu-RN for submit@debbugs.gnu.org; Thu, 04 Feb 2021 11:36:41 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:15723) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7hcR-0000Ec-Sk for 31641@debbugs.gnu.org; Thu, 04 Feb 2021 11:36:39 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 632B5814D7; Thu, 4 Feb 2021 11:36:30 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A5EBF80976; Thu, 4 Feb 2021 11:36:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1612456588; bh=RbkNmIdLMxguZMKj1ACjbBwZSB8+DQmMtj51t/+3Lf0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=icoNgeXAwoR8OT/Mz5wLZLTIpGSKumwv/vsUJdLa3P6shZRjJ1AGp2DbHw/UycUv7 ORYUg4TR4KZRukEpS95K07yXh/Y4rsZbkImLK0Kwn+lCfoRjH+mwHYC/A81PJRoFBp VZpnQIrPmUtpDSJH3vUPrDkScWvnmprV19O/ZuXKdLs3tM7SFJvm2uj2eZyuQ47PnL 68Go+eoXkGIiWoNQfLfHUYR5TYZwzveSWJlP880XxSmkf2lBZjAs6Gc95ADdsOsHP7 ciTtB9anZcn4Fn0HLUfDK6YULK0MfA9VawC4/IhjiaR6+Ces4pSg/xPIGHm2PU/CK0 TUnQal0kpr7Xw== Original-Received: from alfajor (76-10-182-85.dsl.teksavvy.com [76.10.182.85]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 563B81201C3; Thu, 4 Feb 2021 11:36:28 -0500 (EST) In-Reply-To: <87czxgtafv.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 04 Feb 2021 11:05:24 +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:199313 Archived-At: >>> When byte-compiling an iter-do form with a variable intended to be >>> left unused, the compiler emits a false warning: >>> >>> ;;; -*- lexical-binding: t; -*- >>> (require 'generator) >>> (iter-do (_ i)) >>> ;; -> "Warning: variable =E2=80=98_=E2=80=99 not left unused" >> >> Looking at the expansion, I guess the setf should be dropped if the >> variable name starts with _. >> >> (let (_ >> #3=3D#:iter-do-result11 >> (#1=3D#:iter-do-iterator-done8 nil) >> (#2=3D#:iter-do-iterator10 i)) >> (while (not #1#) >> (condition-case #4=3D#:iter-do-condition9 >> (setf _ (iter-next #2#)) >> (iter-end-of-sequence >> (setf #3# (cdr #4#)) >> (setf #1# t))) >> (unless #1#)) >> #3#) FWIW, I find the above expansion to provide somewhat "dirty" semantics in the sense that (let ((funs '())) (iter-do (n i) (push (lambda () n) funs)) funs) will return a list of functions which all return the same value (the last `n`). You can clean up this semantics and the warning at the same time by using an expansion like: (let (#3=3D#:iter-do-result11 (#1=3D#:iter-do-iterator-done8 nil) (#2=3D#:iter-do-iterator10 i)) (while (not #1#) (let ((_ (condition-case #4=3D#:iter-do-condition9 (iter-next #2#) (iter-end-of-sequence (setf #3# (cdr #4#)) (setf #1# t))) (unless #1# [BODY]) #3#) BTW, I think we can remove the duplicate #1 test by moving the body of the `while` into its test, e.g.: (let (#3=3D#:iter-do-result11 (#1=3D#:iter-do-iterator-done8 nil) (#2=3D#:iter-do-iterator10 i)) (while (let ((_ (condition-case #4=3D#:iter-do-condition9 (iter-next #2#) (iter-end-of-sequence (setf #3# (cdr #4#)) (setf #1# t))))) (unless #1# [BODY] t))) #3#) It's too bad that [BODY] can throw `iter-end-of-sequence`, since otherwise we could move the `condition-case` outside of the loop and get something more efficient. Stefan > The following patch does this, but I'm not sure whether this is correct > or not -- in other cases, the _ convention just removes the warning, but > doesn't change the semantics. > > I wondered whether we could just suppress this warning like this: > > ,(if (string-match-p "\\`_" (symbol-name var)) > `(with-suppressed-warnings ((not-unused ,var)) > (setf ,var (iter-next ,it-symbol))) > `(setf ,var (iter-next ,it-symbol))) > > But no, cconv--analyze-use is called too early, and would have to be > taught about `with-suppressed-warnings'... which, looking at the code, > isn't immediately obvious how to do. > > So does anybody have any ideas here? > > diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el > index 9eb6d95964..0b644cc72c 100644 > --- a/lisp/emacs-lisp/generator.el > +++ b/lisp/emacs-lisp/generator.el > @@ -731,7 +731,10 @@ iter-do > (,it-symbol ,iterator)) > (while (not ,done-symbol) > (condition-case ,condition-symbol > - (setf ,var (iter-next ,it-symbol)) > + ;; Variables that start with an underscore shouldn't be set. > + ,(if (string-match-p "\\`_" (symbol-name var)) > + nil > + `(setf ,var (iter-next ,it-symbol))) > (iter-end-of-sequence > (setf ,result-symbol (cdr ,condition-symbol)) > (setf ,done-symbol t)))