Skip to content

Commit 2dbf413

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

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
@@ -2657,7 +2657,10 @@ object Types {
26572657
}
26582658
}
26592659

2660-
trait MethodOrPoly extends LambdaType with MethodicType
2660+
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2661+
final override def hashCode = System.identityHashCode(this)
2662+
final override def equals(other: Any) = this `eq` other.asInstanceOf[AnyRef]
2663+
}
26612664

26622665
trait TermLambda extends LambdaType { thisLambdaType =>
26632666
import DepStatus._
@@ -2774,7 +2777,7 @@ object Types {
27742777
abstract case class MethodType(paramNames: List[TermName])(
27752778
paramInfosExp: MethodType => List[Type],
27762779
resultTypeExp: MethodType => Type)
2777-
extends CachedGroundType with MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
2780+
extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
27782781
import MethodType._
27792782

27802783
type This = MethodType
@@ -2791,28 +2794,6 @@ object Types {
27912794
def computeSignature(implicit ctx: Context): Signature =
27922795
resultSignature.prepend(paramInfos, isJavaMethod)
27932796

2794-
final override def computeHash = doHash(paramNames, resType, paramInfos)
2795-
2796-
final override def equals(that: Any) = that match {
2797-
case that: MethodType =>
2798-
paramNames == that.paramNames &&
2799-
paramInfos == that.paramInfos &&
2800-
resType == that.resType &&
2801-
companion.eq(that.companion)
2802-
case _ =>
2803-
false
2804-
}
2805-
2806-
final override def eql(that: Type) = that match {
2807-
case that: MethodType =>
2808-
paramNames.eqElements(that.paramNames) &&
2809-
paramInfos.eqElements(that.paramInfos) &&
2810-
resType.eq(that.resType) &&
2811-
companion.eq(that.companion)
2812-
case _ =>
2813-
false
2814-
}
2815-
28162797
protected def prefixString = "MethodType"
28172798
}
28182799

@@ -2970,7 +2951,7 @@ object Types {
29702951
*/
29712952
class PolyType(val paramNames: List[TypeName])(
29722953
paramInfosExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)
2973-
extends UncachedGroundType with MethodOrPoly with TypeLambda {
2954+
extends MethodOrPoly with TypeLambda {
29742955

29752956
type This = PolyType
29762957
def companion = PolyType

0 commit comments

Comments
 (0)