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

Avoid cyclic references due to experimental check when inlining #16195

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ object Inlines:
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)

CrossVersionChecks.checkExperimentalRef(tree.symbol, tree.srcPos)
if ctx.isAfterTyper then
// During typer we wait with cross version checks until PostTyper, in order
// not to provoke cyclic references. See i16116 for a test case.
CrossVersionChecks.checkExperimentalRef(tree.symbol, tree.srcPos)

if tree.symbol.isConstructor then return tree // error already reported for the inline constructor definition

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
}
case Inlined(call, bindings, expansion) if !call.isEmpty =>
val pos = call.sourcePos
CrossVersionChecks.checkExperimentalRef(call.symbol, pos)
val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(call)))
case templ: Template =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import scala.annotation.experimental
inline def g() = ()

def test: Unit =
g() // errors
g() // error
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.annotation.experimental

@experimental
transparent inline def g() = ()

def test: Unit =
g() // error
()
39 changes: 39 additions & 0 deletions tests/pos-custom-args/captures/i16116.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package x

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

trait CpsMonad[F[_]] {
type Context
}

object CpsMonad {
type Aux[F[_],C] = CpsMonad[F] { type Context = C }
given CpsMonad[Future] with {}
}

@experimental
object Test {

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

transparent inline def cpsAsync[F[_]](using m:CpsMonad[F]) =
new Test.InfernAsyncArg

class InfernAsyncArg[F[_],C](using am:CpsMonad.Aux[F,C]) {
def apply[A](expr: (CpsTransform[F], C) ?=> A): F[A] = ???
}

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

def testExample1Future(): Unit =
val fr = cpsAsync[Future] {
val y = asyncPlus(1,Future successful 2).asInstanceOf[Int]
y+1
}

}