bugKawa - Bugs: bug #39606, tail calls not performed for...


bug #39606: tail calls not performed for top-level functions

Submitted by:  None
Submitted on:  Mon 29 Jul 2013 10:32:38 AM UTC  
Category: Code generationSeverity: 3 - Normal
Item Group: Run-time exceptionStatus: Wont Fix
Privacy: PublicAssigned to: Per Bothner <bothner>
Open/Closed: Closed

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Tue 10 Sep 2013 08:03:39 AM UTC, comment #1:

If works if you use the --full-tails option when starting up Kawa:
bash$ java -jar kawa-1.13.jar --full-tailcalls

See http://www.gnu.org/software/kawa/Compatibility.html and

Otherwise when using the default calling convention we're limited by JVM (for now at least). The Kawa compiler will optimize away the most common kinds of tail-calls, including (self-)tail-recursion, and some kinds of mutual tail-recursion. For example:

bash$ bin/kawa --debug-dump-zip
#|kawa:1|# (define e? (let () (define (e? x) (if (zero? x) #t (o? (- x 1)))) (define (o? x) (if (zero? x) #f (e? (- x 1)))) e?))
#|kawa:2|# (e? 10000)

We can do better when the JVM gets native tail-call optimization. Maybe Java 9 - if we're lucky - or enough people demand it.

Per Bothner <bothner>
Project AdministratorIn charge of this item.
Mon 29 Jul 2013 10:32:38 AM UTC, original submission:

bash$ wget -q ftp://ftp.gnu.org/pub/gnu/kawa/kawa-1.13.jar
bash$ java -jar kawa-1.13.jar
#|kawa:1|# (define (e? x) (if (zero? x) #t (o? (- x 1))))
/dev/stdin:1:33: warning - no declaration seen for o?
#|kawa:2|# (define (o? x) (if (zero? x) #f (e? (- x 1))))
#|kawa:3|# (map e? '(0 1 2 3 100 101 102 103))
(#t #f #t #f #t #f #t #f)
#|kawa:4|# (e? 10000)
at gnu.math.IntNum.<init>(IntNum.java:41)
at gnu.math.IntNum.make(IntNum.java:82)
at gnu.math.IntNum.add(IntNum.java:431)
at gnu.kawa.functions.AddOp.apply2(AddOp.java:57)
at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:137)
at gnu.mapping.ProcedureN.apply2(ProcedureN.java:39)
at atInteractiveLevel$1.isE(stdin:1)
at atInteractiveLevel$1.apply1(stdin:1)
at gnu.expr.ModuleMethod.apply1(ModuleMethod.java:192)
#|kawa:5|# ;eof



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 07 Oct 2015 08:34:10 PM UTCbothnerOpen/ClosedOpen=>Closed
    Tue 10 Sep 2013 08:03:39 AM UTCbothnerStatusNone=>Wont Fix
      Assigned toNone=>bothner

    Back to the top

    Powered by Savane 3.1-cleanup1