Skip to content

Commit 181490a

Browse files
committed
Fix identityHash for BindingTypes
1 parent dab5e51 commit 181490a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import annotation.tailrec
77

88
object Hashable {
99

10-
class Binders(tp: BindingType, next: Binders) {
11-
val hash: Int = if (next == null) 31 else next.hash * 41 + 31
12-
}
10+
class Binders(val tp: BindingType, val next: Binders)
11+
1312
class BinderPairs(tp1: BindingType, tp2: BindingType, next: BinderPairs) {
1413
@tailrec final def matches(t1: Type, t2: Type): Boolean =
1514
(t1 `eq` tp1) && (t2 `eq` tp2) || next != null && next.matches(t1, t2)
@@ -107,7 +106,7 @@ trait Hashable {
107106
if (elemHash == NotCached) NotCached
108107
else avoidSpecialHashes(elemHash + delta)
109108

110-
private def avoidSpecialHashes(h: Int) =
109+
protected def avoidSpecialHashes(h: Int) =
111110
if (h == NotCached) NotCachedAlt
112111
else if (h == HashUnknown) HashUnknownAlt
113112
else h

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,15 @@ object Types {
15281528
*/
15291529
trait BindingType extends Type {
15301530

1531-
override def identityHash(bs: Binders) =
1532-
if (bs == null) super.identityHash(bs) else bs.hash
1531+
override def identityHash(bs: Binders) = {
1532+
def recur(n: Int, tp: BindingType, rest: Binders): Int =
1533+
if (this `eq` tp) finishHash(hashing.mix(hashSeed, n), 1)
1534+
else if (rest == null) System.identityHashCode(this)
1535+
else recur(n + 1, rest.tp, rest.next)
1536+
avoidSpecialHashes(
1537+
if (bs == null) System.identityHashCode(this)
1538+
else recur(1, bs.tp, bs.next))
1539+
}
15331540

15341541
def equalBinder(that: BindingType, bs: BinderPairs): Boolean =
15351542
(this `eq` that) || bs != null && bs.matches(this, that)

0 commit comments

Comments
 (0)