aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-03 14:21:33 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-03 14:21:33 +0100
commitfd5e45bd71c972fddc0f835cdb011beb76a77770 (patch)
tree619ca441a99605f228add3667ae18d04d463d626 /src/dotty/tools/dotc
parent2d500b7746a38647c7a97db99207ca4972cd49eb (diff)
downloaddotty-fd5e45bd71c972fddc0f835cdb011beb76a77770.tar.gz
dotty-fd5e45bd71c972fddc0f835cdb011beb76a77770.tar.bz2
dotty-fd5e45bd71c972fddc0f835cdb011beb76a77770.zip
Making printing configurable.
Special by-topic printers that can be turned off.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/config/Printers.scala18
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala28
-rw-r--r--src/dotty/tools/dotc/core/Types.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala15
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala11
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala7
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala15
7 files changed, 60 insertions, 37 deletions
diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala
new file mode 100644
index 000000000..3dab2a234
--- /dev/null
+++ b/src/dotty/tools/dotc/config/Printers.scala
@@ -0,0 +1,18 @@
+package dotty.tools.dotc.config
+
+object Printers {
+
+ class Printer {
+ def println(msg: => String): Unit = System.out.println(msg)
+ }
+
+ object noPrinter extends Printer {
+ override def println(msg: => String): Unit = ()
+ }
+
+ val core: Printer = noPrinter
+ val typr: Printer = noPrinter
+ val constr: Printer = noPrinter
+ val unapp: Printer = noPrinter
+
+} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 0d3bf2e94..582fa7b21 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -9,6 +9,7 @@ import collection.mutable
import printing.Disambiguation.disambiguated
import util.SimpleMap
import config.Config
+import config.Printers._
/** Provides methods to compare types.
*/
@@ -62,18 +63,17 @@ class TypeComparer(initctx: Context) extends DotClass {
if (fromBelow) oldBounds.derivedTypeBounds(oldBounds.lo | bound, oldBounds.hi)
else oldBounds.derivedTypeBounds(oldBounds.lo, oldBounds.hi & bound)
finally ignoreConstraint = saved
- // val res = // !!!DEBUG
- (param == bound) ||
- (oldBounds eq newBounds) || {
- val saved = constraint
- constraint = constraint.updated(param, newBounds)
- isSubType(newBounds.lo, newBounds.hi) ||
- { constraint = saved; false } // don't leave the constraint in unsatisfiable state
- }
- //println(s"add constraint $param ${if (fromBelow) ">:" else "<:"} $bound = $res")
- //if (res)
- // println(constraint.show)
- //res
+ val res =
+ (param == bound) ||
+ (oldBounds eq newBounds) || {
+ val saved = constraint
+ constraint = constraint.updated(param, newBounds)
+ isSubType(newBounds.lo, newBounds.hi) ||
+ { constraint = saved; false } // don't leave the constraint in unsatisfiable state
+ }
+ constr.println(s"add constraint $param ${if (fromBelow) ">:" else "<:"} $bound = $res")
+ if (res) constr.println(constraint.show)
+ res
}
/** If current constraint set is not frozen, add the constraint
@@ -89,7 +89,7 @@ class TypeComparer(initctx: Context) extends DotClass {
def addConstraint(param: PolyParam, bound: Type, fromBelow: Boolean): Boolean = {
param == bound ||
!frozenConstraint && {
- // println(s"adding ${param.show} ${if (fromBelow) ">:>" else "<:<"} ${bound.show} to ${constraint.show}")
+ constr.println(s"adding ${param.show} ${if (fromBelow) ">:>" else "<:<"} ${bound.show} to ${constraint.show}")
bound match {
case bound: PolyParam if constraint contains bound =>
addConstraint1(param, bound, fromBelow) &&
@@ -121,7 +121,7 @@ class TypeComparer(initctx: Context) extends DotClass {
val bounds = constraint.bounds(param)
val bound = if (fromBelow) bounds.lo else bounds.hi
val inst = avoidParam(bound)
- println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
+ typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
inst
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index afe531d4e..a3639cbde 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -25,6 +25,7 @@ import printing.Printer
import scala.util.hashing.{ MurmurHash3 => hashing }
import collection.{mutable, Seq, breakOut}
import config.Config
+import config.Printers._
import language.implicitConversions
object Types {
@@ -1708,7 +1709,7 @@ object Types {
/** Instantiate variable with given type */
def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
assert(tp ne this)
- println(s"instantiating ${this.show} with ${tp.show}") // !!!DEBUG
+ typr.println(s"instantiating ${this.show} with ${tp.show}")
assert(ctx.typerState.constraint contains this) // !!! DEBUG
if (ctx.typerState eq owningState) inst = tp
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 2c1384524..5c05b87a0 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -23,6 +23,7 @@ import Inferencing._
import EtaExpansion._
import collection.mutable
import reflect.ClassTag
+import config.Printers._
import language.implicitConversions
object Applications {
@@ -636,12 +637,12 @@ trait Applications extends Compatibility { self: Typer =>
unapply.tpe.widen match {
case mt: MethodType if mt.paramTypes.length == 1 && !mt.isDependent =>
val unapplyArgType = mt.paramTypes.head
- println(s"unapp arg tpe = ${unapplyArgType.show}, pt = ${pt.show}")
+ unapp.println(s"unapp arg tpe = ${unapplyArgType.show}, pt = ${pt.show}")
def wpt = widenForMatchSelector(pt)
val ownType =
if (pt <:< unapplyArgType) {
fullyDefinedType(unapplyArgType, "extractor argument", tree.pos)
- println(i"case 1 $unapplyArgType ${ctx.typerState.constraint}")
+ unapp.println(i"case 1 $unapplyArgType ${ctx.typerState.constraint}")
pt
}
else if (unapplyArgType <:< wpt) {
@@ -662,16 +663,16 @@ trait Applications extends Compatibility { self: Typer =>
if (ctx.settings.verbose.value) ctx.warning(msg, tree.pos)
}
else {
- println(s" ${unapply.symbol.owner} ${unapply.symbol.owner is Scala2x}")
+ unapp.println(s" ${unapply.symbol.owner} ${unapply.symbol.owner is Scala2x}")
ctx.error(msg, tree.pos)
}
case _ =>
}
- println(i"case 2 $unapplyArgType ${ctx.typerState.constraint}")
+ unapp.println(i"case 2 $unapplyArgType ${ctx.typerState.constraint}")
unapplyArgType
} else {
- // println("Neither sub nor super")
- // println(TypeComparer.explained(implicit ctx => unapplyArgType <:< wpt))
+ unapp.println("Neither sub nor super")
+ unapp.println(TypeComparer.explained(implicit ctx => unapplyArgType <:< wpt))
errorType(
i"Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $wpt",
tree.pos)
@@ -696,7 +697,7 @@ trait Applications extends Compatibility { self: Typer =>
}
val unapplyPatterns = (bunchedArgs, argTypes).zipped map (typed(_, _))
val result = cpy.UnApply(tree, unapply, unapplyImplicits, unapplyPatterns) withType ownType
- println(s"unapply patterns = $unapplyPatterns")
+ unapp.println(s"unapply patterns = $unapplyPatterns")
if ((ownType eq pt) || ownType.isError) result
else Typed(result, TypeTree(ownType))
case tp =>
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index 6623edc7d..76e701fee 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -13,6 +13,7 @@ import util.{Stats, SimpleMap}
import util.common._
import Decorators._
import ErrorReporting.{errorType, InfoString}
+import config.Printers._
import collection.mutable
object Inferencing {
@@ -244,7 +245,7 @@ object Inferencing {
case tvar: TypeVar if !tvar.isInstantiated =>
force != ForceDegree.none && {
val inst = tvar.instantiate(fromBelow = !isContravariant(tvar))
- println(i"forced instantiation of ${tvar.origin} = $inst")
+ typr.println(i"forced instantiation of ${tvar.origin} = $inst")
(force == ForceDegree.all || inst != defn.NothingType && inst != defn.NullType) && traverse(inst)
}
case _ =>
@@ -304,10 +305,10 @@ object Inferencing {
val seen = new mutable.HashMap[Name, List[Symbol]] {
override def default(key: Name) = Nil
}
- println(i"cndd $cls")
+ typr.println(i"check no double defs $cls")
for (decl <- cls.info.decls) {
for (other <- seen(decl.name)) {
- println(i"conflict? $decl $other")
+ typr.println(i"conflict? $decl $other")
if (decl.signature matches other.signature) {
val ofType = if (decl.isType) "" else i": ${other.info}"
val explanation =
@@ -375,7 +376,7 @@ object Inferencing {
var changed = false
vs foreachBinding { (tvar, v) =>
if (v != 0) {
- //println(s"interpolate ${if (v == 1) "co" else "contra"}variant ${tvar.show} in ${tp.show}")
+ typr.println(s"interpolate ${if (v == 1) "co" else "contra"}variant ${tvar.show} in ${tp.show}")
tvar.instantiate(fromBelow = v == 1)
changed = true
}
@@ -385,7 +386,7 @@ object Inferencing {
else
constraint.foreachUninstVar { tvar =>
if (!(vs contains tvar) && qualifies(tvar)) {
- //println(s"instantiating non-occurring $tvar in $tp")
+ typr.println(s"instantiating non-occurring $tvar in $tp")
tvar.instantiate(fromBelow = true)
}
}
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 16e965823..97114d410 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -14,6 +14,7 @@ import collection.mutable
import annotation.tailrec
import ErrorReporting._
import tpd.ListOfTreeDecorator
+import config.Printers._
import language.implicitConversions
trait NamerContextOps { this: Context =>
@@ -180,7 +181,7 @@ class Namer { typer: Typer =>
}
else completer
- println(i"creating symbol for $tree")
+ typr.println(i"creating symbol for $tree")
tree match {
case tree: TypeDef if tree.isClassDef =>
val cls = record(ctx.newClassSymbol(
@@ -209,7 +210,7 @@ class Namer { typer: Typer =>
*/
def enterSymbol(sym: Symbol)(implicit ctx: Context) = {
if (sym.exists) {
- println(s"entered: $sym in ${ctx.owner} and ${ctx.effectiveScope}")
+ typr.println(s"entered: $sym in ${ctx.owner} and ${ctx.effectiveScope}")
def preExisting = ctx.effectiveScope.lookup(sym.name)
if (sym.owner is PackageClass) {
if (preExisting.isDefinedInCurrentRun)
@@ -238,7 +239,7 @@ class Namer { typer: Typer =>
def expand(tree: Tree)(implicit ctx: Context): Unit = tree match {
case mdef: DefTree =>
val expanded = desugar.defTree(mdef)
- println(i"Expansion: $mdef expands to $expanded")
+ typr.println(i"Expansion: $mdef expands to $expanded")
if (expanded ne mdef) expandedTree(mdef) = expanded
case _ =>
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 3cdd26b1a..4352a17d6 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -29,6 +29,7 @@ import collection.mutable
import annotation.tailrec
import Implicits._
import util.Stats.track
+import config.Printers._
import language.implicitConversions
trait TyperContextOps { ctx: Context => }
@@ -324,7 +325,7 @@ class Typer extends Namer with Applications with Implicits {
// begin typedIdent
def kind = if (name.isTermName) "" else "type "
- // println(s"typed ident $kind$name in ${ctx.owner}") // !!! DEBUG
+ typr.println(s"typed ident $kind$name in ${ctx.owner}")
if (ctx.mode is Mode.Pattern) {
if (name == nme.WILDCARD)
return tree.withType(pt)
@@ -743,7 +744,7 @@ class Typer extends Namer with Applications with Implicits {
val TypeDef(_, _, Template(_, _, _, refinements1)) = typed(refineClsDef)
assert(tree.refinements.length == refinements1.length, s"${tree.refinements} != $refinements1")
def addRefinement(parent: Type, refinement: Tree): Type = {
- // println(s"adding refinement $refinement") !!!DEBUG
+ typr.println(s"adding refinement $refinement")
foreachSubTreeOf(refinement) {
case tree: RefTree =>
if (tree.symbol.owner == refineCls && tree.pos.start <= tree.symbol.pos.end)
@@ -757,7 +758,7 @@ class Typer extends Namer with Applications with Implicits {
}
val res = cpy.RefinedTypeTree(tree, tpt1, refinements1) withType
(tpt1.tpe /: refinements1)(addRefinement)
- // println(s"typed refinement: ${res.tpe.show}")
+ typr.println(s"typed refinement: ${res.tpe.show}")
res
}
@@ -787,7 +788,7 @@ class Typer extends Namer with Applications with Implicits {
def typedBind(tree: untpd.Bind, pt: Type)(implicit ctx: Context): Bind = track("typedBind") {
val body1 = typed(tree.body, pt)
- // println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}")
+ typr.println(i"typed bind $tree pt = $pt bodytpe = ${body1.tpe}")
val sym = ctx.newSymbol(ctx.owner, tree.name.asTermName, EmptyFlags, body1.tpe, coord = tree.pos)
cpy.Bind(tree, tree.name, body1) withType TermRef(NoPrefix, sym)
}
@@ -1090,7 +1091,7 @@ class Typer extends Namer with Applications with Implicits {
def adaptOverloaded(ref: TermRef) = {
val altDenots = ref.denot.alternatives
- // println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%, %") !!! DEBUG
+ typr.println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%, %")
val alts = altDenots map (alt =>
TermRef.withSig(ref.prefix, ref.name, alt.info.signature, alt))
def expectedStr = err.expectedTypeStr(pt)
@@ -1168,8 +1169,8 @@ class Typer extends Namer with Applications with Implicits {
if (tree.tpe <:< pt) tree
else if (ctx.mode is Mode.Pattern) tree // no subtype check for pattern
else {
- // println(s"adapt to subtype ${tree.tpe} !<:< $pt") // !!!DEBUG
- // println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) // !!!DEBUG
+ typr.println(s"adapt to subtype ${tree.tpe} !<:< $pt")
+ typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt))
adaptToSubType(wtp)
}
}