diff --git a/build.sbt b/build.sbt index 4e86a317..8aab690d 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ val dottyVersion = "3.3.3" //val dottyVersion = "3.4.2-RC1-bin-SNAPSHOT" -ThisBuild/version := "0.9.21" +ThisBuild/version := "0.9.21-SNAPSHOT" ThisBuild/versionScheme := Some("semver-spec") ThisBuild/resolvers ++= Opts.resolver.sonatypeOssSnapshots diff --git a/compiler-plugin/src/test/scala/cc/Test15PE.scala b/compiler-plugin/src/test/scala/cc/Test15PE.scala index 297b61be..e6f48c79 100644 --- a/compiler-plugin/src/test/scala/cc/Test15PE.scala +++ b/compiler-plugin/src/test/scala/cc/Test15PE.scala @@ -1,7 +1,7 @@ package cc import cc.DotcInvocations.IsAlreadyCompiledFlag -import org.junit.Test +import org.junit.{Ignore, Test} import org.junit.Assert.* import scala.concurrent.* @@ -112,6 +112,16 @@ class Test15PE { ) } + @Test + def testExtDirectRefM9() = { + compileAndRunTestAfterCommon("testdata/set15pe/m9", "cps.pe.TestExtDirectRefM9", + DotcInvocationArgs(checkAll = true, + extraDotcArgs = List( + // "-Vprint:rssh.cps", "-Vprint:erasure" + ) + ) + ) + } } diff --git a/compiler-plugin/testdata/set15pe/common/DirectRef.scala b/compiler-plugin/testdata/set15pe/common/DirectRef.scala index b38c63f2..8b57cf74 100644 --- a/compiler-plugin/testdata/set15pe/common/DirectRef.scala +++ b/compiler-plugin/testdata/set15pe/common/DirectRef.scala @@ -38,6 +38,14 @@ object directRef { await(ref.compareAndSet(except,v)) } + + + extension (self: DirectRef.type) { + + def make[T<:AnyRef](t:T)(using CpsDirect[PureEffect]): DirectRef[T] = + DirectRef[T](await(PERef.make(t))) + + } object DirectIntRef { diff --git a/compiler-plugin/testdata/set15pe/m9/TestExtDirectRefM9.scala b/compiler-plugin/testdata/set15pe/m9/TestExtDirectRefM9.scala new file mode 100644 index 00000000..9368865a --- /dev/null +++ b/compiler-plugin/testdata/set15pe/m9/TestExtDirectRefM9.scala @@ -0,0 +1,44 @@ +package cps.pe + +import org.junit.{Test,Ignore} +import org.junit.Assert.* + +import scala.util.* + + +import scala.annotation.experimental +import scala.concurrent.* +import scala.concurrent.duration.* + +import cps.* +import cps.plugin.annotation.CpsDebugLevel +import scala.concurrent.ExecutionContext.Implicits.global + +@experimental +@CpsDebugLevel(20) +class TestExtDirectRefM9: + + import cps.pe.directRef.* + + + def runExtDirectRef(): PureEffect[String] = { + implicit val printCode = cps.macros.flags.PrintCode + implicit val debugLevel = cps.macros.flags.DebugLevel(20) + async[PureEffect] { + //val logger = PEToyLogger.make() + val vs = PureEffect.directRef("AAAa") + vs.set("0") + //logger.log(vs.get) + vs.get + } + } + + @Test def testExtFirectRefM9(): Unit = + val c = runExtDirectRef() + println(s"PE:extDirectRef, c=${c} ") + val future = c.unsafeRunFuture().map{ vs => + println(s"PE:extDirectRef, vs=${vs} ") + assertTrue(vs=="0") + } + val r = Await.result(future,1.second) + diff --git a/shared/src/main/scala/cps/macros/forest/ApplyTreeTransform.scala b/shared/src/main/scala/cps/macros/forest/ApplyTreeTransform.scala index 60f6a266..c0a78e2f 100644 --- a/shared/src/main/scala/cps/macros/forest/ApplyTreeTransform.scala +++ b/shared/src/main/scala/cps/macros/forest/ApplyTreeTransform.scala @@ -1,6 +1,7 @@ package cps.macros.forest import scala.quoted.* +import scala.util.control.NonFatal import cps.* import cps.macros.* import cps.macros.common.* @@ -185,8 +186,9 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: case Ident(name) => handleArgs1(applyTerm, fun, CpsTree.pure(owner, fun), args, tails)(owner) case _ => - val cpsObj = runRoot(obj)(owner) - handleArgs1(applyTerm, fun, cpsObj, args, tails)(owner) + // + val cpsFun = runRoot(fun)(owner) + handleArgs1(applyTerm, fun, cpsFun, args, tails)(owner) } @@ -314,6 +316,7 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: * *@param applyTerm = Apply(fun, args) - origin apply *@param fun - function to apply (with type-paerameters) + *@param cpsFun - cps-sed of representation of functions *@param args - first argument list *@param tails - next argument lists if any *@param unpure - if true, that this is call from shifted substitution, which is already return F[_] by design. @@ -350,14 +353,12 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: && !fun.symbol.name.contains("$") if (callCpsDirect && !fun.symbol.flags.is(Flags.Inline)) then val funSym = TransformUtil.extractCarriedFunSym(fun) - println(s"funSym=${funSym}") if(!funSym.isDefinedInCurrentRun && !funSym.flags.is(Flags.Inline) && !funSym.hasAnnotation(cpsTransformedSymbol) ) then // situation, when external function is not transformed by cps-async. // note, that we can't determinate for function in the current compilation run, because // we can ba called from transparent inline function which run0s before compiler-plusing phase. - println(s"!11:fun=${fun}, fun.symbol.fullName=${fun.symbol.fullName}, hashCode=${fun.symbol.hashCode} isDefinedInCurrentRun=${fun.symbol.isDefinedInCurrentRun}, flags=${fun.symbol.flags}") throw MacroError(s"Function ${fun.symbol} is cps-=direct function compiled without dotty-cps-async-compiler plugin", applyTerm.asExpr) if cpsCtx.flags.debugLevel >= 15 then cpsCtx.log(s" existsShiftedLambda=${existsShiftedLambda}") @@ -666,7 +667,6 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: ), List(cpsCtx.monadContext.asTerm) ) - println(s"shiftedApplyCps CPS_DEFERRED: retval=${retval.show}") CpsTree.impure(owner, retval, applyTerm.tpe.widen) } @@ -760,7 +760,6 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: PartialShiftedApply(ApplicationShiftType.CPS_AWAIT, delayedShift) def applyCpsDeferredShift(): PartialShiftedApply = - println(s"applyCpsDeferredShift: funTerm=${funTerm.show}") PartialShiftedApply(ApplicationShiftType.CPS_DEFERR_TO_PLUGIN, (unused) => Apply(funTerm, argRecords.map(_.term).toList) // TODO: we can eliminate this if we have origin term ) @@ -1014,7 +1013,13 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: case _ => cpsFun.syncOrigin match case Some(fun) => - val applied = fun.appliedToArgss(argss) + val applied = try { + fun.appliedToArgss(argss) + } catch { + case ex: Throwable => + cpsCtx.log(s"buildApply: fun=${safeShow(fun)}") + throw ex + } if (inShiftedCallChain) shiftedResultCpsTree(applyTerm, applied, argsProperties.cpsDirectArg)(owner) else @@ -1139,8 +1144,6 @@ trait ApplyTreeTransform[F[_],CT, CC<:CpsMonadContext[F]]: case _ => TypeRepr.of[F].appliedTo(tpe.widen) - println(s"shiftedType(${tpe.show}) = ${retval.show}") - retval } diff --git a/shared/src/main/scala/cps/macros/forest/RootTreeTransform.scala b/shared/src/main/scala/cps/macros/forest/RootTreeTransform.scala index de016325..a65d947c 100644 --- a/shared/src/main/scala/cps/macros/forest/RootTreeTransform.scala +++ b/shared/src/main/scala/cps/macros/forest/RootTreeTransform.scala @@ -154,6 +154,20 @@ trait RootTreeTransform[F[_], CT, CC <: CpsMonadContext[F] ]: x.asInstanceOf[nestScope.qctx.reflect.Term], args.asInstanceOf[List[nestScope.qctx.reflect.Term]], Nil)(owner.asInstanceOf[nestScope.qctx.reflect.Symbol]).inCake(thisTransform) + case typeApply@TypeApply(tfun,targs) => + val thisScope = this + val nestContext = cpsCtx.nestSame(muted) + val nestScope = new TreeTransformScope[F,CT,CC] { + override val cpsCtx = nestContext + override implicit val qctx = owner.asQuotes + override val fType = thisScope.fType + override val ctType = thisScope.ctType + override val ccType = thisScope.ccType + } + nestScope.runTypeApply(typeApply.asInstanceOf[nestScope.qctx.reflect.TypeApply], + tfun.asInstanceOf[nestScope.qctx.reflect.Term], + targs.asInstanceOf[List[nestScope.qctx.reflect.TypeTree]] + )(owner.asInstanceOf[nestScope.qctx.reflect.Symbol]).inCake(thisTransform) case _ => throw MacroError(s"cps tree transform is not supported yet to ${term}",cpsCtx.patternCode) }