emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1ac74e2862 3/3: Simplify byte-compiler assuming cconv normalisati


From: Mattias Engdegård
Subject: master 1ac74e2862 3/3: Simplify byte-compiler assuming cconv normalisations
Date: Tue, 14 Jun 2022 14:20:36 -0400 (EDT)

branch: master
commit 1ac74e28622e3ebbe76daf84f0a6f310a8ea3c45
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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.
---
 lisp/emacs-lisp/byte-opt.el | 40 +++++++++-------------------------------
 lisp/emacs-lisp/bytecomp.el |  7 ++-----
 2 files changed, 11 insertions(+), 36 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 0e10e332b2..fc49e88f8e 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -422,7 +422,7 @@ for speeding up processing.")
                               (byte-optimize-body (cdr clause) for-effect))))
                     clauses)))
 
-      (`(unwind-protect ,exp . ,exps)
+      (`(unwind-protect ,exp :fun-body ,f)
        ;; The unwinding part of an unwind-protect is compiled (and thus
        ;; optimized) as a top-level form, but run the optimizer for it here
        ;; anyway for lexical variable usage and substitution.  But the
@@ -430,13 +430,7 @@ for speeding up processing.")
        ;; unwind-protect itself.  (The unwinding part is always for effect,
        ;; but that isn't handled properly yet.)
        (let ((bodyform (byte-optimize-form exp for-effect)))
-         (pcase exps
-           (`(:fun-body ,f)
-            `(,fn ,bodyform
-               :fun-body ,(byte-optimize-form f nil)))
-           (_
-            `(,fn ,bodyform
-               . ,(byte-optimize-body exps t))))))
+         `(,fn ,bodyform :fun-body ,(byte-optimize-form f nil))))
 
       (`(catch ,tag . ,exps)
        `(,fn ,(byte-optimize-form tag nil)
@@ -695,13 +689,8 @@ for speeding up processing.")
     (let ((byte-optimize--lexvars nil))
       (cons
        (mapcar (lambda (binding)
-                (if (symbolp binding)
-                    binding
-                  (when (or (atom binding) (cddr binding))
-                    (byte-compile-warn-x
-                      binding "malformed let binding: `%S'" binding))
-                  (list (car binding)
-                        (byte-optimize-form (nth 1 binding) nil))))
+                (list (car binding)
+                      (byte-optimize-form (nth 1 binding) nil)))
               (car form))
        (byte-optimize-body (cdr form) for-effect)))))
 
@@ -1253,28 +1242,17 @@ See Info node `(elisp) Integer Basics'."
     ;; Body is empty or just contains a constant.
     (`(,head ,bindings . ,(or '() `(,(and const (pred macroexp-const-p)))))
      (if (eq head 'let)
-         `(progn ,@(mapcar (lambda (binding)
-                             (and (consp binding) (cadr binding)))
-                           bindings)
-                 ,const)
-       `(,head ,(butlast bindings)
-          ,@(and (consp (car (last bindings)))
-                 (cdar (last bindings)))
-          ,const)))
+         `(progn ,@(mapcar #'cadr bindings) ,const)
+       `(,head ,(butlast bindings) ,(cadar (last bindings)) ,const)))
 
     ;; Body is last variable.
     (`(,head ,(and bindings
-                   (let last-var (let ((last (car (last bindings))))
-                                   (if (consp last) (car last) last))))
+                   (let last-var (caar (last bindings))))
              ,(and last-var             ; non-linear pattern
                    (pred symbolp) (pred (not keywordp)) (pred (not booleanp))))
      (if (eq head 'let)
-         `(progn ,@(mapcar (lambda (binding)
-                             (and (consp binding) (cadr binding)))
-                           bindings))
-       `(,head ,(butlast bindings)
-          ,@(and (consp (car (last bindings)))
-                 (cdar (last bindings))))))
+         `(progn ,@(mapcar #'cadr bindings))
+       `(,head ,(butlast bindings) ,(cadar (last bindings)))))
 
     (_ form)))
 
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index af74c0699b..d28ec0be16 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4806,11 +4806,8 @@ binding slots have been popped."
     (byte-compile-out-tag endtag)))
 
 (defun byte-compile-unwind-protect (form)
-  (pcase (cddr form)
-    (`(:fun-body ,f)
-     (byte-compile-form f))
-    (handlers
-     (byte-compile-form `#'(lambda () ,@handlers))))
+  (cl-assert (eq (caddr form) :fun-body))
+  (byte-compile-form (nth 3 form))
   (byte-compile-out 'byte-unwind-protect 0)
   (byte-compile-form-do-effect (car (cdr form)))
   (byte-compile-out 'byte-unbind 1))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]