diff options
| author | Andrea Corallo | 2020-07-02 21:43:52 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-07-02 22:55:42 +0200 |
| commit | 7e004d24a4abaa4b5aa9f0f1cd4bc70264396ad5 (patch) | |
| tree | 19efd43b6668b79372630fe0c34ed4e5a2eaa5ad /test/src | |
| parent | 8f81859497b7dd0c537d24a27985a26ffc778a3a (diff) | |
| download | emacs-7e004d24a4abaa4b5aa9f0f1cd4bc70264396ad5.tar.gz emacs-7e004d24a4abaa4b5aa9f0f1cd4bc70264396ad5.zip | |
* Add a test to verify tail recursion elimination
* test/src/comp-tests.el (comp-tests-tco): Compile a recursive
functions at speed 3 and verify the tail recursion elimination.
(comp-tests-tco-checker, comp-tests-mentioned-p)
(comp-tests-mentioned-p-1): New support functions.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/comp-tests.el | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 66f7d8c1795..fd1c513d13a 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -583,4 +583,52 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 583 | (should (equal (comp-tests-cl-uninterned-arg-parse-f 1 2) | 583 | (should (equal (comp-tests-cl-uninterned-arg-parse-f 1 2) |
| 584 | '(1 2)))) | 584 | '(1 2)))) |
| 585 | 585 | ||
| 586 | |||
| 587 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 588 | ;; Middle-end specific tests. ;; | ||
| 589 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 590 | |||
| 591 | (defun comp-tests-mentioned-p-1 (x insn) | ||
| 592 | (cl-loop for y in insn | ||
| 593 | when (cond | ||
| 594 | ((consp y) (comp-tests-mentioned-p x y)) | ||
| 595 | ((and (comp-mvar-p y) (comp-mvar-const-vld y)) | ||
| 596 | (equal (comp-mvar-constant y) x)) | ||
| 597 | (t (equal x y))) | ||
| 598 | return t)) | ||
| 599 | |||
| 600 | (defun comp-tests-mentioned-p (x insn) | ||
| 601 | "Check if X is actively mentioned in INSN." | ||
| 602 | (unless (eq (car-safe insn) | ||
| 603 | 'comment) | ||
| 604 | (comp-tests-mentioned-p-1 x insn))) | ||
| 605 | |||
| 606 | (defun comp-tests-tco-checker (_) | ||
| 607 | "Check that inside `comp-tests-tco-f' we have no recursion." | ||
| 608 | (should-not | ||
| 609 | (cl-loop | ||
| 610 | named checker-loop | ||
| 611 | with func-name = (comp-c-func-name 'comp-tests-tco-f "F" t) | ||
| 612 | with f = (gethash func-name (comp-ctxt-funcs-h comp-ctxt)) | ||
| 613 | for bb being each hash-value of (comp-func-blocks f) | ||
| 614 | do (cl-loop | ||
| 615 | for insn in (comp-block-insns bb) | ||
| 616 | when (or (comp-tests-mentioned-p 'comp-tests-tco-f insn) | ||
| 617 | (comp-tests-mentioned-p func-name insn)) | ||
| 618 | do (cl-return-from checker-loop 'mentioned))))) | ||
| 619 | |||
| 620 | (ert-deftest comp-tests-tco () | ||
| 621 | "Check for tail recursion elimination." | ||
| 622 | (let ((comp-speed 3) | ||
| 623 | (comp-post-pass-hooks '((comp-tco comp-tests-tco-checker) | ||
| 624 | (comp-final comp-tests-tco-checker)))) | ||
| 625 | (eval '(defun comp-tests-tco-f (a b count) | ||
| 626 | (if (= count 0) | ||
| 627 | b | ||
| 628 | (comp-tests-tco-f (+ a b) a (- count 1)))) | ||
| 629 | t) | ||
| 630 | (load (native-compile #'comp-tests-tco-f)) | ||
| 631 | (should (subr-native-elisp-p (symbol-function #'comp-tests-tco-f))) | ||
| 632 | (should (= (comp-tests-tco-f 1 0 10) 55)))) | ||
| 633 | |||
| 586 | ;;; comp-tests.el ends here | 634 | ;;; comp-tests.el ends here |