aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorAndrea Corallo2020-07-05 23:00:07 +0100
committerAndrea Corallo2020-07-09 16:23:31 +0100
commita53b446cb021d1afb30b5c86a9b9cb7512dcf55d (patch)
treeb4a08a9ac1cd93051461a52f9e25ec3aff9d6a0f /test/src
parentb4de6baa7b5cc41d15bc94cfcdbea680af6dc7b8 (diff)
downloademacs-a53b446cb021d1afb30b5c86a9b9cb7512dcf55d.tar.gz
emacs-a53b446cb021d1afb30b5c86a9b9cb7512dcf55d.zip
Add some tests for pure function optimization
* test/src/comp-tests.el (comp-tests-fw-prop): Fix docstring. (comp-tests-pure-checker-1, comp-tests-pure-checker-2): New functions. (comp-tests-pure): New test testing for pure function optimization.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/comp-test-pure.el40
-rw-r--r--test/src/comp-tests.el32
2 files changed, 72 insertions, 0 deletions
diff --git a/test/src/comp-test-pure.el b/test/src/comp-test-pure.el
new file mode 100644
index 00000000000..f606a44a10e
--- /dev/null
+++ b/test/src/comp-test-pure.el
@@ -0,0 +1,40 @@
1;;; comp-test-pure.el --- compilation unit tested by comp-tests.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2020 Free Software Foundation, Inc.
4
5;; Author: Andrea Corallo <akrl@sdf.org>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(defun comp-tests-pure-callee-f (x)
27 (1+ x))
28
29(defun comp-tests-pure-caller-f ()
30 (comp-tests-pure-callee-f 3))
31
32(defun comp-tests-pure-fibn-f (a b count)
33 (if (= count 0)
34 b
35 (comp-tests-pure-fibn-f (+ a b) a (- count 1))))
36
37(defun comp-tests-pure-fibn-entry-f ()
38 (comp-tests-pure-fibn-f 1 0 20))
39
40;;; comp-test-pure.el ends here
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index 332facb4cf9..f4bc8156d35 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -662,4 +662,36 @@ CHECKER should always return nil to have a pass."
662 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f))) 662 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f)))
663 (should (= (comp-tests-fw-prop-1-f) 6)))) 663 (should (= (comp-tests-fw-prop-1-f) 6))))
664 664
665(defun comp-tests-pure-checker-1 (_)
666 "Check that inside `comp-tests-pure-caller-f' `comp-tests-pure-callee-f' is
667 folded."
668 (comp-tests-make-insn-checker
669 'comp-tests-pure-caller-f
670 (lambda (insn)
671 (or (comp-tests-mentioned-p 'comp-tests-pure-callee-f insn)
672 (comp-tests-mentioned-p (comp-c-func-name 'comp-tests-pure-callee-f "F" t)
673 insn)))))
674
675(defun comp-tests-pure-checker-2 (_)
676 "Check that `comp-tests-pure-fibn-f' is folded."
677 (comp-tests-make-insn-checker
678 'comp-tests-pure-fibn-entry-f
679 (lambda (insn)
680 (or (comp-tests-mentioned-p 'comp-tests-pure-fibn-f insn)
681 (comp-tests-mentioned-p (comp-c-func-name 'comp-tests-pure-fibn-f "F" t)
682 insn)))))
683
684(ert-deftest comp-tests-pure ()
685 "Some tests for pure functions optimization."
686 (let ((comp-speed 3)
687 (comp-post-pass-hooks '((comp-final comp-tests-pure-checker-1
688 comp-tests-pure-checker-2))))
689 (load (native-compile (concat comp-test-directory "comp-test-pure.el")))
690
691 (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-caller-f)))
692 (should (= (comp-tests-pure-caller-f) 4))
693
694 (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-fibn-entry-f)))
695 (should (= (comp-tests-pure-fibn-entry-f) 6765))))
696
665;;; comp-tests.el ends here 697;;; comp-tests.el ends here