Subject: Re: feature/native-comp; failure to compile json-mode leaves Emacs broken

From: Tom Gillespie <[email-masked]>
Date: Thu, 17 Sep 2020 13:49:28 -0400

Hi Andrea,
    Having poked about a bit more I agree. I don't think it has
anything to do with the native compilation directly. I suspect that it
has to do with how or exactly when the native compiled code is swapped
in. When byte compiling on the command line I get an error at the same
place that I get one when native compiling stating that json-snatcher
could not be required. However when byte compiling the file, the code
to add to kill-buffer-hook is not run. I'm wondering whether the load
starts, native comp kicks in, succeeds on the first couple of forms,
then fails for the same reason as bytecomp, except that the first
forms were successfully loaded? This assumes that native-comp compiles
and loads single expressions at a time. The other possibility that
comes to mind is that maybe the regular el file forms are loaded, and
then there is a step where the forms that would be replaced are
unloaded? My ignorance of how you do the swap doesn't help here. Note
that if you try to repro this now you will have to install an older
version of json-snacher since the patch to fix the issue has been
merged. Best,
Tom

On Fri, Sep 4, 2020 at 12:56 AM Andrea Corallo <[email-masked]> wrote:
>
> Hi Tom,
>
> thanks for the detailed report.
>
> Tom Gillespie <[email-masked]> writes:
>
> > While this is clearly a bug in the way that json-snatcher is written
> > (the symbol should never have been added to the hook before the
> > function was defined), it is only causing an issue with the new native
> > comp code.
>
> had no time to reproduce but to a very first look I'm quite unconvinced
> this is a native-comp bug.  I think you'd get the same exact error
> byte-compiling the file from shell using a vanilla Emacs.
>
> The fact is that native async compilations are child processes so they
> start with a clean environment.  This makes the native compiler a little
> more picky on bugs when the compilation is relaying silently on some
> definition sneaked in from the environment.
>
> This lead already to a number of packages to fix their requires.
>
> The proof is typically trying to byte-compile from shell, this give
> systematically the same error, this because the front-end of the native
> compiler *is* the byte-compiler :)
>
> Each compilation unit should be consistent and compilable autonomously
> without relaying on previous modifications of the environment.
>
> Thanks
>
>   Andrea