Skip to content

Commit b3ad753

Browse files
committed
Merge pull request scala#3364 from retronym/ticket/8152
[nomaster] Backport variance validator performance fix
2 parents d5801b9 + 9df2dcc commit b3ad753

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
909909
// case DeBruijnIndex(_, _) =>
910910
case SingleType(pre, sym) =>
911911
validateVariance(pre, variance)
912+
case TypeRef(_, sym, _) if sym.isAliasType =>
913+
// okay to ignore pre/args here. In 2.10.3 we used to check them in addition to checking
914+
// the normalized type, which led to exponential time type checking, see pos/t8152-performance.scala
915+
validateVariance(tp.normalize, variance)
912916
case TypeRef(pre, sym, args) =>
913917
// println("validate "+sym+" at "+relativeVariance(sym))
914-
if (sym.isAliasType/* && relativeVariance(sym) == AnyVariance*/)
915-
validateVariance(tp.normalize, variance)
916-
else if (sym.variance != NoVariance) {
918+
if (sym.variance != NoVariance) {
917919
val v = relativeVariance(sym)
918920
if (v != AnyVariance && sym.variance != v * variance) {
919921
//Console.println("relativeVariance(" + base + "," + sym + ") = " + v);//DEBUG
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class HListBench {
2+
3+
class A[H, T]
4+
5+
type B[H, T] = A[H, T]
6+
7+
// was okay
8+
type T1 = A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, A[Int, Nothing]]]]]]]]]]]]]]]]]]]]]]]]]]]]
9+
10+
// Took over a minute to validate variance in 2.10.3!
11+
type T2 = B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, B[Int, Nothing]]]]]]]]]]]]]]]]]]]]]]]]]]]]
12+
13+
}

0 commit comments

Comments
 (0)