From 40d2970f4360bd942ffc3f86db9ff1499a5a5393 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Thu, 27 May 2021 14:03:14 +0200 Subject: Don't propagate lexical variables into inlined functions Functions compiled when inlined (thus from inside the optimiser) mustn't retain the lexical environment of the caller or there will be tears. See discussion at https://lists.gnu.org/archive/html/emacs-devel/2021-05/msg01227.html . Bug found by Stefan Monnier. * lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand): Bind byte-optimize--lexvars to nil when re-entering the compiler recursively. * test/lisp/emacs-lisp/bytecomp-resources/bc-test-alpha.el: * test/lisp/emacs-lisp/bytecomp-resources/bc-test-beta.el: New files. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-defsubst): New test. --- lisp/emacs-lisp/byte-opt.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp/byte-opt.el') diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 99b5319ab3d..842697c7245 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -278,7 +278,10 @@ ;; first, and then inline its byte-code. This also has the advantage ;; that the final code does not depend on the order of compilation ;; of ELisp files, making the build more reproducible. - (byte-compile name) + ;; Since we are called from inside the optimiser, we need to make + ;; sure not to propagate lexvar values. + (dlet ((byte-optimize--lexvars nil)) + (byte-compile name)) `(,(symbol-function name) ,@(cdr form)))) (_ ;; Give up on inlining. -- cgit v1.2.3