bugKawa - Bugs: bug #32678, set! and endless loop

 
 

bug #32678: set! and endless loop

Submitter:  Helmut Eller <ellerh>
Submitted:  Fri 04 Mar 2011 03:30:19 PM UTC
   
 
Category:  Code generation Severity:  3 - Normal
Item Group:  Compile-time exception Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 08 Mar 2011 05:49:06 PM UTC, comment #4: 

A warning about dead code is OK, but
it seems undesirable to turn this kind of warning
into an error. 


Helmut Eller <ellerh>
Tue 08 Mar 2011 04:56:51 PM UTC, comment #3: 

I don't believe the warning is a false positive.  Note that 'result' is never assigned to.  I can't see how one would intentionally assign the result of a non-terminating loop to a variable, even in a server-like application.  Notice the warning goes away if the set! is replaced by just the do.
Perhaps an improved diagnostic can help:
/tmp/y.scm:5:22: warning - 'result' can never be set because expression never finishes

Per Bothner <bothner>
Group administrator
Tue 08 Mar 2011 11:00:38 AM UTC, comment #2: 

Just want to note that the warning may be a false
positive if non-local exits are used to terminate the loop.
Not uncommon for server-like applications.

(define (foo x)
  (let ((fail 0)
        (result #!null))
    (if (instance? x pair)
        (set! result (do () (#f) (bar x)))
        (set! fail -1))
    (if (= fail 0)
        result
        #f)))

(define (bar x)
  (if (equal? x '(done))
      (primitive-throw (java.lang.Throwable "done."))))


Helmut Eller <ellerh>
Mon 07 Mar 2011 11:35:52 PM UTC, comment #1: 

I checked in some fixes for this.  Basically I added various extra tests for the code being unreachable.  (I tried some variation of the test-case, too.)

The test-case now produces a warning - I considered making it an error - perhaps later.

Per Bothner <bothner>
Group administrator
Fri 04 Mar 2011 03:30:19 PM UTC, original submission:  

Kawa fails to compile this example:

(define (foo x)
  (let ((fail 0)
        (result #!null))
    (if (instance? x pair)
        (set! result (do () (#f)))
        (set! fail -1))
    (if (= fail 0)
        result
        #f)))

kawa --version -C /tmp/x.scm

Kawa 1.11 (revision 0:6912M)
Copyright (C) 2009 Per Bothner
(compiling /tmp/x.scm to x)
/tmp/x.scm:6: internal error while compiling /tmp/x.scm
java.lang.Error: popType called with empty stack x.foo(java.lang.Object)java.lang.Object
        at gnu.bytecode.CodeAttr.popType(CodeAttr.java:442)
        at gnu.bytecode.CodeAttr.emitStore(CodeAttr.java:1372)
        at gnu.expr.SetExp.compile(SetExp.java:276)
        at gnu.expr.Expression.compileNotePosition(Expression.java:156)
        at gnu.expr.Expression.compileWithPosition(Expression.java:127)
        at gnu.expr.IfExp.compile(IfExp.java:118)
        at gnu.expr.IfExp.compile(IfExp.java:52)
        at gnu.expr.Expression.compileNotePosition(Expression.java:156)
        at gnu.expr.Expression.compileWithPosition(Expression.java:127)
        at gnu.expr.BeginExp.compile(BeginExp.java:142)
        at gnu.expr.Expression.compileNotePosition(Expression.java:156)
        at gnu.expr.Expression.compileWithPosition(Expression.java:127)
        at gnu.expr.LetExp.compile(LetExp.java:196)
        at gnu.expr.Expression.compileNotePosition(Expression.java:156)
        at gnu.expr.Expression.compileWithPosition(Expression.java:142)
        at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1619)
        at gnu.expr.LambdaExp.compileAsMethod(LambdaExp.java:1595)
        at gnu.expr.LambdaExp.compileSetField(LambdaExp.java:656)
        at gnu.expr.SetExp.compile(SetExp.java:168)
        at gnu.expr.Expression.compileNotePosition(Expression.java:156)
        at gnu.expr.Expression.compileWithPosition(Expression.java:142)
        at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1619)
        at gnu.expr.Compilation.generateBytecode(Compilation.java:2014)
        at gnu.expr.Compilation.process(Compilation.java:1892)
        at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:305)
        at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:290)
        at kawa.repl.compileFiles(repl.java:783)
        at kawa.repl.processArgs(repl.java:412)
        at kawa.repl.main(repl.java:829)


Helmut Eller <ellerh>

 

(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)
  • -email is unavailable- added by ellerh (Submitted the item)
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-03-07 bothner CategoryNone Code generation
        Item GroupNone Compile-time exception
        StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code