aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/TreeInfo.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-02-14 18:39:14 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:14:08 +0100
commit5b63106448275d6cc4bb6822af33247c2521a63c (patch)
tree4313312569f2ae3f15f8cb1c763bc30c19c1eeea /src/dotty/tools/dotc/ast/TreeInfo.scala
parent9262d475e648219eb9ef4410d91621cc5f1f17cc (diff)
downloaddotty-5b63106448275d6cc4bb6822af33247c2521a63c.tar.gz
dotty-5b63106448275d6cc4bb6822af33247c2521a63c.tar.bz2
dotty-5b63106448275d6cc4bb6822af33247c2521a63c.zip
Make some tree fields lazy
Lazy fields are - the rhs field of a ValDef or DefDef - the body field of a Template These can be instantiated with Lazy instances. The scheme is such that lazy fields are completely transparent for users of the Trees API. The only downside is that the parameter used to initialize a potentially lazy field has a weak type (now it's Any, with Dotty it would be a union type of the form `T | Lazy[T]`. Therefore, the parameter cannot be recovered through pattern matching.
Diffstat (limited to 'src/dotty/tools/dotc/ast/TreeInfo.scala')
-rw-r--r--src/dotty/tools/dotc/ast/TreeInfo.scala11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala
index 3d633c58d..6ebf29ffa 100644
--- a/src/dotty/tools/dotc/ast/TreeInfo.scala
+++ b/src/dotty/tools/dotc/ast/TreeInfo.scala
@@ -28,8 +28,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
*/
def isPureInterfaceMember(tree: Tree): Boolean = unsplice(tree) match {
case EmptyTree | Import(_, _) | TypeDef(_, _) => true
- case DefDef(_, _, _, _, rhs) => rhs.isEmpty
- case ValDef(_, _, rhs) => rhs.isEmpty
+ case defn: ValOrDefDef => defn.rhs.isEmpty
case _ => false
}
@@ -91,7 +90,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
/** If tree is a closure, it's body, otherwise tree itself */
def closureBody(tree: tpd.Tree): tpd.Tree = tree match {
- case Block(DefDef(nme.ANON_FUN, _, _, _, rhs) :: Nil, Closure(_, _, _)) => rhs
+ case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, Closure(_, _, _)) => meth.rhs
case _ => tree
}
@@ -287,8 +286,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
| Import(_, _)
| DefDef(_, _, _, _, _) =>
Pure
- case vdef @ ValDef(_, _, rhs) =>
- if (vdef.mods is Mutable) Impure else exprPurity(rhs)
+ case vdef @ ValDef(_, _, _) =>
+ if (vdef.mods is Mutable) Impure else exprPurity(vdef.rhs)
case _ =>
Impure
}
@@ -478,7 +477,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
if (stats exists (definedSym(_) == sym)) stats else Nil
encl match {
case Block(stats, _) => verify(stats)
- case Template(_, _, _, stats) => verify(stats)
+ case encl: Template => verify(encl.body)
case PackageDef(_, stats) => verify(stats)
case _ => Nil
}