Skip to content

Commit 127c8a6

Browse files
committed
Get rid of BindingKind
Under direct hk encoding this is no longer needed.
1 parent 38fb6c5 commit 127c8a6

File tree

4 files changed

+17
-61
lines changed

4 files changed

+17
-61
lines changed

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

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,25 +3119,20 @@ object Types {
31193119
unique(new CachedClassInfo(prefix, cls, classParents, decls, selfInfo))
31203120
}
31213121

3122-
/** Type bounds >: lo <: hi
3123-
* @param bindingKind: If != NoBinding, it indicates that this is
3124-
* an introduction of a higher-kinded type parameter.
3125-
* In that case it also defines the variance of the parameter.
3126-
*/
3127-
abstract case class TypeBounds(lo: Type, hi: Type)(val bindingKind: BindingKind) extends CachedProxyType with TypeType {
3122+
/** Type bounds >: lo <: hi */
3123+
abstract case class TypeBounds(lo: Type, hi: Type) extends CachedProxyType with TypeType {
31283124

31293125
assert(lo.isInstanceOf[TermType])
31303126
assert(hi.isInstanceOf[TermType])
31313127

31323128
def variance: Int = 0
3133-
def isBinding = bindingKind != NoBinding
31343129

31353130
override def underlying(implicit ctx: Context): Type = hi
31363131

31373132
/** The non-alias type bounds type with given bounds */
3138-
def derivedTypeBounds(lo: Type, hi: Type, bk: BindingKind = this.bindingKind)(implicit ctx: Context) =
3139-
if ((lo eq this.lo) && (hi eq this.hi) && (bk == this.bindingKind) && (variance == 0)) this
3140-
else TypeBounds(lo, hi, bk)
3133+
def derivedTypeBounds(lo: Type, hi: Type)(implicit ctx: Context) =
3134+
if ((lo eq this.lo) && (hi eq this.hi) && (variance == 0)) this
3135+
else TypeBounds(lo, hi)
31413136

31423137
/** If this is an alias, a derived alias with the new variance,
31433138
* Otherwise the type itself.
@@ -3147,13 +3142,6 @@ object Types {
31473142
case _ => this
31483143
}
31493144

3150-
def withBindingKind(bk: BindingKind)(implicit ctx: Context) = this match {
3151-
case tp: TypeAlias => assert(bk == NoBinding); this
3152-
case _ => derivedTypeBounds(lo, hi, bk)
3153-
}
3154-
3155-
//def checkBinding: this.type = { assert(isBinding); this }
3156-
31573145
def contains(tp: Type)(implicit ctx: Context): Boolean = tp match {
31583146
case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
31593147
case tp: ClassInfo =>
@@ -3166,12 +3154,12 @@ object Types {
31663154
def & (that: TypeBounds)(implicit ctx: Context): TypeBounds =
31673155
if ((this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi)) that
31683156
else if ((that.lo frozen_<:< this.lo) && (this.hi frozen_<:< that.hi)) this
3169-
else TypeBounds(this.lo | that.lo, this.hi & that.hi, this.bindingKind join that.bindingKind)
3157+
else TypeBounds(this.lo | that.lo, this.hi & that.hi)
31703158

31713159
def | (that: TypeBounds)(implicit ctx: Context): TypeBounds =
31723160
if ((this.lo frozen_<:< that.lo) && (that.hi frozen_<:< this.hi)) this
31733161
else if ((that.lo frozen_<:< this.lo) && (this.hi frozen_<:< that.hi)) that
3174-
else TypeBounds(this.lo & that.lo, this.hi | that.hi, this.bindingKind join that.bindingKind)
3162+
else TypeBounds(this.lo & that.lo, this.hi | that.hi)
31753163

31763164
override def & (that: Type)(implicit ctx: Context) = that match {
31773165
case that: TypeBounds => this & that
@@ -3191,25 +3179,22 @@ object Types {
31913179
/** If this type and that type have the same variance, this variance, otherwise 0 */
31923180
final def commonVariance(that: TypeBounds): Int = (this.variance + that.variance) / 2
31933181

3194-
override def computeHash = doHash(variance * 41 + bindingKind.n, lo, hi)
3182+
override def computeHash = doHash(variance, lo, hi)
31953183
override def equals(that: Any): Boolean = that match {
31963184
case that: TypeBounds =>
31973185
(this.lo eq that.lo) && (this.hi eq that.hi) &&
3198-
(this.variance == that.variance) && (this.bindingKind == that.bindingKind)
3186+
(this.variance == that.variance)
31993187
case _ =>
32003188
false
32013189
}
32023190

3203-
override def toString = {
3204-
def bkString = if (isBinding) s"|v=${BindingKind.toVariance(bindingKind)}" else ""
3205-
if (lo eq hi) s"TypeAlias($lo, $variance)"
3206-
else s"TypeBounds($lo, $hi$bkString)"
3207-
}
3191+
override def toString =
3192+
if (lo eq hi) s"TypeAlias($lo, $variance)" else s"TypeBounds($lo, $hi)"
32083193
}
32093194

3210-
class RealTypeBounds(lo: Type, hi: Type, bk: BindingKind) extends TypeBounds(lo, hi)(bk)
3195+
class RealTypeBounds(lo: Type, hi: Type) extends TypeBounds(lo, hi)
32113196

3212-
abstract class TypeAlias(val alias: Type, override val variance: Int) extends TypeBounds(alias, alias)(NoBinding) {
3197+
abstract class TypeAlias(val alias: Type, override val variance: Int) extends TypeBounds(alias, alias) {
32133198
/** pre: this is a type alias */
32143199
def derivedTypeAlias(alias: Type, variance: Int = this.variance)(implicit ctx: Context) =
32153200
if ((alias eq this.alias) && (variance == this.variance)) this
@@ -3240,8 +3225,8 @@ object Types {
32403225
}
32413226

32423227
object TypeBounds {
3243-
def apply(lo: Type, hi: Type, bk: BindingKind = NoBinding)(implicit ctx: Context): TypeBounds =
3244-
unique(new RealTypeBounds(lo, hi, bk))
3228+
def apply(lo: Type, hi: Type)(implicit ctx: Context): TypeBounds =
3229+
unique(new RealTypeBounds(lo, hi))
32453230
def empty(implicit ctx: Context) = apply(defn.NothingType, defn.AnyType)
32463231
def upper(hi: Type)(implicit ctx: Context) = apply(defn.NothingType, hi)
32473232
def lower(lo: Type)(implicit ctx: Context) = apply(lo, defn.AnyType)
@@ -3253,31 +3238,6 @@ object Types {
32533238
def unapply(tp: TypeAlias): Option[Type] = Some(tp.alias)
32543239
}
32553240

3256-
/** A value class defining the interpretation of a TypeBounds
3257-
* as either a regular type bounds or a binding (i.e. introduction) of a
3258-
* higher-kinded type parameter.
3259-
* TODO: drop
3260-
*/
3261-
class BindingKind(val n: Byte) extends AnyVal {
3262-
def join(that: BindingKind) =
3263-
if (this == that) this
3264-
else if (this == NoBinding || that == NoBinding) NoBinding
3265-
else NonvariantBinding
3266-
}
3267-
3268-
val NoBinding = new BindingKind(0) // Regular type bounds
3269-
val ContravariantBinding = new BindingKind(1) // Bounds for contravariant hk type param
3270-
val NonvariantBinding = new BindingKind(2) // Bounds for nonvariant hk type param
3271-
val CovariantBinding = new BindingKind(3) // Bounds for covariant hk type param
3272-
3273-
object BindingKind {
3274-
def fromVariance(v: Int): BindingKind = new BindingKind((v + NonvariantBinding.n).toByte)
3275-
def toVariance(bk: BindingKind): Int = {
3276-
assert(bk.n != 0)
3277-
bk.n - NonvariantBinding.n
3278-
}
3279-
}
3280-
32813241
// ----- Annotated and Import types -----------------------------------------------
32823242

32833243
/** An annotated type tpe @ annot */

src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Standard-Section: "ASTs" TopLevelStat*
130130
SUPERtype Length this_Type underlying_Type
131131
REFINEDtype Length underlying_Type refinement_NameRef info_Type
132132
APPLIEDtype Length tycon_Type arg_Type*
133-
TYPEBOUNDS Length low_Type high_Type bindingKind_Nat?
133+
TYPEBOUNDS Length low_Type high_Type
134134
TYPEALIAS Length alias_Type (COVARIANT | CONTRAVARIANT)?
135135
ANNOTATED Length underlying_Type fullAnnotation_Term
136136
ANDtype Length left_Type right_Type

src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ class TreePickler(pickler: TastyPickler) {
243243
withLength {
244244
pickleType(tpe.lo, richTypes)
245245
pickleType(tpe.hi, richTypes)
246-
if (tpe.isBinding) writeNat(tpe.bindingKind.n)
247246
}
248247
case tpe: AnnotatedType =>
249248
writeByte(ANNOTATED)

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
266266
case APPLIEDtype =>
267267
readType().appliedTo(until(end)(readType()))
268268
case TYPEBOUNDS =>
269-
val lo = readType()
270-
val hi = readType()
271-
val bk = ifBefore(end)(new BindingKind(readNat().toByte), NoBinding)
272-
TypeBounds(lo, hi, bk)
269+
TypeBounds(readType(), readType())
273270
case TYPEALIAS =>
274271
val alias = readType()
275272
val variance =

0 commit comments

Comments
 (0)