diff options
| author | Andrea Corallo | 2020-11-01 14:37:13 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2020-11-01 15:17:00 +0100 |
| commit | e1a168f9a73cfb5a70d3f313e62dd1eaab14e214 (patch) | |
| tree | d0a625aed49a87c6bc1929669613e77db4b3b721 | |
| parent | 42970cceb9b15212f1a2a28a4595efc8c960f929 (diff) | |
| download | emacs-e1a168f9a73cfb5a70d3f313e62dd1eaab14e214.tar.gz emacs-e1a168f9a73cfb5a70d3f313e62dd1eaab14e214.zip | |
* Add some 'cond-rw' pass related tests
* test/src/comp-tests.el (comp-tests-cond-rw-checked-function):
Declare var.
(comp-tests-cond-rw-checker-val): New function.
(comp-tests-cond-rw-checker-type): Declare var.
(comp-tests-cond-rw-checker-type): New function.
(comp-tests-cond-rw-0-var): Declare var.
(comp-tests-cond-rw-0, comp-tests-cond-rw-1, comp-tests-cond-rw-2)
(comp-tests-cond-rw-3, comp-tests-cond-rw-4)
(comp-tests-cond-rw-5): New testcases.
| -rw-r--r-- | test/src/comp-tests.el | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 4834e21fba3..9c3c7f62a30 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -791,4 +791,95 @@ Return a list of results." | |||
| 791 | (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-fibn-entry-f))) | 791 | (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-fibn-entry-f))) |
| 792 | (should (= (comp-tests-pure-fibn-entry-f) 6765)))) | 792 | (should (= (comp-tests-pure-fibn-entry-f) 6765)))) |
| 793 | 793 | ||
| 794 | (defvar comp-tests-cond-rw-checked-function nil | ||
| 795 | "Function to be checked.") | ||
| 796 | (defun comp-tests-cond-rw-checker-val (_) | ||
| 797 | "Check we manage to propagate the correct return value." | ||
| 798 | (should | ||
| 799 | (cl-some | ||
| 800 | #'identity | ||
| 801 | (comp-tests-map-checker | ||
| 802 | comp-tests-cond-rw-checked-function | ||
| 803 | (lambda (insn) | ||
| 804 | (pcase insn | ||
| 805 | (`(return ,mvar) | ||
| 806 | (and (comp-mvar-const-vld mvar) | ||
| 807 | (= (comp-mvar-constant mvar) 123))))))))) | ||
| 808 | |||
| 809 | (defvar comp-tests-cond-rw-expected-type nil | ||
| 810 | "Type to expect in `comp-tests-cond-rw-checker-type'.") | ||
| 811 | (defun comp-tests-cond-rw-checker-type (_) | ||
| 812 | "Check we manage to propagate the correct return type." | ||
| 813 | (should | ||
| 814 | (cl-some | ||
| 815 | #'identity | ||
| 816 | (comp-tests-map-checker | ||
| 817 | comp-tests-cond-rw-checked-function | ||
| 818 | (lambda (insn) | ||
| 819 | (pcase insn | ||
| 820 | (`(return ,mvar) | ||
| 821 | (eq (comp-mvar-type mvar) comp-tests-cond-rw-expected-type)))))))) | ||
| 822 | |||
| 823 | (defvar comp-tests-cond-rw-0-var) | ||
| 824 | (comp-deftest cond-rw-0 () | ||
| 825 | "Check we do not miscompile some simple functions." | ||
| 826 | (let ((lexical-binding t)) | ||
| 827 | (let ((f (native-compile '(lambda (l) | ||
| 828 | (when (eq (car l) 'x) | ||
| 829 | (cdr l)))))) | ||
| 830 | (should (subr-native-elisp-p f)) | ||
| 831 | (should (eq (funcall f '(x . y)) 'y)) | ||
| 832 | (should (null (funcall f '(z . y))))) | ||
| 833 | |||
| 834 | (should | ||
| 835 | (subr-native-elisp-p | ||
| 836 | (native-compile '(lambda () (if (eq comp-tests-cond-rw-0-var 123) 5 10))))))) | ||
| 837 | |||
| 838 | (comp-deftest cond-rw-1 () | ||
| 839 | "Test cond-rw pass allow us to propagate type+val under `eq' tests." | ||
| 840 | (let ((lexical-binding t) | ||
| 841 | (comp-tests-cond-rw-expected-type 'fixnum) | ||
| 842 | (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type) | ||
| 843 | (comp-final comp-tests-cond-rw-checker-val)))) | ||
| 844 | (subr-native-elisp-p (native-compile '(lambda (x) (if (eq x 123) x t)))) | ||
| 845 | (subr-native-elisp-p (native-compile '(lambda (x) (if (eq 123 x) x t)))))) | ||
| 846 | |||
| 847 | (comp-deftest cond-rw-2 () | ||
| 848 | "Test cond-rw pass allow us to propagate type+val under `=' tests." | ||
| 849 | (let ((lexical-binding t) | ||
| 850 | (comp-tests-cond-rw-expected-type 'fixnum) | ||
| 851 | (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type) | ||
| 852 | (comp-final comp-tests-cond-rw-checker-val)))) | ||
| 853 | (subr-native-elisp-p (native-compile '(lambda (x) (if (= x 123) x t)))))) | ||
| 854 | |||
| 855 | (comp-deftest cond-rw-3 () | ||
| 856 | "Test cond-rw pass allow us to propagate type+val under `eql' tests." | ||
| 857 | (let ((lexical-binding t) | ||
| 858 | (comp-tests-cond-rw-expected-type 'fixnum) | ||
| 859 | (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type) | ||
| 860 | (comp-final comp-tests-cond-rw-checker-val)))) | ||
| 861 | (subr-native-elisp-p (native-compile '(lambda (x) (if (eql 123 x) x t)))))) | ||
| 862 | |||
| 863 | (comp-deftest cond-rw-4 () | ||
| 864 | "Test cond-rw pass allow us to propagate type under `=' tests." | ||
| 865 | (let ((lexical-binding t) | ||
| 866 | (comp-tests-cond-rw-expected-type 'number) | ||
| 867 | (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type)))) | ||
| 868 | (subr-native-elisp-p (native-compile '(lambda (x y) (if (= x y) x t)))))) | ||
| 869 | |||
| 870 | (comp-deftest cond-rw-5 () | ||
| 871 | "Test cond-rw pass allow us to propagate type under `=' tests." | ||
| 872 | (let ((lexical-binding t) | ||
| 873 | (comp-tests-cond-rw-checked-function #'comp-tests-cond-rw-4-f) | ||
| 874 | (comp-tests-cond-rw-expected-type 'fixnum) | ||
| 875 | (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type)))) | ||
| 876 | (eval '(defun comp-tests-cond-rw-4-f (x y) | ||
| 877 | (declare (speed 3)) | ||
| 878 | (if (= x (comp-hint-fixnum y)) | ||
| 879 | x | ||
| 880 | t)) | ||
| 881 | t) | ||
| 882 | (native-compile #'comp-tests-cond-rw-4-f) | ||
| 883 | (should (subr-native-elisp-p (symbol-function #'comp-tests-cond-rw-4-f))))) | ||
| 884 | |||
| 794 | ;;; comp-tests.el ends here | 885 | ;;; comp-tests.el ends here |