Skip to content

Commit 7e00b1b

Browse files
author
Aleksander Boruch-Gruszecki
committed
Allow overriding ConstraintHandling logs
1 parent 5195cab commit 7e00b1b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import config.Printers.{constr, typr}
2020
*/
2121
trait ConstraintHandling {
2222

23+
def constr_println(msg: => String): Unit = constr.println(msg)
24+
def typr_println(msg: => String): Unit = typr.println(msg)
25+
2326
implicit def ctx: Context
2427

2528
protected def isSubType(tp1: Type, tp2: Type): Boolean
@@ -107,23 +110,23 @@ trait ConstraintHandling {
107110
if (Config.failOnInstantiationToNothing) assert(false, msg)
108111
else ctx.log(msg)
109112
}
110-
constr.println(i"adding $description$location")
113+
constr_println(i"adding $description$location")
111114
val lower = constraint.lower(param)
112115
val res =
113116
addOneBound(param, bound, isUpper = true) &&
114117
lower.forall(addOneBound(_, bound, isUpper = true))
115-
constr.println(i"added $description = $res$location")
118+
constr_println(i"added $description = $res$location")
116119
res
117120
}
118121

119122
protected def addLowerBound(param: TypeParamRef, bound: Type): Boolean = {
120123
def description = i"constraint $param >: $bound to\n$constraint"
121-
constr.println(i"adding $description")
124+
constr_println(i"adding $description")
122125
val upper = constraint.upper(param)
123126
val res =
124127
addOneBound(param, bound, isUpper = false) &&
125128
upper.forall(addOneBound(_, bound, isUpper = false))
126-
constr.println(i"added $description = $res$location")
129+
constr_println(i"added $description = $res$location")
127130
res
128131
}
129132

@@ -136,20 +139,20 @@ trait ConstraintHandling {
136139
val up2 = p2 :: constraint.exclusiveUpper(p2, p1)
137140
val lo1 = constraint.nonParamBounds(p1).lo
138141
val hi2 = constraint.nonParamBounds(p2).hi
139-
constr.println(i"adding $description down1 = $down1, up2 = $up2$location")
142+
constr_println(i"adding $description down1 = $down1, up2 = $up2$location")
140143
constraint = constraint.addLess(p1, p2)
141144
down1.forall(addOneBound(_, hi2, isUpper = true)) &&
142145
up2.forall(addOneBound(_, lo1, isUpper = false))
143146
}
144-
constr.println(i"added $description = $res$location")
147+
constr_println(i"added $description = $res$location")
145148
res
146149
}
147150

148151
/** Make p2 = p1, transfer all bounds of p2 to p1
149152
* @pre less(p1)(p2)
150153
*/
151154
private def unify(p1: TypeParamRef, p2: TypeParamRef): Boolean = {
152-
constr.println(s"unifying $p1 $p2")
155+
constr_println(s"unifying $p1 $p2")
153156
assert(constraint.isLess(p1, p2))
154157
val down = constraint.exclusiveLower(p2, p1)
155158
val up = constraint.exclusiveUpper(p1, p2)
@@ -247,7 +250,7 @@ trait ConstraintHandling {
247250
case _: TypeBounds =>
248251
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
249252
val inst = avoidParam(bound)
250-
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
253+
typr_println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
251254
inst
252255
case inst =>
253256
assert(inst.exists, i"param = $param\nconstraint = $constraint")
@@ -346,7 +349,7 @@ trait ConstraintHandling {
346349
val lower = constraint.lower(param)
347350
val upper = constraint.upper(param)
348351
if (lower.nonEmpty && !bounds.lo.isRef(defn.NothingClass) ||
349-
upper.nonEmpty && !bounds.hi.isRef(defn.AnyClass)) constr.println(i"INIT*** $tl")
352+
upper.nonEmpty && !bounds.hi.isRef(defn.AnyClass)) constr_println(i"INIT*** $tl")
350353
lower.forall(addOneBound(_, bounds.hi, isUpper = true)) &&
351354
upper.forall(addOneBound(_, bounds.lo, isUpper = false))
352355
case _ =>

0 commit comments

Comments
 (0)