Skip to content

Commit 5f22db6

Browse files
committed
Implement iso (test-only)
1 parent 6db4bef commit 5f22db6

File tree

5 files changed

+235
-63
lines changed

5 files changed

+235
-63
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package core
33

44
import Types._
55
import scala.util.hashing.{ MurmurHash3 => hashing }
6+
import annotation.tailrec
67

78
object Hashable {
89

9-
type Binders = Array[BindingType]
10+
class Binders(val tp: BindingType, val next: Binders)
11+
12+
class BinderPairs(tp1: BindingType, tp2: BindingType, next: BinderPairs) {
13+
@tailrec final def matches(t1: Type, t2: Type): Boolean =
14+
(t1 `eq` tp1) && (t2 `eq` tp2) || next != null && next.matches(t1, t2)
15+
}
1016

1117
/** A hash value indicating that the underlying type is not
1218
* cached in uniques.
@@ -36,7 +42,7 @@ trait Hashable {
3642
avoidSpecialHashes(hashing.finalizeHash(hashCode, arity))
3743

3844
final def typeHash(bs: Binders, tp: Type) =
39-
if (bs == null) tp.hash else tp.computeHash(bs)
45+
if (bs == null || tp.stableHash) tp.hash else tp.computeHash(bs)
4046

4147
def identityHash(bs: Binders) = avoidSpecialHashes(System.identityHashCode(this))
4248

@@ -93,15 +99,14 @@ trait Hashable {
9399
protected final def doHash(bs: Binders, x1: Any, tp2: Type, tps3: List[Type]): Int =
94100
finishHash(bs, hashing.mix(hashSeed, x1.hashCode), 1, tp2, tps3)
95101

96-
97-
protected final def doHash(bs: Binders, x1: Int, x2: Int): Int =
102+
protected final def doHash(x1: Int, x2: Int): Int =
98103
finishHash(hashing.mix(hashing.mix(hashSeed, x1), x2), 1)
99104

100105
protected final def addDelta(elemHash: Int, delta: Int) =
101106
if (elemHash == NotCached) NotCached
102107
else avoidSpecialHashes(elemHash + delta)
103108

104-
private def avoidSpecialHashes(h: Int) =
109+
protected def avoidSpecialHashes(h: Int) =
105110
if (h == NotCached) NotCachedAlt
106111
else if (h == HashUnknown) HashUnknownAlt
107112
else h

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ object TypeErasure {
7979
abstract case class ErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
8080
extends CachedGroundType with ValueType {
8181
override def computeHash(bs: Hashable.Binders) = doHash(bs, tycon, erasedUnderlying)
82-
83-
override def iso(that: Any, bs: Hashable.BinderPairs) = that match {
84-
case that: ErasedValueType =>
85-
tycon.equals(that.tycon, bs) && erasedUnderlying.equals(that.erasedUnderlying)
86-
case _ =>
87-
false
88-
}
8982
}
9083

9184
final class CachedErasedValueType(tycon: TypeRef, erasedUnderlying: Type)

0 commit comments

Comments
 (0)