diff --git a/compiler-plugin/src/main/scala/cps/plugin/CpsTopLevelContext.scala b/compiler-plugin/src/main/scala/cps/plugin/CpsTopLevelContext.scala index 786db9d0..2c639744 100644 --- a/compiler-plugin/src/main/scala/cps/plugin/CpsTopLevelContext.scala +++ b/compiler-plugin/src/main/scala/cps/plugin/CpsTopLevelContext.scala @@ -6,9 +6,7 @@ import core.Types.* import core.Contexts.* import core.Decorators.* import ast.tpd.* -import cps.plugin.observatory.* -case class CpsAutomaticColoring(memoization: Tree, analyzer: AutomaticColoringAnalyzer) case class CpsTopLevelContext( val monadType: Type, // F[_] diff --git a/compiler-plugin/src/main/scala/cps/plugin/PhaseCps.scala b/compiler-plugin/src/main/scala/cps/plugin/PhaseCps.scala index 26fabe1c..1de01fa5 100644 --- a/compiler-plugin/src/main/scala/cps/plugin/PhaseCps.scala +++ b/compiler-plugin/src/main/scala/cps/plugin/PhaseCps.scala @@ -13,7 +13,6 @@ import cps.plugin.DefDefSelectKind.{RETURN_CONTEXT_FUN, USING_CONTEXT_PARAM} import plugins.* import cps.plugin.QuoteLikeAPI.* import cps.plugin.forest.* -import cps.plugin.observatory.AutomaticColoringAnalyzer import dotty.tools.dotc.ast.{Trees, tpd} import dotty.tools.dotc.core.DenotTransformers.{InfoTransformer, SymTransformer} import dotty.tools.dotc.util.SrcPos diff --git a/compiler-plugin/src/main/scala/cps/plugin/forest/ApplyTransform.scala b/compiler-plugin/src/main/scala/cps/plugin/forest/ApplyTransform.scala index fac3aa02..e0daf2a8 100644 --- a/compiler-plugin/src/main/scala/cps/plugin/forest/ApplyTransform.scala +++ b/compiler-plugin/src/main/scala/cps/plugin/forest/ApplyTransform.scala @@ -82,8 +82,6 @@ object ApplyTransform { else Log.trace(s"cpsAwait not recognized",nesting) applyMArgs(term, owner, nesting, Nil) - case observatory.ImplicitAwaitCall(arg, tf, ta, tg, gContext, conversion) => - AwaitTransform.fromApply(term, owner, nesting, tf, ta, tg, arg, gContext, conversion) case Apply(TypeApply(adoptCpsedCallCn,List(tf,ta)),List(a)) if (adoptCpsedCallCn.symbol == Symbols.requiredMethod("cps.plugin.scaffolding.adoptCpsedCall")) => // this means that we walk over nesting async. diff --git a/compiler-plugin/src/main/scala/cps/plugin/observatory/AutomaticColoringAnalyzer.scala b/compiler-plugin/src/main/scala/cps/plugin/observatory/AutomaticColoringAnalyzer.scala deleted file mode 100644 index c3dacdf4..00000000 --- a/compiler-plugin/src/main/scala/cps/plugin/observatory/AutomaticColoringAnalyzer.scala +++ /dev/null @@ -1,113 +0,0 @@ -package cps.plugin.observatory - -import scala.collection.mutable.ArrayBuffer -import scala.collection.mutable.Stack -import dotty.tools.dotc.ast.tpd.* -import dotty.tools.dotc.* -import dotty.tools.dotc.core.* -import dotty.tools.dotc.core.Contexts.* -import dotty.tools.dotc.core.Decorators.* -import dotty.tools.dotc.core.Types.* -import dotty.tools.dotc.core.Symbols.* -import dotty.tools.dotc.util.SrcPos - - -class ValUsage( - var optValDef: Option[ValDef] = None, - val inAwaits: ArrayBuffer[Tree] = ArrayBuffer(), - val withoutAwaits: ArrayBuffer[Tree] = ArrayBuffer(), - val aliases: ArrayBuffer[ValUsage] = ArrayBuffer() - ) { - - def nInAwaits: Int = inAwaits.length + aliases.map(_.nInAwaits).sum - - def nWithoutAwaits: Int = withoutAwaits.length + aliases.map(_.nWithoutAwaits).sum - - def allInAwaits: Seq[Tree] = - (Seq.empty ++ inAwaits.toSeq ++ aliases.toSeq.flatMap(_.allInAwaits)) - - def allWithoutAwaits: Seq[Tree] = - (Seq.empty ++ withoutAwaits.toSeq ++ aliases.toSeq.flatMap(_.allWithoutAwaits)) - - def definedInside: Boolean = !optValDef.isEmpty - - def reportCases()(using Context): Unit = - val firstWithout = allWithoutAwaits.headOption - val firstWith = allInAwaits.headOption - for (t <- firstWithout) { - report.inform("async usage", t.srcPos) - } - for (t <- firstWith) { - report.inform("usage with await", t.srcPos) - } - -} - - -// TODO: deprecated after CpsDirect context will be grown up from an experiment -class AutomaticColoringAnalyzer { - - val usageRecords = new MutableSymbolMap[ValUsage]() - - - def observe(tree: Tree)(using context: Context): Unit = { - - val traverser = new TreeTraverser { - - override def traverse(tree: Tree)(using ctx: Context): Unit = { - tree match { - case tree: ValDef => - if (tree.symbol.is(Flags.Mutable)) { - report.error("Mutable var is not supported in the block with automatic coloring", tree.srcPos) - } - val usage = usageRecords.getOrElseUpdate(tree.symbol, ValUsage()) - usage.optValDef = Some(tree) - tree.rhs match - case id: Ident => - val usageRecord = usageRecords.getOrElseUpdate(id.symbol, ValUsage()) - usageRecord.aliases += usage - case _ => - traverse(tree.rhs)(using ctx.withOwner(tree.symbol)) - case term@Apply(fun, args) => - // to have the same structure as forest/ApplyTransform for the same patterns - checkApply(term, fun, args) - case id: Ident => - val usageRecord = usageRecords.getOrElseUpdate(id.symbol, ValUsage()) - usageRecord.withoutAwaits += id - case _ => - super.traverseChildren(tree) - } - } - - def checkApply(tree: Apply, fun: Tree, args: List[Tree])(using ctx: Context): Unit = { - tree match - case ImplicitAwaitCall(arg, tg, ta, tf, gc, gcn) => - arg match - case id: Ident => - val usageRecord = usageRecords.getOrElseUpdate(id.symbol, ValUsage()) - usageRecord.inAwaits += id - case _ => - super.traverseChildren(tree) - case Apply(Apply(TypeApply(cnAwait, targs), List(arg)), List(monad, conversion)) - if cnAwait.symbol == Symbols.requiredMethod("cps.await") => - arg match - case id: Ident => - val usageRecord = usageRecords.getOrElseUpdate(id.symbol, ValUsage()) - usageRecord.inAwaits += id - case _ => - super.traverseChildren(tree) - case _ => - super.traverseChildren(tree) - } - - - } - traverser.traverse(tree) - - - } - - - - -} \ No newline at end of file diff --git a/compiler-plugin/src/main/scala/cps/plugin/observatory/ImplicitAwaitCall.scala b/compiler-plugin/src/main/scala/cps/plugin/observatory/ImplicitAwaitCall.scala deleted file mode 100644 index f0e946dd..00000000 --- a/compiler-plugin/src/main/scala/cps/plugin/observatory/ImplicitAwaitCall.scala +++ /dev/null @@ -1,43 +0,0 @@ -package cps.plugin.observatory - -import dotty.tools.dotc.ast.tpd.* -import dotty.tools.dotc.* -import dotty.tools.dotc.core.* -import dotty.tools.dotc.core.Contexts.* -import dotty.tools.dotc.core.Symbols.* -import dotty.tools.dotc.core.Types.* - -import dotty.tools.dotc.core.Decorators.* - - - -object ImplicitAwaitCall { - def unapply(tree: Tree)(using ctx: Context): Option[(Tree,Tree,Tree,Tree,Tree,Tree)] = - val retval = tree match - case Apply(sel: Select, List(arg)) if (sel.name.toSimpleName.toString == "apply") => - sel.qualifier match - case ImplicitAwaitLambda(tf,ta,tg,gc,conversion) => Some((arg,tf,ta,tg,gc,conversion)) - case _ => None - case _ => None - retval -} - -object ImplicitAwaitLambda { - - def unapply(tree: Tree)(using Context): Option[(Tree,Tree,Tree,Tree,Tree)] = { - val retval = tree match - case Inlined(call, bindings, ImplicitAwaitLambda(body)) => - Some(body) - case Block(List(), ImplicitAwaitLambda(body)) => - Some(body) - case Block((ddef: DefDef) :: Nil, closure: Closure) if ddef.symbol == closure.meth.symbol => - ddef.rhs match - case Apply(Apply(TypeApply(cnAwait, List(tf,ta,tg)), List(arg)), List(gc, conversion)) - if cnAwait.symbol == Symbols.requiredMethod("cps.await") => Some((tf,ta,tg,gc,conversion)) - case _ => None - case _ => None - retval - } - -} -