Skip to content

Commit 5eaf651

Browse files
committed
Reorder pattern match based on frequency
foldOver total number of matches when compiling the dotty bootstrapped compiler (TypeRef,880390) (AppliedType,276595) (BoundType,122879) (ThisType,117388) (LambdaType,95690) (NoPrefix,94493) (TermRef,88508) (TypeVar,30322) (ExprType,16702) (TypeBounds,16432) (AndOrType,6234) (AnnotatedType,5948) (default,5252) (ProtoType,4044) (RefinedType,3270) (WildcardType,2064) (ClassInfo,1520) (JavaArrayType,516) (SkolemType,210) (TypeArgRef,98) (SuperType,77) (LazyRef,3)
1 parent 61f897c commit 5eaf651

File tree

1 file changed

+40
-48
lines changed

1 file changed

+40
-48
lines changed

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

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,14 +4198,6 @@ object Types {
41984198
val tp1 = tp.prefix.lookupRefined(tp.name)
41994199
if (tp1.exists) this(x, tp1) else applyToPrefix(x, tp)
42004200
}
4201-
case tp: TermRef =>
4202-
if (stopAtStatic && tp.currentSymbol.isStatic) x
4203-
else applyToPrefix(x, tp)
4204-
4205-
case _: ThisType
4206-
| _: BoundType
4207-
| NoPrefix => x
4208-
42094201
case tp @ AppliedType(tycon, args) =>
42104202
@tailrec def foldArgs(x: T, tparams: List[ParamInfo], args: List[Type]): T =
42114203
if (args.isEmpty) {
@@ -4221,10 +4213,20 @@ object Types {
42214213
foldArgs(acc, tparams.tail, args.tail)
42224214
}
42234215
foldArgs(this(x, tycon), tp.typeParams, args)
4224-
4225-
case tp: RefinedType =>
4226-
this(this(x, tp.parent), tp.refinedInfo)
4227-
4216+
case _: BoundType | _: ThisType => x
4217+
case tp: LambdaType =>
4218+
variance = -variance
4219+
val y = foldOver(x, tp.paramInfos)
4220+
variance = -variance
4221+
this(y, tp.resultType)
4222+
case NoPrefix => x
4223+
case tp: TermRef =>
4224+
if (stopAtStatic && tp.currentSymbol.isStatic) x
4225+
else applyToPrefix(x, tp)
4226+
case tp: TypeVar =>
4227+
this(x, tp.underlying)
4228+
case ExprType(restpe) =>
4229+
this(x, restpe)
42284230
case bounds @ TypeBounds(lo, hi) =>
42294231
if (lo eq hi) atVariance(0)(this(x, lo))
42304232
else {
@@ -4233,52 +4235,30 @@ object Types {
42334235
variance = -variance
42344236
this(y, hi)
42354237
}
4236-
4237-
case tp: RecType =>
4238-
this(x, tp.parent)
4239-
4240-
case ExprType(restpe) =>
4241-
this(x, restpe)
4242-
4243-
case tp: TypeVar =>
4244-
this(x, tp.underlying)
4245-
4246-
case SuperType(thistp, supertp) =>
4247-
this(this(x, thistp), supertp)
4248-
4249-
case tp @ ClassInfo(prefix, _, _, _, _) =>
4250-
this(x, prefix)
4251-
4252-
case tp: LambdaType =>
4253-
variance = -variance
4254-
val y = foldOver(x, tp.paramInfos)
4255-
variance = -variance
4256-
this(y, tp.resultType)
4257-
42584238
case tp: AndOrType =>
42594239
this(this(x, tp.tp1), tp.tp2)
4260-
4261-
case tp: SkolemType =>
4262-
this(x, tp.info)
4263-
4264-
case tp @ TypeArgRef(prefix, _, _) =>
4265-
atVariance(0)(this(x, prefix))
4266-
42674240
case AnnotatedType(underlying, annot) =>
42684241
this(applyToAnnot(x, annot), underlying)
4269-
4242+
case tp: ProtoType =>
4243+
tp.fold(x, this)
4244+
case tp: RefinedType =>
4245+
this(this(x, tp.parent), tp.refinedInfo)
42704246
case tp: WildcardType =>
42714247
this(x, tp.optBounds)
4272-
4248+
case tp @ ClassInfo(prefix, _, _, _, _) =>
4249+
this(x, prefix)
42734250
case tp: JavaArrayType =>
42744251
this(x, tp.elemType)
4275-
4252+
case tp: SkolemType =>
4253+
this(x, tp.info)
4254+
case tp @ TypeArgRef(prefix, _, _) =>
4255+
atVariance(0)(this(x, prefix))
4256+
case SuperType(thistp, supertp) =>
4257+
this(this(x, thistp), supertp)
42764258
case tp: LazyRef =>
42774259
this(x, tp.ref)
4278-
4279-
case tp: ProtoType =>
4280-
tp.fold(x, this)
4281-
4260+
case tp: RecType =>
4261+
this(x, tp.parent)
42824262
case _ => x
42834263
}}
42844264

@@ -4446,3 +4426,15 @@ object Types {
44464426

44474427
implicit def decorateTypeApplications(tpe: Type): TypeApplications = new TypeApplications(tpe)
44484428
}
4429+
4430+
object stats {
4431+
val map = scala.collection.mutable.LinkedHashMap.empty[String, Int]
4432+
4433+
def register(name: String): Unit = map.update(name, map.getOrElse(name, 0) + 1)
4434+
4435+
override def toString: String = {
4436+
("=" * 20) + "\n" +
4437+
map.toArray.sortBy(_._2).reverse.mkString("\n") +
4438+
"\n" + ("-" * 20)
4439+
}
4440+
}

0 commit comments

Comments
 (0)