From: Andrea Corallo Date: Wed, 10 Jul 2024 21:50:18 +0000 (+0200) Subject: Add a type-check--optim test X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cc1815adf906e15c92b6e37939cb32bd13567687;p=emacs.git Add a type-check--optim test * test/src/comp-tests.el (comp-tests-type-branch-optim-checker): New function. (comp-tests-type-branch-optim): Add new test. (cherry picked from commit dc8cde2b6f3e7c55a85439c771284df2b4fa0e37) --- diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index bab5a358290..dfeeaff05d8 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -1570,4 +1570,28 @@ folded." (comp-deftest comp-tests-result-lambda () (native-compile 'comp-tests-result-lambda) (should (eq (funcall (comp-tests-result-lambda) '(a . b)) 'a))) + +(defun comp-tests-type-branch-optim-checker (_) + "Check there's only a single call to `type-of'." + (should (= (cl-count t (comp-tests-map-checker + #'comp-tests-type-branch-optim-1-f + (lambda (insn) + (pcase insn + (`(set ,_mvar-1 (call type-of ,_mvar-2)) + t))))) + 1))) + +(declare-function comp-tests-type-branch-optim-1-f nil) + +(comp-deftest comp-tests-type-branch-optim () + (let ((native-comp-speed 2) + (comp-post-pass-hooks '((comp--final comp-tests-type-branch-optim-checker)))) + (eval '(progn + (cl-defstruct type-branch-optim-struct a b c) + (defun comp-tests-type-branch-optim-1-f (x) + (setf (type-branch-optim-struct-a x) 3) + (+ (type-branch-optim-struct-b x) (type-branch-optim-struct-c x)))) + t) + (native-compile #'comp-tests-type-branch-optim-1-f))) + ;;; comp-tests.el ends here