Skip to content

Commit 7de7efa

Browse files
Backport "Simple performance improvement for Denotations" to LTS (#22133)
Backports #21584 to the 3.3.5. PR submitted by the release tooling. [skip ci]
2 parents 0c5915c + 4ee9d5a commit 7de7efa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ object Types extends TypeUtils {
12621262
final def widen(using Context): Type = this match
12631263
case _: TypeRef | _: MethodOrPoly => this // fast path for most frequent cases
12641264
case tp: TermRef => // fast path for next most frequent case
1265-
if tp.isOverloaded then tp else tp.underlying.widen
1265+
val denot = tp.denot
1266+
if denot.isOverloaded then tp else denot.info.widen
12661267
case tp: SingletonType => tp.underlying.widen
12671268
case tp: ExprType => tp.resultType.widen
12681269
case tp =>
@@ -1276,15 +1277,20 @@ object Types extends TypeUtils {
12761277
* base type by applying one or more `underlying` dereferences.
12771278
*/
12781279
final def widenSingleton(using Context): Type = stripped match {
1279-
case tp: SingletonType if !tp.isOverloaded => tp.underlying.widenSingleton
1280+
case tp: TermRef =>
1281+
val denot = tp.denot
1282+
if denot.isOverloaded then this else denot.info.widenSingleton
1283+
case tp: SingletonType => tp.underlying.widenSingleton
12801284
case _ => this
12811285
}
12821286

12831287
/** Widen from TermRef to its underlying non-termref
12841288
* base type, while also skipping Expr types.
12851289
*/
12861290
final def widenTermRefExpr(using Context): Type = stripTypeVar match {
1287-
case tp: TermRef if !tp.isOverloaded => tp.underlying.widenExpr.widenTermRefExpr
1291+
case tp: TermRef =>
1292+
val denot = tp.denot
1293+
if denot.isOverloaded then this else denot.info.widenExpr.widenTermRefExpr
12881294
case _ => this
12891295
}
12901296

0 commit comments

Comments
 (0)