Subject: Misplaced tail call optimization

From: [email-masked] (Ludovic Courtès)
Date: Sun, 16 Oct 2011 22:29:00 +0200

(This is a copy of <http://savannah.gnu.org/bugs/?34300>, so it doesn't
get lost.  :-))

Consider this example:

  (define bar
    (lambda ()
      (let ((fail (lambda () 'fail)))
        (let loop ((a (iota 3)))
          (if (pair? a)
              (loop (cdr a))
              (fail)))
        (pk 'done))))

This function should return 'done but it instead returns 'fail, because both
the call to `loop' and the call to `fail' are compiled as if they were tail
calls.

To reproduce the test, turn partial evaluation off---otherwise the call to
`fail' is inlined and the problem doesn't show up.

Ludo'.