Skip to content

Commit 07f09cc

Browse files
committed
Simplify AndType.make logic
Use a boolean instead of a lambda for efficiency.
1 parent e125525 commit 07f09cc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ object Types {
22192219

22202220
def derivedAndType(tp1: Type, tp2: Type)(implicit ctx: Context): Type =
22212221
if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this
2222-
else AndType.make(tp1, tp2, AndType.apply)
2222+
else AndType.make(tp1, tp2, checkValid = true)
22232223

22242224
def derived_& (tp1: Type, tp2: Type)(implicit ctx: Context): Type =
22252225
if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this
@@ -2247,13 +2247,13 @@ object Types {
22472247
/** Make an AndType using `op` unless clearly unnecessary (i.e. without
22482248
* going through `&`).
22492249
*/
2250-
def make(tp1: Type, tp2: Type, op: (Type, Type) => AndType)(implicit ctx: Context): Type =
2250+
def make(tp1: Type, tp2: Type, checkValid: Boolean = false)(implicit ctx: Context): Type =
22512251
if ((tp1 eq tp2) || (tp2 eq defn.AnyType))
22522252
tp1
22532253
else if (tp1 eq defn.AnyType)
22542254
tp2
22552255
else
2256-
op(tp1, tp2)
2256+
if (checkValid) apply(tp1, tp2) else unchecked(tp1, tp2)
22572257
}
22582258

22592259
abstract case class OrType(tp1: Type, tp2: Type) extends CachedGroundType with AndOrType {

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,18 @@ trait ImplicitRunInfo { self: RunInfo =>
374374
case tp: TypeRef if tp.symbol.isAbstractOrAliasType =>
375375
val pre = tp.prefix
376376
def joinClass(tp: Type, cls: ClassSymbol) =
377-
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner), AndType.unchecked)
377+
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner))
378378
val lead = if (tp.prefix eq NoPrefix) defn.AnyType else apply(tp.prefix)
379379
(lead /: tp.classSymbols)(joinClass)
380380
case tp: TypeVar =>
381381
apply(tp.underlying)
382382
case tp: HKApply =>
383383
def applyArg(arg: Type) = arg match {
384-
case TypeBounds(lo, hi) => AndType.make(lo, hi, AndType.unchecked)
384+
case TypeBounds(lo, hi) => AndType.make(lo, hi)
385385
case _: WildcardType => defn.AnyType
386386
case _ => arg
387387
}
388-
(apply(tp.tycon) /: tp.args)((tc, arg) => AndType.make(tc, applyArg(arg), AndType.unchecked))
388+
(apply(tp.tycon) /: tp.args)((tc, arg) => AndType.make(tc, applyArg(arg)))
389389
case tp: TypeLambda =>
390390
apply(tp.resType)
391391
case _ =>

0 commit comments

Comments
 (0)