Skip to content

Commit be10596

Browse files
authored
Simple performance improvement for Denotations (scala#21584)
A simple performance improvement extracted from scala#21278. This PR reduces `denot` calls in `widen`s. This is a simpler approach which can reduce the compilation time of scala#20217 from 60s to about 40s.
2 parents 65a53b5 + d9e13e5 commit be10596

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
@@ -1311,7 +1311,8 @@ object Types extends TypeUtils {
13111311
final def widen(using Context): Type = this match
13121312
case _: TypeRef | _: MethodOrPoly => this // fast path for most frequent cases
13131313
case tp: TermRef => // fast path for next most frequent case
1314-
if tp.isOverloaded then tp else tp.underlying.widen
1314+
val denot = tp.denot
1315+
if denot.isOverloaded then tp else denot.info.widen
13151316
case tp: SingletonType => tp.underlying.widen
13161317
case tp: ExprType => tp.resultType.widen
13171318
case tp =>
@@ -1325,15 +1326,20 @@ object Types extends TypeUtils {
13251326
* base type by applying one or more `underlying` dereferences.
13261327
*/
13271328
final def widenSingleton(using Context): Type = stripped match {
1328-
case tp: SingletonType if !tp.isOverloaded => tp.underlying.widenSingleton
1329+
case tp: TermRef =>
1330+
val denot = tp.denot
1331+
if denot.isOverloaded then this else denot.info.widenSingleton
1332+
case tp: SingletonType => tp.underlying.widenSingleton
13291333
case _ => this
13301334
}
13311335

13321336
/** Widen from TermRef to its underlying non-termref
13331337
* base type, while also skipping Expr types.
13341338
*/
13351339
final def widenTermRefExpr(using Context): Type = stripTypeVar match {
1336-
case tp: TermRef if !tp.isOverloaded => tp.underlying.widenExpr.widenTermRefExpr
1340+
case tp: TermRef =>
1341+
val denot = tp.denot
1342+
if denot.isOverloaded then this else denot.info.widenExpr.widenTermRefExpr
13371343
case _ => this
13381344
}
13391345

0 commit comments

Comments
 (0)