Skip to content

Commit a2e812e

Browse files
committed
Drop uniqueRefinedType and uniqueTypeAlias
With the change to native applied types, both are now quite rare, so no need for special casing their allocation.
1 parent 93d312a commit a2e812e

File tree

3 files changed

+9
-90
lines changed

3 files changed

+9
-90
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,24 +603,16 @@ object Contexts {
603603
override def hash(x: Type): Int = x.hash
604604
}
605605

606-
/** A table for hash consing unique refined types */
607-
private[dotc] val uniqueRefinedTypes = new RefinedUniques // @!!! replace with uniqueAppliedTypes
608-
609-
/** A table for hash consing unique refined types */
606+
/** A table for hash consing unique applied types */
610607
private[dotc] val uniqueAppliedTypes = new AppliedUniques
611608

612609
/** A table for hash consing unique named types */
613610
private[core] val uniqueNamedTypes = new NamedTypeUniques
614611

615-
/** A table for hash consing unique type bounds */
616-
private[core] val uniqueTypeAliases = new TypeAliasUniques // @!!! replace
617-
618612
private def uniqueSets = Map(
619613
"uniques" -> uniques,
620-
"uniqueRefinedTypes" -> uniqueRefinedTypes,
621614
"uniqueAppliedTypes" -> uniqueAppliedTypes,
622-
"uniqueNamedTypes" -> uniqueNamedTypes,
623-
"uniqueTypeAliases" -> uniqueTypeAliases)
615+
"uniqueNamedTypes" -> uniqueNamedTypes)
624616

625617
/** A map that associates label and size of all uniques sets */
626618
def uniquesSizes: Map[String, Int] = uniqueSets.mapValues(_.size)

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,23 +2293,11 @@ object Types {
22932293
if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
22942294
else parent
22952295

2296-
override def equals(that: Any) = that match {
2297-
case that: RefinedType =>
2298-
this.parent == that.parent &&
2299-
this.refinedName == that.refinedName &&
2300-
this.refinedInfo == that.refinedInfo
2301-
case _ =>
2302-
false
2303-
}
23042296
override def computeHash = doHash(refinedName, refinedInfo, parent)
2305-
override def toString = s"RefinedType($parent, $refinedName, $refinedInfo)"
23062297
}
23072298

2308-
class CachedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type, hc: Int)
2309-
extends RefinedType(parent, refinedName, refinedInfo) {
2310-
myHash = hc
2311-
override def computeHash = unsupported("computeHash")
2312-
}
2299+
class CachedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)
2300+
extends RefinedType(parent, refinedName, refinedInfo)
23132301

23142302
object RefinedType {
23152303
@tailrec def make(parent: Type, names: List[Name], infos: List[Type])(implicit ctx: Context): Type =
@@ -2318,7 +2306,7 @@ object Types {
23182306

23192307
def apply(parent: Type, name: Name, info: Type)(implicit ctx: Context): RefinedType = {
23202308
assert(!ctx.erasedTypes)
2321-
ctx.base.uniqueRefinedTypes.enterIfNew(parent, name, info).checkInst
2309+
unique(new CachedRefinedType(parent, name, info)).checkInst
23222310
}
23232311
}
23242312

@@ -3662,12 +3650,12 @@ object Types {
36623650
if (variance == 0) this
36633651
else if (variance < 0) TypeBounds.lower(alias)
36643652
else TypeBounds.upper(alias)
3665-
}
36663653

3667-
class CachedTypeAlias(alias: Type, variance: Int, hc: Int) extends TypeAlias(alias, variance) {
3668-
myHash = hc
3654+
override def computeHash = doHash(variance, alias)
36693655
}
36703656

3657+
class CachedTypeAlias(alias: Type, variance: Int) extends TypeAlias(alias, variance)
3658+
36713659
object TypeBounds {
36723660
def apply(lo: Type, hi: Type)(implicit ctx: Context): TypeBounds =
36733661
unique(new RealTypeBounds(lo, hi))
@@ -3678,7 +3666,7 @@ object Types {
36783666

36793667
object TypeAlias {
36803668
def apply(alias: Type, variance: Int = 0)(implicit ctx: Context) =
3681-
ctx.uniqueTypeAliases.enterIfNew(alias, variance)
3669+
unique(new CachedTypeAlias(alias, variance))
36823670
def unapply(tp: TypeAlias): Option[Type] = Some(tp.alias)
36833671
}
36843672

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,6 @@ object Uniques {
6666
}
6767
}
6868

69-
final class TypeAliasUniques extends HashSet[TypeAlias](Config.initialUniquesCapacity) with Hashable {
70-
override def hash(x: TypeAlias): Int = x.hash
71-
72-
private def findPrevious(h: Int, alias: Type, variance: Int): TypeAlias = {
73-
var e = findEntryByHash(h)
74-
while (e != null) {
75-
if ((e.alias eq alias) && (e.variance == variance)) return e
76-
e = nextEntryByHash(h)
77-
}
78-
e
79-
}
80-
81-
def enterIfNew(alias: Type, variance: Int): TypeAlias = {
82-
val h = doHash(variance, alias)
83-
if (monitored) recordCaching(h, classOf[TypeAlias])
84-
def newAlias = new CachedTypeAlias(alias, variance, h)
85-
if (h == NotCached) newAlias
86-
else {
87-
val r = findPrevious(h, alias, variance)
88-
if (r ne null) r
89-
else addEntryAfterScan(newAlias)
90-
}
91-
}
92-
}
93-
94-
9569
final class AppliedUniques extends HashSet[AppliedType](Config.initialUniquesCapacity) with Hashable {
9670
override def hash(x: AppliedType): Int = x.hash
9771

@@ -121,39 +95,4 @@ object Uniques {
12195
}
12296
}
12397
}
124-
125-
final class RefinedUniques extends HashSet[RefinedType](Config.initialUniquesCapacity) with Hashable {
126-
override val hashSeed = classOf[CachedRefinedType].hashCode // some types start life as CachedRefinedTypes, need to have same hash seed
127-
override def hash(x: RefinedType): Int = x.hash
128-
129-
private def findPrevious(h: Int, parent: Type, refinedName: Name, refinedInfo: Type): RefinedType = {
130-
var e = findEntryByHash(h)
131-
while (e != null) {
132-
if ((e.parent eq parent) && (e.refinedName eq refinedName) && (e.refinedInfo eq refinedInfo))
133-
return e
134-
e = nextEntryByHash(h)
135-
}
136-
e
137-
}
138-
139-
def enterIfNew(parent: Type, refinedName: Name, refinedInfo: Type): RefinedType = {
140-
val h = doHash(refinedName, refinedInfo, parent)
141-
def newType = new CachedRefinedType(parent, refinedName, refinedInfo, h)
142-
if (monitored) recordCaching(h, classOf[CachedRefinedType])
143-
if (h == NotCached) newType
144-
else {
145-
val r = findPrevious(h, parent, refinedName, refinedInfo)
146-
if (r ne null) r else addEntryAfterScan(newType)
147-
}
148-
}
149-
150-
def enterIfNew(rt: RefinedType) = {
151-
if (monitored) recordCaching(rt)
152-
if (rt.hash == NotCached) rt
153-
else {
154-
val r = findPrevious(rt.hash, rt.parent, rt.refinedName, rt.refinedInfo)
155-
if (r ne null) r else addEntryAfterScan(rt)
156-
}
157-
}
158-
}
15998
}

0 commit comments

Comments
 (0)