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

Compiler crash with -Ycc when using capacity passed via intermediate inline function #16095

Closed
rssh opened this issue Sep 24, 2022 · 1 comment · Fixed by #16098
Closed

Compiler crash with -Ycc when using capacity passed via intermediate inline function #16095

rssh opened this issue Sep 24, 2022 · 1 comment · Fixed by #16098

Comments

@rssh
Copy link
Contributor

rssh commented Sep 24, 2022

Compiler version

3.2.1-RC2

-Ycc flag should be enabled.

Minimized code

package x

import scala.annotation.*
import scala.concurrent.*

@capability
class CpsTransform[F[_]] {
     def await[T](ft: F[T]): { this } T = ???
}

inline def cpsAsync[F[_]] =
  Test.InfernAsyncArg
object Test {

  class InfernAsyncArg[F[_]] {
      def apply[A](expr: CpsTransform[F] ?=> A): F[A] = ???
  }

  def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): { cps } Int =
    a + cps.await(b)

  def testExample1Future(): Unit =
     val fr = cpsAsync[Future] {
        val y = asyncPlus(1,Future successful 2)
        y+1
     }
     val r = Await.result(fr)
     assert(r == Success(3))

}

Output (click arrow to expand)

[info] exception occurred while compiling /Users/rssh/tests/dotty/cc-crash1/src/main/scala/cps/CpsTransform.scala
scala.MatchError: TypeApply(Ident(cpsAsync),List(Ident(Future))) (of class dotty.tools.dotc.ast.Trees$TypeApply) while compiling /Users/rssh/tests/dotty/cc-crash1/src/main/scala/cps/CpsTransform.scala
[error] ## Exception when compiling 1 sources to /Users/rssh/tests/dotty/cc-crash1/target/scala-3.2.1-RC2/classes
[error] scala.MatchError: TypeApply(Ident(cpsAsync),List(Ident(Future))) (of class dotty.tools.dotc.ast.Trees$TypeApply)
[error] dotty.tools.dotc.typer.Typer.newExpr$1(Typer.scala:4033)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4061)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3431)
[error] dotty.tools.dotc.typer.Typer.tryApply$1(Typer.scala:3270)
[error] dotty.tools.dotc.typer.Typer.tryInsertApplyOrImplicit$$anonfun$2(Typer.scala:3288)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3194)
[error] dotty.tools.dotc.typer.Typer.tryInsertApplyOrImplicit(Typer.scala:3295)
[error] dotty.tools.dotc.typer.Typer.adaptToArgs$1(Typer.scala:3523)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4076)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3431)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3050)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3170)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:910)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1052)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:327)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:121)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2920)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2983)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3050)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3170)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1619)
[error] dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1609)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1619)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1871)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:249)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1871)
[error] dotty.tool
@rssh rssh added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 24, 2022
@rssh rssh changed the title Compiler crash with -cc when using cpacity passed via inline function Compiler crash with -Ycc when using capacity passed via intermediate inline function Sep 24, 2022
@jchyb jchyb added area:typer cc-experiment Intended to be merged with cc-experiment branch on origin and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 25, 2022
@jchyb
Copy link
Contributor

jchyb commented Sep 25, 2022

Minimised (produces the same MatchError as above when in typer):

package x

import scala.concurrent.*

def cpsAsync[F[_]] =
  Test.InfernAsyncArg

object Test {
  class InfernAsyncArg[F[_]] {
    def apply[A](): F[A] = ???
  }

  def testExample1Future(): Unit =
    val fr = cpsAsync[Future]()
}

Compiler crashes this way even without using the -Ycc option.

@jchyb jchyb removed the cc-experiment Intended to be merged with cc-experiment branch on origin label Sep 25, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 25, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 25, 2022
mpollmeier pushed a commit to mpollmeier/dotty that referenced this issue Oct 16, 2022
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants