aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-16 22:00:16 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-16 22:00:40 +0100
commitbf59937182b66d12d01c11ff5dd27346ee4a9db4 (patch)
treeda1aa5ce95b86aa9b17cd3911ef97698c5fa5f40
parentd00c3f5e7925cd246fb10916f6a2d26111ac2689 (diff)
downloaddotty-bf59937182b66d12d01c11ff5dd27346ee4a9db4.tar.gz
dotty-bf59937182b66d12d01c11ff5dd27346ee4a9db4.tar.bz2
dotty-bf59937182b66d12d01c11ff5dd27346ee4a9db4.zip
Refactoring to avoid multiple overloaded traceIndent methods.
-rw-r--r--src/dotty/tools/dotc/config/Printers.scala3
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--src/dotty/tools/dotc/reporting/Reporter.scala20
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala12
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala2
6 files changed, 22 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala
index ee1acb71e..19e7e1891 100644
--- a/src/dotty/tools/dotc/config/Printers.scala
+++ b/src/dotty/tools/dotc/config/Printers.scala
@@ -10,11 +10,12 @@ object Printers {
override def println(msg: => String): Unit = ()
}
+ val default: Printer = new Printer
val core: Printer = noPrinter
val typr: Printer = new Printer
val constr: Printer = noPrinter
val overload: Printer = noPrinter
- val implicits: Printer = noPrinter
+ val implicits: Printer = new Printer
val unapp: Printer = noPrinter
val completions = noPrinter
val gadts = noPrinter
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 8f7725fbe..4cf392f13 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -128,7 +128,7 @@ object SymDenotations {
if (myFlags is Touched) throw new CyclicReference(this)
myFlags |= Touched
- Context.theBase.initialCtx.traceIndented(completions, s"completing ${this.debugString}") {
+ Context.theBase.initialCtx.traceIndented(s"completing ${this.debugString}", completions) {
// println("completing " + debugString)
completer.complete(this)
}
diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala
index 913290a00..e2b320588 100644
--- a/src/dotty/tools/dotc/reporting/Reporter.scala
+++ b/src/dotty/tools/dotc/reporting/Reporter.scala
@@ -8,6 +8,7 @@ import util.{SourceFile, NoSource}
import core.Decorators.PhaseListDecorator
import collection.mutable
import config.Settings.Setting
+import config.Printers
import java.lang.System.currentTimeMillis
object Reporter {
@@ -128,23 +129,20 @@ trait Reporting { this: Context =>
def debugwarn(msg: => String, pos: SourcePosition = NoSourcePosition): Unit =
if (this.settings.debug.value) warning(msg, pos)
- def debugTraceIndented[T](question: => String, show: Boolean = false)(op: => T): T =
- conditionalTraceIndented(this.settings.debugTrace.value, question, show)(op)
+ def debugTraceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T =
+ conditionalTraceIndented(this.settings.debugTrace.value, question, printer, show)(op)
- def conditionalTraceIndented[T](cond: Boolean, question: => String, show: Boolean = false)(op: => T): T =
- if (cond) traceIndented(question, show)(op)
+ def conditionalTraceIndented[T](cond: Boolean, question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T =
+ if (cond) traceIndented(question, printer, show)(op)
else op
- def traceIndented[T](printer: config.Printers.Printer, question: => String, show: Boolean = false)(op: => T): T =
- if (printer ne config.Printers.noPrinter) traceIndented(question, show)(op)
- else op
-
- def traceIndented[T](question: => String, show: Boolean = false)(op: => T): T = {
+ def traceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = {
def resStr(res: Any): String = res match {
case res: printing.Showable if show => res.show
case _ => String.valueOf(res)
}
- traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op)
+ if (printer eq config.Printers.noPrinter) op
+ else traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op)
}
def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T = {
@@ -258,7 +256,7 @@ abstract class Reporter {
countElementsAsString(count(severity.level), label(severity).dropRight(2))
}
- def printSummary(implicit ctx: Context) {
+ def printSummary(implicit ctx: Context): Unit = {
if (count(WARNING.level) > 0) ctx.echo(countString(WARNING) + " found")
if ( count(ERROR.level) > 0) ctx.echo(countString(ERROR ) + " found")
for (cwarning <- conditionalWarnings) {
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 6b73740bb..400c43e3c 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -741,7 +741,7 @@ trait Applications extends Compatibility { self: Typer =>
/** In a set of overloaded applicable alternatives, is `alt1` at least as good as
* `alt2`? `alt1` and `alt2` are nonoverloaded references.
*/
- def isAsGood(alt1: TermRef, alt2: TermRef)(implicit ctx: Context): Boolean = track("isAsGood") { ctx.traceIndented(overload, i"isAsGood($alt1, $alt2)") {
+ def isAsGood(alt1: TermRef, alt2: TermRef)(implicit ctx: Context): Boolean = track("isAsGood") { ctx.traceIndented(i"isAsGood($alt1, $alt2)", overload) {
assert(alt1 ne alt2)
@@ -760,7 +760,7 @@ trait Applications extends Compatibility { self: Typer =>
* 2. `tp2` and `tp1` are method or poly types and `tp2` can be applied to the parameters of `tp1`.
* 3. Neither `tp1` nor `tp2` are method or poly types and `tp1` is compatible with `tp2`.
*/
- def isAsSpecific(alt1: TermRef, tp1: Type, alt2: TermRef, tp2: Type): Boolean = ctx.traceIndented(overload, i"isAsSpecific $tp1 $tp2") { tp1 match {
+ def isAsSpecific(alt1: TermRef, tp1: Type, alt2: TermRef, tp2: Type): Boolean = ctx.traceIndented(i"isAsSpecific $tp1 $tp2", overload) { tp1 match {
case tp1: PolyType =>
def bounds(tparamRefs: List[TypeRef]) = tp1.paramBounds map (_.substParams(tp1, tparamRefs))
val tparams = ctx.newTypeParams(alt1.symbol.owner, tp1.paramNames, EmptyFlags, bounds)
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 5ab40d529..b5f7f0366 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -62,7 +62,7 @@ object Implicits {
}
/** The implicit references that are eligible for expected type `tp` */
- lazy val eligible: List[TermRef] = ctx.traceIndented(implicits, i"eligible($tp), companions = ${companionRefs.toList}%, %", show = true)(filterMatching(tp))
+ lazy val eligible: List[TermRef] = ctx.traceIndented(i"eligible($tp), companions = ${companionRefs.toList}%, %", implicits, show = true)(filterMatching(tp))
override def toString =
i"OfTypeImplicits($tp), companions = ${companionRefs.toList}%, %; refs = $refs%, %."
@@ -215,7 +215,7 @@ trait ImplicitRunInfo { self: RunInfo =>
// todo: compute implicits directly, without going via companionRefs?
def collectCompanions(tp: Type): TermRefSet = track("computeImplicicScope") {
- ctx.traceIndented(implicits, i"collectCompanions($tp)") {
+ ctx.traceIndented(i"collectCompanions($tp)", implicits) {
val comps = new TermRefSet
tp match {
case tp: NamedType =>
@@ -295,7 +295,7 @@ trait Implicits { self: Typer =>
* !!! todo: catch potential cycles
*/
def inferImplicit(pt: Type, argument: Tree, pos: Position)(implicit ctx: Context): SearchResult = track("inferImplicit") {
- ctx.traceIndented(implicits, s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}, constraint = ${ctx.typerState.constraint.show}", show = true) {
+ ctx.traceIndented(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}, constraint = ${ctx.typerState.constraint.show}", implicits, show = true) {
assert(!pt.isInstanceOf[ExprType])
val isearch =
if (ctx.settings.explaintypes.value) new ExplainedImplicitSearch(pt, argument, pos)
@@ -349,7 +349,7 @@ trait Implicits { self: Typer =>
def searchImplicits(eligible: List[TermRef], contextual: Boolean): SearchResult = {
/** Try to typecheck an implicit reference */
- def typedImplicit(ref: TermRef)(implicit ctx: Context): SearchResult = track("typedImplicit") { ctx.traceIndented(implicits, i"typed implicit $ref, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", show = true) {
+ def typedImplicit(ref: TermRef)(implicit ctx: Context): SearchResult = track("typedImplicit") { ctx.traceIndented(i"typed implicit $ref, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
var generated: Tree = Ident(ref).withPos(pos)
if (!argument.isEmpty)
generated = typedUnadapted(
@@ -544,4 +544,6 @@ class TermRefSet(implicit ctx: Context) extends mutable.Traversable[TermRef] {
for (sym <- elems.keysIterator)
for (pre <- elems(sym))
f(TermRef(pre, sym))
-} \ No newline at end of file
+}
+
+object EmptyTermRefSet extends TermRefSet()(NoContext)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index d35e5fa93..c1e771f16 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -663,7 +663,7 @@ class Typer extends Namer with Applications with Implicits {
* which appear with variances +1 and -1 (in different
* places) be considered as well?
*/
- val gadtSyms: Set[Symbol] = ctx.traceIndented(gadts, i"GADT syms of $selType") {
+ val gadtSyms: Set[Symbol] = ctx.traceIndented(i"GADT syms of $selType", gadts) {
val accu = new TypeAccumulator[Set[Symbol]] {
def apply(tsyms: Set[Symbol], t: Type): Set[Symbol] = {
val tsyms1 = t match {