unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Aymeric Agon-Rambosson <aymeric.agon@yandex.com>
To: Sean Whitton <spwhitton@spwhitton.name>
Cc: Eli Zaretskii <eliz@gnu.org>,
	monnier@iro.umontreal.ca, emacs-devel@gnu.org, akrl@sdf.org,
	larsi@gnus.org, rlb@defaultvalue.org
Subject: Re: Finalizing 'inhibit-automatic-native-compilation'
Date: Mon, 06 Feb 2023 11:57:41 +0100	[thread overview]
Message-ID: <87cz6nxdqy.fsf@X570GP> (raw)
In-Reply-To: <87r0v811pm.fsf@melete.silentflame.com>


Hello everyone, and sorry for my being late.

Le jeudi 2 février 2023 à 09:17, Sean Whitton 
<spwhitton@spwhitton.name> a écrit :

> Aymeric, you investigated one of these cases in details.  Would 
> you be
> able to summarise the situation we had in Debian for Eli, 
> please?

The case Sean refers to is probably the packaging of projectile 
(https://github.com/bbatsov/projectile).

In the testbed of this package, the buttercup library 
(https://github.com/jorgenschaefer/emacs-buttercup) is used to 
advise some primitives, like `file-exists-p', 
`insert-file-contents', `file-directory-p' and probably 
others. These primitives can be advised so as to be replaced by a 
function that does nothing, or that always returns a specific 
value, etc...

The following test was interesting :

(describe "projectile-parse-dirconfig-file"
  (it "parses dirconfig and returns directories to ignore and 
  keep"
    (spy-on 'file-exists-p :and-return-value t)
    (spy-on 'file-truename :and-call-fake (lambda (filename) 
    filename))
    (spy-on 'insert-file-contents :and-call-fake
            (lambda (filename)
              (save-excursion (insert 
              "\n-exclude\n+include\n#may-be-a-comment\nno-prefix\n 
              left-wspace\nright-wspace\t\n"))))
    (expect (projectile-parse-dirconfig-file) :to-equal 
    '(("include/")
                                                          ("exclude"
							   "#may-be-a-comment"
							   "no-prefix"
							   "left-wspace"
							   "right-wspace")
                                                          nil))
    ;; same test - but with comment lines enabled using prefix '#'
    (let ((projectile-dirconfig-comment-prefix ?#))
      (expect (projectile-parse-dirconfig-file) :to-equal 
      '(("include/")
							    ("exclude"
							     "no-prefix"
							     "left-wspace"
							     "right-wspace")
							    nil)))
    ))

The primitive `file-exists-p' is advised as to always return t, 
whether the argument corresponds to an existing file or not. If we 
assume the trampoline is not already there (and that is the case 
in our build environment), a trampoline compilation is triggered, 
and exits without error. The advice is effective only after that.

Then `file-truename' is advised, but it is not a primitive.

Then `insert-file-contents' is advised as well, it is a 
primitive. We enter the function `comp-subr-trampoline-install', 
and we begin by checking whether the corresponding trampoline 
already exists by entering the function 
`comp-trampoline-search'. This function relies on `file-exists-p', 
which answers that the file corresponding to the compiled 
trampoline exists, even if it doesn't. Hence we enter 
`native-elisp-load' with a filename that doesn't exist as 
argument, and we error out :

comp-subr-trampoline-install(insert-file-contents)
comp-trampoline-search(insert-file-contents)
native-elisp-load("/tmp/buttercupKuLmvD/28.2-4001e2a9/subr--trampoline-696...
error: (native-lisp-load-failed "file does not exists" 
"/tmp/buttercupKuLmvD/28.2-4001e2a9/subr--trampoline-696e736572742d66696c652d636f6e74656e7473_insert_file_contents_0.eln")

We always get the error because the trampoline is never there 
beforehand, and upstream did not get it precisely because it was 
lucky to always have it before running the test. If we have to 
load *any* trampoline after the advice of `file-exists-p' is 
effective, and we're not lucky enough to already have the 
trampoline, then we reach the error.

In that case, we worked around the problem by adding the primitive 
`insert-file-contents' to the variable 
`native-comp-never-optimize-functions'.

>>   . where and under what circumstances will those advised 
>>   functions be
>>     called, as part of your preparation of the packages?  (if 
>>     the
>>     advised functions are only called when the end-user uses 
>>     the
>>     package, that is not relevant to the present discussion)

As far as we can tell, this advising of primitives happens mostly 
in tests, that is in our build environment on our build machines.

>>   . if we provide a way to specify, via 
>>   comp-enable-subr-trampolines,
>>     the directory to which the trampolines will be written, 
>>     will that
>>     satisfy your uses? if not, why not (details, please)?
>>   . why cannot you use native-comp-eln-load-path to force the
>>     trampolines go to a directory of your choice?

In this case, this is not pertinent. We need to :
- either not to have to install a trampoline
- or, if we have to, be certain to find it in the *first* 
  directory returned by `comp-eln-load-path-eff'.

If neither condition are met, we reach the error. The only 
variables that are of help here are 
`native-comp-never-optimize-functions' or 
`comp-enable-subr-trampolines'.

Since EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION acts on neither 
of these, we have to manually add

(with-eval-after-load 'comp (push 'insert-file-contents 
native-comp-never-optimize-functions))

At the beginning of the test file.

For this reason, it would be nice, if possible, that 
EMACS_INHIBIT_AUTOMATIC_NATIVE_COMPILATION also disables 
trampoline compilation, for instance by setting 
`comp-enable-subr-trampolines'. The name of the environment 
variable would be changed accordingly, of course.

The performance penalty wouldn't be a problem, since this would 
only be for the duration of the test. If Andrea prefers, we could 
also have two different environment variables, one for trampoline 
and the other for deferred async compilation. But I don't see why 
only one knob doesn't work : if we had an environment variable 
that acted on both `inhibit-automatic-native-compilation' and 
`comp-enable-subr-trampolines', like what happens when 
`native-comp-available-p' evaluates to nil, wouldn't that exactly 
"really disable native compilation", or am I missing something ?

>> I dislike having environment variables that alter Emacs 
>> behavior,
>> because environment variables are inherited by sub-processes.

This is precisely why I like it. Our build mechanism can have 
emacs instances nested deep in layers of wrapper scripts. Because 
of this, we can simply export the variable in the environment of 
the ancestor process, and not worry about adding --eval arguments 
in various places in the middle of our scripts. But only the 
descendants of this ancestor process are concerned by this 
environment variable, and they live only as long as the building 
mechanism runs, so I don't see the reason for worry. Then, if 
users want to use this variable in normal use, and they decide on 
top of that to have multiple nested emacsen, then I agree that 
they have to be careful, but that situation seems a bit 
far-fetched.

I hope everything was clear.

Best,

Aymeric Agon-Rambosson

P.S. We have a couple of packages for which we have deactivated 
some trampoline compilation in order to pass tests or avoid an 
error. I haven't been able to find out why like I did with 
projectile, but I guess these cases can be of interest to you :

https://github.com/joaotavora/yasnippet/pull/1158

https://github.com/DamienCassou/beginend/pull/75

P.P.S. The new mechanism consisting in having all the trampolines 
compiled as part of the building process would probably solve 
these two problems, but not the one from projectile. I assume 
these trampolines would be put in the system eln cache, which is 
not returned as the first directory by 
`comp-eln-load-path-eff'. We would therefore reach the error 
anyway. But this is very good in my opinion, as are all efforts to 
increase the amount of stuff native compiled eagerly (like 
NATIVE_FULL_AOT).




  reply	other threads:[~2023-02-06 10:57 UTC|newest]

Thread overview: 146+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 12:57 Finalizing 'inhibit-automatic-native-compilation' Eli Zaretskii
2023-01-27 14:19 ` Andrea Corallo
2023-01-27 23:11 ` Stephen Leake
2023-01-27 23:58   ` Stefan Monnier
2023-01-28  0:32     ` Stephen Leake
2023-01-28  8:31       ` Eli Zaretskii
2023-01-28  8:08   ` Eli Zaretskii
2023-01-29 21:42     ` Stephen Leake
2023-01-27 23:57 ` Stefan Monnier
2023-01-28  9:17   ` Eli Zaretskii
2023-01-28 17:00     ` Stefan Monnier
2023-01-28 17:09       ` Eli Zaretskii
2023-01-28 17:42         ` Stefan Monnier
2023-01-28 17:54           ` Eli Zaretskii
2023-01-28 18:00             ` Stefan Monnier
2023-01-28 18:09               ` Eli Zaretskii
2023-01-28 21:41                 ` Andy Moreton
2023-01-29  6:46                   ` Eli Zaretskii
2023-01-29 11:46                     ` Andy Moreton
2023-01-28 22:24                 ` Stefan Monnier
2023-01-29  6:25                   ` Eli Zaretskii
2023-01-29 14:58                     ` Stefan Monnier
2023-01-29 15:30                       ` Eli Zaretskii
2023-01-30  2:30                         ` Stefan Monnier
2023-01-30 12:47                           ` Eli Zaretskii
2023-01-30 14:57                             ` Stefan Monnier
2023-01-30 17:07                               ` Eli Zaretskii
2023-01-30 17:18                                 ` Stefan Monnier
2023-01-31  4:19                               ` Richard Stallman
2023-01-31 14:26                                 ` Stefan Monnier
2023-02-01  5:04                                   ` Richard Stallman
2023-02-04 19:55                                     ` Lynn Winebarger
2023-02-04 20:08                                       ` Eli Zaretskii
2023-02-04 22:05                                         ` Lynn Winebarger
2023-02-05  7:40                                           ` Eli Zaretskii
2023-02-05 16:22                                             ` Lynn Winebarger
2023-02-06 10:15                                             ` Andrea Corallo
2023-02-06 10:25                                               ` Andrea Corallo
2023-02-06 13:05                                               ` Eli Zaretskii
2023-02-06 13:37                                                 ` Lynn Winebarger
2023-02-06 14:07                                                   ` Eli Zaretskii
2023-02-06 14:29                                                     ` Lynn Winebarger
2023-02-06 15:28                                                       ` Eli Zaretskii
2023-02-07  3:57                                                         ` Lynn Winebarger
2023-02-06 15:26                                               ` Lynn Winebarger
2023-02-02  5:18                           ` Sean Whitton
2023-02-02  7:55                             ` Eli Zaretskii
2023-02-02 16:17                               ` Sean Whitton
2023-02-06 10:57                                 ` Aymeric Agon-Rambosson [this message]
2023-02-06 14:29                                   ` Eli Zaretskii
2023-02-07  3:39                                     ` Aymeric Agon-Rambosson
2023-02-07 12:49                                       ` Eli Zaretskii
2023-02-09  8:40                                         ` Aymeric Agon-Rambosson
2023-02-09 10:11                                           ` Eli Zaretskii
2023-02-09 21:07                                             ` Sean Whitton
2023-02-10  8:13                                               ` Eli Zaretskii
2023-02-10  8:37                                             ` Aymeric Agon-Rambosson
2023-02-10 16:53                                               ` Andrea Corallo
2023-02-10 17:34                                                 ` Aymeric Agon-Rambosson
2023-02-11  8:11                                                   ` Andrea Corallo
2023-02-11 10:06                                                     ` Aymeric Agon-Rambosson
2023-02-11 10:44                                                       ` Eli Zaretskii
2023-02-12 16:47                                                         ` Aymeric Agon-Rambosson
2023-02-12 16:55                                                           ` Eli Zaretskii
2023-02-12 19:58                                                             ` Aymeric Agon-Rambosson
2023-02-12 20:09                                                               ` Eli Zaretskii
2023-02-14 10:36                                                                 ` Aymeric Agon-Rambosson
2023-02-14 13:51                                                                   ` Eli Zaretskii
2023-02-15 22:39                                                                     ` Aymeric Agon-Rambosson
2023-02-16  8:04                                                                       ` Eli Zaretskii
2023-02-17  8:15                                                                         ` Eli Zaretskii
2023-02-17 10:16                                                                           ` Andrea Corallo
2023-02-17 14:17                                                                             ` Eli Zaretskii
2023-02-18 21:48                                                                               ` Andrea Corallo
2023-02-19  9:21                                                                                 ` Eli Zaretskii
2023-02-20  9:14                                                                                   ` Andrea Corallo
2023-02-20 12:02                                                                                     ` Eli Zaretskii
2023-02-09 21:05                                       ` Sean Whitton
2023-02-10  8:08                                         ` Eli Zaretskii
2023-02-10 22:13                                           ` Sean Whitton
2023-02-11  9:16                                             ` Eli Zaretskii
2023-02-13 22:57                                               ` Sean Whitton
2023-02-14  5:17                                                 ` tomas
2023-02-14 13:21                                                   ` Eli Zaretskii
2023-02-14 11:29                                                 ` Andrea Corallo
2023-02-14 17:11                                                   ` Sean Whitton
2023-02-16 18:10                                                   ` Sean Whitton
2023-02-17  9:00                                                     ` Andrea Corallo
2023-02-17 16:42                                                       ` Sean Whitton
2023-02-17 19:18                                                         ` Eli Zaretskii
2023-02-17 21:13                                                         ` Bug#1021842: " Tatsuya Kinoshita
2023-02-18 21:56                                                           ` Andrea Corallo
2023-02-19  4:22                                                             ` Stefan Monnier
2023-02-20  9:03                                                               ` Andrea Corallo
2023-02-20 12:01                                                                 ` Eli Zaretskii
2023-02-20 15:42                                                                   ` Andrea Corallo
2023-02-20 16:02                                                                     ` Stefan Monnier
2023-02-20 20:22                                                                       ` Andrea Corallo
2023-02-20 16:57                                                                     ` Eli Zaretskii
2023-02-20 20:29                                                                       ` Andrea Corallo
2023-02-20 12:48                                                                 ` Stefan Monnier
2023-02-20 16:07                                                                   ` Andrea Corallo
2023-02-20 17:24                                                                     ` tomas
2023-02-07 13:56                                   ` Andrea Corallo
2023-02-07 15:03                                     ` Stefan Monnier
2023-02-07 15:27                                       ` Andrea Corallo
2023-02-09  7:26                                     ` Aymeric Agon-Rambosson
2023-02-09  7:52                                       ` Eli Zaretskii
2023-02-10  8:04                                         ` Aymeric Agon-Rambosson
2023-02-10  8:46                                           ` Eli Zaretskii
2023-02-10 17:02                                             ` Andrea Corallo
2023-02-02  5:40 ` Sean Whitton
2023-02-02  8:02   ` Eli Zaretskii
2023-02-02  8:41     ` tomas
2023-02-02  9:18       ` Eli Zaretskii
2023-02-02 16:28     ` Sean Whitton
2023-02-02 17:21       ` Eli Zaretskii
2023-02-09 21:12         ` Sean Whitton
2023-02-04 17:48 ` Liliana Marie Prikler
2023-02-04 18:18   ` Eli Zaretskii
2023-02-06 10:21     ` Andrea Corallo
2023-02-13 12:05 ` Andrea Corallo
2023-02-13 13:19   ` Eli Zaretskii
2023-02-13 15:21     ` Andrea Corallo
2023-02-13 15:37       ` Eli Zaretskii
2023-02-13 16:15         ` Andrea Corallo
2023-02-13 19:17   ` Stefan Monnier
2023-02-13 19:34     ` Andrea Corallo
2023-02-13 20:43       ` Stefan Monnier
2023-02-13 21:53         ` Andrea Corallo
2023-02-13 23:04           ` Stefan Monnier
2023-02-14  8:56             ` Andrea Corallo
2023-02-14 11:32             ` Andrea Corallo
     [not found]               ` <166586215062.368699.18398270685158383578.reportbug@convex>
2023-02-19 14:31                 ` Bug#1021842: " Tatsuya Kinoshita
2023-02-20  9:18                 ` Andrea Corallo
2023-02-20 12:03                   ` Eli Zaretskii
2023-02-20 20:50                 ` Bug#1021842: " Lynn Winebarger
2023-02-20 21:34                   ` Stefan Monnier
2023-02-20 22:17                     ` Lynn Winebarger
2023-02-20 22:02                 ` Bug#1021842: " Tatsuya Kinoshita
2023-02-21 15:40                 ` Andrea Corallo
2023-02-14  3:23       ` Eli Zaretskii
2023-02-14  3:31         ` Stefan Monnier
2023-02-14  8:55           ` Andrea Corallo
2023-02-14 13:11           ` Eli Zaretskii
2023-02-14 15:09             ` Stefan Monnier

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=87cz6nxdqy.fsf@X570GP \
    --to=aymeric.agon@yandex.com \
    --cc=akrl@sdf.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rlb@defaultvalue.org \
    --cc=spwhitton@spwhitton.name \
    /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).