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

inline def apply throws unhandled exception #19724

Closed
erikerlandson opened this issue Feb 18, 2024 · 12 comments · Fixed by #19801
Closed

inline def apply throws unhandled exception #19724

erikerlandson opened this issue Feb 18, 2024 · 12 comments · Fixed by #19801
Assignees
Labels
Milestone

Comments

@erikerlandson
Copy link

Compiler version

3.4.0-RC2

Minimized code

object repro:
    abstract class Mapper[A, B] extends (A => B)

    given Mapper[Int, Double] with
        // inlining causes a compiler crash
        inline def apply(v: Int): Double = v.toDouble

Output (click arrow to expand)

  exception while retyping final module class given_Mapper_Int_Double() extends
  coulomb.repro.Mapper[Int, Double]() {
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(
      classOf[coulomb.repro.given_Mapper_Int_Double.type])
  inline def apply(v: Int): Double = this.apply$mcDI$sp(v)
  inline def apply$mcDI$sp(v: Int): Double = v.toDouble:Double
  private def apply$retainedBody(v: Int): Double = v.toDouble:Double
} of class TypeDef # -1

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: /home/eje/git/coulomb/core/src/main/scala/coulomb/quantity.scala
        during phase: MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, etaReduce, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars}
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.4.0-RC2
            settings: -Ykind-projector underscores -bootclasspath /home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.0-RC2/scala3-library_3-3.4.0-RC2.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -classpath /home/eje/git/coulomb/core/.jvm/target/scala-3.4.0-RC2/classes:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/scalac-compat-annotation_3/0.1.4/scalac-compat-annotation_3-0.1.4.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/algebra_3/2.10.0/algebra_3-2.10.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire_3/0.18.0/spire_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_3/2.10.0/cats-kernel_3-2.10.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-macros_3/0.18.0/spire-macros_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-platform_3/0.18.0/spire-platform_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-util_3/0.18.0/spire-util_3-0.18.0.jar -d /home/eje/git/coulomb/core/.jvm/target/scala-3.4.0-RC2/classes -deprecation true -feature true


  Exception while compiling /home/eje/git/coulomb/core/src/main/scala/coulomb/conversion/coefficients.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/conversion/conversion.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/conversion/standard/scala.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/conversion/standard/unit.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/conversion/standard/value.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/define/define.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/deltaquantity.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/infra/meta.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/infra/show.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/infra/typeexpr.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/infra/utils.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/ops/algebra/cats/all.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/ops/algebra/cats/deltaquantity.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/ops/algebra/cats/quantity.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/policy.scala, /home/eje/git/coulomb/core/src/main/scala/coulomb/quantity.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/lampepfl/dotty/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: <no file>
        during phase: parser
                mode: Mode()
     library version: version 2.13.12
    compiler version: version 3.4.0-RC2
            settings: -Ykind-projector underscores -bootclasspath /home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.0-RC2/scala3-library_3-3.4.0-RC2.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -classpath /home/eje/git/coulomb/core/.jvm/target/scala-3.4.0-RC2/classes:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/scalac-compat-annotation_3/0.1.4/scalac-compat-annotation_3-0.1.4.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/algebra_3/2.10.0/algebra_3-2.10.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire_3/0.18.0/spire_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_3/2.10.0/cats-kernel_3-2.10.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-macros_3/0.18.0/spire-macros_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-platform_3/0.18.0/spire-platform_3-0.18.0.jar:/home/eje/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/spire-util_3/0.18.0/spire-util_3-0.18.0.jar -d /home/eje/git/coulomb/core/.jvm/target/scala-3.4.0-RC2/classes -deprecation true -feature true

[error] ## Exception when compiling 16 sources to /home/eje/git/coulomb/core/.jvm/target/scala-3.4.0-RC2/classes
[error] java.util.NoSuchElementException: key not found: method apply$mcDI$sp
[error] scala.collection.immutable.Map$Map1.apply(Map.scala:263)
[error] dotty.tools.dotc.transform.Erasure$Typer.addRetainedInlineBodies$$anonfun$1(Erasure.scala:1019)
[error] scala.collection.immutable.List.mapConserve(List.scala:472)
[error] dotty.tools.dotc.transform.Erasure$Typer.addRetainedInlineBodies(Erasure.scala:1030)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1054)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1047)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3102)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3106)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1058)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1047)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3102)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3106)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1058)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2922)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3148)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3198)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3391)
[error] dotty.tools.dotc.transform.Erasure.run(Erasure.scala:143)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:360)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:357)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:267)
[error] dotty.tools.dotc.Driver.finish(Driver.scala:58)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[error] sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] sbt.Execute.work(Execute.scala:292)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] java.base/java.lang.Thread.run(Thread.java:840)
[error]            
[error] java.util.NoSuchElementException: key not found: method apply$mcDI$sp
[error] 	at scala.collection.immutable.Map$Map1.apply(Map.scala:263)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.addRetainedInlineBodies$$anonfun$1(Erasure.scala:1019)
[error] 	at scala.collection.immutable.List.mapConserve(List.scala:472)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.addRetainedInlineBodies(Erasure.scala:1030)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1054)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1047)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3102)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3106)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1058)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1047)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3102)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3106)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3301)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3347)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1058)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2922)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3148)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3198)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3275)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3279)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3391)
[error] 	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:143)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.immutable.List.foreach(List.scala:333)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:360)
[error] 	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] 	at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:357)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:267)
[error] 	at dotty.tools.dotc.Driver.finish(Driver.scala:58)
[error] 	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error] 	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
[error] 	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] 	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] 	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] 	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] 	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] 	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] 	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] 	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] 	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] 	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
[error] 	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] 	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] 	at sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] 	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] 	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] 	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] 	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] 	at sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] 	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] 	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] 	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] 	at sbt.Execute.work(Execute.scala:292)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] 	at java.base/java.lang.Thread.run(Thread.java:840)
[error] (coreJVM / Compile / compileIncremental) java.util.NoSuchElementException: key not found: method apply$mcDI$sp
[error] Total time: 10 s, completed Feb 18, 2024, 10:19:00 AM
eje@localhost:~/git/coulomb$ 
@erikerlandson erikerlandson added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 18, 2024
@erikerlandson
Copy link
Author

It works if class does not inherit from A => B

object repro:
    // works when Mapper does not extend A=>B
    abstract class Mapper[A, B]:
        def apply(a: A): B

    given Mapper[Int, Double] with
        inline def apply(v: Int): Double = v.toDouble

@nicolasstucki nicolasstucki added area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 19, 2024
@nicolasstucki nicolasstucki self-assigned this Feb 19, 2024
@nicolasstucki
Copy link
Contributor

Minimization

class MyMapper extends (Int => Double):
    inline def apply(v: Int): Double = v.toDouble

@nicolasstucki
Copy link
Contributor

It seems there is a buggy interaction between function specialization and retained inlines.

  exception while retyping 
    class MyMapper() extends Object(), (Int => Double) {
      inline def apply(v: Int): Double = this.apply$mcDI$sp(v)
      inline def apply$mcDI$sp(v: Int): Double = v.toDouble:Double
      private def apply$retainedBody(v: Int): Double = v.toDouble:Double
    }

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 19, 2024

We probably need to generate an apply$mcDI$sp$retainedBody method when specializing functions (SpecializeFunctions).

@nicolasstucki nicolasstucki added the Spree Suitable for a future Spree label Feb 19, 2024
@nicolasstucki
Copy link
Contributor

We also do not need to specialize the inline version of the method.

@mbovel
Copy link
Member

mbovel commented Feb 25, 2024

This issue was picked for the Issue Spree of Februrary 27th, 2024. @nicolasstucki, @EugeneFlesselle, @SethTisue and @nmcb will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@SethTisue
Copy link
Member

We also do not need to specialize the inline version of the method.

As far as we can see, this is as simple as adding an is(Inline) check to the SpecializeFunctions mini phase.

This change isn't actually necessary to fix the bug, as the extra specialized method ends up disappearing during erasure anyway, but I agree it's worth doing while we're messing with this.

@SethTisue
Copy link
Member

SethTisue commented Feb 27, 2024

As for the main change, this will also be in SpecializeFunctions, specifically in transformDefDef.

It's a bit complicated because of the way the $retainedBody dance works, as Nico explained to us. Early in compilation, we have inline def apply and private def apply$retainedBody. Then at erasure (?), the inline def apply goes away and the apply$retainedBody takes it place, with $retainedBody removed from the name.

We are provisionally thinking that to be consistent with the handling of non-specialized inline methods, it seems best to generate apply$mcDI$sp$retainedBody and then let erasure rename it later (and make it public), rather than generate the desired final code directly. (If we sometimes do this weird dance, we should always do it?)

@SethTisue
Copy link
Member

This change isn't actually necessary to fix the bug, as the extra specialized method ends up disappearing during erasure anyway, but I agree it's worth doing while we're messing with this.

Heh, we're already second-guessing this, as it seems that erasure (addRetainedInlineBodies) gets confused if we leave it out.

@SethTisue
Copy link
Member

SethTisue commented Feb 27, 2024

A tricky bit here is that the body of the unspecialized version of apply$retainedBody calls the specialized version. But then when erasure shuffles things around, the method call ends up pointing to something that doesn't exist anymore.

Do we need to back up and rethink?

@SethTisue
Copy link
Member

SethTisue commented Feb 27, 2024

I'm not able to summarize the remaining twists and turns the work took, but Nico's PR will show where this ended up. Besides looking at the code, the other best way to understand how it works is to compile the test case with -Vprint:all, so you can see how the trees look at first, then before erasure, then after erasure.

Scala 3 also specializes tuples, but we don't see any way for this issue to arise there, since tuples are final.

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 28, 2024

It's a bit complicated because of the way the $retainedBody dance works, as Nico explained to us. Early in compilation, we have inline def apply and private def apply$retainedBody. Then at erasure (?), the inline def apply goes away and the apply$retainedBody takes it place, with $retainedBody removed from the name.

I refactored the solution to do all the work in SpecializeFunctions (no change in erasure). This implemention is much simpler and it is probly easier to follow. I left a comment in SpecializeFunctions.transformDefDef (in #19801) to explain how it is handled now.

WojciechMazur pushed a commit that referenced this issue Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants