X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fdynamic-extent.impure.lisp;h=685ff6d5b926fe814b928ab78adff92f46b0028b;hb=6b8baeece6cf870e3f979a9f09c32985c64c04de;hp=10677accfb27ed2066a8e3abc455ffa1a2083246;hpb=96bb2dc76dddb1a21b3886fa7522796879e9ed9d;p=sbcl.git diff --git a/tests/dynamic-extent.impure.lisp b/tests/dynamic-extent.impure.lisp index 10677ac..685ff6d 100644 --- a/tests/dynamic-extent.impure.lisp +++ b/tests/dynamic-extent.impure.lisp @@ -14,13 +14,12 @@ (when (eq sb-ext:*evaluator-mode* :interpret) (sb-ext:quit :unix-status 104)) -(setq sb-c::*check-consistency* t) +(setq sb-c::*check-consistency* t + sb-ext:*stack-allocate-dynamic-extent* t) (defmacro defun-with-dx (name arglist &body body) - `(locally - (declare (optimize sb-c::stack-allocate-dynamic-extent)) - (defun ,name ,arglist - ,@body))) + `(defun ,name ,arglist + ,@body)) (declaim (notinline opaque-identity)) (defun opaque-identity (x) @@ -129,11 +128,10 @@ ;;; value-cells (defun-with-dx dx-value-cell (x) - (declare (optimize sb-c::stack-allocate-value-cells)) ;; Not implemented everywhere, yet. #+(or x86 x86-64 mips) (let ((cell x)) - (declare (dynamic-extent cell)) + (declare (sb-int:truly-dynamic-extent cell)) (flet ((f () (incf cell))) (declare (dynamic-extent #'f)) @@ -382,7 +380,23 @@ (true dx) nil)) -;;; with-spinlock should use DX and not cons +;;; handler-case and handler-bind should use DX internally + +(defun dx-handler-bind (x) + (handler-bind ((error + (lambda (c) (break "OOPS: ~S caused ~S" x c))) + ((and serious-condition (not error)) + #'(lambda (c) (break "OOPS2: ~S did ~S" x c)))) + (/ 2 x))) + +(defun dx-handler-case (x) + (assert (zerop (handler-case (/ 2 x) + (error (c) + (break "OOPS: ~S caused ~S" x c)) + (:no-error (res) + (1- res)))))) + +;;; with-spinlock and with-mutex should use DX and not cons (defvar *slock* (sb-thread::make-spinlock :name "slocklock")) @@ -390,6 +404,12 @@ (sb-thread::with-spinlock (*slock*) (true *slock*))) +(defvar *mutex* (sb-thread::make-mutex :name "mutexlock")) + +(defun test-mutex () + (sb-thread:with-mutex (*mutex*) + (true *mutex*))) + ;;; not really DX, but GETHASH and (SETF GETHASH) should not cons (defvar *table* (make-hash-table)) @@ -446,10 +466,14 @@ (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 - (assert-no-consing (test-spinlock))) + (progn + (assert-no-consing (test-spinlock)) + (assert-no-consing (test-mutex)))) ;;; Bugs found by Paul F. Dietz @@ -517,4 +541,50 @@ (declare (dynamic-extent #'mget #'mset)) ((lambda (f g) (eval `(progn ,f ,g (values 4 5 6)))) #'mget #'mset))))) (assert (equal (bug419 42) '(1 2 3 4 5 6))) + +;;; Multiple DX arguments in a local function call +(defun test-dx-flet-test (fun n f1 f2 f3) + (let ((res (with-output-to-string (s) + (assert (eql n (ignore-errors (funcall fun s))))))) + (multiple-value-bind (x pos) (read-from-string res nil) + (assert (equalp f1 x)) + (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))))) +(macrolet ((def (n f1 f2 f3) + (let ((name (sb-pcl::format-symbol :cl-user "DX-FLET-TEST.~A" n))) + `(progn + (defun-with-dx ,name (s) + (flet ((f (x) + (declare (dynamic-extent x)) + (when s + (print x s) + (finish-output s)) + nil)) + (f ,f1) + (f ,f2) + (f ,f3) + ,n)) + (test-dx-flet-test #',name ,n ,f1 ,f2 ,f3))))) + (def 0 (list :one) (list :two) (list :three)) + (def 1 (make-array 128) (list 1 2 3 4 5 6 7 8) (list 'list)) + (def 2 (list 1) (list 2 3) (list 4 5 6 7))) + +;;; Test that unknown-values coming after a DX value won't mess up the stack analysis +(defun test-update-uvl-live-sets (x y z) + (declare (optimize speed (safety 0))) + (flet ((bar (a b) + (declare (dynamic-extent a)) + (eval `(list (length ',a) ',b)))) + (list (bar x y) + (bar (list x y z) ; dx push + (list + (multiple-value-call 'list + (eval '(values 1 2 3)) ; uv push + (max y z) + ) ; uv pop + 14) + )))) +(assert (equal '((0 4) (3 ((1 2 3 5) 14))) (test-update-uvl-live-sets #() 4 5)))