Skip to content

Reorder match based on frequency #3262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 46 additions & 41 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4198,13 +4198,6 @@ object Types {
val tp1 = tp.prefix.lookupRefined(tp.name)
if (tp1.exists) this(x, tp1) else applyToPrefix(x, tp)
}
case tp: TermRef =>
if (stopAtStatic && tp.currentSymbol.isStatic) x
else applyToPrefix(x, tp)

case _: ThisType
| _: BoundType
| NoPrefix => x

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

case tp: RefinedType =>
this(this(x, tp.parent), tp.refinedInfo)
case _: BoundType | _: ThisType => x

case tp: LambdaType =>
variance = -variance
val y = foldOver(x, tp.paramInfos)
variance = -variance
this(y, tp.resultType)

case NoPrefix => x

case tp: TermRef =>
if (stopAtStatic && tp.currentSymbol.isStatic) x
else applyToPrefix(x, tp)

case tp: TypeVar =>
this(x, tp.underlying)

case ExprType(restpe) =>
this(x, restpe)

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

case tp: RecType =>
this(x, tp.parent)
case tp: AndOrType =>
this(this(x, tp.tp1), tp.tp2)

case ExprType(restpe) =>
this(x, restpe)
case AnnotatedType(underlying, annot) =>
this(applyToAnnot(x, annot), underlying)

case tp: TypeVar =>
this(x, tp.underlying)
case tp: ProtoType =>
tp.fold(x, this)

case SuperType(thistp, supertp) =>
this(this(x, thistp), supertp)
case tp: RefinedType =>
this(this(x, tp.parent), tp.refinedInfo)

case tp: WildcardType =>
this(x, tp.optBounds)

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

case tp: LambdaType =>
variance = -variance
val y = foldOver(x, tp.paramInfos)
variance = -variance
this(y, tp.resultType)

case tp: AndOrType =>
this(this(x, tp.tp1), tp.tp2)
case tp: JavaArrayType =>
this(x, tp.elemType)

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

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

case AnnotatedType(underlying, annot) =>
this(applyToAnnot(x, annot), underlying)

case tp: WildcardType =>
this(x, tp.optBounds)

case tp: JavaArrayType =>
this(x, tp.elemType)
case SuperType(thistp, supertp) =>
this(this(x, thistp), supertp)

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

case tp: ProtoType =>
tp.fold(x, this)
case tp: RecType =>
this(x, tp.parent)

case _ => x
}}
Expand Down Expand Up @@ -4314,19 +4315,23 @@ object Types {
else {
seen += tp
tp match {
case tp: TermRef =>
apply(foldOver(maybeAdd(x, tp), tp), tp.underlying)
case tp: TypeRef =>
foldOver(maybeAdd(x, tp), tp)
case tp: ThisType =>
apply(x, tp.tref)
case NoPrefix =>
foldOver(x, tp)
case tp: TermRef =>
apply(foldOver(maybeAdd(x, tp), tp), tp.underlying)
case tp: AppliedType =>
foldOver(x, tp)
case TypeBounds(lo, hi) =>
if (!excludeLowerBounds) apply(x, lo)
apply(x, hi)
case tp: ThisType =>
apply(x, tp.tref)
case tp: ConstantType =>
apply(x, tp.underlying)
case tp: ParamRef =>
apply(x, tp.underlying)
case tp: ConstantType =>
apply(x, tp.underlying)
case _ =>
foldOver(x, tp)
}
Expand Down
Loading