diff options
7 files changed, 36 insertions, 41 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index 62865a7643..0df9bbed57 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -32,7 +32,7 @@ trait TreePrinters { trees: SymbolTable => def backquotedPath(t: Tree): String = t match { case Select(qual, name) => "%s.%s".format(backquotedPath(qual), quotedName(name)) case Ident(name) => quotedName(name) - case t => t.toString + case _ => t.toString } class TreePrinter(out: PrintWriter) extends trees.AbsTreePrinter(out) { diff --git a/src/compiler/scala/tools/nsc/interpreter/package.scala b/src/compiler/scala/tools/nsc/interpreter/package.scala index d732719d62..88e54abcde 100644 --- a/src/compiler/scala/tools/nsc/interpreter/package.scala +++ b/src/compiler/scala/tools/nsc/interpreter/package.scala @@ -14,7 +14,12 @@ package object interpreter { def repldbg(msg: String) = if (isReplDebug) Console println msg /** Tracing */ - def tracing[T](msg: String)(x: T): T = { println("(" + msg + ") " + x) ; x } + def tracing[T](msg: String)(x: T): T = { + if (isReplDebug) + println("(" + msg + ") " + x) + + x + } /** Frequency counter */ def freq[T](seq: Seq[T]) = seq groupBy identity mapValues (_.length) diff --git a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala index 7cd8a27d3e..1008688bde 100644 --- a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala +++ b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala @@ -9,6 +9,7 @@ package matching import transform.ExplicitOuter import ast.{ TreePrinters, Trees } import java.io.{ StringWriter, PrintWriter } +import annotation.elidable /** Ancillary bits of ParallelMatching which are better off * out of the way. @@ -97,34 +98,24 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching => }) } - def ifDebug(body: => Unit): Unit = { if (settings.debug.value) body } - def DBG(msg: => String): Unit = { ifDebug(println(msg)) } - - // @elidable(elidable.FINE) - def TRACE(f: String, xs: Any*): Unit = { + @elidable(elidable.FINE) def ifDebug(body: => Unit): Unit = { if (settings.debug.value) body } + @elidable(elidable.FINE) def DBG(msg: => String): Unit = { ifDebug(println(msg)) } + @elidable(elidable.FINE) def TRACE(f: String, xs: Any*): Unit = { if (trace) { val msg = if (xs.isEmpty) f else f.format(xs map pp: _*) println(msg) } } - - def tracing2[T](x: T)(category: String, xs: String*) = { - val preamble = "[" + """%10s""".format(category) + "] " - if (xs.isEmpty) TRACE(preamble, x) - else TRACE(preamble + xs.head, xs.tail: _*) - - x + @elidable(elidable.FINE) def traceCategory(cat: String, f: String, xs: Any*) = { + if (trace) + TRACE("[" + """%10s""".format(cat) + "] " + f, xs: _*) } + def tracing[T](s: String)(x: T): T = { + if (trace) + println(("[" + """%10s""".format(s) + "] %s") format pp(x)) - def tracing[T](s: String, x: T): T = { - val format = "[" + """%10s""".format(s) + "] %s" - TRACE(format, x) x } - def traceCategory(cat: String, f: String, xs: Any*) = { - val format = "[" + """%10s""".format(cat) + "] " + f - TRACE(format, xs: _*) - } def indent(s: Any) = s.toString() split "\n" map (" " + _) mkString "\n" def indentAll(s: Seq[Any]) = s map (" " + _.toString() + "\n") mkString diff --git a/src/compiler/scala/tools/nsc/matching/Matrix.scala b/src/compiler/scala/tools/nsc/matching/Matrix.scala index 95b87060f4..60daf749e0 100644 --- a/src/compiler/scala/tools/nsc/matching/Matrix.scala +++ b/src/compiler/scala/tools/nsc/matching/Matrix.scala @@ -88,7 +88,7 @@ trait Matrix extends MatrixAdditions { context: MatrixContext): Tree = { import context._ - log("handlePattern: selector.tpe = " + selector.tpe) + // log("handlePattern: selector.tpe = " + selector.tpe) // sets up top level match val matrixInit: MatrixInit = { @@ -104,7 +104,7 @@ trait Matrix extends MatrixAdditions { // redundancy check matrix.targets filter (_.isNotReached) foreach (cs => cunit.error(cs.body.pos, "unreachable code")) // optimize performs squeezing and resets any remaining NO_EXHAUSTIVE - tracing("handlePattern(" + selector + ")", matrix optimize dfatree) + tracing("handlePattern")(matrix optimize dfatree) } case class MatrixContext( @@ -226,7 +226,7 @@ trait Matrix extends MatrixAdditions { val name = cunit.freshTermName(label) val sym = newVar(root.pos, tpe, flags(checked), name) - tracing("copy", new PatternVar(sym, root, checked)) + tracing("copy")(new PatternVar(sym, root, checked)) } /** Creates a new synthetic variable of the specified type and @@ -236,7 +236,7 @@ trait Matrix extends MatrixAdditions { val lhs = newVar(owner.pos, tpe, flags(checked)) val rhs = f(lhs) - tracing("create", new PatternVar(lhs, rhs, checked)) + tracing("create")(new PatternVar(lhs, rhs, checked)) } private def newVar( @@ -251,6 +251,6 @@ trait Matrix extends MatrixAdditions { } def typedValDef(x: Symbol, rhs: Tree) = - tracing("typedVal", typer typedValDef (VAL(x) === rhs)) + tracing("typedVal")(typer typedValDef (VAL(x) === rhs)) } }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 55ca66c608..540ed5b7f2 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -197,7 +197,7 @@ trait ParallelMatching extends ast.TreeDSL } def mkRule(rest: Rep): RuleApplication = { - tracing("Rule", head match { + tracing("Rule")(head match { case x if isEquals(x.tree.tpe) => new MixEquals(this, rest) case x: SequencePattern => new MixSequence(this, rest, x) case AnyUnapply(false) => new MixUnapply(this, rest, false) @@ -375,7 +375,7 @@ trait ParallelMatching extends ast.TreeDSL def unapply(p: Pattern) = condOpt(p) { case Pattern(UnApply(Apply(fn1, _), args), _) if sameFunction(fn1) => - tracing("sameUnapply", args) + tracing("sameUnapply")(args) } } object SameUnapply { @@ -644,8 +644,8 @@ trait ParallelMatching extends ast.TreeDSL case class Row(pats: List[Pattern], subst: Bindings, guard: Guard, bx: Int) { private def nobindings = subst.get().isEmpty private def bindstr = if (nobindings) "" else pp(subst) - if (pats exists (p => !p.isDefault)) - traceCategory("Row", "%s%s", pats, bindstr) + // if (pats exists (p => !p.isDefault)) + // traceCategory("Row", "%s%s", pats, bindstr) /** Extracts the 'i'th pattern. */ def extractColumn(i: Int) = { @@ -664,7 +664,7 @@ trait ParallelMatching extends ast.TreeDSL def rebind(b: Bindings) = copy(subst = b) // substitutes for bindings def insert2(hs: List[Pattern], vs: Iterable[Symbol], tvar: Symbol) = - tracing("insert2", copy(pats = hs ::: pats, subst = subst.add(vs, tvar))) + tracing("insert2")(copy(pats = hs ::: pats, subst = subst.add(vs, tvar))) // returns this rows with alternatives expanded def expandAlternatives(classifyPat: (Pattern, Int) => Pattern): List[Row] = { @@ -745,10 +745,9 @@ trait ParallelMatching extends ast.TreeDSL if (isLabellable) { val mtype = MethodType(freeVars, bodyTpe) _labelSym = owner.newLabel(body.pos, name) setInfo mtype - - TRACE("Creating index %d: mtype = %s".format(bx, mtype)) _label = typer typedLabelDef LabelDef(_labelSym, freeVars, body setType bodyTpe) - TRACE("[New label] def %s%s: %s = %s".format(name, pp(freeVars), bodyTpe, body)) + // TRACE("Creating index %d: mtype = %s".format(bx, mtype)) + // TRACE("[New label] def %s%s: %s = %s".format(name, pp(freeVars), bodyTpe, body)) } ifLabellable(vdefs, squeezedBlock(vdefs, label)) @@ -793,7 +792,7 @@ trait ParallelMatching extends ast.TreeDSL } /** Converts this to a tree - recursively acquires subreps. */ - final def toTree(): Tree = tracing("toTree", typer typed applyRule()) + final def toTree(): Tree = tracing("toTree")(typer typed applyRule()) /** The VariableRule. */ private def variable() = { @@ -826,7 +825,7 @@ trait ParallelMatching extends ast.TreeDSL val NoRep = Rep(Nil, Nil) /** Expands the patterns recursively. */ final def expand(roots: List[PatternVar], cases: List[CaseDef]) = - tracing("Expanded", ExpandedMatrix( + tracing("Expanded")(ExpandedMatrix( for ((CaseDef(pat, guard, body), index) <- cases.zipWithIndex) yield { def mkRow(ps: List[Tree]) = Row(toPats(ps), NoBinding, Guard(guard), index) diff --git a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala index 61ab4f31d1..8a36216e77 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala @@ -74,7 +74,7 @@ trait PatternBindings extends ast.TreeDSL def boundTree = if (_boundTree == null) tree else _boundTree def withBoundTree(x: Bind): this.type = { _boundTree = x - tracing[this.type]("Bound", this) + tracing[this.type]("Bound")(this) } // If a tree has bindings, boundTree looks something like @@ -127,8 +127,8 @@ trait PatternBindings extends ast.TreeDSL } class Bindings(private val vlist: List[Binding]) { - if (!vlist.isEmpty) - traceCategory("Bindings", this.toString) + // if (!vlist.isEmpty) + // traceCategory("Bindings", this.toString) def get() = vlist diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala index c1d60a9fe1..9594d9a368 100644 --- a/src/compiler/scala/tools/nsc/matching/Patterns.scala +++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala @@ -300,7 +300,7 @@ trait Patterns extends ast.TreeDSL { p match { case WildcardPattern() => p case _: LiteralPattern => p - case _ => tracing("Pattern", p) + case _ => tracing("Pattern")(p) } } def unapply(other: Any): Option[(Tree, List[Symbol])] = other match { @@ -496,7 +496,7 @@ trait Patterns extends ast.TreeDSL { } def equalsCheck = - tracing("equalsCheck", + tracing("equalsCheck")( if (sym.isValue) singleType(NoPrefix, sym) else tpe.narrow ) |