Skip to content

Commit 2d5d0fa

Browse files
committed
Remove generation of old bytecodes for catch/unwind
* lisp/emacs-lisp/bytecomp.el (byte-compile--use-old-handlers) (byte-compile-condition-case, byte-compile-condition-case--old): Remove. (byte-compile-condition-case--new): Rename to byte-compile-condition-case. (byte-compile-catch, byte-compile-unwind-protect): * lisp/emacs-lisp/cconv.el (cconv-convert, cconv-analyze-form): * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Simplify.
1 parent e086a9f commit 2d5d0fa

File tree

3 files changed

+18
-123
lines changed

3 files changed

+18
-123
lines changed

lisp/emacs-lisp/byte-opt.el

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,12 @@
498498
form)
499499

500500
((eq fn 'condition-case)
501-
(if byte-compile--use-old-handlers
502-
;; Will be optimized later.
503-
form
504-
`(condition-case ,(nth 1 form) ;Not evaluated.
505-
,(byte-optimize-form (nth 2 form) for-effect)
506-
,@(mapcar (lambda (clause)
507-
`(,(car clause)
508-
,@(byte-optimize-body (cdr clause) for-effect)))
509-
(nthcdr 3 form)))))
501+
`(condition-case ,(nth 1 form) ;Not evaluated.
502+
,(byte-optimize-form (nth 2 form) for-effect)
503+
,@(mapcar (lambda (clause)
504+
`(,(car clause)
505+
,@(byte-optimize-body (cdr clause) for-effect)))
506+
(nthcdr 3 form))))
510507

511508
((eq fn 'unwind-protect)
512509
;; the "protected" part of an unwind-protect is compiled (and thus
@@ -521,12 +518,7 @@
521518
((eq fn 'catch)
522519
(cons fn
523520
(cons (byte-optimize-form (nth 1 form) nil)
524-
(if byte-compile--use-old-handlers
525-
;; The body of a catch is compiled (and thus
526-
;; optimized) as a top-level form, so don't do it
527-
;; here.
528-
(cdr (cdr form))
529-
(byte-optimize-body (cdr form) for-effect)))))
521+
(byte-optimize-body (cdr form) for-effect))))
530522

531523
((eq fn 'ignore)
532524
;; Don't treat the args to `ignore' as being

lisp/emacs-lisp/bytecomp.el

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,96 +4529,25 @@ binding slots have been popped."
45294529
;; (byte-defop-compiler-1 save-window-excursion) ;Obsolete: now a macro.
45304530
;; (byte-defop-compiler-1 with-output-to-temp-buffer) ;Obsolete: now a macro.
45314531

4532-
(defvar byte-compile--use-old-handlers nil
4533-
"If nil, use new byte codes introduced in Emacs-24.4.")
4534-
45354532
(defun byte-compile-catch (form)
45364533
(byte-compile-form (car (cdr form)))
4537-
(if (not byte-compile--use-old-handlers)
4538-
(let ((endtag (byte-compile-make-tag)))
4539-
(byte-compile-goto 'byte-pushcatch endtag)
4540-
(byte-compile-body (cddr form) nil)
4541-
(byte-compile-out 'byte-pophandler)
4542-
(byte-compile-out-tag endtag))
4543-
(pcase (cddr form)
4544-
(`(:fun-body ,f)
4545-
(byte-compile-form `(list 'funcall ,f)))
4546-
(body
4547-
(byte-compile-push-constant
4548-
(byte-compile-top-level (cons 'progn body) byte-compile--for-effect))))
4549-
(byte-compile-out 'byte-catch 0)))
4534+
(let ((endtag (byte-compile-make-tag)))
4535+
(byte-compile-goto 'byte-pushcatch endtag)
4536+
(byte-compile-body (cddr form) nil)
4537+
(byte-compile-out 'byte-pophandler)
4538+
(byte-compile-out-tag endtag)))
45504539

45514540
(defun byte-compile-unwind-protect (form)
45524541
(pcase (cddr form)
45534542
(`(:fun-body ,f)
4554-
(byte-compile-form
4555-
(if byte-compile--use-old-handlers `(list (list 'funcall ,f)) f)))
4543+
(byte-compile-form f))
45564544
(handlers
4557-
(if byte-compile--use-old-handlers
4558-
(byte-compile-push-constant
4559-
(byte-compile-top-level-body handlers t))
4560-
(byte-compile-form `#'(lambda () ,@handlers)))))
4545+
(byte-compile-form `#'(lambda () ,@handlers))))
45614546
(byte-compile-out 'byte-unwind-protect 0)
45624547
(byte-compile-form-do-effect (car (cdr form)))
45634548
(byte-compile-out 'byte-unbind 1))
45644549

45654550
(defun byte-compile-condition-case (form)
4566-
(if byte-compile--use-old-handlers
4567-
(byte-compile-condition-case--old form)
4568-
(byte-compile-condition-case--new form)))
4569-
4570-
(defun byte-compile-condition-case--old (form)
4571-
(let* ((var (nth 1 form))
4572-
(fun-bodies (eq var :fun-body))
4573-
(byte-compile-bound-variables
4574-
(if (and var (not fun-bodies))
4575-
(cons var byte-compile-bound-variables)
4576-
byte-compile-bound-variables)))
4577-
(byte-compile-set-symbol-position 'condition-case)
4578-
(unless (symbolp var)
4579-
(byte-compile-warn
4580-
"`%s' is not a variable-name or nil (in condition-case)" var))
4581-
(if fun-bodies (setq var (make-symbol "err")))
4582-
(byte-compile-push-constant var)
4583-
(if fun-bodies
4584-
(byte-compile-form `(list 'funcall ,(nth 2 form)))
4585-
(byte-compile-push-constant
4586-
(byte-compile-top-level (nth 2 form) byte-compile--for-effect)))
4587-
(let ((compiled-clauses
4588-
(mapcar
4589-
(lambda (clause)
4590-
(let ((condition (car clause)))
4591-
(cond ((not (or (symbolp condition)
4592-
(and (listp condition)
4593-
(let ((ok t))
4594-
(dolist (sym condition)
4595-
(if (not (symbolp sym))
4596-
(setq ok nil)))
4597-
ok))))
4598-
(byte-compile-warn
4599-
"`%S' is not a condition name or list of such (in condition-case)"
4600-
condition))
4601-
;; (not (or (eq condition 't)
4602-
;; (and (stringp (get condition 'error-message))
4603-
;; (consp (get condition
4604-
;; 'error-conditions)))))
4605-
;; (byte-compile-warn
4606-
;; "`%s' is not a known condition name
4607-
;; (in condition-case)"
4608-
;; condition))
4609-
)
4610-
(if fun-bodies
4611-
`(list ',condition (list 'funcall ,(cadr clause) ',var))
4612-
(cons condition
4613-
(byte-compile-top-level-body
4614-
(cdr clause) byte-compile--for-effect)))))
4615-
(cdr (cdr (cdr form))))))
4616-
(if fun-bodies
4617-
(byte-compile-form `(list ,@compiled-clauses))
4618-
(byte-compile-push-constant compiled-clauses)))
4619-
(byte-compile-out 'byte-condition-case 0)))
4620-
4621-
(defun byte-compile-condition-case--new (form)
46224551
(let* ((var (nth 1 form))
46234552
(body (nth 2 form))
46244553
(depth byte-compile-depth)

lisp/emacs-lisp/cconv.el

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,7 @@ places where they originally did not directly appear."
462462
;; and may be an invalid expression (e.g. ($# . 678)).
463463
(cdr forms)))))
464464

465-
;condition-case
466-
((and `(condition-case ,var ,protected-form . ,handlers)
467-
(guard byte-compile--use-old-handlers))
468-
(let ((newform (cconv--convert-function
469-
() (list protected-form) env form)))
470-
`(condition-case :fun-body ,newform
471-
,@(mapcar (lambda (handler)
472-
(list (car handler)
473-
(cconv--convert-function
474-
(list (or var cconv--dummy-var))
475-
(cdr handler) env form)))
476-
handlers))))
477-
478-
; condition-case with new byte-codes.
465+
; condition-case
479466
(`(condition-case ,var ,protected-form . ,handlers)
480467
`(condition-case ,var
481468
,(cconv-convert protected-form env extend)
@@ -496,10 +483,8 @@ places where they originally did not directly appear."
496483
`((let ((,var (list ,var))) ,@body))))))
497484
handlers))))
498485

499-
(`(,(and head (or (and 'catch (guard byte-compile--use-old-handlers))
500-
'unwind-protect))
501-
,form . ,body)
502-
`(,head ,(cconv-convert form env extend)
486+
(`(unwind-protect ,form . ,body)
487+
`(unwind-protect ,(cconv-convert form env extend)
503488
:fun-body ,(cconv--convert-function () body env form)))
504489

505490
(`(setq . ,forms) ; setq special form
@@ -718,15 +703,6 @@ and updates the data stored in ENV."
718703
(`(quote . ,_) nil) ; quote form
719704
(`(function . ,_) nil) ; same as quote
720705

721-
((and `(condition-case ,var ,protected-form . ,handlers)
722-
(guard byte-compile--use-old-handlers))
723-
;; FIXME: The bytecode for condition-case forces us to wrap the
724-
;; form and handlers in closures.
725-
(cconv--analyze-function () (list protected-form) env form)
726-
(dolist (handler handlers)
727-
(cconv--analyze-function (if var (list var)) (cdr handler)
728-
env form)))
729-
730706
(`(condition-case ,var ,protected-form . ,handlers)
731707
(cconv-analyze-form protected-form env)
732708
(when (and var (symbolp var) (byte-compile-not-lexical-var-p var))
@@ -741,9 +717,7 @@ and updates the data stored in ENV."
741717
form "variable"))))
742718

743719
;; FIXME: The bytecode for unwind-protect forces us to wrap the unwind.
744-
(`(,(or (and 'catch (guard byte-compile--use-old-handlers))
745-
'unwind-protect)
746-
,form . ,body)
720+
(`(unwind-protect ,form . ,body)
747721
(cconv-analyze-form form env)
748722
(cconv--analyze-function () body env form))
749723

0 commit comments

Comments
 (0)