diff options
author | Martin Odersky <odersky@gmail.com> | 2015-02-14 18:39:14 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:14:08 +0100 |
commit | 5b63106448275d6cc4bb6822af33247c2521a63c (patch) | |
tree | 4313312569f2ae3f15f8cb1c763bc30c19c1eeea /src/dotty/tools/dotc/ast/TreeTypeMap.scala | |
parent | 9262d475e648219eb9ef4410d91621cc5f1f17cc (diff) | |
download | dotty-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/TreeTypeMap.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/TreeTypeMap.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 98027cd39..d2ec3ea10 100644 --- a/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -78,22 +78,22 @@ final class TreeTypeMap( } override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = treeMap(tree) match { - case impl @ Template(constr, parents, self, body) => + case impl @ Template(constr, parents, self, _) => val tmap = withMappedSyms(localSyms(impl :: self :: Nil)) cpy.Template(impl)( constr = tmap.transformSub(constr), parents = parents mapconserve transform, self = tmap.transformSub(self), - body = body mapconserve tmap.transform + body = impl.body mapconserve tmap.transform ).withType(tmap.mapType(impl.tpe)) case tree1 => tree1.withType(mapType(tree1.tpe)) match { case id: Ident if tpd.needsSelect(id.tpe) => ref(id.tpe.asInstanceOf[TermRef]).withPos(id.pos) - case ddef @ DefDef(name, tparams, vparamss, tpt, rhs) => + case ddef @ DefDef(name, tparams, vparamss, tpt, _) => val (tmap1, tparams1) = transformDefs(ddef.tparams) val (tmap2, vparamss1) = tmap1.transformVParamss(vparamss) - cpy.DefDef(ddef)(name, tparams1, vparamss1, tmap2.transform(tpt), tmap2.transform(rhs)) + cpy.DefDef(ddef)(name, tparams1, vparamss1, tmap2.transform(tpt), tmap2.transform(ddef.rhs)) case blk @ Block(stats, expr) => val (tmap1, stats1) = transformDefs(stats) val expr1 = tmap1.transform(expr) |