Opened 4 years ago

Last modified 4 years ago

#1377 new defect

Tail-calls and FLETs

Reported by: svspire Owned by:
Priority: normal Milestone: Future Clozure CL
Component: Compiler Version: trunk
Keywords: Cc:

Description

Is this supposed to compile as tail-recursive? Because it's not doing so now. It appears that the call to tr-test within the flet isn't compiled as a jump to the containing global function. I don't remember if this is one of those "don't do that!" cases or it really should work. I'd prefer the latter; this is just a small test case but I'm writing a larger program where tail-jumps within flets would be very useful.

(defun tr-test (array &optional (startindex 0))
  (declare (optimize (debug 1)))
  (flet ((next ()
           (tr-test array (1+ startindex))))
    (when (< startindex (length array))
      (next))))

(trace tr-test)
(tr-test (make-array 100 :initial-element 0))

Change History (3)

comment:1 Changed 4 years ago by gb

I don't think that the generated code is very goog. but if you are concerned about whether or not the call to NEXT is or ia not a tail-call that involves a jumo ... it is.

comment:2 Changed 4 years ago by gb

[165]
    (movq (@ '#<Compiled-function (:INTERNAL NEXT TR-TEST) (Non-Global)  #x30200061B71F> (% fn)) (% temp0)) ;   [170]
    (movq (% rbp) (% rsp))                  ;   [177]
    (popq (% rbp))                          ;   [180]
    (movq (% fn) (% temp1))                 ;   [181]
    (movq (% temp0) (% fn))                 ;   [184]
    (jmpq (% fn))                           ;   [187]

comment:3 Changed 4 years ago by svspire

I looked at that, and yes, the call to NEXT is a jump. It's the call from within NEXT to TR-TEXT that is probably not a jump. But I don't know how to find the code for internal functions.

Note: See TracTickets for help on using tickets.