Skip to content

Commit e96b8ca

Browse files
committed
Address reviewers comments
1 parent 9559161 commit e96b8ca

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,16 +1394,21 @@ object Types {
13941394
*/
13951395
def simplified(implicit ctx: Context) = ctx.simplify(this, null)
13961396

1397+
/** Compare `this == that`, assuming corresponding binders in `bs` are equal.
1398+
* The normal `equals` should be equivalent to `equals(that, null`)`.
1399+
* We usually override `equals` when we override `iso` except if the
1400+
* `equals` comes from a case class, so it already has the right definition anyway.
1401+
*/
13971402
final def equals(that: Any, bs: BinderPairs): Boolean =
13981403
(this `eq` that.asInstanceOf[AnyRef]) || this.iso(that, bs)
13991404

1400-
/** Is `this` isomorphic to that, using comparer `e`?
1405+
/** Is `this` isomorphic to `that`, assuming pairs of matching binders `bs`?
14011406
* It is assumed that `this.ne(that)`.
14021407
*/
14031408
protected def iso(that: Any, bs: BinderPairs): Boolean = this.equals(that)
14041409

14051410
/** Equality used for hash-consing; uses `eq` on all recursive invocations,
1406-
* except where a BindingType is inloved. The latter demand a deep isomorphism check.
1411+
* except where a BindingType is involved. The latter demand a deep isomorphism check.
14071412
*/
14081413
def eql(that: Type): Boolean = this.equals(that)
14091414

@@ -1531,7 +1536,7 @@ object Types {
15311536
* Otherise the standard identity hash.
15321537
*/
15331538
override def identityHash(bs: Binders) = {
1534-
def recur(n: Int, tp: BindingType, rest: Binders): Int =
1539+
def recur(n: Int, tp: BindingType, rest: Binders): Int =
15351540
if (this `eq` tp) finishHash(hashing.mix(hashSeed, n), 1)
15361541
else if (rest == null) System.identityHashCode(this)
15371542
else recur(n + 1, rest.tp, rest.next)
@@ -2311,6 +2316,7 @@ object Types {
23112316
parent.equals(that.parent, bs)
23122317
case _ => false
23132318
}
2319+
// equals comes from case class; no matching override is needed
23142320
}
23152321

23162322
class CachedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)
@@ -2473,6 +2479,7 @@ object Types {
24732479
case that: AndOrType => isAnd == that.isAnd && tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
24742480
case _ => false
24752481
}
2482+
// equals comes from case classes; no matching override is needed
24762483
}
24772484

24782485
abstract case class AndType(tp1: Type, tp2: Type) extends AndOrType {
@@ -2615,6 +2622,7 @@ object Types {
26152622
case that: ExprType => resType.equals(that.resType, bs)
26162623
case _ => false
26172624
}
2625+
// equals comes from case class; no matching override is needed
26182626
}
26192627

26202628
final class CachedExprType(resultType: Type) extends ExprType(resultType)
@@ -2718,6 +2726,22 @@ object Types {
27182726
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
27192727
final override def hashCode = System.identityHashCode(this)
27202728
final override def equals(other: Any) = this `eq` other.asInstanceOf[AnyRef]
2729+
2730+
final override def equals(that: Any) = equals(that, null)
2731+
2732+
// No definition of `eql` --> fall back on equals, which calls iso
2733+
2734+
final override def iso(that: Any, bs: BinderPairs) = that match {
2735+
case that: MethodOrPoly =>
2736+
paramNames.eqElements(that.paramNames) &&
2737+
companion.eq(that.companion) && {
2738+
val bs1 = new BinderPairs(this, that, bs)
2739+
paramInfos.equalElements(that.paramInfos, bs1) &&
2740+
resType.equals(that.resType, bs1)
2741+
}
2742+
case _ =>
2743+
false
2744+
}
27212745
}
27222746

27232747
trait TermLambda extends LambdaType { thisLambdaType =>
@@ -3183,6 +3207,7 @@ object Types {
31833207
case that: AppliedType => tycon.equals(that.tycon, bs) && args.equalElements(that.args, bs)
31843208
case _ => false
31853209
}
3210+
// equals comes from case class; no matching override is needed
31863211
}
31873212

31883213
final class CachedAppliedType(tycon: Type, args: List[Type], hc: Int) extends AppliedType(tycon, args) {
@@ -3221,7 +3246,7 @@ object Types {
32213246
override def equals(that: Any) = equals(that, null)
32223247

32233248
override def iso(that: Any, bs: BinderPairs) = that match {
3224-
case that: ParamRef => binder.equalBinder(that.binder, bs) && paramNum == that.paramNum
3249+
case that: ParamRef => paramNum == that.paramNum && binder.equalBinder(that.binder, bs)
32253250
case _ => false
32263251
}
32273252

@@ -3608,6 +3633,7 @@ object Types {
36083633
case that: TypeAlias => alias.equals(that.alias, bs)
36093634
case _ => false
36103635
}
3636+
// equals comes from case class; no matching override is needed
36113637

36123638
override def eql(that: Type): Boolean = that match {
36133639
case that: TypeAlias => alias.eq(that.alias)
@@ -3652,6 +3678,7 @@ object Types {
36523678
case that: AnnotatedType => tpe.equals(that.tpe, bs) && (annot `eq` that.annot)
36533679
case _ => false
36543680
}
3681+
// equals comes from case class; no matching override is needed
36553682
}
36563683

36573684
object AnnotatedType {
@@ -3742,6 +3769,7 @@ object Types {
37423769
case that: WildcardType => optBounds.equals(that.optBounds, bs)
37433770
case _ => false
37443771
}
3772+
// equals comes from case class; no matching override is needed
37453773
}
37463774

37473775
final class CachedWildcardType(optBounds: Type) extends WildcardType(optBounds)

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ object ProtoTypes {
402402
if (state.constraint contains tl) {
403403
var paramInfos = tl.paramInfos
404404
if (tl.isInstanceOf[HKLambda]) {
405-
// HKLambdas care hash-consed, need to create an artificial difference by adding
405+
// HKLambdas are hash-consed, need to create an artificial difference by adding
406406
// a LazyRef to a bound.
407407
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
408408
paramInfos = TypeBounds(lo, LazyRef(_ => hi)) :: pinfos1

0 commit comments

Comments
 (0)