GNU bug report logs -
#8711
24.0.50; binding _ to unused values with lexical-binding
Previous Next
Reported by: Helmut Eller <eller.helmut <at> gmail.com>
Date: Sat, 21 May 2011 18:45:02 UTC
Severity: minor
Found in versions 24.0.50, 26.0.50
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):
* Stefan Monnier [2011-05-23 14:24] writes:
> The two warnings come from different analyzes:
> - The warning for `bar' comes from cconv.el which is intended to check
> whether the variable is syntactically used, rather than semantically.
> - The warning for `foo' checks whether pure functions are not called for
> their side-effects and it's applied after optimizations so in the
> above code, the code generated by destructuring-bind ends up optimized
> to something that calls `car' without binding the result to _ because
> it figured that _ is not used and just got rid of it without warning.
>
> So most likely the answers I give here aren't satisfactory to the OP,
> since his real problem is probably different than (destructuring-bind
> (_) x) and the solution for that problem is probably going to be
> yet different.
My problem is basically that I have a macro "destructure-case" that
expands to destructuring-bind, e.g.:
(destructure-case location
((:error _) nil)) ; do nothing
expands to
(ecase (car location)
(:error (destructuring-bind (_) (cdr location)
(ignore _)
nil)))
The macro inserts the (ignore _) to suppress the "value returned from
(car --cl-rest--) is unused" warning. But that trick only works for the
non-lexical-binding case.
I think that rewriting (let ((_ foo))) to (progn foo nil) is not quite
right because that loses the information that the value that flows to
the variable _ is intentionally ignored, but I guess that is somewhat
hard to fix this. (Maybe byte-optimize-letX could call
byte-optimize-form-code-walker directly but instead of specifying that
the form is evaluated "for-effect" somehow say that the value is
"ignorable".)
It's perhaps easier to teach destructuring-bind the _ convention so that
it can produce more direct code.
There is also a somewhat related problem with loop:
;; -*- lexical-binding: t -*-
(defun foo (alist) (loop for (_key . value) in alist collect value))
produces a "variable `_key' not left unused" warning.
Helmut
This bug report was last modified 3 years and 64 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.