Skip to content

Commit a527b10

Browse files
committed
Fix isFullyDefined trace
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.
1 parent d99d9bf commit a527b10

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
@@ -170,14 +170,18 @@ object Inferencing {
170170

171171
private var toMaximize: List[TypeVar] = Nil
172172

173-
def apply(x: Boolean, tp: Type): Boolean =
174-
try tp.dealias match
173+
def apply(x: Boolean, tp: Type): Boolean = trace(i"isFullyDefined($tp, $force)", typr) {
174+
try {
175+
val tpd = tp.dealias
176+
if tpd ne tp then apply(x, tpd)
177+
else tp match
175178
case _: WildcardType | _: ProtoType =>
176179
false
177180
case tvar: TypeVar if !tvar.isInstantiated =>
178181
force.appliesTo(tvar)
179182
&& ctx.typerState.constraint.contains(tvar)
180183
&& {
184+
var fail = false
181185
val direction = instDirection(tvar.origin)
182186
if minimizeSelected then
183187
if direction <= 0 && tvar.hasLowerBound then
@@ -190,17 +194,16 @@ object Inferencing {
190194
else if variance >= 0 && (force.ifBottom == IfBottom.ok || tvar.hasLowerBound) then
191195
instantiate(tvar, fromBelow = true)
192196
else if variance >= 0 && force.ifBottom == IfBottom.fail then
193-
return false
197+
fail = true
194198
else
195199
toMaximize = tvar :: toMaximize
196-
foldOver(x, tvar)
197-
}
198-
case tp =>
199-
reporting.trace(s"IFT $tp") {
200-
foldOver(x, tp)
200+
!fail && foldOver(x, tvar)
201201
}
202+
case tp => foldOver(x, tp)
203+
}
202204
catch case ex: Throwable =>
203205
handleRecursive("check fully defined", tp.show, ex)
206+
}
204207

205208
def process(tp: Type): Boolean =
206209
// 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)