Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala.reflect.Code.lift on polymorphic functions causes infinite recursion #3566

Closed
scabug opened this issue Jun 14, 2010 · 7 comments
Closed

scala.reflect.Code.lift on polymorphic functions causes infinite recursion #3566

scabug opened this issue Jun 14, 2010 · 7 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jun 14, 2010

Using Scala version 2.8.0.r22204-b20100614112503 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20), compiling the following program causes an infinite recursion:

object Append extends Application {

  def append[A](l1: List[A], l2: List[A]):List[A] =
    l1 match {
      case Nil => l2
      case x::xs => x :: append(xs, l2)
    }

  println(scala.reflect.Code.lift(append _).tree)
}

It appears that the recursion occurs during reification of the List[A] type. The stack trace is as follows:

Exception in thread "main" java.lang.StackOverflowError
	at scala.tools.nsc.symtab.Symbols$$ClassSymbol.name(Symbols.scala:1923)
	at scala.reflect.generic.Symbols$$AbsSymbol.isEmptyPackageClass(Symbols.scala:162)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:25)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:56)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:63)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$$$anonfun$$3.apply(Reifiers.scala:86)
	at scala.tools.nsc.transform.Reifiers$$$$anonfun$$3.apply(Reifiers.scala:84)
	at scala.collection.TraversableLike$$$$anonfun$$map$$1.apply(TraversableLike.scala:206)
	at scala.collection.TraversableLike$$$$anonfun$$map$$1.apply(TraversableLike.scala:206)
	at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:61)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.collection.TraversableLike$$class.map(TraversableLike.scala:206)
	at scala.collection.immutable.List.map(List.scala:45)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:84)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$class.mkGlobalSymbol(Reifiers.scala:19)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:37)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$class.reify(Reifiers.scala:31)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:22)
	at scala.tools.nsc.transform.Reifiers$$$$anonfun$$reify$$2.apply(Reifiers.scala:89)
	at scala.tools.nsc.transform.Reifiers$$$$anonfun$$reify$$2.apply(Reifiers.scala:89)
	at scala.collection.TraversableLike$$$$anonfun$$map$$1.apply(TraversableLike.scala:206)
	at scala.collection.TraversableLike$$$$anonfun$$map$$1.apply(TraversableLike.scala:206)
	at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:61)
...
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 14, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3566?orig=1
Reporter: Joseph Near (jnear)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 5, 2011

@soc said (edited on Aug 5, 2011 11:31:59 PM UTC):
I'm not sure if it is exactly the same, but I can get the crash in Scala version 2.10.0.r25323-b20110719020429 with much simpler code:

import scala.reflect.Code
def codeOf[A](code: Code[A]) = code
codeOf((x: Iterator[A]) => x.sum)

results in a StackOverflowError:

scala> codeOf((x: Iterable[Int]) => x.head)
java.lang.StackOverflowError
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:57)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:64)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$$anonfun$3.apply(Reifiers.scala:89)
	at scala.tools.nsc.transform.Reifiers$$anonfun$3.apply(Reifiers.scala:87)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:197)
	at scala.collection.immutable.List.map(List.scala:45)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:87)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.mkGlobalSymbol(Reifiers.scala:20)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:38)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:32)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$$anonfun$reify$2.apply(Reifiers.scala:92)
	at scala.tools.nsc.transform.Reifiers$$anonfun$reify$2.apply(Reifiers.scala:92)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:197)
	at scala.collection.immutable.List.map(List.scala:45)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:92)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.mkGlobalSymbol(Reifiers.scala:20)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:38)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$class.reify(Reifiers.scala:32)
	at scala.tools.nsc.transform.LiftCode.reify(LiftCode.scala:21)
	at scala.tools.nsc.transform.Reifiers$$anonfun$reify$2.apply(Reifiers.scala:92)
	at scala.tools.nsc.transform.Reifiers$$anonfun$reify$2.apply(Reifiers.scala:92)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:197)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:197)
	at scala.collection.immutable.List.map(List.scala:45)
        ...

Replacing the type with an existential does not reify it, but prevents the crash.

scala> codeOf((x: Iterable[_]) => null)
could not reify: Iterable[_]
res14: scala.reflect.Code[Iterable[_] => Null] = scala.reflect.Code@3c21251c
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 10, 2011

@gkossakowski said:
Assigning to Chris who will be looking into liftcode-related bugs.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 23, 2011

Commit Message Bot (anonymous) said:
(vogt in r26060) - fixed code lifting of String, Int, ...

Closes #3566. Review by moors.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 23, 2011

@cvogt said:
closed wrong issue

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 28, 2011

@cvogt said:
I can reproduce this in Scala 2.9.

In 2.10 trunk it does not happen anymore. Seems to have been fixed in the reflection overhaul.

@scabug scabug closed this Nov 28, 2011
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Nov 28, 2011

Commit Message Bot (anonymous) said:
(vogt in r26080) test case for #3566

no review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.