Details

      Description

      class CompilerHang {
        trait TC[M[_]]
        trait S[A]
      
        implicit def tc[M[_]](implicit M0: TC[M]): TC[S] = null
        def breakage[F[_] : TC] = 0
        breakage  // type checker doesn't terminate, should report inference failure
      }
      

      This gives SOE with the repeated section:

      	at scala.tools.nsc.Global$$anon$1.inferImplicit(Global.scala:401)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$applyImplicitArgs$1.apply(Typers.scala:120)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$applyImplicitArgs$1.apply(Typers.scala:115)
      	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
      	at scala.collection.immutable.List.foreach(List.scala:77)
      	at scala.tools.nsc.typechecker.Typers$Typer.applyImplicitArgs(Typers.scala:115)
      	at scala.tools.nsc.typechecker.Typers$Typer.adaptToImplicitMethod$1(Typers.scala:747)
      	at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:895)
      	at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:893)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.typedImplicit1(Implicits.scala:524)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.typedImplicit0(Implicits.scala:486)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.scala$tools$nsc$typechecker$Implicits$ImplicitSearch$$typedImplicit(Implicits.scala:398)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch$ImplicitComputation.tryImplicitInfo$1(Implicits.scala:740)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch$ImplicitComputation.rankImplicits(Implicits.scala:743)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch$ImplicitComputation.findBest(Implicits.scala:767)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:825)
      	at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1157)
      	at scala.tools.nsc.typechecker.Implicits$class.inferImplicit(Implicits.scala:67)
      	at scala.tools.nsc.Global$$anon$1.inferImplicit(Global.scala:401)
      

      Similar code without a type constructor as a type parmaeter reports the divergent implicit failure correctly:

      class DivergingImplicitReported {
        trait TC[M]
        trait S
      
        implicit def tc[M](implicit M0: TC[M]): TC[S] = null
        def breakage[F: TC] = 0
        breakage // correct: diverging implicit expansion
      }
      

      It looks like a pathological case, but it's based on some real life implicits from Scalaz. Possibly the underlying problem of: https://scala-ide-portfolio.assembla.com/spaces/scala-ide/tickets/1000674

        Activity

        Hide
        Kris Nuttycombe added a comment -

        This bug is causing ReportGrid major hassles - in one piece of our current development work, we seem to hang the compiler on this bug in probably 25% of our build attempts. We're able to work around it by explicitly annotating every type, but this can be pretty challenging with the complexity of some of our types - in numerous places, the volume of type annotations is several times as large as the code being annotated.

        Show
        Kris Nuttycombe added a comment - This bug is causing ReportGrid major hassles - in one piece of our current development work, we seem to hang the compiler on this bug in probably 25% of our build attempts. We're able to work around it by explicitly annotating every type, but this can be pretty challenging with the complexity of some of our types - in numerous places, the volume of type annotations is several times as large as the code being annotated.
        Hide
        Daniel Spiewak added a comment -

        I can reproduce this bug on the current HEAD (2.10.0.rdev-4148-2012-01-09-g820491e) simply by dropping the snippet into the repl in :paste mode. Interesting sidebar: it no longer hangs in head, but stack overflows.

        Show
        Daniel Spiewak added a comment - I can reproduce this bug on the current HEAD (2.10.0.rdev-4148-2012-01-09-g820491e) simply by dropping the snippet into the repl in :paste mode. Interesting sidebar: it no longer hangs in head, but stack overflows.
        Hide
        Paul Phillips added a comment -

        I fixed it, will check in shortly.

        Show
        Paul Phillips added a comment - I fixed it, will check in shortly.
        Hide
        Paul Phillips added a comment -

        More slippery than I thought. For now I only note what is happening: when searching for the implicit parameter M0, the method tc is seen as eligible, and it recursively keeps trying to satisfy it with itself. The symbols are cloned each time in adapt and so new ones keep showing up. The mechanism which normally prevents this fails to do so when type constructors are used this way.

        Show
        Paul Phillips added a comment - More slippery than I thought. For now I only note what is happening: when searching for the implicit parameter M0, the method tc is seen as eligible, and it recursively keeps trying to satisfy it with itself. The symbols are cloned each time in adapt and so new ones keep showing up. The mechanism which normally prevents this fails to do so when type constructors are used this way.
        Hide
        Jason Zaugg added a comment -

        Here's a two line patch to fix this. I haven't run the full test suite yet, and I'm not totally happy with those two lines, but it at least pinpoints the problem.

        https://github.com/retronym/scala/compare/ticket/5318

        Show
        Jason Zaugg added a comment - Here's a two line patch to fix this. I haven't run the full test suite yet, and I'm not totally happy with those two lines, but it at least pinpoints the problem. https://github.com/retronym/scala/compare/ticket/5318

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Jason Zaugg
          • Votes:
            6 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development