[bitc-dev] Tail recursion bug?

Jonathan S. Shapiro shap at eros-os.com
Tue Jan 6 17:15:54 CST 2009


Definitely a bug, but not clear whether it is in the tail call analyzer or
the code generator. I will look.

On Jan 6, 2009 5:51 PM, "Marvin Sielenkemper" <sielenk at gmx.de> wrote:

I compiled this program (fact.bitc)
--- snip ---
(bitc-version "0.10")
(import bitc.main as main)
(provide bitc.main main)

(define (factorial x:int32)
 (letrec
   ((fac (lambda (n r)
           (if (<= n 0) 1 (fac (- n 1) (* n r))))))
   (fac x 1)))

(define main.main:(fn (vector string) -> int32)
 (lambda (argv)
   (factorial 10)
   0))
--- snip ---
with
       bitcc --emit c fact.bitc
and expected to see the tail call of 'fac' compiled to a 'goto'.
But I found the following code for the 'if'-expression:
--- snip ---
 if (__t11241) {
   __t11245 = 1;
 }
 else {
   __t11252 = _16bitc_DTprelude_DT___HY_SHFN2_5int32_5int32_5int32
(_1n_SH_5int32_SH7462, 1);
   __t11256 = _16bitc_DTprelude_DT___ST_SHFN2_5int32_5int32_5int32
(_1n_SH_5int32_SH7462, _1r_SH_5int32_SH7464);
   __t11260 = (* __clArg_SH9094->_3fac_SHFN2_5int32_5int32_5int32)(__t11252,
__t11256);
   __t11245 = __t11260;
 }
--- snip ---
and __t11245 really is returned without further operations apart from
copying.
So 'fac' is in tail position but is called. And as far as i can see 12.2 of
the spec v0.10+ applies here.

Another bug?

--
MfG Marvin H. Sielenkemper
_______________________________________________
bitc-dev mailing list
bitc-dev at coyotos.org
http://www.coyotos.org/mailman/listinfo/bitc-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.coyotos.org/pipermail/bitc-dev/attachments/20090106/3ed38e02/attachment.html 


More information about the bitc-dev mailing list