aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/Types.scala70
-rw-r--r--src/dotty/tools/dotc/core/tasty/TastyFormat.scala2
-rw-r--r--src/dotty/tools/dotc/core/tasty/TreePickler.scala1
-rw-r--r--src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala5
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala4
5 files changed, 17 insertions, 65 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index d78bbd49e..a2b52d338 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -3119,25 +3119,20 @@ object Types {
unique(new CachedClassInfo(prefix, cls, classParents, decls, selfInfo))
}
- /** Type bounds >: lo <: hi
- * @param bindingKind: If != NoBinding, it indicates that this is
- * an introduction of a higher-kinded type parameter.
- * In that case it also defines the variance of the parameter.
- */
- abstract case class TypeBounds(lo: Type, hi: Type)(val bindingKind: BindingKind) extends CachedProxyType with TypeType {
+ /** Type bounds >: lo <: hi */
+ abstract case class TypeBounds(lo: Type, hi: Type) extends CachedProxyType with TypeType {
assert(lo.isInstanceOf[TermType])
assert(hi.isInstanceOf[TermType])
def variance: Int = 0
- def isBinding = bindingKind != NoBinding
override def underlying(implicit ctx: Context): Type = hi
/** The non-alias type bounds type with given bounds */
- def derivedTypeBounds(lo: Type, hi: Type, bk: BindingKind = this.bindingKind)(implicit ctx: Context) =
- if ((lo eq this.lo) && (hi eq this.hi) && (bk == this.bindingKind) && (variance == 0)) this
- else TypeBounds(lo, hi, bk)
+ def derivedTypeBounds(lo: Type, hi: Type)(implicit ctx: Context) =
+ if ((lo eq this.lo) && (hi eq this.hi) && (variance == 0)) this
+ else TypeBounds(lo, hi)
/** If this is an alias, a derived alias with the new variance,
* Otherwise the type itself.
@@ -3147,13 +3142,6 @@ object Types {
case _ => this
}
- def withBindingKind(bk: BindingKind)(implicit ctx: Context) = this match {
- case tp: TypeAlias => assert(bk == NoBinding); this
- case _ => derivedTypeBounds(lo, hi, bk)
- }
-
- //def checkBinding: this.type = { assert(isBinding); this }
-
def contains(tp: Type)(implicit ctx: Context): Boolean = tp match {
case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
case tp: ClassInfo =>
@@ -3166,12 +3154,12 @@ object Types {
def & (that: TypeBounds)(implicit ctx: Context): TypeBounds =
if ((this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi)) that
else if ((that.lo frozen_<:< this.lo) && (this.hi frozen_<:< that.hi)) this
- else TypeBounds(this.lo | that.lo, this.hi & that.hi, this.bindingKind join that.bindingKind)
+ else TypeBounds(this.lo | that.lo, this.hi & that.hi)
def | (that: TypeBounds)(implicit ctx: Context): TypeBounds =
if ((this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi)) this
else if ((that.lo frozen_<:< this.lo) && (this.hi frozen_<:< that.hi)) that
- else TypeBounds(this.lo & that.lo, this.hi | that.hi, this.bindingKind join that.bindingKind)
+ else TypeBounds(this.lo & that.lo, this.hi | that.hi)
override def & (that: Type)(implicit ctx: Context) = that match {
case that: TypeBounds => this & that
@@ -3191,25 +3179,22 @@ object Types {
/** If this type and that type have the same variance, this variance, otherwise 0 */
final def commonVariance(that: TypeBounds): Int = (this.variance + that.variance) / 2
- override def computeHash = doHash(variance * 41 + bindingKind.n, lo, hi)
+ override def computeHash = doHash(variance, lo, hi)
override def equals(that: Any): Boolean = that match {
case that: TypeBounds =>
(this.lo eq that.lo) && (this.hi eq that.hi) &&
- (this.variance == that.variance) && (this.bindingKind == that.bindingKind)
+ (this.variance == that.variance)
case _ =>
false
}
- override def toString = {
- def bkString = if (isBinding) s"|v=${BindingKind.toVariance(bindingKind)}" else ""
- if (lo eq hi) s"TypeAlias($lo, $variance)"
- else s"TypeBounds($lo, $hi$bkString)"
- }
+ override def toString =
+ if (lo eq hi) s"TypeAlias($lo, $variance)" else s"TypeBounds($lo, $hi)"
}
- class RealTypeBounds(lo: Type, hi: Type, bk: BindingKind) extends TypeBounds(lo, hi)(bk)
+ class RealTypeBounds(lo: Type, hi: Type) extends TypeBounds(lo, hi)
- abstract class TypeAlias(val alias: Type, override val variance: Int) extends TypeBounds(alias, alias)(NoBinding) {
+ abstract class TypeAlias(val alias: Type, override val variance: Int) extends TypeBounds(alias, alias) {
/** pre: this is a type alias */
def derivedTypeAlias(alias: Type, variance: Int = this.variance)(implicit ctx: Context) =
if ((alias eq this.alias) && (variance == this.variance)) this
@@ -3240,8 +3225,8 @@ object Types {
}
object TypeBounds {
- def apply(lo: Type, hi: Type, bk: BindingKind = NoBinding)(implicit ctx: Context): TypeBounds =
- unique(new RealTypeBounds(lo, hi, bk))
+ def apply(lo: Type, hi: Type)(implicit ctx: Context): TypeBounds =
+ unique(new RealTypeBounds(lo, hi))
def empty(implicit ctx: Context) = apply(defn.NothingType, defn.AnyType)
def upper(hi: Type)(implicit ctx: Context) = apply(defn.NothingType, hi)
def lower(lo: Type)(implicit ctx: Context) = apply(lo, defn.AnyType)
@@ -3253,31 +3238,6 @@ object Types {
def unapply(tp: TypeAlias): Option[Type] = Some(tp.alias)
}
- /** A value class defining the interpretation of a TypeBounds
- * as either a regular type bounds or a binding (i.e. introduction) of a
- * higher-kinded type parameter.
- * TODO: drop
- */
- class BindingKind(val n: Byte) extends AnyVal {
- def join(that: BindingKind) =
- if (this == that) this
- else if (this == NoBinding || that == NoBinding) NoBinding
- else NonvariantBinding
- }
-
- val NoBinding = new BindingKind(0) // Regular type bounds
- val ContravariantBinding = new BindingKind(1) // Bounds for contravariant hk type param
- val NonvariantBinding = new BindingKind(2) // Bounds for nonvariant hk type param
- val CovariantBinding = new BindingKind(3) // Bounds for covariant hk type param
-
- object BindingKind {
- def fromVariance(v: Int): BindingKind = new BindingKind((v + NonvariantBinding.n).toByte)
- def toVariance(bk: BindingKind): Int = {
- assert(bk.n != 0)
- bk.n - NonvariantBinding.n
- }
- }
-
// ----- Annotated and Import types -----------------------------------------------
/** An annotated type tpe @ annot */
diff --git a/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index b23ee5aba..d9006eda9 100644
--- a/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -130,7 +130,7 @@ Standard-Section: "ASTs" TopLevelStat*
SUPERtype Length this_Type underlying_Type
REFINEDtype Length underlying_Type refinement_NameRef info_Type
APPLIEDtype Length tycon_Type arg_Type*
- TYPEBOUNDS Length low_Type high_Type bindingKind_Nat?
+ TYPEBOUNDS Length low_Type high_Type
TYPEALIAS Length alias_Type (COVARIANT | CONTRAVARIANT)?
ANNOTATED Length underlying_Type fullAnnotation_Term
ANDtype Length left_Type right_Type
diff --git a/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/src/dotty/tools/dotc/core/tasty/TreePickler.scala
index 6a51b9642..a4fdb2751 100644
--- a/src/dotty/tools/dotc/core/tasty/TreePickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/TreePickler.scala
@@ -243,7 +243,6 @@ class TreePickler(pickler: TastyPickler) {
withLength {
pickleType(tpe.lo, richTypes)
pickleType(tpe.hi, richTypes)
- if (tpe.isBinding) writeNat(tpe.bindingKind.n)
}
case tpe: AnnotatedType =>
writeByte(ANNOTATED)
diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
index 2d9b82c97..31247c005 100644
--- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
@@ -266,10 +266,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
case APPLIEDtype =>
readType().appliedTo(until(end)(readType()))
case TYPEBOUNDS =>
- val lo = readType()
- val hi = readType()
- val bk = ifBefore(end)(new BindingKind(readNat().toByte), NoBinding)
- TypeBounds(lo, hi, bk)
+ TypeBounds(readType(), readType())
case TYPEALIAS =>
val alias = readType()
val variance =
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index 6becd29ec..28f3af7cb 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -177,10 +177,6 @@ object Inferencing {
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
case tp: TypeRef if !tp.symbol.isClass =>
widenForMatchSelector(tp.info.bounds.hi)
- case tp @ RefinedType(parent, rname, rinfo) if !parent.typeSymbol.isClass =>
- tp.derivedRefinedType(widenForMatchSelector(parent), rname, rinfo)
- case tp: RecType if !tp.parent.typeSymbol.isClass =>
- tp.derivedRecType(widenForMatchSelector(tp.parent))
case tp: HKApply =>
widenForMatchSelector(tp.upperBound)
case tp: AnnotatedType =>