Subject: bug#76573: 30.1; native compilation fails for record inside function

From: Eli Zaretskii <[email-masked]>
Date: Sat, 31 May 2025 12:15:27 +0300

Ping!  Andrea, any comments or suggestions, given what Stefan writes?

> From: Stefan Monnier <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],  [email-masked],
>   [email-masked]
> Date: Mon, 12 May 2025 10:19:17 -0400
> 
> >> Ping!  Any further ideas for how to make progress with this issue?
> > Compiler-wise I'm okay to demote the error to a warning (with the
> > proposed patch).
> 
> FWIW, I think `comp.el` should definitely not signal an error here.
> This part of the compiler's code is trying to optimize the code, and
> optimizations should never signal errors: if the code was accepted by
> the byte-compiler, then it's valid and the native compiler should accept
> it as well.
> 
> If you want to emit a warning, that's fine but the wording should
> clarify that this is an issue of lack of info potentially relevant for
> an optimization (like when we warn about defsubst defined after they've
> already been called).  In the current instance, I wonder if the impact
> of this lack of info (on the quality of the generated code) is
> sufficiently important to warrant a warning.
> 
> > Language-wise I asking myself, why should the user create records
> > manually if we have facilities like cl-defstruct?
> 
> Why not?  Maybe they're using their own alternative to
> `cl-defstruct/defclass`?
> 
> BTW, even using `defclass` your code will still signal the same error:
> 
>     % src/emacs -Q batch --eval '(progn (defclass my-foo () ((a :initarg :a))) (native-compile (defun my-fun () (record `my-foo 3))))'
>     
>     Error: error (my-fun "Type my-foo missing from typeof-types!")
>       signal(error (my-fun "Type my-foo missing from typeof-types!"))
>       comp--native-compile(my-fun nil nil)
>       native-compile(my-fun)
>       (progn (defclass my-foo nil ((a :initarg :a))) (native-compile (defun my-fun nil (record `my-foo 3))))
>       eval((progn (defclass my-foo nil ((a :initarg :a))) (native-compile (defun my-fun nil (record `my-foo 3)))) t)
>       command-line-1(("--eval" "(progn (defclass my-foo () ((a :initarg :a))) (native-compile (defun my-fun () (record `my-foo 3))))"))
>       command-line()
>       normal-top-level()
>     
>     debug-early-backtrace...done
>     peculiar error: "Type my-foo missing from typeof-types!"
>     %
> 
> 
> - Stefan
> 
>