Skip to content

Commit 1a8b72a

Browse files
committed
Merge pull request #7 from retronym/topic/scala-2.10.1
Scala 2.10.1 compatibility
2 parents b87b924 + e0b3225 commit 1a8b72a

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
scalaVersion := "2.10.0"
1+
scalaVersion := "2.10.1"
22

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

55
name := "scala-async"
66

src/main/scala/scala/async/AnfTransform.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
8888
if (renamed(tree.symbol)) {
8989
treeCopy.Select(tree, transform(fun), tree.symbol.name)
9090
} else super.transform(tree)
91+
case tt: TypeTree =>
92+
val tt1 = tt.asInstanceOf[symtab.TypeTree]
93+
val orig = tt1.original
94+
if (orig != null) tt1.setOriginal(transform(orig.asInstanceOf[Tree]).asInstanceOf[symtab.Tree])
95+
super.transform(tt)
9196
case _ => super.transform(tree)
9297
}
9398
}

src/main/scala/scala/async/Async.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ abstract class AsyncBase {
152152
else {
153153
Block(List[Tree](
154154
stateMachine,
155-
ValDef(NoMods, name.stateMachine, stateMachineType, New(Ident(name.stateMachineT), Nil)),
155+
ValDef(NoMods, name.stateMachine, stateMachineType, Apply(Select(New(Ident(name.stateMachineT)), nme.CONSTRUCTOR), Nil)),
156156
futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil))
157157
),
158158
futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree)

src/main/scala/scala/async/AsyncAnalysis.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private[async] final case class AsyncAnalysis[C <: Context](c: C, asyncBase: Asy
159159
nextChunk()
160160
case vd: ValDef =>
161161
super.traverse(tree)
162-
valDefChunkId += (vd.symbol ->(vd, chunkId))
162+
valDefChunkId += (vd.symbol -> (vd -> chunkId))
163163
val isPatternBinder = vd.name.toString.contains(name.bindSuffix)
164164
if (isAwait(vd.rhs) || isPatternBinder) valDefsToLift += vd
165165
case as: Assign =>

src/main/scala/scala/async/ExprBuilder.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private[async] final case class ExprBuilder[C <: Context, FS <: FutureSystem](c:
3333

3434
final def body: c.Tree = stats match {
3535
case stat :: Nil => stat
36-
case _ => Block(stats: _*)
36+
case init :+ last => Block(init, last)
3737
}
3838
}
3939

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

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

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

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

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

392392
private def mkHandlerCase(num: Int, rhs: c.Tree): CaseDef =
393393
CaseDef(c.literal(num).tree, EmptyTree, rhs)

src/main/scala/scala/async/TransformUtils.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
5858
val renamer = new Transformer {
5959
override def transform(tree: Tree) = tree match {
6060
case Ident(_) => (renameMap get tree.symbol).fold(tree)(Ident(_))
61+
case tt: TypeTree if tt.original != EmptyTree && tt.original != null =>
62+
// We also have to apply our renaming transform on originals of TypeTrees.
63+
// TODO 2.10.1 Can we find a cleaner way?
64+
val symTab = c.universe.asInstanceOf[reflect.internal.SymbolTable]
65+
val tt1 = tt.asInstanceOf[symTab.TypeTree]
66+
tt1.setOriginal(transform(tt.original).asInstanceOf[symTab.Tree])
67+
super.transform(tree)
6168
case _ => super.transform(tree)
6269
}
6370
}
@@ -267,18 +274,26 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
267274
private object RestorePatternMatchingFunctions extends Transformer {
268275

269276
import language.existentials
277+
val DefaultCaseName: TermName = "defaultCase$"
270278

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

283+
/** Is this pattern node a synthetic catch-all case, added during PartialFuction synthesis before we know
284+
* whether the user provided cases are exhaustive. */
285+
def isSyntheticDefaultCase(cdef: CaseDef) = cdef match {
286+
case CaseDef(Bind(DefaultCaseName, _), EmptyTree, _) => true
287+
case _ => false
288+
}
275289
tree match {
276290
case Block(
277291
(cd@ClassDef(_, _, _, Template(_, _, body))) :: Nil,
278292
Apply(Select(New(a), nme.CONSTRUCTOR), Nil)) if isSynthetic(cd) =>
279293
val restored = (body collectFirst {
280294
case DefDef(_, /*name.apply | */ name.applyOrElse, _, _, _, Match(_, cases)) =>
281-
val transformedCases = super.transformStats(cases, currentOwner).asInstanceOf[List[CaseDef]]
295+
val nonSyntheticCases = cases.takeWhile(cdef => !isSyntheticDefaultCase(cdef))
296+
val transformedCases = super.transformStats(nonSyntheticCases, currentOwner).asInstanceOf[List[CaseDef]]
282297
Match(EmptyTree, transformedCases)
283298
}).getOrElse(c.abort(tree.pos, s"Internal Error: Unable to find original pattern matching cases in: $body"))
284299
restored

src/test/scala/scala/async/TreeInterrogation.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@ object TreeInterrogation extends App {
6969
withDebug {
7070
val cm = reflect.runtime.currentMirror
7171
val tb = mkToolbox("-cp target/scala-2.10/classes -Xprint:flatten")
72+
import scala.async.Async._
7273
val tree = tb.parse(
73-
""" import scala.async.AsyncId.{async, await}
74+
""" import scala.async.AsyncId._
7475
| async {
75-
| await(1)
76-
| val neg1 = -1
77-
| val a = await(1)
78-
| val f = { case x => ({case x => neg1 * x}: PartialFunction[Int, Int])(x + a) }: PartialFunction[Int, Int]
79-
| await(f(2))
76+
| val x = 1
77+
| val opt = Some("")
78+
| await(0)
79+
| val o @ Some(y) = opt
80+
|
81+
| {
82+
| val o @ Some(y) = Some(".")
83+
| }
8084
| }
81-
| ()
8285
| """.stripMargin)
8386
println(tree)
8487
val tree1 = tb.typeCheck(tree.duplicate)

src/test/scala/scala/async/run/nesteddef/NestedDef.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class NestedDef {
2020
def foo(z: Any) = (a.toDouble, bar(x).toDouble, z)
2121
foo(await(2))
2222
}
23-
result mustBe (0d, 44d, 2)
23+
result mustBe ((0d, 44d, 2))
2424
}
2525

2626

@@ -35,6 +35,6 @@ class NestedDef {
3535
val foo = (z: Any) => (a.toDouble, bar(x).toDouble, z)
3636
foo(await(2))
3737
}
38-
result mustBe (0d, 44d, 2)
38+
result mustBe ((0d, 44d, 2))
3939
}
4040
}

0 commit comments

Comments
 (0)