Take a big shortcut when compiling (lambda () nil)
Some checks failed
Linux qemu / ppc64le (push) Failing after 1s
CL-host / ecl (push) Has been cancelled
CL-host / clisp (push) Has been cancelled
CL-host / ccl (push) Has been cancelled
CL-host / cmucl (push) Has been cancelled
CL-host / sbcl (push) Has been cancelled
Linux / build (x86, --with-sb-thread, ) (push) Has been cancelled
Linux / build (x86, --without-sb-thread, ) (push) Has been cancelled
Linux / build (x86, --without-sb-unicode, ) (push) Has been cancelled
Linux / build (x86-64, --with-mark-region-gc) (push) Has been cancelled
Linux / build (x86-64, --with-sb-fasteval --without-sb-eval, fasteval) (push) Has been cancelled
Linux / build (x86-64, --with-sb-thread, ) (push) Has been cancelled
Linux / build (x86-64, --with-sb-thread, sse4) (push) Has been cancelled
Linux / build (x86-64, --without-sb-thread, ) (push) Has been cancelled
Linux / build (x86-64, --without-sb-unicode, ) (push) Has been cancelled
Mac / build (--without-sb-thread, x86-64) (push) Has been cancelled
Mac / build (arm64, --with-mark-region-gc) (push) Has been cancelled
Mac / build (arm64, --with-sb-thread) (push) Has been cancelled
Mac / build (x86-64, --with-mark-region-gc) (push) Has been cancelled
Mac / build (x86-64, --with-sb-thread) (push) Has been cancelled
Windows / build (push) Has been cancelled
CL-host / compare-xc-host-fasls (ccl, false) (push) Has been cancelled
CL-host / compare-xc-host-fasls (clisp, false) (push) Has been cancelled
CL-host / compare-xc-host-fasls (cmucl, false) (push) Has been cancelled
CL-host / compare-xc-host-fasls (self, false) (push) Has been cancelled

This commit is contained in:
Douglas Katzman 2024-12-21 18:02:31 +00:00
parent 42d939ea06
commit 42fd0ced76
2 changed files with 32 additions and 0 deletions

View file

@ -101,6 +101,24 @@
;;; If ERORRP is true signals an error immediately -- otherwise returns
;;; a function that will signal the error.
(defun compile-in-lexenv (form *lexenv* name source-info tlf ephemeral errorp)
;; This ridiculous check for a NIL-returning constant function cuts out hundreds of
;; identical functions that result from all the turds that users seem to generate.
;; It's not coming from CLOS per se because our DEFCLASS knows to use :INITFUNCTION
;; as #'SB-INT:CONSTANTLY-NIL of its own volition when applicable. Likely it is user-
;; written code that employs a similar paradigm with no recognition of common cases.
(when (and (typep form '(cons (eql lambda)))
(let ((cdr (cdr form)))
(and (typep cdr '(cons (eql nil)))
(or (null (setq cdr (cdr cdr)))
(equal cdr '(nil))
(equal cdr '('nil))))))
;; I sure hope that users don't expect COMPILE to necessarily return a
;; unique blob of code. How could they?
(return-from compile-in-lexenv
(values (if (policy *lexenv* (= safety 0))
(load-time-value #'constantly-nil t)
(load-time-value #'sb-impl::0-arg-nil t))
nil nil)))
(let ((source-paths (when source-info *source-paths*)))
(with-compilation-values
(with-compilation-unit ()

View file

@ -0,0 +1,14 @@
(with-test (:name :nil-special-case-unsafe)
(proclaim '(optimize (safety 0)))
(assert (eq (compile nil '(lambda ())) (compile nil '(lambda () nil))))
(assert (eq (compile nil '(lambda ())) (compile nil '(lambda () 'nil))))
(let ((f (compile nil '(lambda ()))))
(assert (null (funcall f 3)))))
(with-test (:name :nil-special-case-safe)
(proclaim '(optimize (safety 1)))
(assert (eq (compile nil '(lambda ())) (compile nil '(lambda () nil))))
(assert (eq (compile nil '(lambda ())) (compile nil '(lambda () 'nil))))
(let ((f (compile nil '(lambda ()))))
(assert (null (funcall f)))
(assert-error (funcall f 3)))) ; arg count error