Subject: Re: bug#52773: Master and (probably) emacs-28: locate-library hides .eln files.

From: Andrea Corallo <[email-masked]>
Date: Fri, 24 Dec 2021 13:18:13 +0000

Alan Mackenzie <[email-masked]> writes:

> Hello, Emacs and Andrea.
>
> With a native compiled recent master branch, do:
>
>     emacs -Q
>     M-x locate-library <RET> files <RET>
>
> The result in the echo area is something like:
>
>
>     Library is file ~/emacs/emacs.git/sub-master-5/lisp/files.el
>                                                              ^^^
>
> ..  This is wrong.  The Emacs is _NOT_ running uncompiled Lisp, it's
> running native compiled files.  The reply should be a file name ending
> in ".eln".
>
> This problem is surely also in the emacs-28 branch.
>
> #########################################################################
>
> The cause of the problem is in `locate-file' in files.el.  There, if a
> ..eln file is found, it's corresponding .el source is looked up in a hash
> table, and the .el name returned instead.
>
> This mechanism was inserted by the following patch:
>
> commit 3224a443060a5f21bb910064fc06fe4432810355
> Author: Andrea Corallo <[email-masked]>
> Date:   Sun Jul 19 10:46:24 2020 +0200
>
>     Move eln files into dedicated cache directories
>
>     When loading a elc file search for a corresponding eln one into
>     `comp-eln-load-path' directories and load it if available.
>     `comp-eln-load-path' contains by default two directory (user and
>     system one).
>
> It seems there is some use case for which returning the .el file name in
> place of the .eln is appropriate.  It isn't appropriate for
> locate-library.
>
> I would suggest moving the hash table mechanism out of locate-file, and
> into the other function which calls locate-file, where the substitution
> is wanted.

[resending as the mail was rejected by [email-masked]]

Hi Alan,

The trouble in this area is that `locate-library' might be used by
existing programs to obtain the source file (.elc files are tipically in
the same directory where the corresponding .el are).

This was the big trouble also for `load-file-name' and that's why we had
to add `load-true-file-name', all other solution caused unacceptable
incompatibilities with existing software.

AFAIR `locate-library' had the same exact issue.

Best Regards

  Andrea