From: Lars Ingebrigtsen <larsi@gnus.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Christopher Wellons <wellons@nullprogram.com>,
31641@debbugs.gnu.org, Noam Postavsky <npostavs@gmail.com>
Subject: bug#31641: 26.1; iter-do variable not left unused warning
Date: Sat, 06 Feb 2021 11:31:49 +0100 [thread overview]
Message-ID: <87mtwhebca.fsf@gnus.org> (raw)
In-Reply-To: <jwv1rdvdcko.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 04 Feb 2021 11:36:27 -0500")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> You can clean up this semantics and the warning at the same time by
> using an expansion like:
>
> (let (#3=#:iter-do-result11
> (#1=#:iter-do-iterator-done8 nil)
> (#2=#:iter-do-iterator10 i))
> (while (not #1#)
> (let ((_ (condition-case #4=#:iter-do-condition9
> (iter-next #2#)
> (iter-end-of-sequence
> (setf #3# (cdr #4#))
> (setf #1# t)))
> (unless #1# [BODY])
> #3#)
So I tried this...
diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el
index 9eb6d95964..dfd2513350 100644
--- a/lisp/emacs-lisp/generator.el
+++ b/lisp/emacs-lisp/generator.el
@@ -725,17 +725,18 @@ iter-do
(condition-symbol (cps--gensym "iter-do-condition"))
(it-symbol (cps--gensym "iter-do-iterator"))
(result-symbol (cps--gensym "iter-do-result")))
- `(let (,var
- ,result-symbol
+ `(let (,result-symbol
(,done-symbol nil)
(,it-symbol ,iterator))
(while (not ,done-symbol)
- (condition-case ,condition-symbol
- (setf ,var (iter-next ,it-symbol))
- (iter-end-of-sequence
- (setf ,result-symbol (cdr ,condition-symbol))
- (setf ,done-symbol t)))
- (unless ,done-symbol ,@body))
+ (let ((,var
+ (condition-case ,condition-symbol
+ (iter-next ,it-symbol)
+ (iter-end-of-sequence
+ (setf ,result-symbol (cdr ,condition-symbol))
+ (setf ,done-symbol t)))))
+ (unless ,done-symbol
+ ,@body)))
,result-symbol)))
(defvar cl--loop-args)
But then this fails:
1 unexpected results:
FAILED iter-lambda-variable-shadowing
Uhm... oh, it fails even without that change? ... If I just say "make
check", then it doesn't fail, but if I say "make generator-tests", then
it fails? Very odd.
> BTW, I think we can remove the duplicate #1 test by moving the body of
> the `while` into its test, e.g.:
>
> (let (#3=#:iter-do-result11
> (#1=#:iter-do-iterator-done8 nil)
> (#2=#:iter-do-iterator10 i))
> (while
> (let ((_ (condition-case #4=#:iter-do-condition9
> (iter-next #2#)
> (iter-end-of-sequence
> (setf #3# (cdr #4#))
> (setf #1# t)))))
> (unless #1#
> [BODY]
> t)))
> #3#)
Indeed. I've now pushed something like this to Emacs 28.
> 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.
Yup.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2021-02-06 10:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-29 13:12 bug#31641: 26.1; iter-do variable not left unused warning Christopher Wellons
2018-05-29 22:13 ` Noam Postavsky
2021-02-04 10:05 ` Lars Ingebrigtsen
2021-02-04 16:36 ` Stefan Monnier
2021-02-05 8:53 ` Lars Ingebrigtsen
2021-02-05 15:03 ` Stefan Monnier
2021-02-06 10:31 ` Lars Ingebrigtsen [this message]
2021-02-05 17:12 ` Basil L. Contovounesios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mtwhebca.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=31641@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=npostavs@gmail.com \
--cc=wellons@nullprogram.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.