limit check pushed inside loop

Matthew Fluet fluet@research.nj.nec.com
Thu, 10 Aug 2000 18:03:35 -0400 (EDT)


Talking with Suresh yesterday about the discussion on n-byte limit checks
pushed inside loops, we were wondering if this aggressive coalescing of
limit checks violates safe-for-space.  I've got one extreme case which I
think does, although it is certainly up for debate as to whether or not it
could be turned into a real case to worry about.

fun f 0 = true
  | f n = g 1
and g  0 = false
  | g  n = f 1

val _ = let
	  val x = Bool.toString (f 2)
	in 
	  print (concat["f(2) = ",
			"",            \
			"",             \
			...,             - n instances of the empty string
			"",             /
			"",            /
			x])
	end

At the top of the (non-allocating, non-terminating) f-g loop, there is a
limitCheck for (24 + 12 * n) bytes; I guess that constant sized lists are
just allocated all at once, not consed.  For any n, this program
shouldn't terminate, but for a fixed heap of 4k (can't get any smaller
with page sizes), n=283 runs but n=284 exits with an out of memory error.

So, the potential might be there for those loop limit checks to change
behavior.  At a minimum, they might force one extra GC and at the worst,
something like this might occur.  Of course, I think the worst case is
very unlikely; it took a lot of tweaking to make sure that the simplifiers
didn't completely elminate the loop.  It's probably near impossible to
have such a loop really "do" something useful.