]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a type-check--optim test
authorAndrea Corallo <acorallo@gnu.org>
Wed, 10 Jul 2024 21:50:18 +0000 (23:50 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 11 Jul 2024 14:39:59 +0000 (16:39 +0200)
* 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)

test/src/comp-tests.el

index bab5a358290d63a418fca5cc295a78dde5c61946..dfeeaff05d8ffbed8f4a622b3970ac4f3f493e59 100644 (file)
@@ -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