Subject: Re: bug#54079: 29.0.50; Method dispatching eratically fails

From: Stefan Monnier <[email-masked]>
Date: Tue, 08 Mar 2022 14:53:07 -0500

> diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
> index 9be44a8d5a..fb9f70bd67 100644
> --- a/lisp/emacs-lisp/bytecomp.el
> +++ b/lisp/emacs-lisp/bytecomp.el
> @@ -499,9 +499,10 @@ byte-compile-initial-macro-environment
>                                         (byte-compile-new-defuns
>                                          byte-compile-new-defuns))
>                                     (setf result
> -                                         (byte-compile-eval
> +                                         (byte-run-strip-symbol-positions
> +                                          (byte-compile-eval
>                                             (byte-compile-top-level
> -                                            (byte-compile-preprocess form)))))))
> +                                            (byte-compile-preprocess form))))))))

I'd expect the reverse: strip first and then eval the result.
Why should we not strip the form passed to `byte-compile-eval`?
Does `byte-compile-top-level` already return a stripped form of code?
And why bother stripping the result of `byte-compile-eval`?

> @@ -512,9 +513,10 @@ byte-compile-initial-macro-environment
>                                ;; or byte-compile-file-form.
>                                (let* ((print-symbols-bare t) ; Possibly redundant binding.
>                                       (expanded
> -                                      (macroexpand--all-toplevel
> -                                       form
> -                                       macroexpand-all-environment)))
> +                                      (byte-run-strip-symbol-positions
> +                                       (macroexpand--all-toplevel
> +                                        form
> +                                        macroexpand-all-environment))))
>                                  (eval expanded lexical-binding)
>                                  expanded)))))
>      (with-suppressed-warnings

Fundamentally, `eval` should always strip before doing its job.  Yes,
I know, it might be a bit expensive, but we should probably define
a local function in `bytecomp.el` which does strip+eval and use that
instead of `eval` (both here and in `byte-compile-eval`).
WDYT?

        Stefan