Skip to content

Commit 8fb5e1e

Browse files
committed
Replace == with eq when determining unique types
When hash-consing TypeBounds, RefinedTypes and NamedTypes, we now check the argument types with `eq`, where before it was `==`. This is necessary for TypeBounds, because it makes a difference whether a TypeBound has `eq` parts (then it is a type alias) or not. So we cannot merge type aliases with non-aliases. The symptom of the problem was when compiling Patterns.scala twice with the new SeqLiterals phase (next commit) enabled. On second run, we encountered an ArrayType[>: String <: String], even if we only created an ArrayType[String]. This was a consequence of the two types being identified by uniques. Todo: Change the system so that type aliases are recognized more robustly. But the present change seems to be useful anyway because it speeds up uniques hashing. I verified that the stricter condition on uniques creates less than 1% more types than before. So the speedup of hashing looks worthwhile.
1 parent a9a8124 commit 8fb5e1e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object Uniques {
4545
private def findPrevious(h: Int, prefix: Type, name: Name): NamedType = {
4646
var e = findEntryByHash(h)
4747
while (e != null) {
48-
if ((e.prefix == prefix) && (e.name eq name)) return e
48+
if ((e.prefix eq prefix) && (e.name eq name)) return e
4949
e = nextEntryByHash(h)
5050
}
5151
e
@@ -71,7 +71,7 @@ object Uniques {
7171
private def findPrevious(h: Int, lo: Type, hi: Type, variance: Int): TypeBounds = {
7272
var e = findEntryByHash(h)
7373
while (e != null) {
74-
if ((e.lo == lo) && (e.hi == hi) && (e.variance == variance)) return e
74+
if ((e.lo eq lo) && (e.hi eq hi) && (e.variance == variance)) return e
7575
e = nextEntryByHash(h)
7676
}
7777
e
@@ -87,7 +87,8 @@ object Uniques {
8787
if (h == NotCached) newBounds
8888
else {
8989
val r = findPrevious(h, lo, hi, variance)
90-
if (r ne null) r else addEntryAfterScan(newBounds)
90+
if (r ne null) r
91+
else addEntryAfterScan(newBounds)
9192
}
9293
}
9394
}
@@ -99,7 +100,7 @@ object Uniques {
99100
private def findPrevious(h: Int, parent: Type, refinedName: Name, refinedInfo: Type): RefinedType = {
100101
var e = findEntryByHash(h)
101102
while (e != null) {
102-
if ((e.parent == parent) && (e.refinedName eq refinedName) && (e.refinedInfo == refinedInfo))
103+
if ((e.parent eq parent) && (e.refinedName eq refinedName) && (e.refinedInfo eq refinedInfo))
103104
return e
104105
e = nextEntryByHash(h)
105106
}

0 commit comments

Comments
 (0)