Merge remote-tracking branch 'origin/scratch/bug-55156'

This commit is contained in:
Stefan Monnier 2022-05-26 16:46:11 -04:00
commit 14cbb75455
3 changed files with 69 additions and 43 deletions

View file

@ -4943,8 +4943,6 @@ binding slots have been popped."
(push (nth 1 (nth 1 form)) byte-compile-global-not-obsolete-vars))
(byte-compile-normal-call form))
(defconst byte-compile-tmp-var (make-symbol "def-tmp-var"))
(defun byte-compile-defvar (form)
;; This is not used for file-level defvar/consts.
(when (and (symbolp (nth 1 form))
@ -4977,18 +4975,17 @@ binding slots have been popped."
string
"third arg to `%s %s' is not a string: %s"
fun var string))
;; Delegate the actual work to the function version of the
;; special form, named with a "-1" suffix.
(byte-compile-form-do-effect
(if (cddr form) ; `value' provided
;; Quote with `quote' to prevent byte-compiling the body,
;; which would lead to an inf-loop.
`(funcall '(lambda (,byte-compile-tmp-var)
(,fun ,var ,byte-compile-tmp-var ,@(nthcdr 3 form)))
,value)
(if (eq fun 'defconst)
;; This will signal an appropriate error at runtime.
`(eval ',form)
;; A simple (defvar foo) just returns foo.
`',var)))))
(cond
((eq fun 'defconst) `(defconst-1 ',var ,@(nthcdr 2 form)))
((not (cddr form)) `',var) ; A simple (defvar foo) just returns foo.
(t `(defvar-1 ',var
;; Don't eval `value' if `defvar' wouldn't eval it either.
,(if (macroexp-const-p value) value
`(if (boundp ',var) nil ,value))
,@(nthcdr 3 form)))))))
(defun byte-compile-autoload (form)
(and (macroexp-const-p (nth 1 form))