Skip to content

Commit f00e883

Browse files
committed
Make MethodTypes uncached
Since correct hashing under binders seems to be very expensive (see performance data for scala#3970), let's try have fewer types that require this.
1 parent 668c499 commit f00e883

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,10 @@ object Types {
26662666
}
26672667
}
26682668

2669-
trait MethodOrPoly extends LambdaType with MethodicType
2669+
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2670+
final override def hashCode = System.identityHashCode(this)
2671+
final override def equals(other: Any) = this `eq` other.asInstanceOf[AnyRef]
2672+
}
26702673

26712674
trait TermLambda extends LambdaType { thisLambdaType =>
26722675
import DepStatus._
@@ -2783,7 +2786,7 @@ object Types {
27832786
abstract case class MethodType(paramNames: List[TermName])(
27842787
paramInfosExp: MethodType => List[Type],
27852788
resultTypeExp: MethodType => Type)
2786-
extends CachedGroundType with MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
2789+
extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
27872790
import MethodType._
27882791

27892792
type This = MethodType
@@ -2800,28 +2803,6 @@ object Types {
28002803
def computeSignature(implicit ctx: Context): Signature =
28012804
resultSignature.prepend(paramInfos, isJavaMethod)
28022805

2803-
final override def computeHash = doHash(paramNames, resType, paramInfos)
2804-
2805-
final override def equals(that: Any) = that match {
2806-
case that: MethodType =>
2807-
paramNames == that.paramNames &&
2808-
paramInfos == that.paramInfos &&
2809-
resType == that.resType &&
2810-
companion.eq(that.companion)
2811-
case _ =>
2812-
false
2813-
}
2814-
2815-
final override def eql(that: Type) = that match {
2816-
case that: MethodType =>
2817-
paramNames.eqElements(that.paramNames) &&
2818-
paramInfos.eqElements(that.paramInfos) &&
2819-
resType.eq(that.resType) &&
2820-
companion.eq(that.companion)
2821-
case _ =>
2822-
false
2823-
}
2824-
28252806
protected def prefixString = "MethodType"
28262807
}
28272808

@@ -2979,7 +2960,7 @@ object Types {
29792960
*/
29802961
class PolyType(val paramNames: List[TypeName])(
29812962
paramInfosExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)
2982-
extends UncachedGroundType with MethodOrPoly with TypeLambda {
2963+
extends MethodOrPoly with TypeLambda {
29832964

29842965
type This = PolyType
29852966
def companion = PolyType

0 commit comments

Comments
 (0)