diff options
author | Philipp Haller <hallerp@gmail.com> | 2013-02-26 01:16:40 +0100 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2013-04-12 18:53:28 +0200 |
commit | ffd7b9649cde61553f16c25f64c3072ecfa6c713 (patch) | |
tree | 54f458e8e9061c8537a0972ca827a56cc0ce9548 /src/main/scala/scala/async/Async.scala | |
parent | 1a8b72a0d1ee16ddcff637df57c2b22e2976b853 (diff) | |
download | scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.tar.gz scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.tar.bz2 scala-async-ffd7b9649cde61553f16c25f64c3072ecfa6c713.zip |
Remove CPS dependency from default async implementation
- move all CPS-related code to `continuations` sub package
- fix CPS-based async implementation
- enable testing of CPS-based async implementation
Diffstat (limited to 'src/main/scala/scala/async/Async.scala')
-rw-r--r-- | src/main/scala/scala/async/Async.scala | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala index 8323ac5..5a71ebe 100644 --- a/src/main/scala/scala/async/Async.scala +++ b/src/main/scala/scala/async/Async.scala @@ -6,7 +6,6 @@ package scala.async import scala.language.experimental.macros import scala.reflect.macros.Context -import scala.util.continuations.{cpsParam, reset} object Async extends AsyncBase { @@ -61,9 +60,7 @@ abstract class AsyncBase { @deprecated("`await` must be enclosed in an `async` block", "0.1") def await[T](awaitable: futureSystem.Fut[T]): T = ??? - def awaitFallback[T, U](awaitable: futureSystem.Fut[T], p: futureSystem.Prom[U]): T @cpsParam[U, Unit] = ??? - - def fallbackEnabled = false + protected[async] def fallbackEnabled = false def asyncImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[futureSystem.Fut[T]] = { import c.universe._ @@ -72,7 +69,8 @@ abstract class AsyncBase { val utils = TransformUtils[c.type](c) import utils.{name, defn} - if (!analyzer.reportUnsupportedAwaits(body.tree) || !fallbackEnabled) { + analyzer.reportUnsupportedAwaits(body.tree) + // Transform to A-normal form: // - no await calls in qualifiers or arguments, // - if/match only used in statement position. @@ -162,35 +160,6 @@ abstract class AsyncBase { AsyncUtils.vprintln(s"async state machine transform expands to:\n ${code.tree}") code - } else { - // replace `await` invocations with `awaitFallback` invocations - val awaitReplacer = new Transformer { - override def transform(tree: Tree): Tree = tree match { - case Apply(fun @ TypeApply(_, List(futArgTpt)), args) if fun.symbol == defn.Async_await => - val typeApp = treeCopy.TypeApply(fun, Ident(defn.Async_awaitFallback), List(TypeTree(futArgTpt.tpe), TypeTree(body.tree.tpe))) - treeCopy.Apply(tree, typeApp, args.map(arg => c.resetAllAttrs(arg.duplicate)) :+ Ident(name.result)) - case _ => - super.transform(tree) - } - } - val newBody = awaitReplacer.transform(body.tree) - - val resetBody = reify { - reset { c.Expr(c.resetAllAttrs(newBody.duplicate)).splice } - } - - val futureSystemOps = futureSystem.mkOps(c) - val code = { - val tree = Block(List( - ValDef(NoMods, name.result, TypeTree(futureSystemOps.promType[T]), futureSystemOps.createProm[T].tree), - futureSystemOps.spawn(resetBody.tree) - ), futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](Ident(name.result))).tree) - c.Expr[futureSystem.Fut[T]](tree) - } - - AsyncUtils.vprintln(s"async CPS fallback transform expands to:\n ${code.tree}") - code - } } def logDiagnostics(c: Context)(anfTree: c.Tree, states: Seq[String]) { |