Skip to content

Commit

Permalink
[nomaster] SI-8152 Backport variance validator performance fix
Browse files Browse the repository at this point in the history
	% 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
retronym committed Jan 14, 2014
1 parent a812241 commit 9df2dcc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -909,11 +909,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
// case DeBruijnIndex(_, _) =>
case SingleType(pre, sym) =>
validateVariance(pre, variance)
case TypeRef(_, sym, _) if sym.isAliasType =>
// okay to ignore pre/args here. In 2.10.3 we used to check them in addition to checking
// the normalized type, which led to exponential time type checking, see pos/t8152-performance.scala
validateVariance(tp.normalize, variance)
case TypeRef(pre, sym, args) =>
// println("validate "+sym+" at "+relativeVariance(sym))
if (sym.isAliasType/* && relativeVariance(sym) == AnyVariance*/)
validateVariance(tp.normalize, variance)
else if (sym.variance != NoVariance) {
if (sym.variance != NoVariance) {
val v = relativeVariance(sym)
if (v != AnyVariance && sym.variance != v * variance) {
//Console.println("relativeVariance(" + base + "," + sym + ") = " + v);//DEBUG
Expand Down
13 changes: 13 additions & 0 deletions test/files/pos/t8152-performance.scala
@@ -0,0 +1,13 @@
class HListBench {

class A[H, T]

type B[H, T] = A[H, T]

// was okay
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]]]]]]]]]]]]]]]]]]]]]]]]]]]]

// Took over a minute to validate variance in 2.10.3!
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]]]]]]]]]]]]]]]]]]]]]]]]]]]]

}

2 comments on commit 9df2dcc

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


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

@aloiscochard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @retronym!

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

Please sign in to comment.