Skip to content

Commit baaa562

Browse files
oderskysmarter
authored andcommitted
Optimize replaceSingletons
Avoid formation of full bounds.
1 parent 18ce5d2 commit baaa562

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-
(ctx.typerComparer.fullUpperBound(param) frozen_<:< ctx.typecomparer.fullLowerBound(param))) {
154-
typr.println(i"replace singleton $param := ${ctx.typeComparer.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 frozen_<:< 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+
val inst = ctx.typeComparer.approximation(param, fromBelow = true)
159+
typr.println(i"replace singleton $param := $inst")
160+
ctx.typerState.constraint = constraint.replace(param, inst)
161+
case _ =>
157162
}
158163
case _ =>
159164
}

0 commit comments

Comments
 (0)