aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Constraint.scala6
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala4
-rw-r--r--src/dotty/tools/dotc/core/Types.scala25
-rw-r--r--src/dotty/tools/dotc/core/Uniques.scala25
4 files changed, 29 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/core/Constraint.scala b/src/dotty/tools/dotc/core/Constraint.scala
index 339dbb64a..e241794d0 100644
--- a/src/dotty/tools/dotc/core/Constraint.scala
+++ b/src/dotty/tools/dotc/core/Constraint.scala
@@ -24,7 +24,9 @@ object Constraint {
private val addDep: DepDelta = (_ + _)
private val removeDep: DepDelta = (_ - _)
- private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType){}
+ private val NoTypeBounds = new TypeBounds(WildcardType, WildcardType) {
+ override def computeHash = unsupported("computeHash")
+ }
/** An accumulator that changes dependencies on `param`.
* @param param The parameter to which changed dependencies refer.
@@ -70,7 +72,7 @@ import Constraint._
* @param dependents a map from PolyTypes to arrays of Sets of PolyParams.
* The i'th set in an array corresponding to polytype `pt` contains
* those dependent `PolyParam`s `dp` that have `PolyParam(pt, i)` in their bounds in
- * significant position. A position is significant if solving the
+ * significant position. A position is significant if solving the
* constraint for `(pt, i)` with a type higher than its lower bound
* would lead to a constraint for `dp` that was not looser than
* the existing constraint. Specifically, it means that all poly params
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index 6824cc36c..bdc8d4f5e 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -526,13 +526,13 @@ object Contexts {
private[core] val uniqueNamedTypes = new NamedTypeUniques
/** A table for hash consing unique type bounds */
- private[core] val uniqueTypeBounds = new TypeBoundsUniques
+ private[core] val uniqueTypeAliases = new TypeAliasUniques
private def uniqueSets = Map(
"uniques" -> uniques,
"uniqueRefinedTypes" -> uniqueRefinedTypes,
"uniqueNamedTypes" -> uniqueNamedTypes,
- "uniqueTypeBounds" -> uniqueTypeBounds)
+ "uniqueTypeAliases" -> uniqueTypeAliases)
/** A map that associates label and size of all uniques sets */
def uniquesSizes: Map[String, Int] = uniqueSets.mapValues(_.size)
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index d9228a5da..e41e7e907 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2461,33 +2461,32 @@ object Types {
override def toString =
if (lo eq hi) s"TypeAlias($lo)" else s"TypeBounds($lo, $hi)"
- override def computeHash = unsupported("computeHash")
- }
-
- class CachedTypeBounds(lo: Type, hi: Type, hc: Int) extends TypeBounds(lo, hi) {
- myHash = hc
}
- final class CoTypeBounds(lo: Type, hi: Type, hc: Int) extends CachedTypeBounds(lo, hi, hc) {
- override def variance = 1
- override def toString = "Co" + super.toString
+ class CachedTypeBounds(lo: Type, hi: Type) extends TypeBounds(lo, hi) {
+ override def computeHash = doHash(variance, lo, hi)
}
- final class ContraTypeBounds(lo: Type, hi: Type, hc: Int) extends CachedTypeBounds(lo, hi, hc) {
- override def variance = -1
- override def toString = "Contra" + super.toString
+ class TypeAlias(val alias: Type, override val variance: Int, hc: Int) extends TypeBounds(alias, alias) {
+ myHash = hc
+ override def computeHash = unsupported("computeHash")
}
object TypeBounds {
def apply(lo: Type, hi: Type, variance: Int = 0)(implicit ctx: Context): TypeBounds =
- ctx.uniqueTypeBounds.enterIfNew(lo, hi, variance)
+ if (lo eq hi) TypeAlias(lo, variance)
+ else unique {
+ assert(variance == 0)
+ new CachedTypeBounds(lo, hi)
+ }
def empty(implicit ctx: Context) = apply(defn.NothingType, defn.AnyType)
def upper(hi: Type, variance: Int = 0)(implicit ctx: Context) = apply(defn.NothingType, hi, variance)
def lower(lo: Type, variance: Int = 0)(implicit ctx: Context) = apply(lo, defn.AnyType, variance)
}
object TypeAlias {
- def apply(tp: Type, variance: Int = 0)(implicit ctx: Context) = TypeBounds(tp, tp, variance)
+ def apply(alias: Type, variance: Int = 0)(implicit ctx: Context) =
+ ctx.uniqueTypeAliases.enterIfNew(alias, variance)
def unapply(tp: Type): Option[Type] = tp match {
case TypeBounds(lo, hi) if lo eq hi => Some(lo)
case _ => None
diff --git a/src/dotty/tools/dotc/core/Uniques.scala b/src/dotty/tools/dotc/core/Uniques.scala
index 0ade58193..fee217dd3 100644
--- a/src/dotty/tools/dotc/core/Uniques.scala
+++ b/src/dotty/tools/dotc/core/Uniques.scala
@@ -65,30 +65,27 @@ object Uniques {
}
}
- final class TypeBoundsUniques extends HashSet[TypeBounds](initialUniquesCapacity) with Hashable {
- override def hash(x: TypeBounds): Int = x.hash
+ final class TypeAliasUniques extends HashSet[TypeAlias](initialUniquesCapacity) with Hashable {
+ override def hash(x: TypeAlias): Int = x.hash
- private def findPrevious(h: Int, lo: Type, hi: Type, variance: Int): TypeBounds = {
+ private def findPrevious(h: Int, alias: Type, variance: Int): TypeAlias = {
var e = findEntryByHash(h)
while (e != null) {
- if ((e.lo eq lo) && (e.hi eq hi) && (e.variance == variance)) return e
+ if ((e.alias eq alias) && (e.variance == variance)) return e
e = nextEntryByHash(h)
}
e
}
- def enterIfNew(lo: Type, hi: Type, variance: Int): TypeBounds = {
- val h = doHash(variance, lo, hi)
- if (monitored) recordCaching(h, classOf[TypeBounds])
- def newBounds =
- if (variance == 0) new CachedTypeBounds(lo, hi, h)
- else if (variance == 1) new CoTypeBounds(lo, hi, h)
- else new ContraTypeBounds(lo, hi, h)
- if (h == NotCached) newBounds
+ def enterIfNew(alias: Type, variance: Int): TypeAlias = {
+ val h = doHash(variance, alias)
+ if (monitored) recordCaching(h, classOf[TypeAlias])
+ def newAlias = new TypeAlias(alias, variance, h)
+ if (h == NotCached) newAlias
else {
- val r = findPrevious(h, lo, hi, variance)
+ val r = findPrevious(h, alias, variance)
if (r ne null) r
- else addEntryAfterScan(newBounds)
+ else addEntryAfterScan(newAlias)
}
}
}