Skip to content

Commit 1a16f91

Browse files
author
Aleksander Boruch-Gruszecki
committed
Move TyperState.instType
1 parent 7e00b1b commit 1a16f91

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ trait ConstraintHandling {
5353
*/
5454
protected var comparedTypeLambdas: Set[TypeLambda] = Set.empty
5555

56+
/** Gives for each instantiated type var that does not yet have its `inst` field
57+
* set, the instance value stored in the constraint. Storing instances in constraints
58+
* is done only in a temporary way for contexts that may be retracted
59+
* without also retracting the type var as a whole.
60+
*/
61+
def instType(tvar: TypeVar): Type = constraint.entry(tvar.origin) match {
62+
case _: TypeBounds => NoType
63+
case tp: TypeParamRef =>
64+
var tvar1 = constraint.typeVarOfParam(tp)
65+
if (tvar1.exists) tvar1 else tp
66+
case tp => tp
67+
}
68+
5669
protected def addOneBound(param: TypeParamRef, bound: Type, isUpper: Boolean): Boolean =
5770
!constraint.contains(param) || {
5871
def occursIn(bound: Type): Boolean = {
@@ -140,6 +153,7 @@ trait ConstraintHandling {
140153
val lo1 = constraint.nonParamBounds(p1).lo
141154
val hi2 = constraint.nonParamBounds(p2).hi
142155
constr_println(i"adding $description down1 = $down1, up2 = $up2$location")
156+
assert(constraint.contains(p2))
143157
constraint = constraint.addLess(p1, p2)
144158
down1.forall(addOneBound(_, hi2, isUpper = true)) &&
145159
up2.forall(addOneBound(_, lo1, isUpper = false))

compiler/src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ class TyperState(previous: TyperState /* | Null */) {
7979
def ownedVars: TypeVars = myOwnedVars
8080
def ownedVars_=(vs: TypeVars): Unit = myOwnedVars = vs
8181

82-
/** Gives for each instantiated type var that does not yet have its `inst` field
83-
* set, the instance value stored in the constraint. Storing instances in constraints
84-
* is done only in a temporary way for contexts that may be retracted
85-
* without also retracting the type var as a whole.
86-
*/
87-
def instType(tvar: TypeVar)(implicit ctx: Context): Type = constraint.entry(tvar.origin) match {
88-
case _: TypeBounds => NoType
89-
case tp: TypeParamRef =>
90-
var tvar1 = constraint.typeVarOfParam(tp)
91-
if (tvar1.exists) tvar1 else tp
92-
case tp => tp
93-
}
94-
9582
/** The closest ancestor of this typer state (including possibly this typer state itself)
9683
* which is not yet committed, or which does not have a parent.
9784
*/
@@ -173,7 +160,7 @@ class TyperState(previous: TyperState /* | Null */) {
173160
val toCollect = new mutable.ListBuffer[TypeLambda]
174161
constraint foreachTypeVar { tvar =>
175162
if (!tvar.inst.exists) {
176-
val inst = instType(tvar)
163+
val inst = ctx.typeComparer.instType(tvar)
177164
if (inst.exists && (tvar.owningState.get eq this)) {
178165
tvar.inst = inst
179166
val lam = tvar.origin.binder

0 commit comments

Comments
 (0)