diff options
author | Martin Odersky <odersky@gmail.com> | 2014-12-03 18:26:23 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-12-03 18:26:23 +0100 |
commit | 8fb5e1e8ee69f14fec52056d43528755544870b7 (patch) | |
tree | e3e9826876ab8c55a7446efe39c08195ca48b74c /src | |
parent | a9a8124199eabe8539152f05718a5d44e4b04855 (diff) | |
download | dotty-8fb5e1e8ee69f14fec52056d43528755544870b7.tar.gz dotty-8fb5e1e8ee69f14fec52056d43528755544870b7.tar.bz2 dotty-8fb5e1e8ee69f14fec52056d43528755544870b7.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Uniques.scala | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/core/Uniques.scala b/src/dotty/tools/dotc/core/Uniques.scala index 5e5b3e225..0ade58193 100644 --- a/src/dotty/tools/dotc/core/Uniques.scala +++ b/src/dotty/tools/dotc/core/Uniques.scala @@ -45,7 +45,7 @@ object Uniques { private def findPrevious(h: Int, prefix: Type, name: Name): NamedType = { var e = findEntryByHash(h) while (e != null) { - if ((e.prefix == prefix) && (e.name eq name)) return e + if ((e.prefix eq prefix) && (e.name eq name)) return e e = nextEntryByHash(h) } e @@ -71,7 +71,7 @@ object Uniques { private def findPrevious(h: Int, lo: Type, hi: Type, variance: Int): TypeBounds = { var e = findEntryByHash(h) while (e != null) { - if ((e.lo == lo) && (e.hi == hi) && (e.variance == variance)) return e + if ((e.lo eq lo) && (e.hi eq hi) && (e.variance == variance)) return e e = nextEntryByHash(h) } e @@ -87,7 +87,8 @@ object Uniques { if (h == NotCached) newBounds else { val r = findPrevious(h, lo, hi, variance) - if (r ne null) r else addEntryAfterScan(newBounds) + if (r ne null) r + else addEntryAfterScan(newBounds) } } } @@ -99,7 +100,7 @@ object Uniques { private def findPrevious(h: Int, parent: Type, refinedName: Name, refinedInfo: Type): RefinedType = { var e = findEntryByHash(h) while (e != null) { - if ((e.parent == parent) && (e.refinedName eq refinedName) && (e.refinedInfo == refinedInfo)) + if ((e.parent eq parent) && (e.refinedName eq refinedName) && (e.refinedInfo eq refinedInfo)) return e e = nextEntryByHash(h) } |