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/transform/TailRec.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/transform/TailRec.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/TailRec.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/transform/TailRec.scala b/src/dotty/tools/dotc/transform/TailRec.scala index b747636c7..2fd0c439c 100644 --- a/src/dotty/tools/dotc/transform/TailRec.scala +++ b/src/dotty/tools/dotc/transform/TailRec.scala @@ -83,8 +83,8 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = { val sym = tree.symbol tree match { - case dd@DefDef(name, tparams, vparamss0, tpt, rhs0) - if (sym.isEffectivelyFinal) && !((sym is Flags.Accessor) || (rhs0 eq EmptyTree) || (sym is Flags.Label)) => + case dd@DefDef(name, tparams, vparamss0, tpt, _) + if (sym.isEffectivelyFinal) && !((sym is Flags.Accessor) || (dd.rhs eq EmptyTree) || (sym is Flags.Label)) => val mandatory = sym.hasAnnotation(defn.TailrecAnnotationClass) atGroupEnd { implicit ctx: Context => @@ -104,7 +104,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete // now this speculatively transforms tree and throws away result in many cases val rhsSemiTransformed = { val transformer = new TailRecElimination(origMeth, owner, thisTpe, mandatory, label, abstractOverClass = defIsTopLevel) - val rhs = atGroupEnd(transformer.transform(rhs0)(_)) + val rhs = atGroupEnd(transformer.transform(dd.rhs)(_)) rewrote = transformer.rewrote rhs } @@ -117,7 +117,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete } else { if (mandatory) ctx.error("TailRec optimisation not applicable, method not tail recursive", dd.pos) - rhs0 + dd.rhs } }) } |