Skip to content

Update to Scala 2.11.0-RC4, adapting to change in quasiquotes #71

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 2 commits into from
Apr 6, 2014
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scalaVersion := "2.11.0-RC3"
scalaVersion := "2.11.0-RC4"

// Uncomment to test with a locally built copy of Scala.
// scalaHome := Some(file("/code/scala2/build/pack"))
Expand Down
18 changes: 2 additions & 16 deletions src/main/scala/scala/async/internal/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private[async] trait AnfTransform {
val stats :+ expr1 = linearize.transformToList(expr)
stats :+ treeCopy.Typed(tree, expr1, tpt)

case q"$fun[..$targs](...$argss)" if argss.nonEmpty =>
case Applied(fun, targs, argss) if argss.nonEmpty =>
// we can assume that no await call appears in a by-name argument position,
// this has already been checked.
val funStats :+ simpleFun = linearize.transformToList(fun)
Expand All @@ -188,21 +188,7 @@ private[async] trait AnfTransform {
}
}


/** The depth of the nested applies: e.g. Apply(Apply(Apply(_, _), _), _)
* has depth 3. Continues through type applications (without counting them.)
*/
def applyDepth: Int = {
def loop(tree: Tree): Int = tree match {
case Apply(fn, _) => 1 + loop(fn)
case TypeApply(fn, _) => loop(fn)
case AppliedTypeTree(fn, _) => loop(fn)
case _ => 0
}
loop(tree)
}

val typedNewApply = copyApplied(tree, applyDepth)
val typedNewApply = copyApplied(tree, argss.length)

funStats ++ argStatss.flatten.flatten :+ typedNewApply

Expand Down
68 changes: 68 additions & 0 deletions src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,74 @@ private[async] trait TransformUtils {
def isAwait(fun: Tree) =
fun.symbol == defn.Async_await

// Copy pasted from TreeInfo in the compiler.
// Using a quasiquote pattern like `case q"$fun[..$targs](...$args)" => is not
// sufficient since https://github.com/scala/scala/pull/3656 as it doesn't match
// constructor invocations.
class Applied(val tree: Tree) {
/** The tree stripped of the possibly nested applications.
* The original tree if it's not an application.
*/
def callee: Tree = {
def loop(tree: Tree): Tree = tree match {
case Apply(fn, _) => loop(fn)
case tree => tree
}
loop(tree)
}

/** The `callee` unwrapped from type applications.
* The original `callee` if it's not a type application.
*/
def core: Tree = callee match {
case TypeApply(fn, _) => fn
case AppliedTypeTree(fn, _) => fn
case tree => tree
}

/** The type arguments of the `callee`.
* `Nil` if the `callee` is not a type application.
*/
def targs: List[Tree] = callee match {
case TypeApply(_, args) => args
case AppliedTypeTree(_, args) => args
case _ => Nil
}

/** (Possibly multiple lists of) value arguments of an application.
* `Nil` if the `callee` is not an application.
*/
def argss: List[List[Tree]] = {
def loop(tree: Tree): List[List[Tree]] = tree match {
case Apply(fn, args) => loop(fn) :+ args
case _ => Nil
}
loop(tree)
}
}

/** Returns a wrapper that knows how to destructure and analyze applications.
*/
def dissectApplied(tree: Tree) = new Applied(tree)

/** Destructures applications into important subparts described in `Applied` class,
* namely into: core, targs and argss (in the specified order).
*
* Trees which are not applications are also accepted. Their callee and core will
* be equal to the input, while targs and argss will be Nil.
*
* The provided extractors don't expose all the API of the `Applied` class.
* For advanced use, call `dissectApplied` explicitly and use its methods instead of pattern matching.
*/
object Applied {
def apply(tree: Tree): Applied = new Applied(tree)

def unapply(applied: Applied): Option[(Tree, List[Tree], List[List[Tree]])] =
Some((applied.core, applied.targs, applied.argss))

def unapply(tree: Tree): Option[(Tree, List[Tree], List[List[Tree]])] =
unapply(dissectApplied(tree))
}
private lazy val Boolean_ShortCircuits: Set[Symbol] = {
import definitions.BooleanClass
def BooleanTermMember(name: String) = BooleanClass.typeSignature.member(newTermName(name).encodedName)
Expand Down