1.0.16.29: workaround for bug 419
authorNikodemus Siivola <nikodemus@random-state.net>
Mon, 12 May 2008 14:12:42 +0000 (14:12 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 12 May 2008 14:12:42 +0000 (14:12 +0000)
 * Require an explicit SB-C::STACK-ALLOCATE-VALUE-CELLS optimize
   declaration before stack allocating value cells to prevent
   returning garbage values from hairy user code.

BUGS
NEWS
make-host-2.lisp
src/compiler/ir2tran.lisp
src/compiler/policies.lisp
tests/dynamic-extent.impure.lisp
version.lisp-expr

diff --git a/BUGS b/BUGS
index 75a62e0..d503d80 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1810,7 +1810,8 @@ WORKAROUND:
 
 419: stack-allocated indirect closure variables are not popped
 
-    (locally (declare (optimize speed (safety 0)))
+    (locally (declare (optimize sb-c::stack-allocate-dynamic-extent
+                                sb-c::stack-allocate-value-cells))
       (defun bug419 (x)
         (multiple-value-call #'list
           (eval '(values 1 2 3))
@@ -1823,7 +1824,13 @@ WORKAROUND:
               (declare (dynamic-extent #'mget #'mset))
               ((lambda (f g) (eval `(progn ,f ,g (values 4 5 6)))) #'mget #'mset))))))
 
-  (ASSERT (EQUAL (BUG419) '(1 2 3 4 5 6))) => failure
+  (ASSERT (EQUAL (BUG419 42) '(1 2 3 4 5 6))) => failure
+
+  Note: as of SBCL 1.0.26.29 this bug no longer affects user code, as
+  SB-C::STACK-ALLOCATE-VALUE-CELLS needs to be explicitly turned on for
+  that to happen. Proper fix for this bug requires (Nikodemus thinks)
+  storing the relevant LAMBDA-VARs in a :DYNAMIC-EXTENT cleanup, and
+  teaching stack analysis how to deal with them.
 
 420: The MISC.556 test from gcl/ansi-tests/misc.lsp fails hard.
 
diff --git a/NEWS b/NEWS
index 808956e..3990725 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 ;;;; -*- coding: utf-8; -*-
 changes in sbcl-1.0.17 relative to 1.0.16:
+  * temporary regression: user code can no longer allocate closure
+    variable storage on stack, due to bug 419 without explicitly
+    requesting it. Please consult sbcl-devel for advice if you need to
+    use this feature in the meanwhile.    
   * optimization: ADJOIN and PUSHNEW are upto ~70% faster in normal
     SPEED policies.
   * optimization: APPEND is upto ~10% faster in normal SPEED policies.
index 8bc96bf..7e66112 100644 (file)
@@ -29,7 +29,9 @@
        ;; never insert stepper conditions
        (sb!c:insert-step-conditions 0)
        ;; always stack-allocate if requested
-       (sb!c::stack-allocate-dynamic-extent 3)))))
+       (sb!c::stack-allocate-dynamic-extent 3)
+       ;; ...even value cells!
+       (sb!c::stack-allocate-value-cells 3)))))
 (compile 'proclaim-target-optimization)
 
 (defun in-target-cross-compilation-mode (fun)
index 3e1385d..f2c5381 100644 (file)
 (defun emit-make-value-cell (node block value res)
   (event make-value-cell-event node)
   (let ((leaf (tn-leaf res)))
-    (vop make-value-cell node block value (and leaf (leaf-dynamic-extent leaf))
+    (vop make-value-cell node block value
+         (and leaf (leaf-dynamic-extent leaf)
+              ;; FIXME: See bug 419
+              (policy node (> stack-allocate-value-cells 1)))
          res)))
 \f
 ;;;; leaf reference
index 9164e6b..0ab60a1 100644 (file)
@@ -100,6 +100,13 @@ and will refer to the new function, bound to FOO.")
   "Control whether allocate objects, declared DYNAMIC-EXTENT, on
 stack.")
 
+(define-optimization-quality stack-allocate-value-cells
+    ;; FIXME, see bug 419
+    0
+  ("no" "maybe" "yes" "yes")
+  "Control whether allocate closure variable storage, declared
+DYNAMIC-EXTENT, on stack.")
+
 (define-optimization-quality stack-allocate-vector
     (cond ((= stack-allocate-dynamic-extent 0) 0)
           ((= safety 0) 3)
index a6034c7..e27f5ae 100644 (file)
 ;;; 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))
 (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.
+(defun-with-dx bug419 (x)
+  (multiple-value-call #'list
+    (eval '(values 1 2 3))
+    (let ((x x))
+      (declare (dynamic-extent x))
+      (flet ((mget (y)
+               (+ x y))
+             (mset (z)
+               (incf x z)))
+        (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)))
 \f
index aca0b21..93fb676 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.16.28"
+"1.0.16.29"