Re: [scala-user] SO exception on 2.10.1 and 2.10.2 but not in 2.10.0

110 views
Skip to first unread message

Jason Zaugg

unread,
Jun 25, 2013, 9:08:58 AM6/25/13
to Denis Bardadym, scala-i...@googlegroups.com
[moving to scala-internals, please followup just to this group]

It sure looks like a genuine bug: the type checker is checking if some type conforms to an existential type

      case et2: ExistentialType =>
        et2.withTypeVars(isSubType(tp1, _, depth), depth) || fourthTry

This instantiates the existentially quantified members with type variables, calls `isSubType` on the result, and then solves those type variables:

    solve(tvars, quantifiedFresh, quantifiedFresh map (x => 0), false, depth)

The type inference computes a Least Upper Bound (LUB) of the encountered type constraints:

   if (depth != AnyDepth) lub(tvar.constr.loBounds, depth) else lub(tvar.constr.loBounds)

It then checks that the result of the lub indeed is a supertype of all of the bounds:

            // Verify that every given type conforms to the calculated lub.
            // In theory this should not be necessary, but higher-order type
            // parameters are not handled correctly.
            val ok = ts forall { t =>
              isSubType(t, lubRefined, depth) || {

Which leads back to another subtype check against an existential type.

Could you please capture the output with the following debugging options:

% sbt -Dscalac.debug.lub=true -Dscalac.debug.tvar=true
> set every scalacOptions in Compile += "-Ydebug"
> compile

You'll get a lot of output, but the part just before the crash will be telling. Hopefully that will be enough of a clue to a) workaround the problem in your code and b) create a standalone test case so we can fix this.

-jason


On Tue, Jun 25, 2013 at 2:34 PM, Denis Bardadym <bardad...@gmail.com> wrote:
Hello, all.

I have sbt project (sbt 0.12.1, java 1.7.0_25 on macosx) that successfully compiled with 2.9.*. Then we switched to 2.10.0 after some time it was out and it is working and compiled perfectly. Now i have tried to use 2.10.2 (on 2.10.1 the same) to compile it and every time got SO exception while compilation (-Xss8m).
I have tried to reproduce this in smaller project but without luck.

So could you advise how to debug compilation to understand cause?

In attachment sbt log output about SO.

Thank, Denis.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Denis Bardadym

unread,
Jun 25, 2013, 10:37:57 AM6/25/13
to scala-i...@googlegroups.com
Thanks, for answer.

In attachment gzipped log. 

set every scalacOptions in Compile += "-Ydebug" failed due to cyclic reference. i added it to build.sbt to ThisBuild (i hope it will help).

Denis.

вторник, 25 июня 2013 г., 17:08:58 UTC+4 пользователь Jason Zaugg написал:
debug.tgz

Jason Zaugg

unread,
Jun 26, 2013, 5:04:03 AM6/26/13
to scala-i...@googlegroups.com
On Tue, Jun 25, 2013 at 4:37 PM, Denis Bardadym <bardad...@gmail.com> wrote:
Thanks, for answer.

In attachment gzipped log. 

set every scalacOptions in Compile += "-Ydebug" failed due to cyclic reference. i added it to build.sbt to ThisBuild (i hope it will help).

The compiler reports that the crash occurs during the pattern matching translation phase (patmat) in the file ingo/lib/email/msgs.scala.

The log suggests that is trying to find a common supertype of the types Conference and User at the point of the crash. That might happen in code like `List(new Conference, new User)`, or `if (true) new Conference else new User`.

You can avoid the compiler doing this work with `List[Any](new Conference, new User)`; that might give you a workaround once you find the spot.

Could you please take a look through that file and gradually remove code (replace with null or ???) until the crash desists? Then, try to take just the crashy code and reproduce it in a smaller project so we can find and fix the bug.

Thanks, and apologies for the inconvenience,

-jason


Denis Bardadym

unread,
Jun 26, 2013, 6:13:47 AM6/26/13
to scala-i...@googlegroups.com
Yes, compiler says it is patmat in this file, but in this file just several case classes that used as messages to akka actors. That is full content of this file:

mac:WebApp den$ cat common/src/main/scala/ingo/lib/email/msgs.scala 
package ingo.lib.email

import ingo.commons.model.{ NonAdoptedAttendeeMeeting, Conference, User }
import ingo.services.google.GoogleContact

case class SendRankedEmail(user: User, conference: Conference)

case class SendInvitationEmail(user: Long, to: GoogleContact, conf: Conference)

case class SendNonAdoptedMeetingRequestEmail(meeting: NonAdoptedAttendeeMeeting)

case class SendContactsUploadedEmail(user: User, conference: Conference, count: Int, ingoId: String, contacts: List[User])

case class SendUserNewEmailRequestEmail(user: User, email: String)

case class SendNewInterestRequestEmail(user: User, interest: String)

mac:WebApp den$ 

If i remove whole package ingo/lib/email where all usages of this file located in this subproject, then this subproject compiled. But when i return just this file the same error begin appeared:

mac:WebApp den$ sbt common/compile
Detected sbt version 0.12.1
[info] Loading project definition from /Users/den/Projects/InGo/WebApp/project
[info] Set current project to root (in build file:/Users/den/Projects/InGo/WebApp/)
[info] Formatting 6 Scala sources {file:/Users/den/Projects/InGo/WebApp/}common(compile) ...
[info] Compiling 7 Scala sources to /Users/den/Projects/InGo/WebApp/common/target/scala-2.10/classes...
[error] 
[error]      while compiling: /Users/den/Projects/InGo/WebApp/common/src/main/scala/ingo/lib/email/msgs.scala
[error]         during phase: patmat
[error]      library version: version 2.10.2
[error]     compiler version: version 2.10.2
[error]   reconstructed args: -deprecation -feature -d /Users/den/Projects/InGo/WebApp/common/target/scala-2.10/classes -language:postfixOps -language:implicitConversions -language:reflectiveCalls -bootclasspath << CLASSPATH_THERE >> -unchecked
[error] 
[error]   last tree to typer: Throw
[error]               symbol: null
[error]    symbol definition: null
[error]                  tpe: Nothing
[error]        symbol owners: 
[error]       context owners: method productElement -> class SendRankedEmail -> package email
[error] 
[error] == Enclosing template or block ==
[error] 
[error] CaseDef( // tree.tpe=Nothing
[error]   "_" // tree.tpe=Int
[error]   Throw( // tree.tpe=Nothing
[error]     Apply( // def <init>(x$1: String): IndexOutOfBoundsException in class IndexOutOfBoundsException, tree.tpe=IndexOutOfBoundsException
[error]       new IndexOutOfBoundsException."<init>" // def <init>(x$1: String): IndexOutOfBoundsException in class IndexOutOfBoundsException, tree.tpe=(x$1: String)IndexOutOfBoundsException
[error]       Apply( // def toString(): String in class Any, tree.tpe=String
[error]         "x$1"."toString" // def toString(): String in class Any, tree.tpe=()String
[error]         Nil
[error]       )
[error]     )
[error]   )
[error] )
[error] 
[error] == Expanded type of tree ==
[error] 
[error] TypeRef(TypeSymbol(final abstract class Nothing extends Any))
[error] 
[error] uncaught exception during compilation: java.lang.StackOverflowError
java.lang.StackOverflowError
<< STACK_TRACE_THERE >>
[error] (common/compile:compile) java.lang.StackOverflowError
[error] Total time: 35 s, completed 26.06.2013 14:07:05
mac:WebApp den$ rm common/src/main/scala/ingo/lib/email/*.scala
mac:WebApp den$ ls common/src/main/scala/ingo/lib/email/
mac:WebApp den$ sbt common/compile
Detected sbt version 0.12.1
[info] Loading project definition from /Users/den/Projects/InGo/WebApp/project
[info] Set current project to root (in build file:/Users/den/Projects/InGo/WebApp/)
[success] Total time: 1 s, completed 26.06.2013 14:08:06
mac:WebApp den$ git checkout HEAD -- common/src/main/scala/ingo/lib/email/msgs.scala
mac:WebApp den$ ls common/src/main/scala/ingo/lib/email/
msgs.scala
mac:WebApp den$ sbt common/compile
Detected sbt version 0.12.1
[info] Loading project definition from /Users/den/Projects/InGo/WebApp/project
[info] Set current project to root (in build file:/Users/den/Projects/InGo/WebApp/)
[info] Formatting 1 Scala source {file:/Users/den/Projects/InGo/WebApp/}common(compile) ...
[info] Compiling 1 Scala source to /Users/den/Projects/InGo/WebApp/common/target/scala-2.10/classes...
[error] 
[error]      while compiling: /Users/den/Projects/InGo/WebApp/common/src/main/scala/ingo/lib/email/msgs.scala
[error]         during phase: patmat
[error]      library version: version 2.10.2
[error]     compiler version: version 2.10.2
[error]   reconstructed args: -deprecation -feature -d /Users/den/Projects/InGo/WebApp/common/target/scala-2.10/classes -language:postfixOps -language:implicitConversions -language:reflectiveCalls -bootclasspath << CLASSPATH_THERE >> -unchecked
[error] 
[error]   last tree to typer: Throw
[error]               symbol: null
[error]    symbol definition: null
[error]                  tpe: Nothing
[error]        symbol owners: 
[error]       context owners: method productElement -> class SendRankedEmail -> package email
[error] 
[error] == Enclosing template or block ==
[error] 
[error] CaseDef( // tree.tpe=Nothing
[error]   "_" // tree.tpe=Int
[error]   Throw( // tree.tpe=Nothing
[error]     Apply( // def <init>(x$1: String): IndexOutOfBoundsException in class IndexOutOfBoundsException, tree.tpe=IndexOutOfBoundsException
[error]       new IndexOutOfBoundsException."<init>" // def <init>(x$1: String): IndexOutOfBoundsException in class IndexOutOfBoundsException, tree.tpe=(x$1: String)IndexOutOfBoundsException
[error]       Apply( // def toString(): String in class Any, tree.tpe=String
[error]         "x$1"."toString" // def toString(): String in class Any, tree.tpe=()String
[error]         Nil
[error]       )
[error]     )
[error]   )
[error] )
[error] 
[error] == Expanded type of tree ==
[error] 
[error] TypeRef(TypeSymbol(final abstract class Nothing extends Any))
[error] 
[error] uncaught exception during compilation: java.lang.StackOverflowError
java.lang.StackOverflowError
<< STACK_TRACE_THERE >>
[error] (common/compile:compile) java.lang.StackOverflowError
[error] Total time: 33 s, completed 26.06.2013 14:10:03
mac:WebApp den$ 


Sorry, but I am very confused how to localize error in this file?

Thanks, Denis.

26.06.2013, в 13:04, Jason Zaugg <jza...@gmail.com> написал(а):

--
You received this message because you are subscribed to a topic in the Google Groups "scala-internals" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-internals/itLkThK-yOY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-interna...@googlegroups.com.

Jason Zaugg

unread,
Jun 26, 2013, 8:03:56 AM6/26/13
to scala-i...@googlegroups.com
On Wed, Jun 26, 2013 at 12:13 PM, Denis Bardadym <bardad...@gmail.com> wrote:
Yes, compiler says it is patmat in this file, but in this file just several case classes that used as messages to akka actors. That is full content of this file:

Sorry, but I am very confused how to localize error in this file?

We're getting pretty close. The error will be coming from a pattern matches in the synthetic `equals` or `productElement` method.

For example, from `case class C(a: A, b: B)`, the compiler generates:

         override def equals(x$1: Any): Boolean = C.this.eq(x$1.asInstanceOf[java.lang.Object]).||(x$1 match {
              case (a: this.A, b: this.B)this.C((a$1 @ _), (b$1 @ _)) if a$1.==(a).&&(b$1.==(b)) => x$1.asInstanceOf[this.C].canEqual(C.this)
              case _ => false
            }); 

          override def productElement(x$1: Int): Any = x$1 match {
              case 0 => a
              case 1 => b
              case _ => throw new java.lang.IndexOutOfBoundsException(x$1.toString())
            };

From your crash report, stack trace, `productElement` is probably at fault. 

Sidenote: We really needn't lub A and B in that case, I've lodged a bug and fix for that as SI-7611 [1].

You can disable generation of those individually by defining them manually:

  case class C(a: A, b: B) { def productElement(i: Int) = ??? }

In the end, I think you'll be able to reproduce the bug with something like:

  def foo(u: User, c: Conference) = List(u, c, ???)

But then, you'll need to decouple those classes from your project enough to report a reproducible bug.

Thanks for your persistence,

-jason


Denis Bardadym

unread,
Jun 26, 2013, 11:43:14 AM6/26/13
to scala-i...@googlegroups.com
Thanks, Jason.

  case class C(a: A, b: B) { def productElement(i: Int) = ??? }

Yes this help, i will use this for now.

def foo(u: User, c: Conference) = List(u, c, ???)

This also create error while compilation.

Smallest code that i get for now that reproduce:

import net.liftweb.mapper._

class A extends MegaProtoUser[A] {
  def getSingleton = A
}

object A extends A with MetaMegaProtoUser[A]

class B extends LongKeyedMapper[B] with IdPK {
  def getSingleton = B
}

object B extends B with LongKeyedMetaMapper[B]

case class C(a: A, c: B)

But it depends from lift:
libraryDependencies += "net.liftweb"               %% "lift-mapper"                % "2.5"

I will try later to extract it from lift. 

Thanks, Denis.

26.06.2013, в 16:03, Jason Zaugg <jza...@gmail.com> написал(а):

Jason Zaugg

unread,
Jun 26, 2013, 12:44:37 PM6/26/13
to scala-i...@googlegroups.com
On Wed, Jun 26, 2013 at 5:43 PM, Denis Bardadym <bardad...@gmail.com> wrote:
I will try later to extract it from lift. 

Thanks a lot. Let's move the discussion to SI-7612.

That was already enough to find when it regressed: "Keep annotations when computing lubs" [2].

It will still be really helpful if you can construct a test case without an external dependency.

-jason


Jason Zaugg

unread,
Jun 26, 2013, 7:00:44 PM6/26/13
to scala-i...@googlegroups.com
On Wed, Jun 26, 2013 at 6:44 PM, Jason Zaugg <jza...@gmail.com> wrote:
On Wed, Jun 26, 2013 at 5:43 PM, Denis Bardadym <bardad...@gmail.com> wrote:
I will try later to extract it from lift. 

Thanks a lot. Let's move the discussion to SI-7612.

That was already enough to find when it regressed: "Keep annotations when computing lubs" [2].

It will still be really helpful if you can construct a test case without an external dependency.

I managed to extract a test case and have a patch in progress [1].

I've also notified Lift with a workaround [2]

-jason

Denis Bardadym

unread,
Jun 27, 2013, 3:48:34 AM6/27/13
to scala-i...@googlegroups.com
Thank you.

Denis.


2013/6/27 Jason Zaugg <jza...@gmail.com>

--
Reply all
Reply to author
Forward
0 new messages