Skip to content

More dotc refactorings #6861

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 10 commits into from
Jul 17, 2019
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ object Decorators {
* give more info about type variables and to disambiguate where needed.
*/
def ex(args: Any*)(implicit ctx: Context): String =
explained(implicit ctx => em(args: _*))
explained(em(args: _*))
}

implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal {
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
//}
assert(!ctx.settings.YnoDeepSubtypes.value)
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2, approx)))
ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx)))
}
// Eliminate LazyRefs before checking whether we have seen a type before
val normalize = new TypeMap {
Expand Down Expand Up @@ -2307,15 +2307,15 @@ object TypeComparer {
*/
val FreshApprox: ApproxState = new ApproxState(4)

/** Show trace of comparison operations when performing `op` as result string */
def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = {
/** Show trace of comparison operations when performing `op` */
def explaining[T](say: String => Unit)(op: given Context => T)(implicit ctx: Context): T = {
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
res
}

/** Like [[explaining]], but returns the trace instead */
def explained[T](op: Context => T)(implicit ctx: Context): String = {
def explained[T](op: given Context => T)(implicit ctx: Context): String = {
var trace: String = null
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
trace
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ object Formatting {
* ex"disambiguate $tpe1 and $tpe2"
* ```
*/
def explained(op: Context => String)(implicit ctx: Context): String = {
def explained(op: given Context => String)(implicit ctx: Context): String = {
val seen = new Seen
val msg = op(explainCtx(seen))
val msg = op given explainCtx(seen)
val addendum = explanations(seen)
if (addendum.isEmpty) msg else msg ++ "\n\n" ++ addendum
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {

/** Is `tp1` a subtype of `tp2`? */
def isSubType(tp1: Type, tp2: Type): Boolean = {
debug.println(TypeComparer.explained(implicit ctx => tp1 <:< tp2))
debug.println(TypeComparer.explained(tp1 <:< tp2))
val res = (tp1 != nullType || tp2 == nullType) && tp1 <:< tp2
res
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ trait Implicits { self: Typer =>
case ex: AssertionError =>
implicits.println(s"view $from ==> $to")
implicits.println(ctx.typerState.constraint.show)
implicits.println(TypeComparer.explained(implicit ctx => from.tpe <:< to))
implicits.println(TypeComparer.explained(from.tpe <:< to))
throw ex
}
}
Expand Down