Skip to content

Commit 6745a85

Browse files
committed
Optimize replaceSingletons
Avoid formation of full bounds.
1 parent cc28980 commit 6745a85

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,16 @@ object Inferencing {
149149
tp match {
150150
case param: TypeParamRef =>
151151
val constraint = ctx.typerState.constraint
152-
if (constraint.contains(param) &&
153-
(constraint.fullUpperBound(param) frozen_<:< constraint.fullLowerBound(param))) {
154-
typr.println(i"replace singleton $param := ${constraint.fullLowerBound(param)}")
155-
ctx.typerState.constraint = constraint.replace(param,
156-
ctx.typeComparer.approximation(param, fromBelow = true))
152+
constraint.entry(param) match {
153+
case TypeBounds(lo, hi)
154+
if constraint.lower(param).isEmpty && constraint.upper(param).isEmpty &&
155+
hi <:< lo =>
156+
// if lower or upper is nonEmpty, the full bounds can't be equal, since
157+
// common type params in lower and upper are eliminated through unification
158+
typr.println(i"replace singleton $param := ${constraint.fullLowerBound(param)}")
159+
ctx.typerState.constraint = constraint.replace(param,
160+
ctx.typeComparer.approximation(param, fromBelow = true))
161+
case _ =>
157162
}
158163
case _ =>
159164
}

0 commit comments

Comments
 (0)