Skip to content

Commit 18dc149

Browse files
committed
Optimize widen
For typer/*.scala, we had 3.4M calls to widen, of which almost 3M were to the three cases that are now handled specially.
1 parent 04dacad commit 18dc149

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,18 @@ object Types {
10981098
* def o: Outer
10991099
* <o.x.type>.widen = o.C
11001100
*/
1101-
final def widen(using Context): Type = widenSingleton match {
1101+
final def widen(using Context): Type = this match
1102+
case _: TypeRef | _: MethodOrPoly => this // fast path for most frequent cases
1103+
case tp: TermRef => // fast path for next most frequent case
1104+
if tp.isOverloaded then tp else tp.underlying.widen
1105+
case tp: SingletonType => tp.underlying.widen
11021106
case tp: ExprType => tp.resultType.widen
1103-
case tp => tp
1104-
}
1107+
case tp =>
1108+
val tp1 = tp.stripTypeVar.stripAnnots
1109+
if tp1 eq tp then tp
1110+
else
1111+
val tp2 = tp1.widen
1112+
if tp2 ne tp1 then tp2 else tp
11051113

11061114
/** Widen from singleton type to its underlying non-singleton
11071115
* base type by applying one or more `underlying` dereferences.

0 commit comments

Comments
 (0)