Subject: bug#64646: Master: Native compiler doesn't always compile lambda forms.

From: Alan Mackenzie <[email-masked]>
Date: Sat, 15 Jul 2023 13:20:04 +0000

Hello, Eli.

On Sat, Jul 15, 2023 at 16:06:18 +0300, Eli Zaretskii wrote:
> > Date: Sat, 15 Jul 2023 12:10:06 +0000
> > From: Alan Mackenzie <[email-masked]>

> > In the master branch:

> > (i) emacs -Q
> > (ii) C-x b foo.el <RET>
> > (iii) Insert into foo.el:
> >     ;; -*- lexical-binding:t -*-
> > (iv) M-x emacs-lisp-mode
> > (v) Insert into foo.el:
> >     (defun foo () "foo doc string"
> >       (lambda (bar) "lambda doc string" (car bar)))
> > (vi) With point after the function, C-x C-e to evaluate it.

> > (vii) M-: (native-compile 'foo)
> > This returns #<subr foo>
> > (viii) M-: (foo)
> > This returns the lambda form as a byte-compiled function.  This is a bug:
> > it should return the lambda form as a native-compiled function.

> Why do you think it should return the native-compiled form?  Based on
> what?

Well, if the native compilation compiled _all_ of the defun, the lambda
form would also have been compiled, and surely that is what should have
been returned.  There is some suspicion that the native compilation on
this defun is incomplete.

When we do byte-compilation, the returned value is byte-compiled.  By
analogy, when we do NC, the return value should be NC'd.

I can't see any reason to return a byte-compiled function.  The fact that
we use byte-compilation as a part of native-compilation should be an
internal detail, not visible from outside.

Also, the returned lambda function being byte-compiled will cause it to
run more slowly that if it were native-compiled.

-- 
Alan Mackenzie (Nuremberg, Germany).