[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/handler-bind-2 10e04044c7b 06/16: (macroexp--with-extended-form-
From: |
Stefan Monnier |
Subject: |
scratch/handler-bind-2 10e04044c7b 06/16: (macroexp--with-extended-form-stack): Use plain `let` |
Date: |
Wed, 27 Dec 2023 23:53:30 -0500 (EST) |
branch: scratch/handler-bind-2
commit 10e04044c7b2c84d4e32b8dc4d8891d6e6047bba
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
(macroexp--with-extended-form-stack): Use plain `let`
`macroexp--with-extended-form-stack` used manual push/pop so that upon
non-local exits the "deeper" value is kept, so the error handler gets
to know what was the deeper value, so as to be able to compute more
precise error locations.
Replace this with a `handler-bind` which catches that "deeper" value
more explicitly.
* lisp/emacs-lisp/bytecomp.el (bytecomp--displaying-warnings):
Use `handler-bind` to catch the value of `byte-compile-form-stack`
at the time of the error. Also consolidate the duplicated code.
* lisp/emacs-lisp/macroexp.el (macroexp--with-extended-form-stack):
Use a plain dynbound let-rebinding.
---
lisp/emacs-lisp/bytecomp.el | 41 +++++++++++++++++++++++------------------
lisp/emacs-lisp/macroexp.el | 10 ++--------
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 6c5051d70c4..69f651befba 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1874,39 +1874,44 @@ It is too wide if it has any lines longer than the
largest of
(setq byte-to-native-plist-environment
overriding-plist-environment)))))
-(defmacro displaying-byte-compile-warnings (&rest body)
+(defmacro displaying-byte-compile-warnings (&rest body) ;FIXME: Namespace!
(declare (debug (def-body)))
`(bytecomp--displaying-warnings (lambda () ,@body)))
(defun bytecomp--displaying-warnings (body-fn)
- (let* ((warning-series-started
+ (let* ((wrapped-body
+ (lambda ()
+ (if byte-compile-debug
+ (funcall body-fn)
+ ;; Use a `handler-bind' to remember the `byte-compile-form-stack'
+ ;; active at the time the error is signaled, so as to
+ ;; get more precise error locations.
+ (let ((form-stack nil))
+ (condition-case error-info
+ (handler-bind
+ ((error (lambda (_err)
+ (setq form-stack byte-compile-form-stack))))
+ (funcall body-fn))
+ (error (let ((byte-compile-form-stack form-stack))
+ (byte-compile-report-error error-info))))))))
+ (warning-series-started
(and (markerp warning-series)
(eq (marker-buffer warning-series)
(get-buffer byte-compile-log-buffer))))
(byte-compile-form-stack byte-compile-form-stack))
- (if (or (eq warning-series 'byte-compile-warning-series)
+ (if (or (eq warning-series #'byte-compile-warning-series)
warning-series-started)
;; warning-series does come from compilation,
;; so don't bind it, but maybe do set it.
- (let (tem)
- ;; Log the file name. Record position of that text.
- (setq tem (byte-compile-log-file))
+ (let ((tem (byte-compile-log-file))) ;; Log the file name.
(unless warning-series-started
- (setq warning-series (or tem 'byte-compile-warning-series)))
- (if byte-compile-debug
- (funcall body-fn)
- (condition-case error-info
- (funcall body-fn)
- (error (byte-compile-report-error error-info)))))
+ (setq warning-series (or tem #'byte-compile-warning-series)))
+ (funcall wrapped-body))
;; warning-series does not come from compilation, so bind it.
(let ((warning-series
;; Log the file name. Record position of that text.
- (or (byte-compile-log-file) 'byte-compile-warning-series)))
- (if byte-compile-debug
- (funcall body-fn)
- (condition-case error-info
- (funcall body-fn)
- (error (byte-compile-report-error error-info))))))))
+ (or (byte-compile-log-file) #'byte-compile-warning-series)))
+ (funcall wrapped-body)))))
;;;###autoload
(defun byte-force-recompile (directory)
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index 78601c0648e..54a3ee9d66f 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -42,14 +42,8 @@ condition-case handling a signaled error.")
(defmacro macroexp--with-extended-form-stack (expr &rest body)
"Evaluate BODY with EXPR pushed onto `byte-compile-form-stack'."
(declare (indent 1))
- ;; FIXME: We really should just be using a simple dynamic let-binding here,
- ;; but these explicit push and pop make the extended stack value visible
- ;; to error handlers. Remove that need for that!
- `(progn
- (push ,expr byte-compile-form-stack)
- (prog1
- (progn ,@body)
- (pop byte-compile-form-stack))))
+ `(let ((byte-compile-form-stack (cons ,expr byte-compile-form-stack)))
+ ,@body))
;; Bound by the top-level `macroexpand-all', and modified to include any
;; macros defined by `defmacro'.
- branch scratch/handler-bind-2 created (now 94b11fc0c9b), Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 a4efbe4c499 01/16: New special form `handler-bind`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 9f8ea786918 07/16: eval.c: Add new var `lisp-eval-depth-reserve`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 40437afc8ee 09/16: (signal_or_quit): Preserve error object identity, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 19f1d2a9f51 02/16: (eval-expression): Fix bug#67196, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 10e04044c7b 06/16: (macroexp--with-extended-form-stack): Use plain `let`,
Stefan Monnier <=
- scratch/handler-bind-2 617d568f4b6 03/16: ert.el: Use `handler-bind` to record backtraces, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 b21a22c86cc 13/16: Allow the `error-message` property to be a function, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 5a3ed126ccc 14/16: tramp.el: Use `handler-bind` instead of `signal-hook-function`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 c03598f1323 11/16: src/eval.c (call_debugger): Don't bind `Qinhibit_changing_match_data`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 bb9e093a106 08/16: Use handler-bind to repair bytecomp-tests, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 bc5500be3b0 15/16: (edebug-format): Make it obsolete, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 d9f047e2da5 05/16: Move batch backtrace code to `top_level_2`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 235907e1764 12/16: Add `redisplay-counter` to catched nested redisplays and abort outer one, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 857f1d37037 04/16: startup.el: Use `handler-bind` to implement `--debug-init`, Stefan Monnier, 2023/12/27
- scratch/handler-bind-2 94b11fc0c9b 16/16: edebug.el: Use `handler-bind` instead of `signal-hook-function`, Stefan Monnier, 2023/12/27