Skip to content

Commit b0fa1fd

Browse files
authored
Merge pull request #14270 from dwijnand/improve-typer-trace
Improve typer traces
2 parents c99f6ca + 97b96b6 commit b0fa1fd

File tree

3 files changed

+28
-51
lines changed

3 files changed

+28
-51
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

tests/neg-custom-args/i11637.check

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,16 @@ conforms to
1313
but the comparison trace ended with `false`:
1414

1515
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
16-
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
17-
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
18-
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
19-
==> [T <: String] =>> Set[T] <: Iterable
20-
==> [T <: String] =>> Set[T] <: Iterable (recurring)
21-
==> type bounds [] <: type bounds [ <: String]
22-
==> type bounds [] <: type bounds [ <: String] (recurring)
23-
==> Any <: String
24-
==> Any <: String (recurring)
25-
==> Any <: String (recurring)
26-
<== Any <: String (recurring) = false
27-
<== Any <: String (recurring) = false
28-
<== Any <: String = false
29-
<== type bounds [] <: type bounds [ <: String] (recurring) = false
30-
<== type bounds [] <: type bounds [ <: String] = false
31-
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
32-
<== [T <: String] =>> Set[T] <: Iterable = false
33-
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
34-
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
35-
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
16+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
17+
==> [T <: String] =>> Set[T] <: Iterable
18+
==> type bounds [] <: type bounds [ <: String]
19+
==> Any <: String
20+
==> Any <: String
21+
<== Any <: String = false
22+
<== Any <: String = false
23+
<== type bounds [] <: type bounds [ <: String] = false
24+
<== [T <: String] =>> Set[T] <: Iterable = false
25+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
3626
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false
3727

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

5444
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
55-
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
56-
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
57-
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
58-
==> [T <: String] =>> Set[T] <: Iterable
59-
==> [T <: String] =>> Set[T] <: Iterable (recurring)
60-
==> type bounds [] <: type bounds [ <: String]
61-
==> type bounds [] <: type bounds [ <: String] (recurring)
62-
==> Any <: String
63-
==> Any <: String (recurring)
64-
==> Any <: String (recurring)
65-
<== Any <: String (recurring) = false
66-
<== Any <: String (recurring) = false
67-
<== Any <: String = false
68-
<== type bounds [] <: type bounds [ <: String] (recurring) = false
69-
<== type bounds [] <: type bounds [ <: String] = false
70-
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
71-
<== [T <: String] =>> Set[T] <: Iterable = false
72-
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
73-
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
74-
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
45+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
46+
==> [T <: String] =>> Set[T] <: Iterable
47+
==> type bounds [] <: type bounds [ <: String]
48+
==> Any <: String
49+
==> Any <: String
50+
<== Any <: String = false
51+
<== Any <: String = false
52+
<== type bounds [] <: type bounds [ <: String] = false
53+
<== [T <: String] =>> Set[T] <: Iterable = false
54+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
7555
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false
7656

7757
The tests were made under the empty constraint

0 commit comments

Comments
 (0)