X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fdynamic-extent.impure.lisp;h=9e7732150c064b03a62b52e1a193c33f5488bc2e;hb=091f0c20d4661994be7be4cc707c2aba4ef86418;hp=685ff6d5b926fe814b928ab78adff92f46b0028b;hpb=6822034325136cde4e14773c83c3769b42721306;p=sbcl.git diff --git a/tests/dynamic-extent.impure.lisp b/tests/dynamic-extent.impure.lisp index 685ff6d..9e77321 100644 --- a/tests/dynamic-extent.impure.lisp +++ b/tests/dynamic-extent.impure.lisp @@ -129,7 +129,7 @@ (defun-with-dx dx-value-cell (x) ;; Not implemented everywhere, yet. - #+(or x86 x86-64 mips) + #+(or x86 x86-64 mips hppa) (let ((cell x)) (declare (sb-int:truly-dynamic-extent cell)) (flet ((f () @@ -147,12 +147,52 @@ ;;; MAKE-ARRAY -(defun-with-dx make-array-on-stack () +(defun force-make-array-on-stack (n) + (declare (optimize safety)) + (let ((v (make-array (min n 1)))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + +(defun-with-dx make-array-on-stack-1 () (let ((v (make-array '(42) :element-type 'single-float))) (declare (dynamic-extent v)) (true v) nil)) +(defun-with-dx make-array-on-stack-2 (n x) + (declare (integer n)) + (let ((v (make-array n :initial-contents x))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + +(defun-with-dx make-array-on-stack-3 (x y z) + (let ((v (make-array 3 + :element-type 'fixnum :initial-contents (list x y z) + :element-type t :initial-contents x))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + +(defun-with-dx make-array-on-stack-4 () + (let ((v (make-array 3 :initial-contents '(1 2 3)))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + +(defun-with-dx make-array-on-stack-5 () + (let ((v (make-array 3 :initial-element 12 :element-type t))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + +(defun-with-dx vector-on-stack (x y) + (let ((v (vector 1 x 2 y 3))) + (declare (sb-int:truly-dynamic-extent v)) + (true v) + nil)) + ;;; MAKE-STRUCTURE (declaim (inline make-fp-struct-1)) @@ -370,6 +410,29 @@ (setf (car x) nil)) nil)) +(defparameter *bar* nil) +(declaim (inline make-nested-bad make-nested-good)) +(defstruct (nested (:constructor make-nested-bad (&key bar &aux (bar (setf *bar* bar)))) + (:constructor make-nested-good (&key bar))) + bar) + +(defun-with-dx nested-good (y) + (let ((x (list (list (make-nested-good :bar (list (list (make-nested-good :bar (list y))))))))) + (declare (dynamic-extent x)) + (true x))) + +(defun-with-dx nested-bad (y) + (let ((x (list (list (make-nested-bad :bar (list (list (make-nested-bad :bar (list y))))))))) + (declare (dynamic-extent x)) + (unless (equalp (caar x) (make-nested-good :bar *bar*)) + (error "got ~S, wanted ~S" (caar x) (make-nested-good :bar *bar*))) + (caar x))) + +(with-test (:name :conservative-nested-dx) + ;; NESTED-BAD should not stack-allocate :BAR due to the SETF. + (assert (equalp (nested-bad 42) (make-nested-good :bar *bar*))) + (assert (equalp *bar* (list (list (make-nested-bad :bar (list 42))))))) + ;;; multiple uses for dx lvar (defun-with-dx multiple-dx-uses () @@ -440,7 +503,7 @@ (defvar *a-cons* (cons nil nil)) -#+(or x86 x86-64 alpha ppc sparc mips) +#+(or x86 x86-64 alpha ppc sparc mips hppa) (progn (assert-no-consing (dxclosure 42)) (assert-no-consing (dxlength 1 2 3)) @@ -452,22 +515,35 @@ (assert-no-consing (test-let-var-subst2 17)) (assert-no-consing (test-lvar-subst 11)) (assert-no-consing (dx-value-cell 13)) - (assert-no-consing (cons-on-stack 42)) - (assert-no-consing (make-array-on-stack)) - (assert-no-consing (make-foo1-on-stack 123)) + ;; Only for platforms with DX FIXED-ALLOC + #+(or hppa mips x86 x86-64) + (progn + (assert-no-consing (cons-on-stack 42)) + (assert-no-consing (make-foo1-on-stack 123)) + (assert-no-consing (nested-good 42)) + (assert-no-consing (nested-dx-conses)) + (assert-no-consing (dx-handler-bind 2)) + (assert-no-consing (dx-handler-case 2))) + ;; Only for platforms with DX ALLOCATE-VECTOR + #+(or hppa mips x86 x86-64) + (progn + (assert-no-consing (force-make-array-on-stack 128)) + (assert-no-consing (make-array-on-stack-1)) + (assert-no-consing (make-array-on-stack-2 5 '(1 2.0 3 4.0 5))) + (assert-no-consing (make-array-on-stack-3 9 8 7)) + (assert-no-consing (make-array-on-stack-4)) + (assert-no-consing (make-array-on-stack-5)) + (assert-no-consing (vector-on-stack :x :y))) (#+raw-instance-init-vops assert-no-consing #-raw-instance-init-vops progn (make-foo2-on-stack 1.24 1.23d0)) (#+raw-instance-init-vops assert-no-consing #-raw-instance-init-vops progn (make-foo3-on-stack)) - (assert-no-consing (nested-dx-conses)) (assert-no-consing (nested-dx-lists)) (assert-consing (nested-dx-not-used *a-cons*)) (assert-no-consing (nested-evil-dx-used *a-cons*)) (assert-no-consing (multiple-dx-uses)) - (assert-no-consing (dx-handler-bind 2)) - (assert-no-consing (dx-handler-case 2)) ;; Not strictly DX.. (assert-no-consing (test-hash-table)) #+sb-thread @@ -514,8 +590,10 @@ (let ((a (make-array 11 :initial-element 0))) (declare (dynamic-extent a)) (assert (every (lambda (x) (eql x 0)) a)))) -(assert-no-consing (bdowning-2005-iv-16)) - +(with-test (:name :bdowning-2005-iv-16) + #+(or hppa mips x86 x86-64) + (assert-no-consing (bdowning-2005-iv-16)) + (bdowning-2005-iv-16)) (defun-with-dx let-converted-vars-dx-allocated-bug (x y z) (let* ((a (list x y z)) @@ -523,9 +601,11 @@ (c (list a b))) (declare (dynamic-extent c)) (values (first c) (second c)))) -(multiple-value-bind (i j) (let-converted-vars-dx-allocated-bug 1 2 3) - (assert (and (equal i j) - (equal i (list 1 2 3))))) + +(with-test (:name :let-converted-vars-dx-allocated-bug) + (multiple-value-bind (i j) (let-converted-vars-dx-allocated-bug 1 2 3) + (assert (and (equal i j) + (equal i (list 1 2 3)))))) ;;; workaround for bug 419 -- real issue remains, but check that the ;;; bandaid holds. @@ -551,7 +631,9 @@ (multiple-value-bind (y pos2) (read-from-string res nil nil :start pos) (assert (equalp f2 y)) (assert (equalp f3 (read-from-string res nil nil :start pos2)))))) - (assert-no-consing (assert (eql n (funcall fun nil))))) + #+(or hppa mips x86 x86-64) + (assert-no-consing (assert (eql n (funcall fun nil)))) + (assert (eql n (funcall fun nil)))) (macrolet ((def (n f1 f2 f3) (let ((name (sb-pcl::format-symbol :cl-user "DX-FLET-TEST.~A" n))) `(progn @@ -587,4 +669,115 @@ 14) )))) (assert (equal '((0 4) (3 ((1 2 3 5) 14))) (test-update-uvl-live-sets #() 4 5))) + +(with-test (:name :regression-1.0.23.38) + (compile nil '(lambda () + (flet ((make (x y) + (let ((res (cons x x))) + (setf (cdr res) y) + res))) + (declaim (inline make)) + (let ((z (make 1 2))) + (declare (dynamic-extent z)) + (print z) + t)))) + (compile nil '(lambda () + (flet ((make (x y) + (let ((res (cons x x))) + (setf (cdr res) y) + (if x res y)))) + (declaim (inline make)) + (let ((z (make 1 2))) + (declare (dynamic-extent z)) + (print z) + t))))) + +;;; On x86 and x86-64 upto 1.0.28.16 LENGTH and WORDS argument +;;; tns to ALLOCATE-VECTOR-ON-STACK could be packed in the same +;;; location, leading to all manner of badness. ...reproducing this +;;; reliably is hard, but this it at least used to break on x86-64. +(defun length-and-words-packed-in-same-tn (m) + (declare (optimize speed (safety 0) (debug 0) (space 0))) + (let ((array (make-array (max 1 m) :element-type 'fixnum))) + (declare (dynamic-extent array)) + (array-total-size array))) +(with-test (:name :length-and-words-packed-in-same-tn) + (assert (= 1 (length-and-words-packed-in-same-tn -3)))) + +(with-test (:name :handler-case-bogus-compiler-note) + (handler-bind ((compiler-note #'error)) + ;; Taken from SWANK, used to signal a bogus stack allocation + ;; failure note. + (compile nil + `(lambda (files fasl-dir load) + (let ((needs-recompile nil)) + (dolist (src files) + (let ((dest (binary-pathname src fasl-dir))) + (handler-case + (progn + (when (or needs-recompile + (not (probe-file dest)) + (file-newer-p src dest)) + (setq needs-recompile t) + (ensure-directories-exist dest) + (compile-file src :output-file dest :print nil :verbose t)) + (when load + (load dest :verbose t))) + (serious-condition (c) + (handle-loadtime-error c dest)))))))))) + +(declaim (inline foovector barvector)) +(defun foovector (x y z) + (let ((v (make-array 3))) + (setf (aref v 0) x + (aref v 1) y + (aref v 2) z) + v)) +(defun barvector (x y z) + (make-array 3 :initial-contents (list x y z))) +(with-test (:name :dx-compiler-notes) + (flet ((assert-notes (j lambda) + (let ((n 0)) + (handler-bind ((compiler-note (lambda (c) + (declare (ignore cc)) + (incf n)))) + (compile nil lambda) + (unless (= j n) + (error "Wanted ~S notes, got ~S for~% ~S" + j n lambda)))))) + ;; These ones should complain. + (assert-notes 1 `(lambda (x) + (let ((v (make-array x))) + (declare (dynamic-extent v)) + (length v)))) + (assert-notes 2 `(lambda (x) + (let ((y (if (plusp x) + (true x) + (true (- x))))) + (declare (dynamic-extent y)) + (print y) + nil))) + (assert-notes 1 `(lambda (x) + (let ((y (foovector x x x))) + (declare (sb-int:truly-dynamic-extent y)) + (print y) + nil))) + ;; These ones should not complain. + (assert-notes 0 `(lambda (name) + (with-alien + ((posix-getenv (function c-string c-string) + :EXTERN "getenv")) + (values + (alien-funcall posix-getenv name))))) + (assert-notes 0 `(lambda (x) + (let ((y (barvector x x x))) + (declare (dynamic-extent y)) + (print y) + nil))) + (assert-notes 0 `(lambda (list) + (declare (optimize (space 0))) + (sort list #'<))) + (assert-notes 0 `(lambda (other) + #'(lambda (s c n) + (ignore-errors (funcall other s c n)))))))