Skip to content

Commit f282783

Browse files
committed
address review
1 parent eec6854 commit f282783

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/transform/IsInstanceOfChecker.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ object Checkable {
6767
def isAbstract(P: Type) = !P.dealias.typeSymbol.isClass
6868
def isPatternTypeSymbol(sym: Symbol) = !sym.isClass && sym.is(Case)
6969

70-
def replaceP(implicit ctx: Context) = new TypeMap {
70+
def replaceP(tp: Type)(implicit ctx: Context) = new TypeMap {
7171
def apply(tp: Type) = tp match {
7272
case tref: TypeRef
7373
if isPatternTypeSymbol(tref.typeSymbol) => WildcardType
7474
case AnnotatedType(_, annot)
7575
if annot.symbol == defn.UncheckedAnnot => WildcardType
7676
case _ => mapOver(tp)
7777
}
78-
}
78+
}.apply(tp)
7979

80-
def replaceX(implicit ctx: Context) = new TypeMap {
80+
def replaceX(tp: Type)(implicit ctx: Context) = new TypeMap {
8181
def apply(tp: Type) = tp match {
8282
case tref: TypeRef
8383
if isPatternTypeSymbol(tref.typeSymbol) =>
@@ -86,18 +86,19 @@ object Checkable {
8686
else OrType(defn.AnyType, defn.NothingType)
8787
case _ => mapOver(tp)
8888
}
89-
}
89+
}.apply(tp)
9090

91-
def stripTypeParam(implicit ctx: Context) = new ApproximatingTypeMap {
91+
/** Approximate type parameters depending on variance */
92+
def stripTypeParam(tp: Type)(implicit ctx: Context) = new ApproximatingTypeMap {
9293
def apply(tp: Type): Type = tp match {
9394
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
94-
val lo = this(tp.info.loBound)
95-
val hi = this(tp.info.hiBound)
95+
val lo = apply(tp.info.loBound)
96+
val hi = apply(tp.info.hiBound)
9697
range(lo, hi)
9798
case _ =>
9899
mapOver(tp)
99100
}
100-
}
101+
}.apply(tp)
101102

102103
def isClassDetermined(X: Type, P: AppliedType)(implicit ctx: Context) = {
103104
val AppliedType(tycon, _) = P
@@ -131,16 +132,17 @@ object Checkable {
131132
case _ => recur(defn.AnyType, tpT)
132133
}
133134
case tpe: AppliedType =>
135+
// first try withou striping type parameters for performance
134136
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) ||
135-
isClassDetermined(stripTypeParam.apply(X), tpe)(ctx.fresh.setNewTyperState())
137+
isClassDetermined(stripTypeParam(X), tpe)(ctx.fresh.setNewTyperState())
136138
case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)
137139
case OrType(tp1, tp2) => recur(X, tp1) && recur(X, tp2)
138140
case AnnotatedType(t, _) => recur(X, t)
139141
case _: RefinedType => false
140142
case _ => true
141143
})
142144

143-
val res = recur(replaceX.apply(X.widen), replaceP.apply(P))
145+
val res = recur(replaceX(X.widen), replaceP(P))
144146

145147
debug.println(i"checking ${X.show} isInstanceOf ${P} = $res")
146148

0 commit comments

Comments
 (0)