Skip to content

Commit 015d922

Browse files
committed
Revert: Cache all method and polytypes (reverted from commit c0e7113)
1 parent c0e7113 commit 015d922

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
@@ -2654,7 +2654,6 @@ object Types {
26542654
final def isHigherKinded = isInstanceOf[TypeProxy]
26552655

26562656
private[this] var myParamRefs: List[ParamRefType] = null
2657-
private[this] var myStableHash: Byte = 0
26582657

26592658
def paramRefs: List[ParamRefType] = {
26602659
if (myParamRefs == null) myParamRefs = paramNames.indices.toList.map(newParamRef)
@@ -2687,20 +2686,24 @@ object Types {
26872686
x => paramInfos.mapConserve(_.subst(this, x).asInstanceOf[PInfo]),
26882687
x => resType.subst(this, x))
26892688

2689+
protected def prefixString: String
2690+
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
2691+
}
2692+
2693+
abstract class HKLambda extends CachedProxyType with LambdaType {
2694+
final override def underlying(implicit ctx: Context) = resType
2695+
26902696
override def computeHash(bs: Binders) =
26912697
doHash(new Binders(this, bs), paramNames, resType, paramInfos)
26922698

2693-
override def stableHash = {
2694-
if (myStableHash == 0) myStableHash = if (resType.stableHash && paramInfos.stableHash) 1 else -1
2695-
myStableHash > 0
2696-
}
2699+
override def stableHash = resType.stableHash && paramInfos.stableHash
26972700

26982701
final override def equals(that: Any) = equals(that, null)
26992702

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

27022705
final override def iso(that: Any, bs: BinderPairs) = that match {
2703-
case that: LambdaType =>
2706+
case that: HKLambda =>
27042707
paramNames.eqElements(that.paramNames) &&
27052708
companion.eq(that.companion) && {
27062709
val bs1 = new BinderPairs(this, that, bs)
@@ -2710,17 +2713,13 @@ object Types {
27102713
case _ =>
27112714
false
27122715
}
2713-
2714-
protected def prefixString: String
2715-
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
27162716
}
27172717

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

2722-
abstract class MethodOrPoly extends CachedGroundType with LambdaType with MethodicType
2723-
27242723
trait TermLambda extends LambdaType { thisLambdaType =>
27252724
import DepStatus._
27262725
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)