aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/TailRec.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2016-04-18 22:11:46 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2016-04-18 22:11:46 +0200
commitd4589a4c337a37fbac29449c3a8fb6a7dad85c66 (patch)
tree6a257607aaa998882e724696b7dcd983c7e1caab /src/dotty/tools/dotc/transform/TailRec.scala
parent8c9a3f7ce5fa7548f9611dc2a14900a5bd42c105 (diff)
downloaddotty-d4589a4c337a37fbac29449c3a8fb6a7dad85c66.tar.gz
dotty-d4589a4c337a37fbac29449c3a8fb6a7dad85c66.tar.bz2
dotty-d4589a4c337a37fbac29449c3a8fb6a7dad85c66.zip
Implement #1221. Allow to specify per-callsite @tailrec annotation.
See examples in following commit.
Diffstat (limited to 'src/dotty/tools/dotc/transform/TailRec.scala')
-rw-r--r--src/dotty/tools/dotc/transform/TailRec.scala7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/transform/TailRec.scala b/src/dotty/tools/dotc/transform/TailRec.scala
index 23686b522..427884e14 100644
--- a/src/dotty/tools/dotc/transform/TailRec.scala
+++ b/src/dotty/tools/dotc/transform/TailRec.scala
@@ -180,7 +180,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
override def transform(tree: Tree)(implicit c: Context): Tree = {
/* A possibly polymorphic apply to be considered for tail call transformation. */
- def rewriteApply(tree: Tree, sym: Symbol): Tree = {
+ def rewriteApply(tree: Tree, sym: Symbol, required: Boolean = false): Tree = {
def receiverArgumentsAndSymbol(t: Tree, accArgs: List[List[Tree]] = Nil, accT: List[Tree] = Nil):
(Tree, Tree, List[List[Tree]], List[Tree], Symbol) = t match {
case TypeApply(fun, targs) if fun.symbol eq t.symbol => receiverArgumentsAndSymbol(fun, accArgs, targs)
@@ -216,7 +216,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
}
}
def fail(reason: String) = {
- if (isMandatory) c.error(s"Cannot rewrite recursive call: $reason", tree.pos)
+ if (isMandatory || required) c.error(s"Cannot rewrite recursive call: $reason", tree.pos)
else c.debuglog("Cannot rewrite recursive call at: " + tree.pos + " because: " + reason)
continue
}
@@ -299,7 +299,8 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
noTailTransforms(stats),
transform(expr)
)
-
+ case tree @ Typed(t: Apply, tpt) if tpt.tpe.hasAnnotation(defn.TailrecAnnot) =>
+ tpd.Typed(rewriteApply(t, t.fun.symbol, required = true), tpt)
case tree@If(cond, thenp, elsep) =>
tpd.cpy.If(tree)(
noTailTransform(cond),