summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2023-08-04 11:08:57 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2023-08-04 11:08:57 +0200
commit44d7fd3805f5b1e0b571ece007abc466e1b39ba5 (patch)
tree2a91d6bf9aa655b893aae0a46ad29accebf4f7b3 /test/lisp/emacs-lisp
parentc75c7997197502189023c9f47140474fa7fd719e (diff)
downloademacs-44d7fd3805f5b1e0b571ece007abc466e1b39ba5.tar.gz
emacs-44d7fd3805f5b1e0b571ece007abc466e1b39ba5.tar.bz2
emacs-44d7fd3805f5b1e0b571ece007abc466e1b39ba5.zip
Don't allow the `eq` and `unbind` byte-ops to commute (bug#65017)
* lisp/emacs-lisp/byte-opt.el (byte-after-unwind-ops): Cease sinking `eq` past `unwind`, because that optimised away the let-binding in (let ((symbols-with-pos-enabled nil)) (eq x y)) and `eq` is currently sensitive to `symbols-with-pos-enabled`. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--eq-symbols-with-pos-enabled): New test.
Diffstat (limited to 'test/lisp/emacs-lisp')
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 593fd117685..246ffff532f 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -2001,6 +2001,40 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \
(backtrace-frame-args frame))
call))))))))))
+(ert-deftest bytecomp--eq-symbols-with-pos-enabled ()
+ ;; Verify that we don't optimise away a binding of
+ ;; `symbols-with-pos-enabled' around an application of `eq' (bug#65017).
+ (let* ((sym-with-pos1 (read-positioning-symbols "sym"))
+ (sym-with-pos2 (read-positioning-symbols " sym")) ; <- space!
+ (without-pos-eq (lambda (a b)
+ (let ((symbols-with-pos-enabled nil))
+ (eq a b))))
+ (without-pos-eq-compiled (byte-compile without-pos-eq))
+ (with-pos-eq (lambda (a b)
+ (let ((symbols-with-pos-enabled t))
+ (eq a b))))
+ (with-pos-eq-compiled (byte-compile with-pos-eq)))
+ (dolist (mode '(interpreted compiled))
+ (ert-info ((symbol-name mode) :prefix "mode: ")
+ (ert-info ("disabled" :prefix "symbol-pos: ")
+ (let ((eq-fn (pcase-exhaustive mode
+ ('interpreted without-pos-eq)
+ ('compiled without-pos-eq-compiled))))
+ (should (equal (funcall eq-fn 'sym 'sym) t))
+ (should (equal (funcall eq-fn sym-with-pos1 'sym) nil))
+ (should (equal (funcall eq-fn 'sym sym-with-pos1) nil))
+ (should (equal (funcall eq-fn sym-with-pos1 sym-with-pos1) t))
+ (should (equal (funcall eq-fn sym-with-pos1 sym-with-pos2) nil))))
+ (ert-info ("enabled" :prefix "symbol-pos: ")
+ (let ((eq-fn (pcase-exhaustive mode
+ ('interpreted with-pos-eq)
+ ('compiled with-pos-eq-compiled))))
+ (should (equal (funcall eq-fn 'sym 'sym) t))
+ (should (equal (funcall eq-fn sym-with-pos1 'sym) t))
+ (should (equal (funcall eq-fn 'sym sym-with-pos1) t))
+ (should (equal (funcall eq-fn sym-with-pos1 sym-with-pos1) t))
+ (should (equal (funcall eq-fn sym-with-pos1 sym-with-pos2) t))))))))
+
;; Local Variables:
;; no-byte-compile: t
;; End: