jimmc / nioserver

Scala multi-client stateful server using Java NIO and Scala continuations
GNU Lesser General Public License v2.1
19 stars 0 forks source link

compilation error with scalac 2.9.0 #1

Open thosmos opened 13 years ago

thosmos commented 13 years ago

Hey Jim,

Thanks for your excellent work on a continuations server! I'm learning some scala by playing with it. :)

One problem I just had when I tried compiling it with the new 2.9.0 scala is the following. I didn't get this error with 2.8.1:

thosmac:scala thomas$ scalac -P:continuations:enable .scala net/jimmc//*.scala net/jimmc/nio/LineDecoder.scala:30: error: could not optimize @tailrec annotated method processChars: it contains a recursive call not in tail position processChars(cb, lineHandler) //handle multiple lines ^ one error found

Any ideas?

jimmc commented 13 years ago

thos37,

Sometimes tailrec and continuations don't mix very well. The CPS transformation can turn loops into recursion and recursion into loops. It may be that the 2.9 compiler is smarter about this so complains when it did not complain in 2.8.

I don't currently have the time to look into this in detail right now. You should be able to get around the tailrec problem by dropping that annotation, then see if it runs without a stack overflow. I will look into it next week.

Jim

On Fri, May 13, 2011 at 07:29:50AM -0700, thos37 wrote:

Date: Fri, 13 May 2011 07:29:50 -0700 From: thos37 reply@reply.github.com To: github@j.jimmc.org Subject: [nioserver] compilation error with scalac 2.9.0 (#1)

Hey Jim,

Thanks for your excellent work on a continuations server! I'm learning some scala by playing with it. :)

One problem I just had when I tried compiling it with the new 2.9.0 scala is the following. I didn't get this error with 2.8.1:

thosmac:scala thomas$ scalac -P:continuations:enable .scala net/jimmc//*.scala net/jimmc/nio/LineDecoder.scala:30: error: could not optimize @tailrec annotated method processChars: it contains a recursive call not in tail position processChars(cb, lineHandler) //handle multiple lines ^ one error found

Any ideas?

jimmc commented 13 years ago

thos37,

It took me longer to get to it than expected, but I looked at the code and ended up simply removing the @tailrec annotation, as I had suggested below. The fact that the code is CPS means the recursion should effectively be turned into a loop that does not consume stack space. It ran my simple test, which is all I plan on doing for it. The code now compiles under 2.9.0, and I have uploaded the fix to github.

Jim

On Mon, May 16, 2011 at 11:32:15PM -0700, Jim McBeath wrote:

Date: Mon, 16 May 2011 23:32:15 -0700 From: Jim McBeath github@j.jimmc.org To: thos37 reply@reply.github.com Subject: Re: [nioserver] compilation error with scalac 2.9.0 (#1)

thos37,

Sometimes tailrec and continuations don't mix very well. The CPS transformation can turn loops into recursion and recursion into loops. It may be that the 2.9 compiler is smarter about this so complains when it did not complain in 2.8.

I don't currently have the time to look into this in detail right now. You should be able to get around the tailrec problem by dropping that annotation, then see if it runs without a stack overflow. I will look into it next week.

Jim

On Fri, May 13, 2011 at 07:29:50AM -0700, thos37 wrote:

Date: Fri, 13 May 2011 07:29:50 -0700 From: thos37 reply@reply.github.com To: github@j.jimmc.org Subject: [nioserver] compilation error with scalac 2.9.0 (#1)

Hey Jim,

Thanks for your excellent work on a continuations server! I'm learning some scala by playing with it. :)

One problem I just had when I tried compiling it with the new 2.9.0 scala is the following. I didn't get this error with 2.8.1:

thosmac:scala thomas$ scalac -P:continuations:enable .scala net/jimmc//*.scala net/jimmc/nio/LineDecoder.scala:30: error: could not optimize @tailrec annotated method processChars: it contains a recursive call not in tail position processChars(cb, lineHandler) //handle multiple lines ^ one error found

Any ideas?