@@ -1394,6 +1394,16 @@ object Types {
1394
1394
*/
1395
1395
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1396
1396
1397
+ final override def equals (that : Any ) = this .equals(that, null )
1398
+
1399
+ final def equals (that : Any , bs : BinderPairs ): Boolean =
1400
+ (this `eq` that.asInstanceOf [AnyRef ]) || this .iso(that, bs)
1401
+
1402
+ /** Is `this` isomorphic to that, using comparer `e`?
1403
+ * It is assumed that `this ne that`.
1404
+ */
1405
+ def iso (that : Any , bs : BinderPairs ): Boolean = false
1406
+
1397
1407
/** Equality used for hash-consing; uses `eq` on all recursive invocations.
1398
1408
*/
1399
1409
def eql (that : Type ): Boolean = this .equals(that)
@@ -1513,7 +1523,14 @@ object Types {
1513
1523
/** A marker trait for types that bind other types that refer to them.
1514
1524
* Instances are: LambdaType, RecType.
1515
1525
*/
1516
- trait BindingType extends Type
1526
+ trait BindingType extends Type {
1527
+
1528
+ override def identityHash (bs : Binders ) =
1529
+ if (bs == null ) super .identityHash(bs) else ???
1530
+
1531
+ def equalBinder (that : BindingType , bs : BinderPairs ): Boolean =
1532
+ (this `eq` that) /* || ??? */
1533
+ }
1517
1534
1518
1535
/** A trait for proto-types, used as expected types in typer */
1519
1536
trait ProtoType extends Type {
@@ -2011,10 +2028,10 @@ object Types {
2011
2028
}
2012
2029
}
2013
2030
2014
- override def equals (that : Any ) = that match {
2031
+ override def iso (that : Any , bs : BinderPairs ) : Boolean = that match {
2015
2032
case that : NamedType =>
2016
- this . designator == that.designator &&
2017
- this . prefix == that.prefix
2033
+ designator == that.designator &&
2034
+ prefix.equals( that.prefix, bs)
2018
2035
case _ =>
2019
2036
false
2020
2037
}
@@ -2149,6 +2166,11 @@ object Types {
2149
2166
case that : ThisType => tref.eq(that.tref)
2150
2167
case _ => false
2151
2168
}
2169
+
2170
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
2171
+ case that : ThisType => tref.equals(that.tref, bs)
2172
+ case _ => false
2173
+ }
2152
2174
}
2153
2175
2154
2176
final class CachedThisType (tref : TypeRef ) extends ThisType (tref)
@@ -2177,6 +2199,12 @@ object Types {
2177
2199
case that : SuperType => thistpe.eq(that.thistpe) && supertpe.eq(that.supertpe)
2178
2200
case _ => false
2179
2201
}
2202
+
2203
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
2204
+ case that : SuperType =>
2205
+ thistpe.equals(that.thistpe, bs) && supertpe.equals(that.supertpe, bs)
2206
+ case _ => false
2207
+ }
2180
2208
}
2181
2209
2182
2210
final class CachedSuperType (thistpe : Type , supertpe : Type ) extends SuperType (thistpe, supertpe)
@@ -2193,6 +2221,11 @@ object Types {
2193
2221
override def underlying (implicit ctx : Context ) = value.tpe
2194
2222
2195
2223
override def computeHash (bs : Binders ) = doHash(value)
2224
+
2225
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
2226
+ case that : ConstantType => value.equals(that.value)
2227
+ case _ => false
2228
+ }
2196
2229
}
2197
2230
2198
2231
final class CachedConstantType (value : Constant ) extends ConstantType (value)
@@ -2219,7 +2252,6 @@ object Types {
2219
2252
def evaluating = computed && myRef == null
2220
2253
override def underlying (implicit ctx : Context ) = ref
2221
2254
override def toString = s " LazyRef( ${if (computed) myRef else " ..." }) "
2222
- override def equals (other : Any ) = this .eq(other.asInstanceOf [AnyRef ])
2223
2255
override def hashCode = System .identityHashCode(this )
2224
2256
}
2225
2257
@@ -2265,6 +2297,14 @@ object Types {
2265
2297
parent.eq(that.parent)
2266
2298
case _ => false
2267
2299
}
2300
+
2301
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
2302
+ case that : RefinedType =>
2303
+ refinedName.eq(that.refinedName) &&
2304
+ refinedInfo.equals(that.refinedInfo, bs) &&
2305
+ parent.equals(that.parent, bs)
2306
+ case _ => false
2307
+ }
2268
2308
}
2269
2309
2270
2310
class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
@@ -2322,13 +2362,14 @@ object Types {
2322
2362
2323
2363
override def computeHash (bs : Binders ) = doHash(bs, parent)
2324
2364
2325
- override def equals (that : Any ) = that match {
2326
- case that : RecType => parent == that.parent
2365
+ override def eql (that : Type ) = that match {
2366
+ case that : RecType => parent.eq( that.parent)
2327
2367
case _ => false
2328
2368
}
2329
2369
2330
- override def eql (that : Type ) = that match {
2331
- case that : RecType => parent.eq(that.parent)
2370
+ override def iso (that : Any , bs : BinderPairs ) = that match {
2371
+ case that : RecType =>
2372
+ parent.equals(that.parent, bs/* !!!*/ )
2332
2373
case _ => false
2333
2374
}
2334
2375
@@ -2432,6 +2473,11 @@ object Types {
2432
2473
case that : AndType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
2433
2474
case _ => false
2434
2475
}
2476
+
2477
+ override def iso (that : Any , bs : BinderPairs ) = that match {
2478
+ case that : AndType => tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
2479
+ case _ => false
2480
+ }
2435
2481
}
2436
2482
2437
2483
final class CachedAndType (tp1 : Type , tp2 : Type ) extends AndType (tp1, tp2)
@@ -2493,6 +2539,11 @@ object Types {
2493
2539
case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
2494
2540
case _ => false
2495
2541
}
2542
+
2543
+ override def iso (that : Any , bs : BinderPairs ) = that match {
2544
+ case that : OrType => tp1.equals(that.tp1, bs) && tp2.equals(that.tp2, bs)
2545
+ case _ => false
2546
+ }
2496
2547
}
2497
2548
2498
2549
final class CachedOrType (tp1 : Type , tp2 : Type ) extends OrType (tp1, tp2)
@@ -2559,6 +2610,11 @@ object Types {
2559
2610
case that : ExprType => resType.eq(that.resType)
2560
2611
case _ => false
2561
2612
}
2613
+
2614
+ override def iso (that : Any , bs : BinderPairs ) = that match {
2615
+ case that : ExprType => resType.equals(that.resType, bs)
2616
+ case _ => false
2617
+ }
2562
2618
}
2563
2619
2564
2620
final class CachedExprType (resultType : Type ) extends ExprType (resultType)
@@ -2639,30 +2695,31 @@ object Types {
2639
2695
2640
2696
final override def computeHash (bs : Binders ) = doHash(bs, paramNames, resType, paramInfos)
2641
2697
2642
- final override def equals (that : Any ) = that match {
2698
+ final override def eql (that : Type ) = that match {
2643
2699
case that : HKLambda =>
2644
- paramNames == that.paramNames &&
2645
- paramInfos == that.paramInfos &&
2646
- resType == that.resType &&
2700
+ paramNames.equals( that.paramNames) &&
2701
+ paramInfos.equals( that.paramInfos) &&
2702
+ resType.equals( that.resType) &&
2647
2703
companion.eq(that.companion)
2648
2704
case _ =>
2649
2705
false
2650
2706
}
2651
2707
2652
- final override def eql (that : Type ) = that match {
2708
+ final override def iso (that : Any , bs : BinderPairs ) = that match {
2653
2709
case that : HKLambda =>
2654
- paramNames.equals(that.paramNames) &&
2655
- paramInfos.equals(that.paramInfos) &&
2656
- resType.equals(that.resType) &&
2657
- companion.eq(that.companion)
2710
+ paramNames.eqElements(that.paramNames) &&
2711
+ companion.eq(that.companion) && {
2712
+ val bs1 = bs
2713
+ paramInfos.equalElements(that.paramInfos, bs1) &&
2714
+ resType.equals(that.resType, bs1)
2715
+ }
2658
2716
case _ =>
2659
2717
false
2660
2718
}
2661
2719
}
2662
2720
2663
2721
abstract class MethodOrPoly extends UncachedGroundType with LambdaType with MethodicType {
2664
2722
final override def hashCode = System .identityHashCode(this )
2665
- final override def equals (other : Any ) = this `eq` other.asInstanceOf [AnyRef ]
2666
2723
}
2667
2724
2668
2725
trait TermLambda extends LambdaType { thisLambdaType =>
@@ -3116,6 +3173,11 @@ object Types {
3116
3173
3117
3174
override def computeHash (bs : Binders ) = doHash(bs, tycon, args)
3118
3175
override def eql (that : Type ) = this `eq` that // safe because applied types are hash-consed separately
3176
+
3177
+ final override def iso (that : Any , bs : BinderPairs ) = that match {
3178
+ case that : AppliedType => tycon.equals(that.tycon, bs) && args.equalElements(that.args, bs)
3179
+ case _ => false
3180
+ }
3119
3181
}
3120
3182
3121
3183
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
@@ -3135,8 +3197,6 @@ object Types {
3135
3197
type BT <: Type
3136
3198
val binder : BT
3137
3199
def copyBoundType (bt : BT ): Type
3138
- override def identityHash (bs : Binders ) =
3139
- if (bs == null ) super .identityHash(bs) else ???
3140
3200
}
3141
3201
3142
3202
abstract class ParamRef extends BoundType {
@@ -3152,8 +3212,8 @@ object Types {
3152
3212
3153
3213
override def computeHash (bs : Binders ) = doHash(bs, paramNum, binder.identityHash(bs))
3154
3214
3155
- override def equals (that : Any ) = that match {
3156
- case that : ParamRef => binder.eq (that.binder) && paramNum == that.paramNum
3215
+ override def iso (that : Any , bs : BinderPairs ) = that match {
3216
+ case that : ParamRef => binder.equalBinder (that.binder, bs ) && paramNum == that.paramNum
3157
3217
case _ => false
3158
3218
}
3159
3219
@@ -3209,8 +3269,8 @@ object Types {
3209
3269
// between RecTypes and RecRefs.
3210
3270
override def computeHash (bs : Binders ) = addDelta(binder.identityHash(bs), 41 )
3211
3271
3212
- override def equals (that : Any ) = that match {
3213
- case that : RecThis => binder.eq (that.binder)
3272
+ override def iso (that : Any , bs : BinderPairs ) = that match {
3273
+ case that : RecThis => binder.equalBinder (that.binder, bs )
3214
3274
case _ => false
3215
3275
}
3216
3276
@@ -3229,7 +3289,6 @@ object Types {
3229
3289
def derivedSkolemType (info : Type )(implicit ctx : Context ) =
3230
3290
if (info eq this .info) this else SkolemType (info)
3231
3291
override def hashCode : Int = System .identityHashCode(this )
3232
- override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3233
3292
3234
3293
def withName (name : Name ): this .type = { myRepr = name; this }
3235
3294
@@ -3335,7 +3394,6 @@ object Types {
3335
3394
}
3336
3395
3337
3396
override def computeHash (bs : Binders ): Int = identityHash(bs)
3338
- override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3339
3397
3340
3398
override def toString = {
3341
3399
def instStr = if (inst.exists) s " -> $inst" else " "
@@ -3421,6 +3479,16 @@ object Types {
3421
3479
case _ => false
3422
3480
}
3423
3481
3482
+ override def iso (that : Any , bs : BinderPairs ) = that match {
3483
+ case that : ClassInfo =>
3484
+ prefix.equals(that.prefix, bs) &&
3485
+ cls.eq(that.cls) &&
3486
+ classParents.equalElements(that.classParents, bs) &&
3487
+ decls.eq(that.decls) &&
3488
+ selfInfo.eq(that.selfInfo)
3489
+ case _ => false
3490
+ }
3491
+
3424
3492
override def toString = s " ClassInfo( $prefix, $cls, $classParents) "
3425
3493
}
3426
3494
@@ -3494,9 +3562,9 @@ object Types {
3494
3562
3495
3563
override def computeHash (bs : Binders ) = doHash(bs, lo, hi)
3496
3564
3497
- override def equals (that : Any ): Boolean = that match {
3565
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
3498
3566
case that : TypeAlias => false
3499
- case that : TypeBounds => lo == that.lo && hi == that.hi
3567
+ case that : TypeBounds => lo.equals( that.lo, bs) && hi.equals( that.hi, bs)
3500
3568
case _ => false
3501
3569
}
3502
3570
@@ -3517,8 +3585,8 @@ object Types {
3517
3585
3518
3586
override def computeHash (bs : Binders ) = doHash(bs, alias)
3519
3587
3520
- override def equals (that : Any ): Boolean = that match {
3521
- case that : TypeAlias => alias == that.alias
3588
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
3589
+ case that : TypeAlias => alias.equals( that.alias, bs)
3522
3590
case _ => false
3523
3591
}
3524
3592
@@ -3560,6 +3628,11 @@ object Types {
3560
3628
derivedAnnotatedType(tpe.stripTypeVar, annot)
3561
3629
3562
3630
override def stripAnnots (implicit ctx : Context ): Type = tpe.stripAnnots
3631
+
3632
+ override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
3633
+ case that : AnnotatedType => tpe.equals(that.tpe, bs) && (annot `eq` that.annot)
3634
+ case _ => false
3635
+ }
3563
3636
}
3564
3637
3565
3638
object AnnotatedType {
@@ -3580,6 +3653,11 @@ object Types {
3580
3653
case that : JavaArrayType => elemType.eq(that.elemType)
3581
3654
case _ => false
3582
3655
}
3656
+
3657
+ override def iso (that : Any , bs : BinderPairs ) = that match {
3658
+ case that : JavaArrayType => elemType.equals(that.elemType, bs)
3659
+ case _ => false
3660
+ }
3583
3661
}
3584
3662
final class CachedJavaArrayType (elemType : Type ) extends JavaArrayType (elemType)
3585
3663
object JavaArrayType {
@@ -3643,6 +3721,11 @@ object Types {
3643
3721
case that : WildcardType => optBounds.eq(that.optBounds)
3644
3722
case _ => false
3645
3723
}
3724
+
3725
+ override def iso (that : Any , bs : BinderPairs ) = that match {
3726
+ case that : WildcardType => optBounds.equals(that.optBounds, bs)
3727
+ case _ => false
3728
+ }
3646
3729
}
3647
3730
3648
3731
final class CachedWildcardType (optBounds : Type ) extends WildcardType (optBounds)
@@ -4425,4 +4508,12 @@ object Types {
4425
4508
// ----- Decorator implicits --------------------------------------------
4426
4509
4427
4510
implicit def decorateTypeApplications (tpe : Type ): TypeApplications = new TypeApplications (tpe)
4511
+
4512
+ implicit class listEquals (val tps1 : List [Type ]) extends AnyVal {
4513
+ @ tailrec def equalElements (tps2 : List [Type ], bs : BinderPairs ): Boolean =
4514
+ (tps1 `eq` tps2) || {
4515
+ if (tps1.isEmpty) tps2.isEmpty
4516
+ else tps2.nonEmpty && tps1.head.equals(tps2.head, bs) && tps1.tail.equalElements(tps2.tail, bs)
4517
+ }
4518
+ }
4428
4519
}
0 commit comments