eholk / harlan

A language for GPU computing.
Other
1.19k stars 83 forks source link

Let lifting breaks things in the presence of set! #56

Open eholk opened 11 years ago

eholk commented 11 years ago

This came up while working on a library version of reduce:

(define (vector_sum xs)
    (while (> (length xs) 1)
      ;;(print "vector_sum length = ");
      ;;(print (length xs))
      ;;(print "\n")
      (let ((len (/ (length xs) 2)))
        (set! xs (kernel ((i (iota len)))
                   (+ (vector-ref xs i) (vector-ref xs (+ i len)))))))
    (vector-ref xs 0))

With the print statements uncommented, the code works correctly. It seems the (let ((len (/ (length xs) 2))) ...) section gets lifted above the while loop, since the lifter assumes xs never changes.

This is probably a good argument for removing set! entirely in favor of named let.

calvis commented 11 years ago

This can be solved without removing set! entirely; i.e. we could just do an assigned-variable analysis. I'm not saying that is necessarily the right way to go, but doing that analysis would probably help out some other passes as well.

eholk commented 11 years ago

Yeah, that makes sense. I was worried that the assigned variable analysis might be kind of intricate, but I guess not. As you say, the analysis will probably be helpful anyway. For example, named let will probably expand into set!s and gotos.

eholk commented 11 years ago

I suspect this bug explains why our Mandelbrot programs only generate white images now.