Skip to content

Commit 7cd930b

Browse files
committed
Address reviewers comments
1 parent cdfd219 commit 7cd930b

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

+32-4
Original file line numberDiff line numberDiff line change
@@ -1399,16 +1399,21 @@ object Types {
13991399
*/
14001400
def simplified(implicit ctx: Context) = ctx.simplify(this, null)
14011401

1402+
/** Compare `this == that`, assuming corresponding binders in `bs` are equal.
1403+
* The normal `equals` should be equivalent to `equals(that, null`)`.
1404+
* We usually override `equals` when we override `iso` except if the
1405+
* `equals` comes from a case class, so it already has the right definition anyway.
1406+
*/
14021407
final def equals(that: Any, bs: BinderPairs): Boolean =
14031408
(this `eq` that.asInstanceOf[AnyRef]) || this.iso(that, bs)
14041409

1405-
/** Is `this` isomorphic to that, using comparer `e`?
1410+
/** Is `this` isomorphic to `that`, assuming pairs of matching binders `bs`?
14061411
* It is assumed that `this.ne(that)`.
14071412
*/
14081413
protected def iso(that: Any, bs: BinderPairs): Boolean = this.equals(that)
14091414

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

@@ -1536,7 +1541,7 @@ object Types {
15361541
* Otherise the standard identity hash.
15371542
*/
15381543
override def identityHash(bs: Binders) = {
1539-
def recur(n: Int, tp: BindingType, rest: Binders): Int =
1544+
def recur(n: Int, tp: BindingType, rest: Binders): Int =
15401545
if (this `eq` tp) finishHash(hashing.mix(hashSeed, n), 1)
15411546
else if (rest == null) System.identityHashCode(this)
15421547
else recur(n + 1, rest.tp, rest.next)
@@ -2320,6 +2325,7 @@ object Types {
23202325
parent.equals(that.parent, bs)
23212326
case _ => false
23222327
}
2328+
// equals comes from case class; no matching override is needed
23232329
}
23242330

23252331
class CachedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)
@@ -2482,6 +2488,7 @@ object Types {
24822488
case that: AndOrType => isAnd == that.isAnd && tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
24832489
case _ => false
24842490
}
2491+
// equals comes from case classes; no matching override is needed
24852492
}
24862493

24872494
abstract case class AndType(tp1: Type, tp2: Type) extends AndOrType {
@@ -2624,6 +2631,7 @@ object Types {
26242631
case that: ExprType => resType.equals(that.resType, bs)
26252632
case _ => false
26262633
}
2634+
// equals comes from case class; no matching override is needed
26272635
}
26282636

26292637
final class CachedExprType(resultType: Type) extends ExprType(resultType)
@@ -2727,6 +2735,22 @@ object Types {
27272735
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
27282736
final override def hashCode = System.identityHashCode(this)
27292737
final override def equals(other: Any) = this `eq` other.asInstanceOf[AnyRef]
2738+
2739+
final override def equals(that: Any) = equals(that, null)
2740+
2741+
// No definition of `eql` --> fall back on equals, which calls iso
2742+
2743+
final override def iso(that: Any, bs: BinderPairs) = that match {
2744+
case that: MethodOrPoly =>
2745+
paramNames.eqElements(that.paramNames) &&
2746+
companion.eq(that.companion) && {
2747+
val bs1 = new BinderPairs(this, that, bs)
2748+
paramInfos.equalElements(that.paramInfos, bs1) &&
2749+
resType.equals(that.resType, bs1)
2750+
}
2751+
case _ =>
2752+
false
2753+
}
27302754
}
27312755

27322756
trait TermLambda extends LambdaType { thisLambdaType =>
@@ -3192,6 +3216,7 @@ object Types {
31923216
case that: AppliedType => tycon.equals(that.tycon, bs) && args.equalElements(that.args, bs)
31933217
case _ => false
31943218
}
3219+
// equals comes from case class; no matching override is needed
31953220
}
31963221

31973222
final class CachedAppliedType(tycon: Type, args: List[Type], hc: Int) extends AppliedType(tycon, args) {
@@ -3230,7 +3255,7 @@ object Types {
32303255
override def equals(that: Any) = equals(that, null)
32313256

32323257
override def iso(that: Any, bs: BinderPairs) = that match {
3233-
case that: ParamRef => binder.equalBinder(that.binder, bs) && paramNum == that.paramNum
3258+
case that: ParamRef => paramNum == that.paramNum && binder.equalBinder(that.binder, bs)
32343259
case _ => false
32353260
}
32363261

@@ -3617,6 +3642,7 @@ object Types {
36173642
case that: TypeAlias => alias.equals(that.alias, bs)
36183643
case _ => false
36193644
}
3645+
// equals comes from case class; no matching override is needed
36203646

36213647
override def eql(that: Type): Boolean = that match {
36223648
case that: TypeAlias => alias.eq(that.alias)
@@ -3661,6 +3687,7 @@ object Types {
36613687
case that: AnnotatedType => tpe.equals(that.tpe, bs) && (annot `eq` that.annot)
36623688
case _ => false
36633689
}
3690+
// equals comes from case class; no matching override is needed
36643691
}
36653692

36663693
object AnnotatedType {
@@ -3751,6 +3778,7 @@ object Types {
37513778
case that: WildcardType => optBounds.equals(that.optBounds, bs)
37523779
case _ => false
37533780
}
3781+
// equals comes from case class; no matching override is needed
37543782
}
37553783

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

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

+1-1
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)