Skip to content

Commit ec5fcf7

Browse files
committed
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.
1 parent 10f3c8d commit ec5fcf7

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ After async transform:
222222

223223
```scala
224224
{
225-
class stateMachine$7 extends StateMachine[scala.concurrent.Promise[Int], scala.concurrent.ExecutionContext] {
225+
class stateMachine$7 extends ... {
226226
def <init>() = {
227227
super.<init>();
228228
()

src/main/scala/scala/async/StateMachine.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/scala/scala/async/internal/AsyncTransform.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ trait AsyncTransform {
2929
DefDef(NoMods, name.apply, Nil, applyVParamss, TypeTree(definitions.UnitTpe), Literal(Constant(())))
3030
}
3131

32-
val stateMachineType = applied("scala.async.StateMachine", List(futureSystemOps.promType[T](uncheckedBoundsResultTag), futureSystemOps.execContextType))
33-
3432
// Create `ClassDef` of state machine with empty method bodies for `resume` and `apply`.
3533
val stateMachine: ClassDef = {
3634
val body: List[Tree] = {
@@ -43,10 +41,15 @@ trait AsyncTransform {
4341
// See SI-1247 for the the optimization that avoids creatio
4442
DefDef(NoMods, name.apply, Nil, Nil, TypeTree(definitions.UnitTpe), Apply(Ident(name.resume), Nil))
4543
}
46-
List(emptyConstructor, stateVar, result, execContextValDef) ++ List(resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef)
44+
val extraValDef: ValDef = {
45+
// We extend () => Unit so we can pass this class as the by-name argument to `Future.apply`.
46+
// See SI-1247 for the the optimization that avoids creatio
47+
ValDef(NoMods, newTermName("extra"), TypeTree(definitions.UnitTpe), Literal(Constant(())))
48+
}
49+
List(emptyConstructor, stateVar, result, execContextValDef) ++ List(resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef, extraValDef)
4750
}
4851

49-
val template = Template(List(stateMachineType), emptyValDef, body)
52+
val template = Template(List(typeOf[(scala.util.Try[Any] => Unit)], typeOf[() => Unit]).map(TypeTree(_)), emptyValDef, body)
5053

5154
val t = ClassDef(NoMods, name.stateMachineT, Nil, template)
5255
callSiteTyper.typedPos(macroPos)(Block(t :: Nil, Literal(Constant(()))))
@@ -93,7 +96,7 @@ trait AsyncTransform {
9396

9497
Block(List[Tree](
9598
stateMachineSpliced,
96-
ValDef(NoMods, name.stateMachine, stateMachineType, Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
99+
ValDef(NoMods, name.stateMachine, TypeTree(), Apply(Select(New(Ident(stateMachine.symbol)), nme.CONSTRUCTOR), Nil)),
97100
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil), selectStateMachine(name.execContext))
98101
),
99102
futureSystemOps.promiseToFuture(Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)

0 commit comments

Comments
 (0)