Skip to content

Improve typer traces #14270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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