aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorAndrea Corallo2020-11-11 17:59:46 +0100
committerAndrea Corallo2020-11-12 00:58:56 +0100
commit2435c103a4da85ae8b6bc48f3f964014d1cb6341 (patch)
tree3ade398a19f0de7696cd5be0c9888f04068ea695 /test/src
parent93a80a4fae2b90471a3a3cf4f17751ce48f4af2f (diff)
downloademacs-2435c103a4da85ae8b6bc48f3f964014d1cb6341.tar.gz
emacs-2435c103a4da85ae8b6bc48f3f964014d1cb6341.zip
* Nativecomp testsuite rework for derived return type specifiers
As we have derived return type specifiers as some test for them. Also rewrite some propagation related test using return type specifiers too as it's way more convenient. * test/src/comp-tests.el (fw-prop-1): Nit rename. (comp-tests-check-ret-type-spec): New function. (comp-tests-type-spec-tests): New variable. (comp-tests-cond-rw-0-var) Remove variable. (cond-rw-0, cond-rw-1, cond-rw-2, cond-rw-3, cond-rw-4, cond-rw-5) Remove tests as now covered by `comp-tests-check-ret-type-spec'.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/comp-tests.el167
1 files changed, 105 insertions, 62 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index 8bedad5db73..23c4df88201 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -743,7 +743,7 @@ Return a list of results."
743 (or (comp-tests-mentioned-p 'concat insn) 743 (or (comp-tests-mentioned-p 'concat insn)
744 (comp-tests-mentioned-p 'length insn))))))) 744 (comp-tests-mentioned-p 'length insn)))))))
745 745
746(comp-deftest fw-prop () 746(comp-deftest fw-prop-1 ()
747 "Some tests for forward propagation." 747 "Some tests for forward propagation."
748 (let ((comp-speed 2) 748 (let ((comp-speed 2)
749 (comp-post-pass-hooks '((comp-final comp-tests-fw-prop-checker-1)))) 749 (comp-post-pass-hooks '((comp-final comp-tests-fw-prop-checker-1))))
@@ -757,6 +757,110 @@ Return a list of results."
757 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f))) 757 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f)))
758 (should (= (comp-tests-fw-prop-1-f) 6)))) 758 (should (= (comp-tests-fw-prop-1-f) 6))))
759 759
760(defun comp-tests-check-ret-type-spec (func-form type-specifier)
761 (let ((lexical-binding t)
762 (speed 2)
763 (comp-post-pass-hooks
764 `((comp-final
765 ,(lambda (_)
766 (let ((f (gethash (comp-c-func-name (cadr func-form) "F" t)
767 (comp-ctxt-funcs-h comp-ctxt))))
768 (should (equal (comp-func-ret-type-specifier f)
769 type-specifier))))))))
770 (eval func-form t)
771 (native-compile (cadr func-form))))
772
773(defconst comp-tests-type-spec-tests
774 `(((defun comp-tests-ret-type-spec-0-f (x)
775 x)
776 (t))
777
778 ((defun comp-tests-ret-type-spec-1-f ()
779 1)
780 (integer 1 1))
781
782 ((defun comp-tests-ret-type-spec-2-f (x)
783 (if x 1 3))
784 (or (integer 1 1) (integer 3 3)))
785
786 ((defun comp-tests-ret-type-spec-3-f (x)
787 (let (y)
788 (if x
789 (setf y 1)
790 (setf y 2))
791 y))
792 (integer 1 2))
793
794 ((defun comp-tests-ret-type-spec-4-f (x)
795 (let (y)
796 (if x
797 (setf y 1)
798 (setf y 3))
799 y))
800 (or (integer 1 1) (integer 3 3)))
801
802 ((defun comp-tests-ret-type-spec-5-f (x)
803 (if x
804 (list x)
805 3))
806 (or cons (integer 3 3)))
807
808 ((defun comp-tests-ret-type-spec-6-f (x)
809 (if x
810 'foo
811 3))
812 (or (member foo) (integer 3 3)))
813
814 ((defun comp-tests-ret-type-spec-7-1-f (x)
815 (if (eq x 3)
816 x
817 'foo))
818 (or (member foo) (integer 3 3)))
819
820 ((defun comp-tests-ret-type-spec-7-2-f (x)
821 (if (eq 3 x)
822 x
823 'foo))
824 (or (member foo) (integer 3 3)))
825
826 ((defun comp-tests-ret-type-spec-8-1-f (x)
827 (if (= x 3)
828 x
829 'foo))
830 (or (member foo) (integer 3 3)))
831
832 ((defun comp-tests-ret-type-spec-8-2-f (x)
833 (if (= 3 x)
834 x
835 'foo))
836 (or (member foo) (integer 3 3)))
837
838 ;; FIXME returning ATM (or t (member foo))
839 ;; ((defun comp-tests-ret-type-spec-8-3-f (x)
840 ;; (if (= x 3)
841 ;; 'foo
842 ;; x))
843 ;; (or number (member foo)))
844
845 ((defun comp-tests-ret-type-spec-8-4-f (x y)
846 (if (= x y)
847 x
848 'foo))
849 (or number (member foo)))
850
851 ((defun comp-tests-ret-type-spec-9-1-f (x)
852 (comp-hint-fixnum y))
853 (integer ,most-negative-fixnum ,most-positive-fixnum))
854
855 ((defun comp-tests-ret-type-spec-9-1-f (x)
856 (comp-hint-cons x))
857 (cons))))
858
859(comp-deftest ret-type-spec ()
860 "Some derived return type specifier tests."
861 (cl-loop for (func-form type-spec) in comp-tests-type-spec-tests
862 do (comp-tests-check-ret-type-spec func-form type-spec)))
863
760(defun comp-tests-pure-checker-1 (_) 864(defun comp-tests-pure-checker-1 (_)
761 "Check that inside `comp-tests-pure-caller-f' `comp-tests-pure-callee-f' is 865 "Check that inside `comp-tests-pure-caller-f' `comp-tests-pure-callee-f' is
762 folded." 866 folded."
@@ -826,67 +930,6 @@ Return a list of results."
826 (equal (comp-mvar-typeset mvar) 930 (equal (comp-mvar-typeset mvar)
827 comp-tests-cond-rw-expected-type)))))))) 931 comp-tests-cond-rw-expected-type))))))))
828 932
829(defvar comp-tests-cond-rw-0-var)
830(comp-deftest cond-rw-0 ()
831 "Check we do not miscompile some simple functions."
832 (let ((lexical-binding t))
833 (let ((f (native-compile '(lambda (l)
834 (when (eq (car l) 'x)
835 (cdr l))))))
836 (should (subr-native-elisp-p f))
837 (should (eq (funcall f '(x . y)) 'y))
838 (should (null (funcall f '(z . y)))))
839
840 (should
841 (subr-native-elisp-p
842 (native-compile '(lambda () (if (eq comp-tests-cond-rw-0-var 123) 5 10)))))))
843
844(comp-deftest cond-rw-1 ()
845 "Test cond-rw pass allow us to propagate type+val under `eq' tests."
846 (let ((lexical-binding t)
847 (comp-tests-cond-rw-expected-type '(integer))
848 (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type
849 comp-tests-cond-rw-checker-val))))
850 (subr-native-elisp-p (native-compile '(lambda (x) (if (eq x 123) x t))))
851 (subr-native-elisp-p (native-compile '(lambda (x) (if (eq 123 x) x t))))))
852
853(comp-deftest cond-rw-2 ()
854 "Test cond-rw pass allow us to propagate type+val under `=' tests."
855 (let ((lexical-binding t)
856 (comp-tests-cond-rw-expected-type '(integer))
857 (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type
858 comp-tests-cond-rw-checker-val))))
859 (subr-native-elisp-p (native-compile '(lambda (x) (if (= x 123) x t))))))
860
861(comp-deftest cond-rw-3 ()
862 "Test cond-rw pass allow us to propagate type+val under `eql' tests."
863 (let ((lexical-binding t)
864 (comp-tests-cond-rw-expected-type '(integer))
865 (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type
866 comp-tests-cond-rw-checker-val))))
867 (subr-native-elisp-p (native-compile '(lambda (x) (if (eql 123 x) x t))))))
868
869(comp-deftest cond-rw-4 ()
870 "Test cond-rw pass allow us to propagate type under `=' tests."
871 (let ((lexical-binding t)
872 (comp-tests-cond-rw-expected-type '(number))
873 (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type))))
874 (subr-native-elisp-p (native-compile '(lambda (x y) (if (= x y) x t))))))
875
876(comp-deftest cond-rw-5 ()
877 "Test cond-rw pass allow us to propagate type under `=' tests."
878 (let ((comp-tests-cond-rw-checked-function #'comp-tests-cond-rw-4-f)
879 (comp-tests-cond-rw-expected-type '(integer))
880 (comp-post-pass-hooks '((comp-final comp-tests-cond-rw-checker-type))))
881 (eval '(defun comp-tests-cond-rw-4-f (x y)
882 (declare (speed 3))
883 (if (= x (comp-hint-fixnum y))
884 x
885 t))
886 t)
887 (native-compile #'comp-tests-cond-rw-4-f)
888 (should (subr-native-elisp-p (symbol-function #'comp-tests-cond-rw-4-f)))))
889
890 933
891;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 934;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
892;; Range propagation tests. ;; 935;; Range propagation tests. ;;