From 13d6e8fa54843b0b087e5a9c266e4b7e0d709c3f Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 16 Oct 2022 12:01:47 -0400 Subject: cl-generic: Fix `advertised-calling-convention` declarations * lisp/emacs-lisp/cl-generic.el (cl-generic-define-method): Preserve the `advertised-calling-convention`, if any (bug#58563). * lisp/subr.el (declare): Warn when we hit this. * lisp/emacs-lisp/byte-run.el (get-advertised-calling-convention): New fun. * lisp/progmodes/elisp-mode.el (elisp-get-fnsym-args-string): * lisp/help-fns.el (help-fns--signature): * lisp/emacs-lisp/bytecomp.el (byte-compile-fdefinition): Use it. * test/lisp/emacs-lisp/cl-generic-tests.el (cl-generic-tests--acc): New fun. (cl-generic-tests--advertised-calling-convention-bug58563): New test. --- test/lisp/emacs-lisp/cl-generic-tests.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/cl-generic-tests.el b/test/lisp/emacs-lisp/cl-generic-tests.el index 56b766769ea..8e807b15915 100644 --- a/test/lisp/emacs-lisp/cl-generic-tests.el +++ b/test/lisp/emacs-lisp/cl-generic-tests.el @@ -297,5 +297,27 @@ Edebug symbols (Bug#42672)." (intern "cl-defgeneric/edebug/method/2 (number)") 'cl-defgeneric/edebug/method/2)))))) +(cl-defgeneric cl-generic-tests--acc (x &optional y) + (declare (advertised-calling-convention (x) "671.2"))) + +(cl-defmethod cl-generic-tests--acc ((x float)) (+ x 5.0)) + +(ert-deftest cl-generic-tests--advertised-calling-convention-bug58563 () + (should (equal (get-advertised-calling-convention + (indirect-function 'cl-generic-tests--acc)) + '(x))) + (should + (condition-case err + (let ((lexical-binding t) + (byte-compile-debug t) + (byte-compile-error-on-warn t)) + (byte-compile '(cl-defmethod cl-generic-tests--acc ((x list)) + (declare (advertised-calling-convention (y) "1.1")) + (cons x '(5 5 5 5 5)))) + nil) + (error + (and (eq 'error (car err)) + (string-match "Stray.*declare" (cadr err))))))) + (provide 'cl-generic-tests) ;;; cl-generic-tests.el ends here -- cgit v1.2.3 From 24b85b10e388303c9c871a65ccf5deeed19b04f8 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 17 Oct 2022 10:37:08 +0200 Subject: Add tests for native-compile-prune-cache * test/lisp/comp-tests.el: New file. --- test/lisp/emacs-lisp/comp-tests.el | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/lisp/emacs-lisp/comp-tests.el (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/comp-tests.el b/test/lisp/emacs-lisp/comp-tests.el new file mode 100644 index 00000000000..97761cd728e --- /dev/null +++ b/test/lisp/emacs-lisp/comp-tests.el @@ -0,0 +1,62 @@ +;;; comp-tests.el --- Tests for comp.el -*- lexical-binding:t -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'ert-x) +(require 'comp) + +(defmacro with-test-native-compile-prune-cache (&rest body) + `(ert-with-temp-directory testdir + (setq testdir (expand-file-name "eln-cache" testdir)) + (make-directory testdir) + (let* ((c1 (expand-file-name "29.0.50-cur" testdir)) + (c2 (expand-file-name "29.0.50-old" testdir)) + (native-comp-eln-load-path (list testdir)) + (comp-native-version-dir "29.0.50-cur")) + (dolist (d (list c1 c2)) + (make-directory d) + (with-temp-file (expand-file-name "some.eln" d) (insert "foo")) + (with-temp-file (expand-file-name "some.eln.tmp" d) (insert "foo"))) + ,@body))) + +(ert-deftest test-native-compile-prune-cache () + (skip-unless (featurep 'native-compile)) + (with-test-native-compile-prune-cache + (native-compile-prune-cache) + (should (file-directory-p c1)) + (should (file-regular-p (expand-file-name "some.eln" c1))) + (should (file-regular-p (expand-file-name "some.eln.tmp" c1))) + (should-not (file-directory-p c2)) + (should-not (file-regular-p (expand-file-name "some.eln" c2))) + (should-not (file-regular-p (expand-file-name "some.eln.tmp" c2))))) + +(ert-deftest test-native-compile-prune-cache/delete-only-eln () + (skip-unless (featurep 'native-compile)) + (with-test-native-compile-prune-cache + (with-temp-file (expand-file-name "keep1.txt" c1) (insert "foo")) + (with-temp-file (expand-file-name "keep2.txt" c2) (insert "foo")) + (native-compile-prune-cache) + (should (file-regular-p (expand-file-name "keep1.txt" c1))) + (should (file-regular-p (expand-file-name "keep2.txt" c2))))) + +;;; comp-tests.el ends here -- cgit v1.2.3 From 40b734c5003c71dc533d588bb00ea51a983bd730 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 17 Oct 2022 15:26:21 +0200 Subject: Don't prune *.eln files in parent of eln-load-path * lisp/emacs-lisp/comp.el (native-compile-prune-cache): Don't prune *.eln files in parent directory of `native-comp-eln-load-path'. * test/lisp/emacs-lisp/comp-tests.el (test-native-compile-prune-cache/dont-delete-in-parent-of-cache): New test. --- lisp/emacs-lisp/comp.el | 4 +++- test/lisp/emacs-lisp/comp-tests.el | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'test/lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 686c7aeb3db..460d260192d 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -4334,7 +4334,9 @@ of (commands) to run simultaneously." ;; `invocation-directory'. (setq dir (expand-file-name dir invocation-directory)) (when (file-exists-p dir) - (dolist (subdir (directory-files dir t)) + (dolist (subdir (seq-filter + (lambda (f) (not (string-match (rx "/." (? ".") eos) f))) + (directory-files dir t))) (when (and (file-directory-p subdir) (file-writable-p subdir) (not (equal (file-name-nondirectory diff --git a/test/lisp/emacs-lisp/comp-tests.el b/test/lisp/emacs-lisp/comp-tests.el index 97761cd728e..31f32dad1f5 100644 --- a/test/lisp/emacs-lisp/comp-tests.el +++ b/test/lisp/emacs-lisp/comp-tests.el @@ -59,4 +59,15 @@ (should (file-regular-p (expand-file-name "keep1.txt" c1))) (should (file-regular-p (expand-file-name "keep2.txt" c2))))) +(ert-deftest test-native-compile-prune-cache/dont-delete-in-parent-of-cache () + (skip-unless (featurep 'native-compile)) + (with-test-native-compile-prune-cache + (let ((f1 (expand-file-name "some.eln" (expand-file-name ".." testdir))) + (f2 (expand-file-name "some.eln" testdir))) + (with-temp-file f1 (insert "foo")) + (with-temp-file f2 (insert "foo")) + (native-compile-prune-cache) + (should (file-regular-p f1)) + (should (file-regular-p f2))))) + ;;; comp-tests.el ends here -- cgit v1.2.3 From dd7f1bb3a137f697552cce6bad8a364035e9c497 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Mon, 17 Oct 2022 18:40:45 +0300 Subject: Silence recent comp-tests.el lexvar warnings * test/lisp/emacs-lisp/comp-tests.el: Mark used native-compile variables as special to pacify unknown lexvar warnings in the default build. (with-test-native-compile-prune-cache): Instrument macro arguments for debugging and indent conventionally. Reindent all callers. (test-native-compile-prune-cache/dont-delete-in-parent-of-cache): Simplify file name expansion. --- test/lisp/emacs-lisp/comp-tests.el | 42 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/comp-tests.el b/test/lisp/emacs-lisp/comp-tests.el index 31f32dad1f5..082b641fe30 100644 --- a/test/lisp/emacs-lisp/comp-tests.el +++ b/test/lisp/emacs-lisp/comp-tests.el @@ -25,7 +25,11 @@ (require 'ert-x) (require 'comp) +(defvar comp-native-version-dir) +(defvar native-comp-eln-load-path) + (defmacro with-test-native-compile-prune-cache (&rest body) + (declare (indent 0) (debug t)) `(ert-with-temp-directory testdir (setq testdir (expand-file-name "eln-cache" testdir)) (make-directory testdir) @@ -42,32 +46,32 @@ (ert-deftest test-native-compile-prune-cache () (skip-unless (featurep 'native-compile)) (with-test-native-compile-prune-cache - (native-compile-prune-cache) - (should (file-directory-p c1)) - (should (file-regular-p (expand-file-name "some.eln" c1))) - (should (file-regular-p (expand-file-name "some.eln.tmp" c1))) - (should-not (file-directory-p c2)) - (should-not (file-regular-p (expand-file-name "some.eln" c2))) - (should-not (file-regular-p (expand-file-name "some.eln.tmp" c2))))) + (native-compile-prune-cache) + (should (file-directory-p c1)) + (should (file-regular-p (expand-file-name "some.eln" c1))) + (should (file-regular-p (expand-file-name "some.eln.tmp" c1))) + (should-not (file-directory-p c2)) + (should-not (file-regular-p (expand-file-name "some.eln" c2))) + (should-not (file-regular-p (expand-file-name "some.eln.tmp" c2))))) (ert-deftest test-native-compile-prune-cache/delete-only-eln () (skip-unless (featurep 'native-compile)) (with-test-native-compile-prune-cache - (with-temp-file (expand-file-name "keep1.txt" c1) (insert "foo")) - (with-temp-file (expand-file-name "keep2.txt" c2) (insert "foo")) - (native-compile-prune-cache) - (should (file-regular-p (expand-file-name "keep1.txt" c1))) - (should (file-regular-p (expand-file-name "keep2.txt" c2))))) + (with-temp-file (expand-file-name "keep1.txt" c1) (insert "foo")) + (with-temp-file (expand-file-name "keep2.txt" c2) (insert "foo")) + (native-compile-prune-cache) + (should (file-regular-p (expand-file-name "keep1.txt" c1))) + (should (file-regular-p (expand-file-name "keep2.txt" c2))))) (ert-deftest test-native-compile-prune-cache/dont-delete-in-parent-of-cache () (skip-unless (featurep 'native-compile)) (with-test-native-compile-prune-cache - (let ((f1 (expand-file-name "some.eln" (expand-file-name ".." testdir))) - (f2 (expand-file-name "some.eln" testdir))) - (with-temp-file f1 (insert "foo")) - (with-temp-file f2 (insert "foo")) - (native-compile-prune-cache) - (should (file-regular-p f1)) - (should (file-regular-p f2))))) + (let ((f1 (expand-file-name "../some.eln" testdir)) + (f2 (expand-file-name "some.eln" testdir))) + (with-temp-file f1 (insert "foo")) + (with-temp-file f2 (insert "foo")) + (native-compile-prune-cache) + (should (file-regular-p f1)) + (should (file-regular-p f2))))) ;;; comp-tests.el ends here -- cgit v1.2.3