Skip to content

Commit abbdc24

Browse files
committed
avoid unnecessary recursion
1 parent f20da6b commit abbdc24

File tree

1 file changed

+9
-9
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+9
-9
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
582582
def instantiate(tp1: Type, tp2: Type)(implicit ctx: Context): Type = {
583583
// map `ThisType` of `tp1` to a type variable
584584
// precondition: `tp1` should have the shape `path.Child`, thus `ThisType` is always covariant
585-
val thisTypeMap = new TypeMap {
585+
def childTypeMap(implicit ctx: Context) = new TypeMap {
586586
def apply(t: Type): Type = t.dealias match {
587587
case tp @ ThisType(tref) if !tref.symbol.isStaticOwner =>
588588
if (tref.symbol.is(Module)) mapOver(tref)
@@ -604,7 +604,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
604604
}
605605

606606
// replace type parameter references with bounds
607-
val typeParamMap = new TypeMap {
607+
def parentTypeMap(implicit ctx: Context) = new TypeMap {
608608
def apply(t: Type): Type = t.dealias match {
609609
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
610610
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
@@ -621,7 +621,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
621621
}
622622

623623
// replace uninstantiated type vars with WildcardType, check tests/patmat/3333.scala
624-
val instUndetMap = new TypeMap {
624+
def instUndetMap(implicit ctx: Context) = new TypeMap {
625625
def apply(t: Type): Type = t match {
626626
case tvar: TypeVar if !tvar.isInstantiated => WildcardType(tvar.origin.underlying.bounds)
627627
case _ => mapOver(t)
@@ -634,27 +634,27 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
634634
)
635635

636636
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
637-
val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
637+
val protoTp1 = childTypeMap.apply(tp1.appliedTo(tvars))
638638

639639
// If parent contains a reference to an abstract type, then we should
640640
// refine subtype checking to eliminate abstract types according to
641641
// variance. As this logic is only needed in exhaustivity check, thus
642642
// we manually patch subtyping check instead of changing TypeComparer.
643643
// See tests/patmat/3645b.scala
644644
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
645-
(parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
646-
instantiate(parent, tp2)(ctx.fresh.setNewTyperState()).exists
645+
implicit val ictx = ctx.fresh.setNewTyperState()
646+
parent.argInfos.nonEmpty && childTypeMap.apply(parent) <:< parentTypeMap.apply(tp2)
647647
}
648648

649649
if (protoTp1 <:< tp2) {
650650
if (isFullyDefined(protoTp1, force)) protoTp1
651-
else instUndetMap(protoTp1)
651+
else instUndetMap.apply(protoTp1)
652652
}
653653
else {
654-
val protoTp2 = typeParamMap(tp2)
654+
val protoTp2 = parentTypeMap.apply(tp2)
655655
if (protoTp1 <:< protoTp2 || parentQualify) {
656656
if (isFullyDefined(AndType(protoTp1, protoTp2), force)) protoTp1
657-
else instUndetMap(protoTp1)
657+
else instUndetMap.apply(protoTp1)
658658
}
659659
else {
660660
debug.println(s"$protoTp1 <:< $protoTp2 = false")

0 commit comments

Comments
 (0)