Scala Programming Language
  1. Scala Programming Language
  2. SI-3566

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      reflect, lift

      Description

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

        Issue Links

          Activity

          Hide
          Simon Ochsenreither added a comment - - edited

          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
          
          Show
          Simon Ochsenreither added a comment - - edited 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
          Hide
          Grzegorz Kossakowski added a comment -

          Assigning to Chris who will be looking into liftcode-related bugs.

          Show
          Grzegorz Kossakowski added a comment - Assigning to Chris who will be looking into liftcode-related bugs.
          Hide
          Commit Message Bot added a comment -

          (vogt in r26060) - fixed code lifting of String, Int, ...

          Closes SI-3566. Review by moors.

          Show
          Commit Message Bot added a comment - (vogt in r26060 ) - fixed code lifting of String, Int, ... Closes SI-3566 . Review by moors.
          Hide
          Christopher Vogt added a comment -

          closed wrong issue

          Show
          Christopher Vogt added a comment - closed wrong issue
          Hide
          Christopher Vogt added a comment -

          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.

          Show
          Christopher Vogt added a comment - 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.
          Hide
          Commit Message Bot added a comment -

          (vogt in r26080) test case for SI-3566

          no review

          Show
          Commit Message Bot added a comment - (vogt in r26080 ) test case for SI-3566 no review

            People

            • Assignee:
              Christopher Vogt
              Reporter:
              Joseph Near
              TracCC:
              Johannes Rudolph
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development