aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-11-27 08:36:26 +0100
committerJason Zaugg <jzaugg@gmail.com>2012-11-27 09:00:33 +0100
commit7c93a9e0e288b55027646016913c7368732d54e4 (patch)
treea4f4a2b8a6848577bae9f82805ffb61fe9b25e00 /src/main
parent38c362b45fa3f5ae006ebdebaaf163c701313967 (diff)
downloadscala-async-7c93a9e0e288b55027646016913c7368732d54e4.tar.gz
scala-async-7c93a9e0e288b55027646016913c7368732d54e4.tar.bz2
scala-async-7c93a9e0e288b55027646016913c7368732d54e4.zip
No need to extract vals for inlinable args.
We use `isExprSafeToInline` from the non-public reflection API to check. In addtion, we now that an untyped Ident("await$N") is also an inlinable expression.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/scala/async/AnfTransform.scala9
-rw-r--r--src/main/scala/scala/async/TransformUtils.scala9
2 files changed, 14 insertions, 4 deletions
diff --git a/src/main/scala/scala/async/AnfTransform.scala b/src/main/scala/scala/async/AnfTransform.scala
index 6b17b94..2fa96c9 100644
--- a/src/main/scala/scala/async/AnfTransform.scala
+++ b/src/main/scala/scala/async/AnfTransform.scala
@@ -194,13 +194,14 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
// this has already been checked.
val isByName: (Int) => Boolean = utils.isByName(fun)
val funStats :+ simpleFun = inline.transformToList(fun)
+ def isAwaitRef(name: Name) = name.toString.startsWith(utils.name.await + "$")
val argLists: List[List[Tree]] = args.zipWithIndex map {
- case (arg, i) if isByName(i) => List(arg)
- case (arg, i) => inline.transformToList(arg) match {
+ case (arg, i) if isByName(i) || isSafeToInline(arg) => List(arg)
+ case (arg@Ident(name), _) if isAwaitRef(name) => List(arg) // not typed, so it eludes the check in `isSafeToInline`
+ case (arg, i) => inline.transformToList(arg) match {
case stats :+ expr =>
- val valDef = defineVal(s"arg$i", expr, arg.pos)
+ val valDef = defineVal(name.arg(i), expr, arg.pos)
stats ::: List(valDef, Ident(valDef.name))
- case xs => xs
}
}
val allArgStats = argLists flatMap (_.init)
diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala
index 7571f88..23f39d2 100644
--- a/src/main/scala/scala/async/TransformUtils.scala
+++ b/src/main/scala/scala/async/TransformUtils.scala
@@ -30,6 +30,7 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
val ifRes = "ifres"
val await = "await"
val bindSuffix = "$bind"
+ def arg(i: Int) = "arg" + i
def fresh(name: TermName): TermName = newTermName(fresh(name.toString))
@@ -244,4 +245,12 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
}
}
+ def isSafeToInline(tree: Tree) = {
+ val symtab = c.universe.asInstanceOf[scala.reflect.internal.SymbolTable]
+ object treeInfo extends {
+ val global: symtab.type = symtab
+ } with reflect.internal.TreeInfo
+ val castTree = tree.asInstanceOf[symtab.Tree]
+ treeInfo.isExprSafeToInline(castTree)
+ }
}