unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Vigouroux via "Emacs development discussions." <emacs-devel@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: pcase map binding form expansion failure on Emacs 27 only
Date: Wed, 08 Sep 2021 15:07:18 +0200	[thread overview]
Message-ID: <87o8932p2x.fsf@laposte.net> (raw)
In-Reply-To: <87eea0610n.fsf@alphapapa.net> (Adam Porter's message of "Tue, 07 Sep 2021 07:08:56 -0500")

Adam Porter <adam@alphapapa.net> writes:

> Hi,
>
> I've come upon a very strange--to me, anyway--problem: When
> byte-compiling a file at package installation time or in a batch
> session, this pcase binding form:
>
>   (pcase-let* (((map :max-width) plist))
>     max-width)
>
> correctly expands to this, on Emacs 26.3 and 28.0.50:
>
>   (let* ((x6 (map-elt plist :max-width)))
>     (let ((max-width x6))
>       max-width))
>
> However, on Emacs 27, it incorrectly expands to:
>
>   (let* ((x6 (map-elt plist ':max-width)))
>     (progn max-width))

Your patch is not included in the latest Emacs release (27.2). So, the
macro expansion works as expected.

>
> This leads to warnings, errors, complete failure of the installed
> package, and repeated bug reports.  In these reports, sometimes users
> reinstall the package in question (sometimes after deleting the package
> and restarting Emacs) and see the problem resolved, and in other cases,
> nothing works.  (And sometimes the package author mistakenly accuses the
> users of having configuration problems (which, sometimes, they did, but
> not always).)
>
> I confirmed that this happens even though map.el is installed at version
> 3.1, and even though that version is actually loaded, by using this form
> in the file:
>
>   (eval-when-compile
>     (save-excursion
>       (message "MAP VERSION IS: %S"
>                (package-desc-version (car (alist-get 'map package-alist))))
>       (message "MAP IS AT: %S"
>                (locate-library "map"))
>       (message "EXPANSION TEST: %S"
>                (macroexpand-all '(pcase-let* (((map :max-width) plist))
>                                    max-width)))))
>
> Which produces output like (using my makem.sh script[0], which I use for
> linting and testing Emacs packages locally and on CI):
>
>   LOG (2021-09-07 11:31:03): Compiling file: bufler-workspace.el...
>   MAP VERSION IS: (3 1)
>   MAP IS AT: "/tmp/tmp.cEPHlNUWYk/27.1/elpa/map-3.1/map.elc"
>   EXPANSION TEST: (let* ((x6 (map-elt plist ':max-width))) (progn max-width))
>   Eager macro-expansion failure: (void-variable max-width)
>

It seems to me that the `eval-when-compile' code is wrong. What does the
compiler really generate?

#+begin_src emacs-lisp
(defvar plist (list :max-height 3 :max-width 2))

(eval-when-compile
  (message "EXPANSION TEST: %S"
	   (macroexpand-all '(pcase-let* (((map :max-width) plist))
			       max-width))))
#+end_src

#+begin_src emacs-lisp
;; Load the latest version of the `map' library (v3.1)
;;  located in the Download directory.
(load-file "~/Downloads/map.el")

;; Byte-compile the sample test stored in the file
;;  /tmp/sample.el
(byte-compile-file "/tmp/sample.el")

;; Look at the compiled file
(find-file "/tmp/sample.elc")
#+end_src

You can see in the compiled file that there is no instruction related to
the macro expansion. Obviously, there is no message displayed when the
byte-code interpreter runs the compiled code.

#+begin_quote
;ELC
;;; Compiled
;;; in Emacs version 27.2
;;; with all optimizations.

;;; This file uses dynamic docstrings, first added in Emacs 19.29.

;;; This file does not contain utf-8 non-ASCII characters,
;;; and so can be loaded in Emacs versions earlier than 23.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defvar plist (list :max-height 3 :max-width 2))
#+end_quote

So, I think that you have mixed things up when testing.

> Even though I submitted the (very small) patch to map.el that added
> support for the (map :KEYWORD) binding form, I finally had to give in
> and apply a workaround in my package, using this binding form instead:
>
>   ((map (:face face) (:max-width max-width)) plist)
>
> That form correctly expands on Emacs 26.3, 27, and 28.0.50.  So at least
> I won't get any more bug reports about this problem on my package.
>
> But I would like to understand what's going on here, if possible.  I'm
> pretty sure that there's no bug in my code: my the package depends on
> map 3.1, that version gets installed before my package does, that
> version is loaded before my package is compiled, and my package does
> (require 'map).  I can't find any reason for it to only fail on Emacs
> 27.  And since it's not only happening in my testing, but in the wild,
> something certainly seems fishy.

Looking at things again, I'm not sure that imposing a given version for
a package is a good thing.

>
> The bug report on my package may be found at
> <https://github.com/alphapapa/bufler.el/issues/70>, but it's long, and
> I've reproduced the relevant parts here, so hopefully it won't be
> necessary to refer to it.
>
> I considered filing this as a bug report, but since Emacs 27 probably
> won't get any new releases IIUC, and since I don't think it's a bug in
> map.el, a discussion here seemed more appropriate.
>
> Thanks for any help,
> Adam
>
> 0: https://github.com/alphapapa/makem.sh
>
>
>

-- 
Best regards,
Kevin Vigouroux



  parent reply	other threads:[~2021-09-08 13:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 12:08 pcase map binding form expansion failure on Emacs 27 only Adam Porter
2021-09-07 16:44 ` Kevin Vigouroux via Emacs development discussions.
2021-09-07 23:49   ` Michael Heerdegen
2021-09-08 11:58     ` Kevin Vigouroux via Emacs development discussions.
2021-09-08  5:43   ` Adam Porter
2021-09-08 13:07 ` Kevin Vigouroux via Emacs development discussions. [this message]
2021-09-08 14:28   ` Adam Porter
2021-09-08 16:47     ` Kevin Vigouroux via Emacs development discussions.
2021-09-08 18:48       ` Adam Porter
2021-09-09  6:20         ` Kevin Vigouroux via Emacs development discussions.
2021-09-10 18:35         ` Kevin Vigouroux via Emacs development discussions.

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o8932p2x.fsf@laposte.net \
    --to=emacs-devel@gnu.org \
    --cc=ke.vigouroux@laposte.net \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).