Skip to content

Commit 25542cb

Browse files
authored
Fix isFullyDefined trace (#16748)
First, switch to the "i" interpolator and replace "IFT" with "isFullyDefined". Then apply it to the whole apply, and make the dealias appear in the trace. Requires fixing an early return usage. Also expose the ForceDegree specified. Found this in the course of enabling tracing and the typr printer and seeing lots of verbose type case classes printed.
2 parents c5c5aa6 + a527b10 commit 25542cb

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ object Formatting {
9090
given Show[util.SourceFile] = ShowAny
9191
given Show[util.Spans.Span] = ShowAny
9292
given Show[tasty.TreeUnpickler#OwnerTree] = ShowAny
93+
given Show[typer.ForceDegree.Value] = ShowAny
9394

9495
private def show1[A: Show](x: A)(using Context) = show2(Show[A].show(x).ctxShow)
9596
private def show2(x: Shown)(using Context): String = x match

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,18 @@ object Inferencing {
166166

167167
private var toMaximize: List[TypeVar] = Nil
168168

169-
def apply(x: Boolean, tp: Type): Boolean =
170-
try tp.dealias match
169+
def apply(x: Boolean, tp: Type): Boolean = trace(i"isFullyDefined($tp, $force)", typr) {
170+
try {
171+
val tpd = tp.dealias
172+
if tpd ne tp then apply(x, tpd)
173+
else tp match
171174
case _: WildcardType | _: ProtoType =>
172175
false
173176
case tvar: TypeVar if !tvar.isInstantiated =>
174177
force.appliesTo(tvar)
175178
&& ctx.typerState.constraint.contains(tvar)
176179
&& {
180+
var fail = false
177181
val direction = instDirection(tvar.origin)
178182
if minimizeSelected then
179183
if direction <= 0 && tvar.hasLowerBound then
@@ -186,17 +190,16 @@ object Inferencing {
186190
else if variance >= 0 && (force.ifBottom == IfBottom.ok && !tvar.hasUpperBound || tvar.hasLowerBound) then
187191
instantiate(tvar, fromBelow = true)
188192
else if variance >= 0 && force.ifBottom == IfBottom.fail then
189-
return false
193+
fail = true
190194
else
191195
toMaximize = tvar :: toMaximize
192-
foldOver(x, tvar)
193-
}
194-
case tp =>
195-
reporting.trace(s"IFT $tp") {
196-
foldOver(x, tp)
196+
!fail && foldOver(x, tvar)
197197
}
198+
case tp => foldOver(x, tp)
199+
}
198200
catch case ex: Throwable =>
199201
handleRecursive("check fully defined", tp.show, ex)
202+
}
200203

201204
def process(tp: Type): Boolean =
202205
// Maximize type vars in the order they were visited before */
@@ -767,13 +770,14 @@ trait Inferencing { this: Typer =>
767770
end constrainIfDependentParamRef
768771
}
769772

770-
/** An enumeration controlling the degree of forcing in "is-dully-defined" checks. */
773+
/** An enumeration controlling the degree of forcing in "is-fully-defined" checks. */
771774
@sharable object ForceDegree {
772-
class Value(val appliesTo: TypeVar => Boolean, val ifBottom: IfBottom)
773-
val none: Value = new Value(_ => false, IfBottom.ok)
774-
val all: Value = new Value(_ => true, IfBottom.ok)
775-
val failBottom: Value = new Value(_ => true, IfBottom.fail)
776-
val flipBottom: Value = new Value(_ => true, IfBottom.flip)
775+
class Value(val appliesTo: TypeVar => Boolean, val ifBottom: IfBottom):
776+
override def toString = s"ForceDegree.Value(.., $ifBottom)"
777+
val none: Value = new Value(_ => false, IfBottom.ok) { override def toString = "ForceDegree.none" }
778+
val all: Value = new Value(_ => true, IfBottom.ok) { override def toString = "ForceDegree.all" }
779+
val failBottom: Value = new Value(_ => true, IfBottom.fail) { override def toString = "ForceDegree.failBottom" }
780+
val flipBottom: Value = new Value(_ => true, IfBottom.flip) { override def toString = "ForceDegree.flipBottom" }
777781
}
778782

779783
enum IfBottom:

0 commit comments

Comments
 (0)