Subject: bug#44103: 28.0.50; [feature/native-comp] let-bound dynamic variables are optimized away

From: Andrea Corallo <[email-masked]>
Date: Tue, 20 Oct 2020 19:27:02 +0000

Kisaragi Hiu via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> --text follows this line--
>
> Some functions use a dynamic (special, marked with defvar) variable to
> change their behaviors. In a lexically bound file, those dynamic
> variable bindings are currently optimized away.
>
> # Reproduction
>
> Run this function with the interpreter:
>
> ```elisp
> (defun k/test ()
>   (with-current-buffer (get-buffer-create "testing")
>     (erase-buffer)
>     (let ((data '((a . "b") (c . "b")))
>           (json-encoding-pretty-print t))
>       (insert (json-encode data)))))
> ```
>
> the contents of #<buffer "testing"> after running `(k/test)` should be
>
> ```
> {
>   "a": "b",
>   "c": "b"
> }
> ```
>
> whereas if you native-compile the code, the contents would become
>
> ```
> {"a":"b","c":"b"}
> ```
>
> because `json-encoding-pretty-print` is optimized away (I think).

Hi Kisaragi,

I just tried native compiling this function but the result for me is the
first one (the expected).

Could you share a full recipe starting from emacs -Q to reproduce this
behavior?

Thanks!

  Andrea