@@ -1398,16 +1398,23 @@ object Types {
1398
1398
*/
1399
1399
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1400
1400
1401
- /** customized hash code of this type.
1402
- * NotCached for uncached types. Cached types
1403
- * compute hash and use it as the type's hashCode.
1401
+ final override def equals (that : Any ) = StructEquality .equals(this , that)
1402
+
1403
+ /** Is `this` isomorphic to that, using comparer `e`?
1404
+ * It is assumed that `this ne that`.
1404
1405
*/
1405
- def hash : Int
1406
+ def iso ( that : Any , e : StructEquality ) : Boolean = false
1406
1407
1407
1408
/** Equality used for hash-consing; uses `eq` on all recursive invocations.
1408
1409
*/
1409
1410
def eql (that : Type ): Boolean = this .equals(that)
1410
1411
1412
+ /** customized hash code of this type.
1413
+ * NotCached for uncached types. Cached types
1414
+ * compute hash and use it as the type's hashCode.
1415
+ */
1416
+ def hash : Int
1417
+
1411
1418
/** Compute `hash` using given `Hashing` */
1412
1419
def computeHash (h : Hashing ): Int
1413
1420
@@ -2015,10 +2022,10 @@ object Types {
2015
2022
}
2016
2023
}
2017
2024
2018
- override def equals (that : Any ) = that match {
2025
+ override def iso (that : Any , e : StructEquality ) : Boolean = that match {
2019
2026
case that : NamedType =>
2020
2027
this .designator == that.designator &&
2021
- this .prefix == that.prefix
2028
+ e.equals( this .prefix, that.prefix)
2022
2029
case _ =>
2023
2030
false
2024
2031
}
@@ -2153,6 +2160,11 @@ object Types {
2153
2160
case that : ThisType => tref.eq(that.tref)
2154
2161
case _ => false
2155
2162
}
2163
+
2164
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
2165
+ case that : ThisType => e.equals(tref, that.tref)
2166
+ case _ => false
2167
+ }
2156
2168
}
2157
2169
2158
2170
final class CachedThisType (tref : TypeRef ) extends ThisType (tref)
@@ -2181,6 +2193,12 @@ object Types {
2181
2193
case that : SuperType => thistpe.eq(that.thistpe) && supertpe.eq(that.supertpe)
2182
2194
case _ => false
2183
2195
}
2196
+
2197
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
2198
+ case that : SuperType =>
2199
+ e.equals(thistpe, that.thistpe) && e.equals(supertpe, that.supertpe)
2200
+ case _ => false
2201
+ }
2184
2202
}
2185
2203
2186
2204
final class CachedSuperType (thistpe : Type , supertpe : Type ) extends SuperType (thistpe, supertpe)
@@ -2197,6 +2215,11 @@ object Types {
2197
2215
override def underlying (implicit ctx : Context ) = value.tpe
2198
2216
2199
2217
override def computeHash (h : Hashing ) = h.doHash(getClass, value)
2218
+
2219
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
2220
+ case that : ConstantType => value.equals(that.value)
2221
+ case _ => false
2222
+ }
2200
2223
}
2201
2224
2202
2225
final class CachedConstantType (value : Constant ) extends ConstantType (value)
@@ -2223,7 +2246,6 @@ object Types {
2223
2246
def evaluating = computed && myRef == null
2224
2247
override def underlying (implicit ctx : Context ) = ref
2225
2248
override def toString = s " LazyRef( ${if (computed) myRef else " ..." }) "
2226
- override def equals (other : Any ) = this .eq(other.asInstanceOf [AnyRef ])
2227
2249
override def hashCode = System .identityHashCode(this )
2228
2250
}
2229
2251
@@ -2269,6 +2291,14 @@ object Types {
2269
2291
parent.eq(that.parent)
2270
2292
case _ => false
2271
2293
}
2294
+
2295
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
2296
+ case that : RefinedType =>
2297
+ refinedName.eq(that.refinedName) &&
2298
+ e.equals(refinedInfo, that.refinedInfo) &&
2299
+ e.equals(parent, that.parent)
2300
+ case _ => false
2301
+ }
2272
2302
}
2273
2303
2274
2304
class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
@@ -2324,15 +2354,16 @@ object Types {
2324
2354
refacc.apply(false , tp)
2325
2355
}
2326
2356
2327
- override def computeHash (h : Hashing ) = h.doHash(getClass, parent)
2357
+ override def computeHash (h : Hashing ) = h.withBinder( this ). doHash(getClass, parent)
2328
2358
2329
- override def equals (that : Any ) = that match {
2330
- case that : RecType => parent == that.parent
2359
+ override def eql (that : Type ) = that match {
2360
+ case that : RecType => parent.eq( that.parent)
2331
2361
case _ => false
2332
2362
}
2333
2363
2334
- override def eql (that : Type ) = that match {
2335
- case that : RecType => parent.eq(that.parent)
2364
+ override def iso (that : Any , e : StructEquality ) = that match {
2365
+ case that : RecType =>
2366
+ e.withBinders(this , that).equals(parent, that.parent)
2336
2367
case _ => false
2337
2368
}
2338
2369
@@ -2436,6 +2467,11 @@ object Types {
2436
2467
case that : AndType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
2437
2468
case _ => false
2438
2469
}
2470
+
2471
+ override def iso (that : Any , e : StructEquality ) = that match {
2472
+ case that : AndType => e.equals(tp1, that.tp1) && e.equals(tp2, that.tp2)
2473
+ case _ => false
2474
+ }
2439
2475
}
2440
2476
2441
2477
final class CachedAndType (tp1 : Type , tp2 : Type ) extends AndType (tp1, tp2)
@@ -2497,6 +2533,11 @@ object Types {
2497
2533
case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
2498
2534
case _ => false
2499
2535
}
2536
+
2537
+ override def iso (that : Any , e : StructEquality ) = that match {
2538
+ case that : OrType => e.equals(tp1, that.tp1) && e.equals(tp2, that.tp2)
2539
+ case _ => false
2540
+ }
2500
2541
}
2501
2542
2502
2543
final class CachedOrType (tp1 : Type , tp2 : Type ) extends OrType (tp1, tp2)
@@ -2563,6 +2604,11 @@ object Types {
2563
2604
case that : ExprType => resType.eq(that.resType)
2564
2605
case _ => false
2565
2606
}
2607
+
2608
+ override def iso (that : Any , e : StructEquality ) = that match {
2609
+ case that : ExprType => e.equals(resType, that.resType)
2610
+ case _ => false
2611
+ }
2566
2612
}
2567
2613
2568
2614
final class CachedExprType (resultType : Type ) extends ExprType (resultType)
@@ -2641,30 +2687,33 @@ object Types {
2641
2687
abstract class HKLambda extends CachedProxyType with LambdaType {
2642
2688
final override def underlying (implicit ctx : Context ) = resType
2643
2689
2644
- final override def computeHash (h : Hashing ) = h.doHash(getClass, paramNames, resType, paramInfos)
2690
+ final override def computeHash (h : Hashing ) =
2691
+ h.withBinder(this ).doHash(getClass, paramNames, resType, paramInfos)
2645
2692
2646
- final override def equals (that : Any ) = that match {
2693
+ final override def eql (that : Type ) = that match {
2647
2694
case that : HKLambda =>
2648
- paramNames == that.paramNames &&
2649
- paramInfos == that.paramInfos &&
2650
- resType == that.resType &&
2695
+ paramNames.equals( that.paramNames) &&
2696
+ paramInfos.equals( that.paramInfos) &&
2697
+ resType.equals( that.resType) &&
2651
2698
companion.eq(that.companion)
2652
2699
case _ =>
2653
2700
false
2654
2701
}
2655
2702
2656
- final override def eql (that : Type ) = that match {
2703
+ final override def iso (that : Any , e : StructEquality ) = that match {
2657
2704
case that : HKLambda =>
2658
- paramNames.equals(that.paramNames) &&
2659
- paramInfos.equals(that.paramInfos) &&
2660
- resType.equals(that.resType) &&
2661
- companion.eq(that.companion)
2705
+ paramNames.eqElements(that.paramNames) &&
2706
+ companion.eq(that.companion) && {
2707
+ val e1 = e.withBinders(this , that)
2708
+ e1.equals(paramInfos, that.paramInfos) &&
2709
+ e1.equals(resType, that.resType)
2710
+ }
2662
2711
case _ =>
2663
2712
false
2664
2713
}
2665
2714
}
2666
2715
2667
- trait MethodOrPoly extends LambdaType with MethodicType
2716
+ trait MethodOrPoly extends LambdaType with MethodicType // TODO: Make PolyTypes cached
2668
2717
2669
2718
trait TermLambda extends LambdaType { thisLambdaType =>
2670
2719
import DepStatus ._
@@ -2800,23 +2849,25 @@ object Types {
2800
2849
2801
2850
final override def computeHash (h : Hashing ) = h.doHash(getClass, paramNames, resType, paramInfos)
2802
2851
2803
- final override def equals (that : Any ) = that match {
2852
+ final override def eql (that : Type ) = that match {
2804
2853
case that : MethodType =>
2805
- paramNames == that.paramNames &&
2806
- paramInfos == that.paramInfos &&
2807
- resType == that.resType &&
2854
+ paramNames.eqElements( that.paramNames) &&
2855
+ paramInfos.eqElements( that.paramInfos) &&
2856
+ resType.eq( that.resType) &&
2808
2857
companion.eq(that.companion)
2809
2858
case _ =>
2810
2859
false
2811
2860
}
2812
2861
2813
- final override def eql (that : Type ) = that match {
2862
+ final override def iso (that : Any , e : StructEquality ) = that match {
2814
2863
case that : MethodType =>
2815
2864
paramNames.eqElements(that.paramNames) &&
2816
- paramInfos.eqElements(that.paramInfos) &&
2817
- resType.eq(that.resType) &&
2818
- companion.eq(that.companion)
2819
- case _ =>
2865
+ companion.eq(that.companion) && {
2866
+ val e1 = e.withBinders(this , that)
2867
+ e1.equals(paramInfos, that.paramInfos) &&
2868
+ e1.equals(resType, that.resType)
2869
+ }
2870
+ case _ =>
2820
2871
false
2821
2872
}
2822
2873
@@ -3008,6 +3059,18 @@ object Types {
3008
3059
case _ => this
3009
3060
}
3010
3061
3062
+ final override def iso (that : Any , e : StructEquality ) = that match { // TODO: Move up to MethodOrPoly
3063
+ case that : PolyType =>
3064
+ paramNames.eqElements(that.paramNames) &&
3065
+ companion.eq(that.companion) && {
3066
+ val e1 = e.withBinders(this , that)
3067
+ e1.equals(paramInfos, that.paramInfos) &&
3068
+ e1.equals(resType, that.resType)
3069
+ }
3070
+ case _ =>
3071
+ false
3072
+ }
3073
+
3011
3074
protected def prefixString = " PolyType"
3012
3075
}
3013
3076
@@ -3136,12 +3199,18 @@ object Types {
3136
3199
def derivedAppliedType (tycon : Type , args : List [Type ])(implicit ctx : Context ): Type =
3137
3200
if ((tycon eq this .tycon) && (args eq this .args)) this
3138
3201
else tycon.appliedTo(args)
3202
+
3203
+ override def computeHash (h : Hashing ) = h.doHash(getClass, tycon, args)
3204
+ override def eql (that : Type ) = this eq that // safe because applied types are hash-consed separately
3205
+
3206
+ final override def iso (that : Any , e : StructEquality ) = that match {
3207
+ case that : AppliedType => e.equals(tycon, that.tycon) && e.equals(args, that.args)
3208
+ case _ => false
3209
+ }
3139
3210
}
3140
3211
3141
3212
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
3142
3213
myHash = hc
3143
- override def computeHash (h : Hashing ) = h.doHash(getClass, tycon, args)
3144
- override def eql (that : Type ) = this eq that // safe because applied types are hash-consed separately
3145
3214
}
3146
3215
3147
3216
object AppliedType {
@@ -3172,8 +3241,8 @@ object Types {
3172
3241
3173
3242
override def computeHash (h : Hashing ) = h.doHash(getClass, paramNum, h.identityHash(binder))
3174
3243
3175
- override def equals (that : Any ) = that match {
3176
- case that : ParamRef => binder.eq( that.binder) && paramNum == that.paramNum
3244
+ override def iso (that : Any , e : StructEquality ) = that match {
3245
+ case that : ParamRef => e.equalBinders(binder, that.binder) && paramNum == that.paramNum
3177
3246
case _ => false
3178
3247
}
3179
3248
@@ -3229,8 +3298,8 @@ object Types {
3229
3298
// between RecTypes and RecRefs.
3230
3299
override def computeHash (h : Hashing ) = h.addDelta(h.identityHash(binder), 41 )
3231
3300
3232
- override def equals (that : Any ) = that match {
3233
- case that : RecThis => binder.eq( that.binder)
3301
+ override def iso (that : Any , e : StructEquality ) = that match {
3302
+ case that : RecThis => e.equalBinders(binder, that.binder)
3234
3303
case _ => false
3235
3304
}
3236
3305
@@ -3249,7 +3318,6 @@ object Types {
3249
3318
def derivedSkolemType (info : Type )(implicit ctx : Context ) =
3250
3319
if (info eq this .info) this else SkolemType (info)
3251
3320
override def hashCode : Int = System .identityHashCode(this )
3252
- override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3253
3321
3254
3322
def withName (name : Name ): this .type = { myRepr = name; this }
3255
3323
@@ -3356,7 +3424,6 @@ object Types {
3356
3424
}
3357
3425
3358
3426
override def computeHash (h : Hashing ): Int = h.identityHash(this )
3359
- override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3360
3427
3361
3428
override def toString = {
3362
3429
def instStr = if (inst.exists) s " -> $inst" else " "
@@ -3442,6 +3509,16 @@ object Types {
3442
3509
case _ => false
3443
3510
}
3444
3511
3512
+ override def iso (that : Any , e : StructEquality ) = that match {
3513
+ case that : ClassInfo =>
3514
+ e.equals(prefix, that.prefix) &&
3515
+ cls.eq(that.cls) &&
3516
+ e.equals(classParents, that.classParents) &&
3517
+ decls.eq(that.decls) &&
3518
+ selfInfo.eq(that.selfInfo)
3519
+ case _ => false
3520
+ }
3521
+
3445
3522
override def toString = s " ClassInfo( $prefix, $cls, $classParents) "
3446
3523
}
3447
3524
@@ -3515,9 +3592,9 @@ object Types {
3515
3592
3516
3593
override def computeHash (h : Hashing ) = h.doHash(getClass, lo, hi)
3517
3594
3518
- override def equals (that : Any ): Boolean = that match {
3595
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
3519
3596
case that : TypeAlias => false
3520
- case that : TypeBounds => lo == that.lo && hi == that.hi
3597
+ case that : TypeBounds => e.equals(lo, that.lo) && e.equals(hi, that.hi)
3521
3598
case _ => false
3522
3599
}
3523
3600
@@ -3538,8 +3615,8 @@ object Types {
3538
3615
3539
3616
override def computeHash (h : Hashing ) = h.doHash(getClass, alias)
3540
3617
3541
- override def equals (that : Any ): Boolean = that match {
3542
- case that : TypeAlias => alias == that.alias
3618
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
3619
+ case that : TypeAlias => e.equals( alias, that.alias)
3543
3620
case _ => false
3544
3621
}
3545
3622
@@ -3581,6 +3658,11 @@ object Types {
3581
3658
derivedAnnotatedType(tpe.stripTypeVar, annot)
3582
3659
3583
3660
override def stripAnnots (implicit ctx : Context ): Type = tpe.stripAnnots
3661
+
3662
+ override def iso (that : Any , e : StructEquality ): Boolean = that match {
3663
+ case that : AnnotatedType => e.equals(tpe, that.tpe) && (annot `eq` that.annot)
3664
+ case _ => false
3665
+ }
3584
3666
}
3585
3667
3586
3668
object AnnotatedType {
@@ -3601,6 +3683,11 @@ object Types {
3601
3683
case that : JavaArrayType => elemType.eq(that.elemType)
3602
3684
case _ => false
3603
3685
}
3686
+
3687
+ override def iso (that : Any , e : StructEquality ) = that match {
3688
+ case that : JavaArrayType => e.equals(elemType, that.elemType)
3689
+ case _ => false
3690
+ }
3604
3691
}
3605
3692
final class CachedJavaArrayType (elemType : Type ) extends JavaArrayType (elemType)
3606
3693
object JavaArrayType {
@@ -3664,6 +3751,11 @@ object Types {
3664
3751
case that : WildcardType => optBounds.eq(that.optBounds)
3665
3752
case _ => false
3666
3753
}
3754
+
3755
+ override def iso (that : Any , e : StructEquality ) = that match {
3756
+ case that : WildcardType => e.equals(optBounds, that.optBounds)
3757
+ case _ => false
3758
+ }
3667
3759
}
3668
3760
3669
3761
final class CachedWildcardType (optBounds : Type ) extends WildcardType (optBounds)
0 commit comments