Skip to content
This repository
Browse code

[nomaster] SI-8152 Backport variance validator performance fix

	% time qbin/scalac test/files/pos/t8146-performance.scala

	real	0m2.015s
	user	0m2.892s
	sys	0m0.215s

	% time scalac-hash v2.10.3 test/files/pos/t8146-performance.scala

	real	1m13.652s
	user	1m14.245s
	sys	0m0.508s

Cherry-picks one hunk from 882f8e6.
  • Loading branch information...
commit 9df2dcc58439cf75420da68d4e6d9bb5504aabb4 1 parent a812241
Jason Zaugg authored January 14, 2014
8  src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -909,11 +909,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
909 909
           // case DeBruijnIndex(_, _) =>
910 910
           case SingleType(pre, sym) =>
911 911
             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)
912 916
           case TypeRef(pre, sym, args) =>
913 917
 //            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) {
917 919
               val v = relativeVariance(sym)
918 920
               if (v != AnyVariance && sym.variance != v * variance) {
919 921
                 //Console.println("relativeVariance(" + base + "," + sym + ") = " + v);//DEBUG
13  test/files/pos/t8152-performance.scala
... ...
@@ -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
+}

2 notes on commit 9df2dcc

scala-jenkins
Collaborator

Job pr-scala failed for 9df2dcc Took 50 min. (ping @retronym) (results):


To retry exactly this commit, comment "PLS REBUILD/pr-scala@9df2dcc" on PR 3364.
NOTE: New commits are rebuilt automatically as they appear. A forced rebuild is only necessary for transient failures.

Alois Cochard

Awesome @retronym!

I'm looking forward to see the impact on shapeless compilation time! /cc @milessabin

Please sign in to comment.
Something went wrong with that request. Please try again.