Skip to content

Commit

Permalink
Improve typer traces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dwijnand committed Jan 15, 2022
1 parent c01d596 commit 97b96b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 51 deletions.
17 changes: 7 additions & 10 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
* types (as when we go from an abstract type to one of its bounds). In that case
* one should use `isSubType(_, _, a)` where `a` defines the kind of approximation.
*
* Note: Logicaly, `recur` could be nested in `isSubType`, which would avoid
* Note: Logically, `recur` could be nested in `isSubType`, which would avoid
* the instance state consisting `approx` and `leftRoot`. But then the implemented
* code would have two extra parameters for each of the many calls that go from
* one sub-part of isSubType to another.
Expand Down Expand Up @@ -2955,27 +2955,24 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
if (skipped) op
else {
indent += 2
b.append("\n").append(" " * indent).append("==> ").append(str)
val str1 = str.replace('\n', ' ')
b.append("\n").append(" " * indent).append("==> ").append(str1)
val res = op
b.append("\n").append(" " * indent).append("<== ").append(str).append(" = ").append(show(res))
b.append("\n").append(" " * indent).append("<== ").append(str1).append(" = ").append(show(res))
indent -= 2
res
}

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

override def isSubType(tp1: Type, tp2: Type, approx: ApproxState): Boolean =
override def recur(tp1: Type, tp2: Type): Boolean =
def moreInfo =
if Config.verboseExplainSubtype || ctx.settings.verbose.value
then s" ${tp1.getClass} ${tp2.getClass}"
else ""
val approx = approxState
traceIndented(s"${show(tp1)} <: ${show(tp2)}$moreInfo${approx.show}$frozenNotice") {
super.isSubType(tp1, tp2, approx)
}

override def recur(tp1: Type, tp2: Type): Boolean =
traceIndented(s"${show(tp1)} <: ${show(tp2)} (recurring)$frozenNotice") {
super.recur(tp1, tp2)
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ trait TraceSyntax:
else
// Avoid evaluating question multiple time, since each evaluation
// may cause some extra logging output.
val q = question
val q = question.replace('\n', ' ')
val leading = s"==> $q?"
val trailing = (res: T) => s"<== $q = ${showOp(res)}"
var finalized = false
Expand Down
60 changes: 20 additions & 40 deletions tests/neg-custom-args/i11637.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,16 @@ conforms to
but the comparison trace ended with `false`:

==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
==> [T <: String] =>> Set[T] <: Iterable
==> [T <: String] =>> Set[T] <: Iterable (recurring)
==> type bounds [] <: type bounds [ <: String]
==> type bounds [] <: type bounds [ <: String] (recurring)
==> Any <: String
==> Any <: String (recurring)
==> Any <: String (recurring)
<== Any <: String (recurring) = false
<== Any <: String (recurring) = false
<== Any <: String = false
<== type bounds [] <: type bounds [ <: String] (recurring) = false
<== type bounds [] <: type bounds [ <: String] = false
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
<== [T <: String] =>> Set[T] <: Iterable = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
==> [T <: String] =>> Set[T] <: Iterable
==> type bounds [] <: type bounds [ <: String]
==> Any <: String
==> Any <: String
<== Any <: String = false
<== Any <: String = false
<== type bounds [] <: type bounds [ <: String] = false
<== [T <: String] =>> Set[T] <: Iterable = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false

The tests were made under the empty constraint
Expand All @@ -52,26 +42,16 @@ conforms to
but the comparison trace ended with `false`:

==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
==> [T <: String] =>> Set[T] <: Iterable
==> [T <: String] =>> Set[T] <: Iterable (recurring)
==> type bounds [] <: type bounds [ <: String]
==> type bounds [] <: type bounds [ <: String] (recurring)
==> Any <: String
==> Any <: String (recurring)
==> Any <: String (recurring)
<== Any <: String (recurring) = false
<== Any <: String (recurring) = false
<== Any <: String = false
<== type bounds [] <: type bounds [ <: String] (recurring) = false
<== type bounds [] <: type bounds [ <: String] = false
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
<== [T <: String] =>> Set[T] <: Iterable = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
==> [T <: String] =>> Set[T] <: Iterable
==> type bounds [] <: type bounds [ <: String]
==> Any <: String
==> Any <: String
<== Any <: String = false
<== Any <: String = false
<== type bounds [] <: type bounds [ <: String] = false
<== [T <: String] =>> Set[T] <: Iterable = false
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false

The tests were made under the empty constraint

0 comments on commit 97b96b6

Please sign in to comment.