Skip to content

Scala 2.10.1 compatibility #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
scalaVersion := "2.10.0"
scalaVersion := "2.10.1"

organization := "org.typesafe.async"
organization := "org.typesafe.async" // TODO new org name under scala-lang.

name := "scala-async"

Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/scala/async/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
if (renamed(tree.symbol)) {
treeCopy.Select(tree, transform(fun), tree.symbol.name)
} else super.transform(tree)
case tt: TypeTree =>
val tt1 = tt.asInstanceOf[symtab.TypeTree]
val orig = tt1.original
if (orig != null) tt1.setOriginal(transform(orig.asInstanceOf[Tree]).asInstanceOf[symtab.Tree])
super.transform(tt)
case _ => super.transform(tree)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/Async.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ abstract class AsyncBase {
else {
Block(List[Tree](
stateMachine,
ValDef(NoMods, name.stateMachine, stateMachineType, New(Ident(name.stateMachineT), Nil)),
ValDef(NoMods, name.stateMachine, stateMachineType, Apply(Select(New(Ident(name.stateMachineT)), nme.CONSTRUCTOR), Nil)),
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil))
),
futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/AsyncAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private[async] final case class AsyncAnalysis[C <: Context](c: C, asyncBase: Asy
nextChunk()
case vd: ValDef =>
super.traverse(tree)
valDefChunkId += (vd.symbol ->(vd, chunkId))
valDefChunkId += (vd.symbol -> (vd -> chunkId))
val isPatternBinder = vd.name.toString.contains(name.bindSuffix)
if (isAwait(vd.rhs) || isPatternBinder) valDefsToLift += vd
case as: Assign =>
Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/scala/async/ExprBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:

final def body: c.Tree = stats match {
case stat :: Nil => stat
case _ => Block(stats: _*)
case init :+ last => Block(init, last)
}
}

Expand Down Expand Up @@ -94,8 +94,8 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:
c.Expr[scala.util.Try[T]](
TypeApply(Select(Ident(name.tr), newTermName("asInstanceOf")),
List(TypeTree(weakTypeOf[scala.util.Try[T]]))))).tree,
Block(List(tryGetTree, mkStateTree(nextState), mkResumeApply): _*)
)
Block(List(tryGetTree, mkStateTree(nextState)), mkResumeApply)
)

Some(mkHandlerCase(state, List(ifIsFailureTree)))
}
Expand Down Expand Up @@ -146,7 +146,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:
// 1. build changed if-else tree
// 2. insert that tree at the end of the current state
val cond = renameReset(condTree)
def mkBranch(state: Int) = Block(mkStateTree(state), mkResumeApply)
def mkBranch(state: Int) = Block(mkStateTree(state) :: Nil, mkResumeApply)
this += If(cond, mkBranch(thenState), mkBranch(elseState))
new AsyncStateWithoutAwait(stats.toList, state)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:
}

def resultWithLabel(startLabelState: Int): AsyncState = {
this += Block(mkStateTree(startLabelState), mkResumeApply)
this += Block(mkStateTree(startLabelState) :: Nil, mkResumeApply)
new AsyncStateWithoutAwait(stats.toList, state)
}

Expand Down Expand Up @@ -387,7 +387,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:
Assign(Ident(name.state), c.literal(nextState).tree)

private def mkHandlerCase(num: Int, rhs: List[c.Tree]): CaseDef =
mkHandlerCase(num, Block(rhs: _*))
mkHandlerCase(num, Block(rhs, c.literalUnit.tree))

private def mkHandlerCase(num: Int, rhs: c.Tree): CaseDef =
CaseDef(c.literal(num).tree, EmptyTree, rhs)
Expand Down
17 changes: 16 additions & 1 deletion src/main/scala/scala/async/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
val renamer = new Transformer {
override def transform(tree: Tree) = tree match {
case Ident(_) => (renameMap get tree.symbol).fold(tree)(Ident(_))
case tt: TypeTree if tt.original != EmptyTree && tt.original != null =>
// We also have to apply our renaming transform on originals of TypeTrees.
// TODO 2.10.1 Can we find a cleaner way?
val symTab = c.universe.asInstanceOf[reflect.internal.SymbolTable]
val tt1 = tt.asInstanceOf[symTab.TypeTree]
tt1.setOriginal(transform(tt.original).asInstanceOf[symTab.Tree])
super.transform(tree)
case _ => super.transform(tree)
}
}
Expand Down Expand Up @@ -267,18 +274,26 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
private object RestorePatternMatchingFunctions extends Transformer {

import language.existentials
val DefaultCaseName: TermName = "defaultCase$"

override def transform(tree: Tree): Tree = {
val SYNTHETIC = (1 << 21).toLong.asInstanceOf[FlagSet]
def isSynthetic(cd: ClassDef) = cd.mods hasFlag SYNTHETIC

/** Is this pattern node a synthetic catch-all case, added during PartialFuction synthesis before we know
* whether the user provided cases are exhaustive. */
def isSyntheticDefaultCase(cdef: CaseDef) = cdef match {
case CaseDef(Bind(DefaultCaseName, _), EmptyTree, _) => true
case _ => false
}
tree match {
case Block(
(cd@ClassDef(_, _, _, Template(_, _, body))) :: Nil,
Apply(Select(New(a), nme.CONSTRUCTOR), Nil)) if isSynthetic(cd) =>
val restored = (body collectFirst {
case DefDef(_, /*name.apply | */ name.applyOrElse, _, _, _, Match(_, cases)) =>
val transformedCases = super.transformStats(cases, currentOwner).asInstanceOf[List[CaseDef]]
val nonSyntheticCases = cases.takeWhile(cdef => !isSyntheticDefaultCase(cdef))
val transformedCases = super.transformStats(nonSyntheticCases, currentOwner).asInstanceOf[List[CaseDef]]
Match(EmptyTree, transformedCases)
}).getOrElse(c.abort(tree.pos, s"Internal Error: Unable to find original pattern matching cases in: $body"))
restored
Expand Down
17 changes: 10 additions & 7 deletions src/test/scala/scala/async/TreeInterrogation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ object TreeInterrogation extends App {
withDebug {
val cm = reflect.runtime.currentMirror
val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:flatten")
import scala.async.Async._
val tree = tb.parse(
""" import scala.async.AsyncId.{async, await}
""" import scala.async.AsyncId._
| async {
| await(1)
| val neg1 = -1
| val a = await(1)
| val f = { case x => ({case x => neg1 * x}: PartialFunction[Int, Int])(x + a) }: PartialFunction[Int, Int]
| await(f(2))
| val x = 1
| val opt = Some("")
| await(0)
| val o @ Some(y) = opt
|
| {
| val o @ Some(y) = Some(".")
| }
| }
| ()
| """.stripMargin)
println(tree)
val tree1 = tb.typeCheck(tree.duplicate)
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/scala/async/run/nesteddef/NestedDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NestedDef {
def foo(z: Any) = (a.toDouble, bar(x).toDouble, z)
foo(await(2))
}
result mustBe (0d, 44d, 2)
result mustBe ((0d, 44d, 2))
}


Expand All @@ -35,6 +35,6 @@ class NestedDef {
val foo = (z: Any) => (a.toDouble, bar(x).toDouble, z)
foo(await(2))
}
result mustBe (0d, 44d, 2)
result mustBe ((0d, 44d, 2))
}
}