Skip to content

Commit 0c63930

Browse files
committed
Revert: Cache all method and polytypes (reverted from commit c0e7113)
1 parent d4764c5 commit 0c63930

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,6 @@ object Types {
26632663
final def isHigherKinded = isInstanceOf[TypeProxy]
26642664

26652665
private[this] var myParamRefs: List[ParamRefType] = null
2666-
private[this] var myStableHash: Byte = 0
26672666

26682667
def paramRefs: List[ParamRefType] = {
26692668
if (myParamRefs == null) myParamRefs = paramNames.indices.toList.map(newParamRef)
@@ -2696,20 +2695,24 @@ object Types {
26962695
x => paramInfos.mapConserve(_.subst(this, x).asInstanceOf[PInfo]),
26972696
x => resType.subst(this, x))
26982697

2698+
protected def prefixString: String
2699+
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
2700+
}
2701+
2702+
abstract class HKLambda extends CachedProxyType with LambdaType {
2703+
final override def underlying(implicit ctx: Context) = resType
2704+
26992705
override def computeHash(bs: Binders) =
27002706
doHash(new Binders(this, bs), paramNames, resType, paramInfos)
27012707

2702-
override def stableHash = {
2703-
if (myStableHash == 0) myStableHash = if (resType.stableHash && paramInfos.stableHash) 1 else -1
2704-
myStableHash > 0
2705-
}
2708+
override def stableHash = resType.stableHash && paramInfos.stableHash
27062709

27072710
final override def equals(that: Any) = equals(that, null)
27082711

27092712
// No definition of `eql` --> fall back on equals, which calls iso
27102713

27112714
final override def iso(that: Any, bs: BinderPairs) = that match {
2712-
case that: LambdaType =>
2715+
case that: HKLambda =>
27132716
paramNames.eqElements(that.paramNames) &&
27142717
companion.eq(that.companion) && {
27152718
val bs1 = new BinderPairs(this, that, bs)
@@ -2719,17 +2722,13 @@ object Types {
27192722
case _ =>
27202723
false
27212724
}
2722-
2723-
protected def prefixString: String
2724-
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
27252725
}
27262726

2727-
abstract class HKLambda extends CachedProxyType with LambdaType {
2728-
final override def underlying(implicit ctx: Context) = resType
2727+
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2728+
final override def hashCode = System.identityHashCode(this)
2729+
final override def equals(other: Any) = this `eq` other.asInstanceOf[AnyRef]
27292730
}
27302731

2731-
abstract class MethodOrPoly extends CachedGroundType with LambdaType with MethodicType
2732-
27332732
trait TermLambda extends LambdaType { thisLambdaType =>
27342733
import DepStatus._
27352734
type ThisName = TermName

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,14 @@ object ProtoTypes {
400400
/** Ensure that `tl` is not already in constraint, make a copy of necessary */
401401
def ensureFresh(tl: TypeLambda): TypeLambda =
402402
if (state.constraint contains tl) {
403-
// Type lambdas are hash-consed, need to create an artificial difference by adding
404-
// a LazyRef to a bound.
405-
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
406-
val newParamInfos = TypeBounds(lo, LazyRef(_ => hi)) :: pinfos1
407-
ensureFresh(tl.newLikeThis(tl.paramNames, newParamInfos, tl.resultType))
403+
var paramInfos = tl.paramInfos
404+
if (tl.isInstanceOf[HKLambda]) {
405+
// HKLambdas care hash-consed, need to create an artificial difference by adding
406+
// a LazyRef to a bound.
407+
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
408+
paramInfos = TypeBounds(lo, LazyRef(_ => hi)) :: pinfos1
409+
}
410+
ensureFresh(tl.newLikeThis(tl.paramNames, paramInfos, tl.resultType))
408411
}
409412
else tl
410413
val added = ensureFresh(tl)

0 commit comments

Comments
 (0)