Skip to content

Commit b749b0f

Browse files
author
Aleksander Boruch-Gruszecki
committed
Clean up SmartGADTMap#addBound
1 parent 3084bf9 commit b749b0f

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,11 @@ object Contexts {
811811
res
812812
}
813813

814+
def unify(tv: TypeVar, tp: Type): Unit = {
815+
gadts.println(i"manually unifying $tv with $tp")
816+
constraint = constraint.updateEntry(tv.origin, tp)
817+
}
818+
814819
val symTvar: TypeVar = stripInst(tvar(sym)) match {
815820
case tv: TypeVar => tv
816821
case inst =>
@@ -819,37 +824,22 @@ object Contexts {
819824
return true
820825
}
821826

822-
def doAddBound(bound: Type): Boolean = {
823-
val res = stripInst(bound) match {
824-
case boundTvar: TypeVar =>
825-
if (boundTvar eq symTvar) true
826-
else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
827-
else addLess(boundTvar.origin, symTvar.origin)
828-
case bound =>
829-
if (cautiousSubtype(symTvar, bound, isSubtype = !isUpper)) { unify(symTvar, bound); true }
830-
else if (isUpper) addUpperBound(symTvar.origin, bound)
831-
else addLowerBound(symTvar.origin, bound)
832-
}
833-
834-
res
835-
}
836-
837-
def unify(tv: TypeVar, tp: Type): Unit = {
838-
gadts.println(i"manually unifying $tv with $tp")
839-
constraint = constraint.updateEntry(tv.origin, tp)
840-
}
841-
842-
val tvarBound = (new TypeVarInsertingMap()(ctx))(bound)
843-
val res = tvarBound match {
827+
val internalizedBound = (new TypeVarInsertingMap()(ctx))(bound)
828+
val res = stripInst(internalizedBound) match {
844829
case boundTvar: TypeVar =>
845-
doAddBound(boundTvar)
846-
case tp => doAddBound(tp)
830+
if (boundTvar eq symTvar) true
831+
else if (isUpper) addLess(symTvar.origin, boundTvar.origin)
832+
else addLess(boundTvar.origin, symTvar.origin)
833+
case bound =>
834+
if (cautiousSubtype(symTvar, bound, isSubtype = !isUpper)) { unify(symTvar, bound); true }
835+
else if (isUpper) addUpperBound(symTvar.origin, bound)
836+
else addLowerBound(symTvar.origin, bound)
847837
}
848838

849839
gadts.println {
850840
val descr = if (isUpper) "upper" else "lower"
851841
val op = if (isUpper) "<:" else ">:"
852-
i"adding $descr bound $sym $op $bound = $res\t( $symTvar $op $tvarBound )"
842+
i"adding $descr bound $sym $op $bound = $res\t( $symTvar $op $internalizedBound )"
853843
}
854844
res
855845
} finally checkInProgress = false

0 commit comments

Comments
 (0)