Skip to content

Commit 9f56463

Browse files
committed
Improve typer traces
1. Drop traceIndented from isSubType, which calls recur so it was just doubling the lines 2. Replace newlines with spaces, in doTrace and traceIndented, as they're meant to be single lines. For example ErrorType and MatchType have toText that are multi-line and mess up the output. 3. Change ExplainingTypeComparer#addConstraint to use show like the other methods.
1 parent c01d596 commit 9f56463

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
210210
* types (as when we go from an abstract type to one of its bounds). In that case
211211
* one should use `isSubType(_, _, a)` where `a` defines the kind of approximation.
212212
*
213-
* Note: Logicaly, `recur` could be nested in `isSubType`, which would avoid
213+
* Note: Logically, `recur` could be nested in `isSubType`, which would avoid
214214
* the instance state consisting `approx` and `leftRoot`. But then the implemented
215215
* code would have two extra parameters for each of the many calls that go from
216216
* one sub-part of isSubType to another.
@@ -2955,27 +2955,24 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
29552955
if (skipped) op
29562956
else {
29572957
indent += 2
2958-
b.append("\n").append(" " * indent).append("==> ").append(str)
2958+
val str1 = str.replace('\n', ' ')
2959+
b.append("\n").append(" " * indent).append("==> ").append(str1)
29592960
val res = op
2960-
b.append("\n").append(" " * indent).append("<== ").append(str).append(" = ").append(show(res))
2961+
b.append("\n").append(" " * indent).append("<== ").append(str1).append(" = ").append(show(res))
29612962
indent -= 2
29622963
res
29632964
}
29642965

29652966
private def frozenNotice: String =
29662967
if frozenConstraint then " in frozen constraint" else ""
29672968

2968-
override def isSubType(tp1: Type, tp2: Type, approx: ApproxState): Boolean =
2969+
override def recur(tp1: Type, tp2: Type): Boolean =
29692970
def moreInfo =
29702971
if Config.verboseExplainSubtype || ctx.settings.verbose.value
29712972
then s" ${tp1.getClass} ${tp2.getClass}"
29722973
else ""
2974+
val approx = approxState
29732975
traceIndented(s"${show(tp1)} <: ${show(tp2)}$moreInfo${approx.show}$frozenNotice") {
2974-
super.isSubType(tp1, tp2, approx)
2975-
}
2976-
2977-
override def recur(tp1: Type, tp2: Type): Boolean =
2978-
traceIndented(s"${show(tp1)} <: ${show(tp2)} (recurring)$frozenNotice") {
29792976
super.recur(tp1, tp2)
29802977
}
29812978

@@ -2995,7 +2992,7 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
29952992
}
29962993

29972994
override def addConstraint(param: TypeParamRef, bound: Type, fromBelow: Boolean)(using Context): Boolean =
2998-
traceIndented(i"add constraint $param ${if (fromBelow) ">:" else "<:"} $bound $frozenConstraint, constraint = ${ctx.typerState.constraint}") {
2995+
traceIndented(s"add constraint ${show(param)} ${if (fromBelow) ">:" else "<:"} ${show(bound)} $frozenNotice, constraint = ${show(ctx.typerState.constraint)}") {
29992996
super.addConstraint(param, bound, fromBelow)
30002997
}
30012998

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ trait TraceSyntax:
7676
else
7777
// Avoid evaluating question multiple time, since each evaluation
7878
// may cause some extra logging output.
79-
val q = question
79+
val q = question.replace('\n', ' ')
8080
val leading = s"==> $q?"
8181
val trailing = (res: T) => s"<== $q = ${showOp(res)}"
8282
var finalized = false

0 commit comments

Comments
 (0)