Subject: bug#60996: 29.0.60; Native compile fails to remove temp file for trampoline

From: Andrea Corallo <[email-masked]>
Date: Thu, 26 Jan 2023 16:57:44 +0000

Eli Zaretskii <[email-masked]> writes:

>> Cc: [email-masked]
>> Date: Tue, 24 Jan 2023 14:56:00 +0200
>> From: Eli Zaretskii <[email-masked]>
>> 
>> But first, I'd like to understand whether indeed it could happen that
>> we are deleting a temporary .eln file for a trampoline we just
>> compiled when we are still using that .eln file.  If this happens,
>> we'd need to find a way to delay the deletion till Emacs is about to
>> exit or something.
>
> I keep looking at the backtraces you provided, this:
>
>> Debugger entered--Lisp error: (permission-denied "Removing old name" 
>> "Permission denied" "c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
>> delete-file("c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
>>    #f(compiled-function () #<bytecode 0xb2aa5c0c9e24501>)()
>>    comp--native-compile((lambda (arg0 &optional arg1 arg2 arg3) (let ((f 
>> #'format-mode-line)) (funcall f arg0 arg1 arg2 arg3))) nil nil)
>>    comp-trampoline-compile(format-mode-line)
>>    comp-subr-trampoline-install(format-mode-line)
>>    advice--add-function(:around (#f(compiled-function () #<bytecode 
>> 0x3c5d8019df7e91>) . #f(compiled-function (gv--val) #<bytecode 
>> 0x8fdecbbba7cb3c2>)) delight--format-mode-line nil)
>>    advice-add(format-mode-line :around delight--format-mode-line)
>>    require(delight nil t)
>
> And this:
>
>> delete file("path/to/comp-lambda-XXXXX.eln")
>> comp--native-compile((lambda (...) ...))
>> comp-trampoline-compile(function-name)
>> comp-subr-trampoline-install(function-name)
>> advice--add-function(...)
>> advice-add(function-name ...)
>
> and I still don't have a clear picture regarding which code calls
> delete-file and why.  For example, the first backtrace above says that
> comp--native-compile calls delete-file via some byte-compiled
> function, not directly.  But what is that byte-compiled function? can
> you figure that out?
>
> There is a direct call to delete-file in comp--native-compile, but is
> that the call which fails?  And if so, why does it fail?  Which code
> created the .eln file that comp--native-compile tries to delete?
>
> Andrea, can you please describe in detail what happens, step by step,
> when comp-subr-trampoline-install is called like above, to compile a
> trampoline for an advised function?  What is that file which
> comp--native-compile is deleting at the end?

Hi Eli,

comp-subr-trampoline-install just search for an existing trampoline with
comp-trampoline-search, if this is not found is using
comp-trampoline-compile to produce that.  Once the trampoline is found
or created it gets installed.

In this case as the trampoline is not found and so
comp-trampoline-compile is invoking comp--native-compile to produce one.

Please see my other reply into this thread for more, as there might be
more to investigate here.

BR

  Andrea