[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finalizing 'inhibit-automatic-native-compilation'

From: Andrea Corallo
Subject: Re: Finalizing 'inhibit-automatic-native-compilation'
Date: Tue, 07 Feb 2023 13:56:00 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Aymeric Agon-Rambosson <aymeric.agon@yandex.com> writes:

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

Advising primitives is a dangerous action, it can lead the Emacs
machinery to malfunction anytime, these misbehaviors are not documented
and can change from version to version as from configuration to
configuration.  The programmer who advises or redefines a primitive
should be ready to understand the underlying machinery and work out
potential issues (as it was done in this case).

I don't think this is a native comp specific problem, I'm sure one can
find similar examples also on non native comp enabled Emacses.

Best Regards


reply via email to

[Prev in Thread] Current Thread [Next in Thread]