aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2022-06-06 11:10:05 +0200
committerMattias EngdegÄrd2022-06-14 20:19:59 +0200
commit1ac74e28622e3ebbe76daf84f0a6f310a8ea3c45 (patch)
tree964a6252a41b5506d88910886067d606c5759900
parentd6600481ae9423eb2c51150967050afb05c301b8 (diff)
downloademacs-1ac74e28622e3ebbe76daf84f0a6f310a8ea3c45.tar.gz
emacs-1ac74e28622e3ebbe76daf84f0a6f310a8ea3c45.zip
Simplify byte-compiler assuming cconv normalisations
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker) (byte-optimize-let-form, byte-optimize-letX): * lisp/emacs-lisp/bytecomp.el (byte-compile-unwind-protect): Simplify source optimisation and codegen code that can now rely on normalised let/let* and unwind-protect forms.
-rw-r--r--lisp/emacs-lisp/byte-opt.el40
-rw-r--r--lisp/emacs-lisp/bytecomp.el7
2 files changed, 11 insertions, 36 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 0e10e332b29..fc49e88f8ee 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -422,7 +422,7 @@ for speeding up processing.")
422 (byte-optimize-body (cdr clause) for-effect)))) 422 (byte-optimize-body (cdr clause) for-effect))))
423 clauses))) 423 clauses)))
424 424
425 (`(unwind-protect ,exp . ,exps) 425 (`(unwind-protect ,exp :fun-body ,f)
426 ;; The unwinding part of an unwind-protect is compiled (and thus 426 ;; The unwinding part of an unwind-protect is compiled (and thus
427 ;; optimized) as a top-level form, but run the optimizer for it here 427 ;; optimized) as a top-level form, but run the optimizer for it here
428 ;; anyway for lexical variable usage and substitution. But the 428 ;; anyway for lexical variable usage and substitution. But the
@@ -430,13 +430,7 @@ for speeding up processing.")
430 ;; unwind-protect itself. (The unwinding part is always for effect, 430 ;; unwind-protect itself. (The unwinding part is always for effect,
431 ;; but that isn't handled properly yet.) 431 ;; but that isn't handled properly yet.)
432 (let ((bodyform (byte-optimize-form exp for-effect))) 432 (let ((bodyform (byte-optimize-form exp for-effect)))
433 (pcase exps 433 `(,fn ,bodyform :fun-body ,(byte-optimize-form f nil))))
434 (`(:fun-body ,f)
435 `(,fn ,bodyform
436 :fun-body ,(byte-optimize-form f nil)))
437 (_
438 `(,fn ,bodyform
439 . ,(byte-optimize-body exps t))))))
440 434
441 (`(catch ,tag . ,exps) 435 (`(catch ,tag . ,exps)
442 `(,fn ,(byte-optimize-form tag nil) 436 `(,fn ,(byte-optimize-form tag nil)
@@ -695,13 +689,8 @@ for speeding up processing.")
695 (let ((byte-optimize--lexvars nil)) 689 (let ((byte-optimize--lexvars nil))
696 (cons 690 (cons
697 (mapcar (lambda (binding) 691 (mapcar (lambda (binding)
698 (if (symbolp binding) 692 (list (car binding)
699 binding 693 (byte-optimize-form (nth 1 binding) nil)))
700 (when (or (atom binding) (cddr binding))
701 (byte-compile-warn-x
702 binding "malformed let binding: `%S'" binding))
703 (list (car binding)
704 (byte-optimize-form (nth 1 binding) nil))))
705 (car form)) 694 (car form))
706 (byte-optimize-body (cdr form) for-effect))))) 695 (byte-optimize-body (cdr form) for-effect)))))
707 696
@@ -1253,28 +1242,17 @@ See Info node `(elisp) Integer Basics'."
1253 ;; Body is empty or just contains a constant. 1242 ;; Body is empty or just contains a constant.
1254 (`(,head ,bindings . ,(or '() `(,(and const (pred macroexp-const-p))))) 1243 (`(,head ,bindings . ,(or '() `(,(and const (pred macroexp-const-p)))))
1255 (if (eq head 'let) 1244 (if (eq head 'let)
1256 `(progn ,@(mapcar (lambda (binding) 1245 `(progn ,@(mapcar #'cadr bindings) ,const)
1257 (and (consp binding) (cadr binding))) 1246 `(,head ,(butlast bindings) ,(cadar (last bindings)) ,const)))
1258 bindings)
1259 ,const)
1260 `(,head ,(butlast bindings)
1261 ,@(and (consp (car (last bindings)))
1262 (cdar (last bindings)))
1263 ,const)))
1264 1247
1265 ;; Body is last variable. 1248 ;; Body is last variable.
1266 (`(,head ,(and bindings 1249 (`(,head ,(and bindings
1267 (let last-var (let ((last (car (last bindings)))) 1250 (let last-var (caar (last bindings))))
1268 (if (consp last) (car last) last))))
1269 ,(and last-var ; non-linear pattern 1251 ,(and last-var ; non-linear pattern
1270 (pred symbolp) (pred (not keywordp)) (pred (not booleanp)))) 1252 (pred symbolp) (pred (not keywordp)) (pred (not booleanp))))
1271 (if (eq head 'let) 1253 (if (eq head 'let)
1272 `(progn ,@(mapcar (lambda (binding) 1254 `(progn ,@(mapcar #'cadr bindings))
1273 (and (consp binding) (cadr binding))) 1255 `(,head ,(butlast bindings) ,(cadar (last bindings)))))
1274 bindings))
1275 `(,head ,(butlast bindings)
1276 ,@(and (consp (car (last bindings)))
1277 (cdar (last bindings))))))
1278 1256
1279 (_ form))) 1257 (_ form)))
1280 1258
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index af74c0699b9..d28ec0be16d 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4806,11 +4806,8 @@ binding slots have been popped."
4806 (byte-compile-out-tag endtag))) 4806 (byte-compile-out-tag endtag)))
4807 4807
4808(defun byte-compile-unwind-protect (form) 4808(defun byte-compile-unwind-protect (form)
4809 (pcase (cddr form) 4809 (cl-assert (eq (caddr form) :fun-body))
4810 (`(:fun-body ,f) 4810 (byte-compile-form (nth 3 form))
4811 (byte-compile-form f))
4812 (handlers
4813 (byte-compile-form `#'(lambda () ,@handlers))))
4814 (byte-compile-out 'byte-unwind-protect 0) 4811 (byte-compile-out 'byte-unwind-protect 0)
4815 (byte-compile-form-do-effect (car (cdr form))) 4812 (byte-compile-form-do-effect (car (cdr form)))
4816 (byte-compile-out 'byte-unbind 1)) 4813 (byte-compile-out 'byte-unbind 1))