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

 
 

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

Submitter:  None
Submitted:  Mon 29 Jul 2013 10:32:38 AM UTC
   
 
Category:  Code generation Severity:  3 - Normal
Item Group:  Run-time exception Status:  Wont Fix
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

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
http://www.gnu.org/software/kawa/Options.html#Options-for-compiling-and-optimizing

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)
#t

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>
Group administrator
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)
java.lang.StackOverflowError
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

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-10-07 bothner Open/ClosedOpen Closed
    2013-09-10 bothner StatusNone Wont Fix
        Assigned toNone bothner

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code