aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-11-07 15:51:18 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-11-07 15:59:54 +0100
commitec5fcf703df4d6aa3ed53316fbe49989ea3fa1b1 (patch)
tree571cc37a586afe13f22963082f5e0ec34ab7c56a
parent10f3c8db6163ebe3196173c1d87e69c1fb6a3a65 (diff)
downloadscala-async-ec5fcf703df4d6aa3ed53316fbe49989ea3fa1b1.tar.gz
scala-async-ec5fcf703df4d6aa3ed53316fbe49989ea3fa1b1.tar.bz2
scala-async-ec5fcf703df4d6aa3ed53316fbe49989ea3fa1b1.zip
Remove scala.async.StateMachine
The generated code can simply extends Function1 and Function0. This class was a hacky means to get the macro working a long time ago.
-rw-r--r--README.md2
-rw-r--r--src/main/scala/scala/async/StateMachine.scala14
-rw-r--r--src/main/scala/scala/async/internal/AsyncTransform.scala13
3 files changed, 9 insertions, 20 deletions
diff --git a/README.md b/README.md
index 09a40c4..552320f 100644
--- a/README.md
+++ b/README.md
@@ -222,7 +222,7 @@ After async transform:
```scala
{
- class stateMachine$7 extends StateMachine[scala.concurrent.Promise[Int], scala.concurrent.ExecutionContext] {
+ class stateMachine$7 extends ... {
def <init>() = {
super.<init>();
()
diff --git a/src/main/scala/scala/async/StateMachine.scala b/src/main/scala/scala/async/StateMachine.scala
deleted file mode 100644
index cae8312..0000000
--- a/src/main/scala/scala/async/StateMachine.scala
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
- */
-
-package scala.async
-
-/** Internal class used by the `async` macro; should not be manually extended by client code */
-// NOTE: this is not in the `internal` package as we must keep this binary compatible as it extended
-// by the translated code.
-abstract class StateMachine[Result, EC] extends (scala.util.Try[Any] => Unit) with (() => Unit) {
- def result: Result
-
- def execContext: EC
-}
diff --git a/src/main/scala/scala/async/internal/AsyncTransform.scala b/src/main/scala/scala/async/internal/AsyncTransform.scala
index cdae074..d27b4b8 100644
--- a/src/main/scala/scala/async/internal/AsyncTransform.scala
+++ b/src/main/scala/scala/async/internal/AsyncTransform.scala
@@ -29,8 +29,6 @@ trait AsyncTransform {
DefDef(NoMods, name.apply, Nil, applyVParamss, TypeTree(definitions.UnitTpe), Literal(Constant(())))
}
- val stateMachineType = applied("scala.async.StateMachine", List(futureSystemOps.promType[T](uncheckedBoundsResultTag), futureSystemOps.execContextType))
-
// Create `ClassDef` of state machine with empty method bodies for `resume` and `apply`.
val stateMachine: ClassDef = {
val body: List[Tree] = {
@@ -43,10 +41,15 @@ trait AsyncTransform {
// See SI-1247 for the the optimization that avoids creatio
DefDef(NoMods, name.apply, Nil, Nil, TypeTree(definitions.UnitTpe), Apply(Ident(name.resume), Nil))
}
- List(emptyConstructor, stateVar, result, execContextValDef) ++ List(resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef)
+ val extraValDef: ValDef = {
+ // We extend () => Unit so we can pass this class as the by-name argument to `Future.apply`.
+ // See SI-1247 for the the optimization that avoids creatio
+ ValDef(NoMods, newTermName("extra"), TypeTree(definitions.UnitTpe), Literal(Constant(())))
+ }
+ List(emptyConstructor, stateVar, result, execContextValDef) ++ List(resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef, extraValDef)
}
- val template = Template(List(stateMachineType), emptyValDef, body)
+ val template = Template(List(typeOf[(scala.util.Try[Any] => Unit)], typeOf[() => Unit]).map(TypeTree(_)), emptyValDef, body)
val t = ClassDef(NoMods, name.stateMachineT, Nil, template)
callSiteTyper.typedPos(macroPos)(Block(t :: Nil, Literal(Constant(()))))
@@ -93,7 +96,7 @@ trait AsyncTransform {
Block(List[Tree](
stateMachineSpliced,
- ValDef(NoMods, name.stateMachine, stateMachineType, Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
+ ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil), selectStateMachine(name.execContext))
),
futureSystemOps.promiseToFuture(Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)