From adac6fa11a95b5c3dd5ae5766b1539687d5931f5 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Mon, 21 Oct 2019 11:30:39 +0200 Subject: [PATCH] make non local handler bb generation robust for all order of creation --- lisp/emacs-lisp/comp.el | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 9ce1e96b3c8..d9b0c184625 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -511,12 +511,14 @@ Restore the original value afterwards." The basic block is returned." (if-let ((bb (gethash name (comp-func-blocks comp-func)))) ;; If was already declared sanity check sp. - (cl-assert (or (null sp) (= sp (comp-block-sp bb))) - (sp (comp-block-sp bb)) "sp %d %d differs") - ;; Mark it pending in case is not already. - (unless (cl-find-if (lambda (bb) - (eq (comp-block-name bb) name)) - (comp-limplify-pending-blocks comp-pass)) + (progn + (cl-assert (or (null sp) (= sp (comp-block-sp bb))) + (sp (comp-block-sp bb)) "sp %d %d differs") + bb) + ;; Look into the pendings and add the a new one there if necessary. + (or (cl-find-if (lambda (bb) + (eq (comp-block-name bb) name)) + (comp-limplify-pending-blocks comp-pass)) (car (push (apply #'make--comp-block args) (comp-limplify-pending-blocks comp-pass)))))) @@ -548,12 +550,17 @@ The basic block is returned." do (aset v i mvar) finally (return v))) -(defsubst comp-emit (insn &optional bb) - "Emit INSN in BB is specified or the current basic block otherwise." - (let ((bb (or bb (comp-limplify-curr-block comp-pass)))) +(defsubst comp-emit (insn) + "Emit INSN into basic block BB." + (let ((bb (comp-limplify-curr-block comp-pass))) (cl-assert (not (comp-block-closed bb))) (push insn (comp-block-insns bb)))) +(defsubst comp-emit-as-head (insn bb) + "Emit INSN at the head of basic block BB. +NOTE: this is used for late fixup therefore ignore if the basic block is closed." + (setf (comp-block-insns bb) (nconc (comp-block-insns bb) (list insn)))) + (defun comp-emit-set-call (call) "Emit CALL assigning the result the the current slot frame. If the callee function is known to have a return type propagate it." @@ -656,7 +663,7 @@ Return value is the fall through block name." handler-name guarded-name)) (setf (comp-block-closed (comp-limplify-curr-block comp-pass)) t) - (comp-emit `(fetch-handler ,(comp-slot+1) ,handler-buff-n) handler-bb) + (comp-emit-as-head `(fetch-handler ,(comp-slot+1) ,handler-buff-n) handler-bb) (cl-incf (comp-func-handler-cnt comp-func))))) (defun comp-limplify-listn (n) -- 2.39.5