From ec5fcf703df4d6aa3ed53316fbe49989ea3fa1b1 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 7 Nov 2013 15:51:18 +0100 Subject: 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. --- README.md | 2 +- src/main/scala/scala/async/StateMachine.scala | 14 -------------- src/main/scala/scala/async/internal/AsyncTransform.scala | 13 ++++++++----- 3 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 src/main/scala/scala/async/StateMachine.scala 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 () = { super.(); () 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. - */ - -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) -- cgit v1.2.3