From fdfe8f1d067bbc62037708d563b3686cc84fc4a7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 27 Dec 2013 16:27:39 +0100 Subject: Avoiding redundant tuple formations. In a case like val (x, y) = if (...) (a, b) else (c, d) we can pass the tuples directly. Previously, this would have been translated to val (x, y) = (if (...) (a, b) else (c, d): @unchecked) match { case (s, t) => (s, t) } --- src/dotty/tools/dotc/ast/TreeInfo.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/dotty/tools/dotc/ast/TreeInfo.scala') diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala index 29ff492d4..e1715ae26 100644 --- a/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -260,6 +260,16 @@ trait TreeInfo[T >: Untyped] { self: Trees.Instance[T] => case Bind(_, y) => unbind(y) case y => y } + + /** Checks whether predicate `p` is true for all result parts of this epression, + * where we zoom into Ifs, Matches, and Blocks. + */ + def forallResults(tree: Tree, p: Tree => Boolean): Boolean = tree match { + case If(_, thenp, elsep) => forallResults(thenp, p) && forallResults(elsep, p) + case Match(_, cases) => cases forall (c => forallResults(c.body, p)) + case Block(_, expr) => forallResults(expr, p) + case _ => p(tree) + } } trait TypedTreeInfo extends TreeInfo[Type] {self: Trees.Instance[Type] => -- cgit v1.2.3