unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* pcase map binding form expansion failure on Emacs 27 only
@ 2021-09-07 12:08 Adam Porter
  2021-09-07 16:44 ` Kevin Vigouroux via Emacs development discussions.
  2021-09-08 13:07 ` Kevin Vigouroux via Emacs development discussions.
  0 siblings, 2 replies; 11+ messages in thread
From: Adam Porter @ 2021-09-07 12:08 UTC (permalink / raw)
  To: emacs-devel

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))

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)

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.

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




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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  5:43   ` Adam Porter
  2021-09-08 13:07 ` Kevin Vigouroux via Emacs development discussions.
  1 sibling, 2 replies; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-07 16:44 UTC (permalink / raw)
  To: adam; +Cc: emacs-devel

Hi Adam,

Your pattern seems incorrect.

#+begin_quote
(map :max-width) ≈ (map (:max-width :max-width))
#+end_quote

:max-width is a keyword (pattern) but should be a symbol `max-width'.

#+begin_quote
-- (map &rest ARGS)

Build a ‘pcase’ pattern matching map elements.

ARGS is a list of elements to be matched in the map.

Each element of ARGS can be of the form (KEY PAT), in which case KEY is
evaluated and searched for in the map.  The match fails if for any KEY
found in the map, the corresponding PAT doesn’t match the value
associated to the KEY.

Each element can also be a SYMBOL, which is an abbreviation of a (KEY
PAT) tuple of the form ('SYMBOL SYMBOL).

Keys in ARGS not found in the map are ignored, and the match doesn’t
fail.
#+end_quote

#+begin_src emacs-lisp
(pcase-let* (((map (:max-width max-width)) plist))
  max-width)
#+end_src

-- 
Best regards,
Kevin Vigouroux



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2021-09-07 23:49 UTC (permalink / raw)
  To: emacs-devel

Kevin Vigouroux via "Emacs development discussions."
<emacs-devel@gnu.org> writes:

> Each element can also be a SYMBOL, which is an abbreviation of a (KEY
> PAT) tuple of the form ('SYMBOL SYMBOL).

Your Emacs seems to be too old.  Newer versions also have this line:

When SYMBOL is a keyword, it is an abbreviation of the form (:SYMBOL
SYMBOL), useful for binding plist values.


Michael.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  2021-09-07 16:44 ` Kevin Vigouroux via Emacs development discussions.
  2021-09-07 23:49   ` Michael Heerdegen
@ 2021-09-08  5:43   ` Adam Porter
  1 sibling, 0 replies; 11+ messages in thread
From: Adam Porter @ 2021-09-08  5:43 UTC (permalink / raw)
  To: emacs-devel

Kevin Vigouroux via "Emacs development discussions."
<emacs-devel@gnu.org> writes:

> Hi Adam,
>
> Your pattern seems incorrect.
>
> #+begin_quote
> (map :max-width) ≈ (map (:max-width :max-width))
> #+end_quote
>
>
> :max-width is a keyword (pattern) but should be a symbol `max-width'.
>
> #+begin_quote
> -- (map &rest ARGS)
>
> Build a ‘pcase’ pattern matching map elements.
>
> ARGS is a list of elements to be matched in the map.
>
> Each element of ARGS can be of the form (KEY PAT), in which case KEY is
> evaluated and searched for in the map.  The match fails if for any KEY
> found in the map, the corresponding PAT doesn’t match the value
> associated to the KEY.
>
> Each element can also be a SYMBOL, which is an abbreviation of a (KEY
> PAT) tuple of the form ('SYMBOL SYMBOL).
>
> Keys in ARGS not found in the map are ignored, and the match doesn’t
> fail.
> #+end_quote
>
> #+begin_src emacs-lisp
> (pcase-let* (((map (:max-width max-width)) plist))
>   max-width)
> #+end_src

Please see:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e287da5a8154d83a97107b64915ccc17e3a086b8




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  2021-09-07 23:49   ` Michael Heerdegen
@ 2021-09-08 11:58     ` Kevin Vigouroux via Emacs development discussions.
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-08 11:58 UTC (permalink / raw)
  To: emacs-devel

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Kevin Vigouroux via "Emacs development discussions."
> <emacs-devel@gnu.org> writes:
>
>> Each element can also be a SYMBOL, which is an abbreviation of a (KEY
>> PAT) tuple of the form ('SYMBOL SYMBOL).
>
> Your Emacs seems to be too old.  Newer versions also have this line:
>
> When SYMBOL is a keyword, it is an abbreviation of the form (:SYMBOL
> SYMBOL), useful for binding plist values.
>

It is clearer, thank you! By the way, my Emacs version is "27.2": the
latest release.

>
> Michael.
>
>
>

-- 
Best regards,
Kevin Vigouroux



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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-08 13:07 ` Kevin Vigouroux via Emacs development discussions.
  2021-09-08 14:28   ` Adam Porter
  1 sibling, 1 reply; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-08 13:07 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  2021-09-08 13:07 ` Kevin Vigouroux via Emacs development discussions.
@ 2021-09-08 14:28   ` Adam Porter
  2021-09-08 16:47     ` Kevin Vigouroux via Emacs development discussions.
  0 siblings, 1 reply; 11+ messages in thread
From: Adam Porter @ 2021-09-08 14:28 UTC (permalink / raw)
  To: emacs-devel

Kevin Vigouroux via "Emacs development discussions."
<emacs-devel@gnu.org> writes:

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

I am not using the version of map.el included with Emacs 27.2.  As I
wrote in the original message:

>> 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. 

How is it wrong?  The purpose of that code is to output a debug message
when the file is being compiled, which it does.

> What does the compiler really generate?

It generates an incorrect macro expansion, which causes the eager macro
expansion/void-variable errors which precipitated this thread.

> #+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.

It is not intended for a message to be displayed at runtime.  That's why
it's in `eval-when-compile'.

> #+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.

I'm not sure you understand the problem I'm describing.  Please see my
original message.

>> 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.

I don't know what you mean by "imposing a given version for a package."
The "Package-Requires" header instructs package.el to ensure that
certain dependencies are installed at certain minimum versions.  This is
a standard practice in Emacs packages.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-08 16:47 UTC (permalink / raw)
  To: emacs-devel

Adam Porter <adam@alphapapa.net> writes:

> I am not using the version of map.el included with Emacs 27.2.  As I
> wrote in the original message.

>> What does the compiler really generate?

> It generates an incorrect macro expansion, which causes the eager macro
> expansion/void-variable errors which precipitated this thread.

However, in my test, the macro expansion returns a good result. Why?

It seems to me that I proceeded as indicated by first loading ‘map v3.1’
and then compiling the code.

#+begin_quote
;ELC\0\0
;;; 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))
(byte-code "\300\301\302\303!\"\207" [message "EXPANSION TEST: %S" macroexpand-all (pcase-let* (((map :max-width) plist)) max-width)] 4)
#+end_quote

The message displayed in the echo area is:

#+begin_quote
EXPANSION TEST: (let* ((x3 (map-elt plist :max-width))) (let ((max-width x3)) max-width))
#+end_quote

> I'm not sure you understand the problem I'm describing.  Please see my
> original message.

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

> I don't know what you mean by "imposing a given version for a package."
> The "Package-Requires" header instructs package.el to ensure that
> certain dependencies are installed at certain minimum versions.  This is
> a standard practice in Emacs packages.

Maybe I’m not right.
-- 
Best regards,
Kevin Vigouroux



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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.
  0 siblings, 2 replies; 11+ messages in thread
From: Adam Porter @ 2021-09-08 18:48 UTC (permalink / raw)
  To: emacs-devel

Kevin Vigouroux via "Emacs development discussions."
<emacs-devel@gnu.org> writes:

> However, in my test, the macro expansion returns a good result. Why?
>
> It seems to me that I proceeded as indicated by first loading ‘map
> v3.1’ and then compiling the code.

After further digging, the problem seems to be that Emacs 27.2 is not
activating the newer version of map.el installed from ELPA.  I'm able to
reproduce the problem like so:

1.  Ensure that map.el >=2.1 is installed into ~/.emacs.d/elpa.

2.  Make file "/tmp/argh.el" with these contents:

      (require 'package)
      (message "PACKAGE-DIR: %S"
               package-user-dir)
      (package-activate-all)
      (require 'map)
      (message "MAP 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)))
      (byte-compile-file "argh2.el" t)

3.  Make file "/tmp/argh2.el" with these contents:

      (let ((plist '(:max-width 2)))
        (pcase-let* (((map :max-width) plist))
          (message "MAX-WIDTH: %S" max-width)))

4.  Run this command:

      emacs -q --batch -l /tmp/argh.el

On Emacs 27.2, I get this output:

  PACKAGE-DIR: "~/.emacs.d/elpa"
  MAP IS: (2 1)
  MAP IS AT: "/home/me/.emacs.d/elpa/map-2.1/map.elc"
  EXPANSION TEST: (let* ((x6 (map-elt plist ':max-width))) (progn max-width))
  In toplevel form:
  argh2.el:3:30:Warning: reference to free variable ‘max-width’
  Loading /tmp/argh2.elc...
  Symbol’s value as variable is void: max-width

You can see that, even though `locate-library' returns the map-2.1
version, the expansion is not correct.  And when I run Emacs
interactively and `eval-buffer', I get the same result.

However, when I do "M-x unload-feature RET map RET", I get this message:

  Loaded libraries ("/home/me/tmp/src/emacs/emacs/lisp/json.elc")
  depend on /home/me/tmp/src/emacs/emacs/lisp/emacs-lisp/map.elc

So even though `locate-library' returns the map-2.1 version, apparently
the non-ELPA version is what's actually loaded, and that version does
not support the pcase pattern in question.

So, changing "/tmp/argh.el" to these contents, adding a call to
`unload-feature' to force the already-loaded version to be unloaded, and
allowing the subsequent `require' to load the newer version, fixes it:

  (require 'package)
  (message "PACKAGE-DIR: %S"
           package-user-dir)
  (package-activate-all)
  (unload-feature 'map t)
  (require 'map)
  (message "MAP 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)))
  (byte-compile-file "argh2.el" t)

When run in batch mode, that gives this output:

  PACKAGE-DIR: "~/.emacs.d/elpa"
  MAP IS: (2 1)
  MAP IS AT: "/home/me/.emacs.d/elpa/map-2.1/map.elc"
  EXPANSION TEST: (let* ((x6 (map-elt plist :max-width))) (let ((max-width x6)) max-width))
  Loading /tmp/argh2.elc...
  MAX-WIDTH: 2

So there seems to be a discrepancy between the version of the library
returned by `locate-library' and the version of the activated package,
and the version *actually* loaded into Emacs.  Installing newer versions
of core libraries from ELPA doesn't seem to work, or at least not
reliably, on Emacs 27.  But on Emacs 26.3 and Emacs 28.0.50, it seems to
work--for me, anyway.

Is this a bug in Emacs 27, or am I misunderstanding something?  I
thought the point of having newer versions of these core libs on ELPA
was that they could be used in older--or current--Emacs versions, but
this doesn't seem to be working reliably.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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.
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-09  6:20 UTC (permalink / raw)
  To: emacs-devel

Adam Porter <adam@alphapapa.net> writes:

> So there seems to be a discrepancy between the version of the library
> returned by `locate-library' and the version of the activated package,
> and the version *actually* loaded into Emacs.  Installing newer versions
> of core libraries from ELPA doesn't seem to work, or at least not
> reliably, on Emacs 27.  But on Emacs 26.3 and Emacs 28.0.50, it seems to
> work--for me, anyway.
>
> Is this a bug in Emacs 27, or am I misunderstanding something?  I
> thought the point of having newer versions of these core libs on ELPA
> was that they could be used in older--or current--Emacs versions, but
> this doesn't seem to be working reliably.
>

You should file a bug report. It is unclear if a built-in package should
be updated because there are potentially competing indications (or
contradictory).

Look at bug#40971: Updating built-in packages that seq depends on is
broken due to a bug in package.el
-- 
Best regards,
Kevin Vigouroux



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: pcase map binding form expansion failure on Emacs 27 only
  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.
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Vigouroux via Emacs development discussions. @ 2021-09-10 18:35 UTC (permalink / raw)
  To: emacs-devel

It seems to me that this corresponds to the bug 40971: [Updating built-in packages that seq depends on is
broken due to a bug in package.el](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40971)

#+begin_quote
unload-feature: Loaded libraries ("/usr/share/emacs/27.2/lisp/json.elc") depend on /usr/share/emacs/27.2/lisp/emacs-lisp/map.elc
unload-feature: Loaded libraries ("/usr/share/emacs/27.2/lisp/auth-source.elc") depend on /usr/share/emacs/27.2/lisp/json.elc
unload-feature: Loaded libraries ("/usr/share/emacs/27.2/lisp/url/url-parse.elc") depend on /usr/share/emacs/27.2/lisp/auth-source.elc
unload-feature: Loaded libraries ("/usr/share/emacs/27.2/lisp/url/url-handlers.elc") depend on /usr/share/emacs/27.2/lisp/url/url-parse.elc
unload-feature: Loaded libraries ("/usr/share/emacs/27.2/lisp/emacs-lisp/package.elc") depend on /usr/share/emacs/27.2/lisp/url/url-handlers.elc
#+end_quote
-- 
Best regards,
Kevin Vigouroux



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-09-10 18:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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.
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.

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).