Skip to content

Commit 16bb3d5

Browse files
oderskysmarter
authored andcommitted
Cache skolem types
Skolem types were not cached, which means that any type containing a skolem type was not cached either. This meant that the same match type with a skolem type as selector was created many times instead of once, so its reduction was not cached either. We now cache skolem types. It's a bet that in practice few skolem types are created and that therefore the hashtable pollution with skolemtypes is less of a problem than the potential problem of losing identity of types containing skolem types. This was originally motivated by #14903 but that ended up being fixed in a different way. It still seems like a good idea to do this since it matches what we do for type variables.
1 parent 0040417 commit 16bb3d5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,11 +4621,12 @@ object Types {
46214621
* Note that care is needed when creating them, since not all types need to be inhabited.
46224622
* A skolem is equal to itself and no other type.
46234623
*/
4624-
case class SkolemType(info: Type) extends UncachedProxyType with ValueType with SingletonType {
4624+
case class SkolemType(info: Type) extends CachedProxyType with ValueType with SingletonType {
46254625
override def underlying(using Context): Type = info
46264626
def derivedSkolemType(info: Type)(using Context): SkolemType =
46274627
if (info eq this.info) this else SkolemType(info)
4628-
override def hashCode: Int = System.identityHashCode(this)
4628+
4629+
override def computeHash(bs: Binders): Int = identityHash(bs)
46294630
override def equals(that: Any): Boolean = this.eq(that.asInstanceOf[AnyRef])
46304631

46314632
def withName(name: Name): this.type = { myRepr = name; this }

0 commit comments

Comments
 (0)