Skip to content

Commit 57661ee

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 57661ee

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,13 +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
42084201

42094202
case tp @ AppliedType(tycon, args) =>
42104203
@tailrec def foldArgs(x: T, tparams: List[ParamInfo], args: List[Type]): T =
@@ -4222,8 +4215,25 @@ object Types {
42224215
}
42234216
foldArgs(this(x, tycon), tp.typeParams, args)
42244217

4225-
case tp: RefinedType =>
4226-
this(this(x, tp.parent), tp.refinedInfo)
4218+
case _: BoundType | _: ThisType => x
4219+
4220+
case tp: LambdaType =>
4221+
variance = -variance
4222+
val y = foldOver(x, tp.paramInfos)
4223+
variance = -variance
4224+
this(y, tp.resultType)
4225+
4226+
case NoPrefix => x
4227+
4228+
case tp: TermRef =>
4229+
if (stopAtStatic && tp.currentSymbol.isStatic) x
4230+
else applyToPrefix(x, tp)
4231+
4232+
case tp: TypeVar =>
4233+
this(x, tp.underlying)
4234+
4235+
case ExprType(restpe) =>
4236+
this(x, restpe)
42274237

42284238
case bounds @ TypeBounds(lo, hi) =>
42294239
if (lo eq hi) atVariance(0)(this(x, lo))
@@ -4234,50 +4244,41 @@ object Types {
42344244
this(y, hi)
42354245
}
42364246

4237-
case tp: RecType =>
4238-
this(x, tp.parent)
4247+
case tp: AndOrType =>
4248+
this(this(x, tp.tp1), tp.tp2)
42394249

4240-
case ExprType(restpe) =>
4241-
this(x, restpe)
4250+
case AnnotatedType(underlying, annot) =>
4251+
this(applyToAnnot(x, annot), underlying)
42424252

4243-
case tp: TypeVar =>
4244-
this(x, tp.underlying)
4253+
case tp: ProtoType =>
4254+
tp.fold(x, this)
42454255

4246-
case SuperType(thistp, supertp) =>
4247-
this(this(x, thistp), supertp)
4256+
case tp: RefinedType =>
4257+
this(this(x, tp.parent), tp.refinedInfo)
4258+
4259+
case tp: WildcardType =>
4260+
this(x, tp.optBounds)
42484261

42494262
case tp @ ClassInfo(prefix, _, _, _, _) =>
42504263
this(x, prefix)
42514264

4252-
case tp: LambdaType =>
4253-
variance = -variance
4254-
val y = foldOver(x, tp.paramInfos)
4255-
variance = -variance
4256-
this(y, tp.resultType)
4257-
4258-
case tp: AndOrType =>
4259-
this(this(x, tp.tp1), tp.tp2)
4265+
case tp: JavaArrayType =>
4266+
this(x, tp.elemType)
42604267

42614268
case tp: SkolemType =>
42624269
this(x, tp.info)
42634270

42644271
case tp @ TypeArgRef(prefix, _, _) =>
42654272
atVariance(0)(this(x, prefix))
42664273

4267-
case AnnotatedType(underlying, annot) =>
4268-
this(applyToAnnot(x, annot), underlying)
4269-
4270-
case tp: WildcardType =>
4271-
this(x, tp.optBounds)
4272-
4273-
case tp: JavaArrayType =>
4274-
this(x, tp.elemType)
4274+
case SuperType(thistp, supertp) =>
4275+
this(this(x, thistp), supertp)
42754276

42764277
case tp: LazyRef =>
42774278
this(x, tp.ref)
42784279

4279-
case tp: ProtoType =>
4280-
tp.fold(x, this)
4280+
case tp: RecType =>
4281+
this(x, tp.parent)
42814282

42824283
case _ => x
42834284
}}

0 commit comments

Comments
 (0)