Skip to content

Compiler crash with inline #2980

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

Closed
jpmartin2 opened this issue Aug 15, 2017 · 0 comments
Closed

Compiler crash with inline #2980

jpmartin2 opened this issue Aug 15, 2017 · 0 comments

Comments

@jpmartin2
Copy link

With the following:

trait Foo {
  def apply[~>[_,_]](x: Int ~> Int): Int ~> Int
}

object Foo {
  inline def foo: Foo = new Foo {
    def apply[~>[_,_]](x: Int ~> Int): Int ~> Int = x
  }

  def main(args: Array[String]): Unit = {
    val x = foo((x: Int) => x)
  }
}

I get the dotty compiler to crash with:

error when pickling tree [_$3, _$4] ->  >: Nothing <: Any
error when pickling tree def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
error when pickling tree () extends Object() with Foo { 
  def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
}
error when pickling tree final class $anon() extends Object() with Foo { 
  def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
}
error when pickling tree {
  final class $anon() extends Object() with Foo { 
    def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
  }
  new Object with Foo{...}(): Foo
}
error when pickling tree /* inlined from Foo*/ 
  {
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      new Object with Foo{...}(): Foo
    }
  }
error when pickling tree /* inlined from Foo*/ 
  {
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      (new Object with Foo{...}(): Foo)
    }
  }
.apply
error when pickling tree /* inlined from Foo*/ 
  {
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      (new Object with Foo{...}(): Foo)
    }
  }
.apply[Function1]
error when pickling tree /* inlined from Foo*/ 
  {
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      (new Object with Foo{...}(): Foo)
    }
  }
.apply[Function1](
  {
    def $anonfun(x: Int): Int = x
    closure($anonfun)
  }
)
error when pickling tree val x: Int => Int = 
  /* inlined from Foo*/ 
    {
      {
        final class $anon() extends Object() with Foo { 
          def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
        }
        (new Object with Foo{...}(): Foo)
      }
    }
  .apply[Function1](
    {
      def $anonfun(x: Int): Int = x
      closure($anonfun)
    }
  )
error when pickling tree {
  val x: Int => Int = 
    /* inlined from Foo*/ 
      {
        {
          final class $anon() extends Object() with Foo { 
            def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = 
              x
          }
          (new Object with Foo{...}(): Foo)
        }
      }
    .apply[Function1](
      {
        def $anonfun(x: Int): Int = x
        closure($anonfun)
      }
    )
  ()
}
error when pickling tree def main(args: Array[String]): Unit = 
  {
    val x: Int => Int = 
      /* inlined from Foo*/ 
        {
          {
            final class $anon() extends Object() with Foo { 
              def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int]
                 = 
              x
            }
            (new Object with Foo{...}(): Foo)
          }
        }
      .apply[Function1](
        {
          def $anonfun(x: Int): Int = x
          closure($anonfun)
        }
      )
    ()
  }
error when pickling tree () extends Object() { this: Foo.type => 
  @{
    final class $anon() extends Object() with Foo { 
      def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
    }
    (new Object with Foo{...}(): Foo)
  } inline def foo: Foo = 
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      new Object with Foo{...}(): Foo
    }
  def main(args: Array[String]): Unit = 
    {
      val x: Int => Int = 
        /* inlined from Foo*/ 
          {
            {
              final class $anon() extends Object() with Foo { 
                def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): 
                  ~>[Int, Int]
                 = x
              }
              (new Object with Foo{...}(): Foo)
            }
          }
        .apply[Function1](
          {
            def $anonfun(x: Int): Int = x
            closure($anonfun)
          }
        )
      ()
    }
}
error when pickling tree @scala.annotation.internal.SourceFile("test.scala") final module class Foo()
   extends
 Object() { this: Foo.type => 
  @{
    final class $anon() extends Object() with Foo { 
      def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
    }
    (new Object with Foo{...}(): Foo)
  } inline def foo: Foo = 
    {
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      new Object with Foo{...}(): Foo
    }
  def main(args: Array[String]): Unit = 
    {
      val x: Int => Int = 
        /* inlined from Foo*/ 
          {
            {
              final class $anon() extends Object() with Foo { 
                def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): 
                  ~>[Int, Int]
                 = x
              }
              (new Object with Foo{...}(): Foo)
            }
          }
        .apply[Function1](
          {
            def $anonfun(x: Int): Int = x
            closure($anonfun)
          }
        )
      ()
    }
}
error when pickling tree package <empty> {
  @scala.annotation.internal.SourceFile("test.scala") <trait> interface trait 
    Foo
  () extends Object { 
    def apply[~> <: [_$1, _$2] => Any](x: ~>[Int, Int]): ~>[Int, Int]
  }
  final lazy module val Foo: Foo = new Foo()
  @scala.annotation.internal.SourceFile("test.scala") final module class Foo()
     extends
   Object() { this: Foo.type => 
    @{
      final class $anon() extends Object() with Foo { 
        def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
      }
      (new Object with Foo{...}(): Foo)
    } inline def foo: Foo = 
      {
        final class $anon() extends Object() with Foo { 
          def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): ~>[Int, Int] = x
        }
        new Object with Foo{...}(): Foo
      }
    def main(args: Array[String]): Unit = 
      {
        val x: Int => Int = 
          /* inlined from Foo*/ 
            {
              {
                final class $anon() extends Object() with Foo { 
                  def apply[~> <: [_$3, _$4] => Any](x: ~>[Int, Int]): 
                    ~>[Int, Int]
                   = x
                }
                (new Object with Foo{...}(): Foo)
              }
            }
          .apply[Function1](
            {
              def $anonfun(x: Int): Int = x
              closure($anonfun)
            }
          )
        ()
      }
  }
}

exception occurred while compiling test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: type _$3
	at scala.Predef$.assert(Predef.scala:170)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:284)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParam(TreePickler.scala:304)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParams$$anonfun$2(TreePickler.scala:310)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParams(TreePickler.scala:310)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$33(TreePickler.scala:533)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:533)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:278)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:292)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParam(TreePickler.scala:304)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParams$$anonfun$2(TreePickler.scala:310)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleParams(TreePickler.scala:310)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleAllParams$1(TreePickler.scala:448)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$22(TreePickler.scala:454)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:289)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:454)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:315)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:315)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$24(TreePickler.scala:485)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:486)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:291)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:456)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$8$$anonfun$1(TreePickler.scala:396)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$8(TreePickler.scala:396)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:396)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$17(TreePickler.scala:425)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:425)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:352)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$2(TreePickler.scala:362)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:364)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$1(TreePickler.scala:356)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:358)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTreeUnlessEmpty(TreePickler.scala:281)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:294)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:445)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$8$$anonfun$1(TreePickler.scala:396)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$8(TreePickler.scala:396)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:396)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTreeUnlessEmpty(TreePickler.scala:281)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:294)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:454)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:315)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:315)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$24(TreePickler.scala:485)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:486)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef$$anonfun$2(TreePickler.scala:291)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:296)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:456)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:315)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:315)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$26(TreePickler.scala:501)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.core.tasty.TreePickler.withLength(TreePickler.scala:32)
	at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:501)
	at dotty.tools.dotc.core.tasty.TreePickler.pickle$$anonfun$1(TreePickler.scala:597)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:597)
	at dotty.tools.dotc.transform.Pickler.run$$anonfun$7$$anonfun$1(Pickler.scala:52)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.transform.Pickler.run$$anonfun$7(Pickler.scala:72)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:72)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$2(Phases.scala:283)
	at scala.collection.immutable.List.map(List.scala:284)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:285)
	at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:76)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$1(Run.scala:82)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:90)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:95)
	at dotty.tools.dotc.Run.compileSources(Run.scala:64)
	at dotty.tools.dotc.Run.compile(Run.scala:48)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
	at dotty.tools.dotc.Driver.process(Driver.scala:124)
	at dotty.tools.dotc.Driver.process(Driver.scala:93)
	at dotty.tools.dotc.Driver.process(Driver.scala:105)
	at dotty.tools.dotc.Driver.main(Driver.scala:132)
	at dotty.tools.dotc.Main.main(Main.scala)

Interestingly, removing the use of higher kinded types (and monomorphising ~> into => manually), or turning the inline def into val compiles just fine.

smarter added a commit to dotty-staging/dotty that referenced this issue Aug 15, 2017
When we inline we need to construct new trees with new symbols. This is
handled by TreeTypeMap which was missing a case for LambdaTypeTree (the
parameters of a type lambda are TypeDefs and thus have symbols that need
to be replaced). This caused a crash in pickling since we ended up
trying to pickle the same symbol twice.
smarter added a commit to dotty-staging/dotty that referenced this issue Aug 15, 2017
When we inline we need to construct new trees with new symbols. This is
handled by TreeTypeMap which was missing a case for LambdaTypeTree (the
parameters of a type lambda are TypeDefs and thus have symbols that need
to be replaced). This caused a crash in pickling since we ended up
trying to pickle the same symbol twice.
smarter added a commit that referenced this issue Aug 16, 2017
Fix #2980: Crash when inlining HK type parameters
liufengyun pushed a commit to dotty-staging/dotty that referenced this issue Aug 16, 2017
When we inline we need to construct new trees with new symbols. This is
handled by TreeTypeMap which was missing a case for LambdaTypeTree (the
parameters of a type lambda are TypeDefs and thus have symbols that need
to be replaced). This caused a crash in pickling since we ended up
trying to pickle the same symbol twice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants