Skip to content

Commit 9634f1b

Browse files
committed
avoid unnecessary recursion
1 parent 9128823 commit 9634f1b

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
@@ -601,7 +601,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
601601
def instantiate(tp1: Type, tp2: Type)(implicit ctx: Context): Type = {
602602
// map `ThisType` of `tp1` to a type variable
603603
// precondition: `tp1` should have the shape `path.Child`, thus `ThisType` is always covariant
604-
val thisTypeMap = new TypeMap {
604+
def childTypeMap(implicit ctx: Context) = new TypeMap {
605605
def apply(t: Type): Type = t.dealias match {
606606
case tp @ ThisType(tref) if !tref.symbol.isStaticOwner =>
607607
if (tref.symbol.is(Module)) mapOver(tref)
@@ -623,7 +623,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
623623
}
624624

625625
// replace type parameter references with bounds
626-
val typeParamMap = new TypeMap {
626+
def parentTypeMap(implicit ctx: Context) = new TypeMap {
627627
def apply(t: Type): Type = t.dealias match {
628628
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
629629
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
@@ -640,7 +640,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
640640
}
641641

642642
// replace uninstantiated type vars with WildcardType, check tests/patmat/3333.scala
643-
val instUndetMap = new TypeMap {
643+
def instUndetMap(implicit ctx: Context) = new TypeMap {
644644
def apply(t: Type): Type = t match {
645645
case tvar: TypeVar if !tvar.isInstantiated => WildcardType(tvar.origin.underlying.bounds)
646646
case _ => mapOver(t)
@@ -653,27 +653,27 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
653653
)
654654

655655
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
656-
val protoTp1 = thisTypeMap(tp1.appliedTo(tvars))
656+
val protoTp1 = childTypeMap.apply(tp1.appliedTo(tvars))
657657

658658
// If parent contains a reference to an abstract type, then we should
659659
// refine subtype checking to eliminate abstract types according to
660660
// variance. As this logic is only needed in exhaustivity check, thus
661661
// we manually patch subtyping check instead of changing TypeComparer.
662662
// See tests/patmat/3645b.scala
663663
def parentQualify = tp1.widen.classSymbol.info.parents.exists { parent =>
664-
(parent.argInfos.nonEmpty || parent.abstractTypeMembers.nonEmpty) &&
665-
instantiate(parent, tp2)(ctx.fresh.setNewTyperState()).exists
664+
implicit val ictx = ctx.fresh.setNewTyperState()
665+
parent.argInfos.nonEmpty && childTypeMap.apply(parent) <:< parentTypeMap.apply(tp2)
666666
}
667667

668668
if (protoTp1 <:< tp2) {
669669
if (isFullyDefined(protoTp1, force)) protoTp1
670-
else instUndetMap(protoTp1)
670+
else instUndetMap.apply(protoTp1)
671671
}
672672
else {
673-
val protoTp2 = typeParamMap(tp2)
673+
val protoTp2 = parentTypeMap.apply(tp2)
674674
if (protoTp1 <:< protoTp2 || parentQualify) {
675675
if (isFullyDefined(AndType(protoTp1, protoTp2), force)) protoTp1
676-
else instUndetMap(protoTp1)
676+
else instUndetMap.apply(protoTp1)
677677
}
678678
else {
679679
debug.println(s"$protoTp1 <:< $protoTp2 = false")

0 commit comments

Comments
 (0)