inlining a recursive function causes compiler to stack overflow
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Won't Fix
|
High
|
Unassigned |
Bug Description
I made a naive recursive function to calculate a Google codejam problem. Declaim inlining it is probably not a good idea. However, it would be nice if the compiler didn't crash to ldb (git head and 1.0.29).
$ sbcl --eval '(compile-file "C.lisp")'
This is SBCL 1.0.34.10, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
; loading system definition from
; /home/john/
; registering #<SYSTEM SB-GROVEL {100404EBA1}> as SB-GROVEL
STYLE-WARNING: redefining ALTERNATIVE-
; compiling file "/tmp/C.lisp" (written 01 FEB 2010 05:38:21 PM):
; compiling (DECLAIM (OPTIMIZE DEBUG ...))
; compiling (DECLAIM (INLINE COUNT-FILL-
; compiling (DEFUN COUNT-FILL-IN-GRID ...)INFO: Control stack guard page unprotected
Control stack guard page temporarily disabled: proceed with caution
fatal error encountered in SBCL pid 17001(tid 140737353901808):
Control stack exhausted
Welcome to LDB, a low-level debugger for the Lisp runtime environment.
ldb>
Here is the function inlne (also attached)
(declaim (optimize debug safety))
(declaim (inline count-fill-
(defun count-fill-in-grid (grid rows cols &optional (c-start 0) (r-start 0))
(declare (type fixnum rows cols c-start r-start) (optimize speed))
(macrolet ((a (c r)
`(aref grid ,c ,r)))
(loop for c from c-start below cols
do (loop
for r from r-start below rows
for v = (a c r)
do
(unless v
(let ((min 0) (max 25))
(flet ((maybe-min (val)
(when val
(setf min (max min val)))))
(unless (zerop r)
(maybe-min (a c (1- r))))
(unless (zerop c)
(maybe-min (a (1- c) r))))
(flet ((maybe-max (val)
(when val
(setf max (min max val)))))
(unless (= r (1- rows))
(maybe-max (a c (1+ r))))
(unless (= c (1- cols))
(maybe-max (a (1+ c) r))))
(when (> min max)
(return-from count-fill-in-grid 0))
(let ((count 0))
(loop for v from min upto max do
(setf (a c r) v)
(let ((recur (count-fill-in-grid grid rows cols c r)))
(when (zerop recur) (return))
(setf count (mod (+ count recur) 10007))))
(setf (a c r) nil)
(return-from count-fill-in-grid count)))))
(setf r-start 0)))
1)
SBCL 1.0.34.10
Marked as "high" because of the fall into LDB.