@@ -1399,15 +1399,18 @@ object Types {
1399
1399
*/
1400
1400
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1401
1401
1402
+ /** Equality used for hash-consing; uses `eq` on all recursive invocations.
1403
+ */
1404
+ def eql (that : Type ): Boolean = this .equals(that)
1405
+
1402
1406
/** customized hash code of this type.
1403
1407
* NotCached for uncached types. Cached types
1404
1408
* compute hash and use it as the type's hashCode.
1405
1409
*/
1406
1410
def hash : Int
1407
1411
1408
- /** Equality used for hash-consing; uses `eq` on all recursive invocations.
1409
- */
1410
- def eql (that : Type ): Boolean = this .equals(that)
1412
+ /** Compute hashcode relative to enclosing binders `bs` */
1413
+ def computeHash (bs : Binders ): Int
1411
1414
1412
1415
} // end Type
1413
1416
@@ -1445,34 +1448,33 @@ object Types {
1445
1448
private [this ] var myHash = HashUnknown
1446
1449
final def hash = {
1447
1450
if (myHash == HashUnknown ) {
1448
- myHash = computeHash
1451
+ myHash = computeHash( null )
1449
1452
assert(myHash != HashUnknown )
1450
1453
}
1451
1454
myHash
1452
1455
}
1453
1456
override final def hashCode =
1454
1457
if (hash == NotCached ) System .identityHashCode(this ) else hash
1455
- def computeHash : Int
1456
1458
}
1457
1459
1458
1460
/** Instances of this class are cached and are proxies. */
1459
1461
abstract class CachedProxyType extends TypeProxy with CachedType {
1460
1462
protected [this ] var myHash = HashUnknown
1461
1463
final def hash = {
1462
1464
if (myHash == HashUnknown ) {
1463
- myHash = computeHash
1465
+ myHash = computeHash( null )
1464
1466
assert(myHash != HashUnknown )
1465
1467
}
1466
1468
myHash
1467
1469
}
1468
1470
override final def hashCode =
1469
1471
if (hash == NotCached ) System .identityHashCode(this ) else hash
1470
- def computeHash : Int
1471
1472
}
1472
1473
1473
1474
/** Instances of this class are uncached and are not proxies. */
1474
1475
abstract class UncachedGroundType extends Type {
1475
1476
final def hash = NotCached
1477
+ final def computeHash (bs : Binders ) = NotCached
1476
1478
if (monitored) {
1477
1479
record(s " uncachable " )
1478
1480
record(s " uncachable: $getClass" )
@@ -1482,6 +1484,7 @@ object Types {
1482
1484
/** Instances of this class are uncached and are proxies. */
1483
1485
abstract class UncachedProxyType extends TypeProxy {
1484
1486
final def hash = NotCached
1487
+ final def computeHash (bs : Binders ) = NotCached
1485
1488
if (monitored) {
1486
1489
record(s " uncachable " )
1487
1490
record(s " uncachable: $getClass" )
@@ -2025,7 +2028,7 @@ object Types {
2025
2028
false
2026
2029
}
2027
2030
2028
- override def computeHash = unsupported( " computeHash " )
2031
+ override def computeHash ( bs : Binders ) = doHash(bs, designator, prefix )
2029
2032
2030
2033
override def eql (that : Type ) = this eq that // safe because named types are hash-consed separately
2031
2034
}
@@ -2149,7 +2152,7 @@ object Types {
2149
2152
// can happen in IDE if `cls` is stale
2150
2153
}
2151
2154
2152
- override def computeHash = doHash(tref)
2155
+ override def computeHash ( bs : Binders ) = doHash(bs, tref)
2153
2156
2154
2157
override def eql (that : Type ) = that match {
2155
2158
case that : ThisType => tref.eq(that.tref)
@@ -2177,7 +2180,7 @@ object Types {
2177
2180
if ((thistpe eq this .thistpe) && (supertpe eq this .supertpe)) this
2178
2181
else SuperType (thistpe, supertpe)
2179
2182
2180
- override def computeHash = doHash(thistpe, supertpe)
2183
+ override def computeHash ( bs : Binders ) = doHash(bs, thistpe, supertpe)
2181
2184
2182
2185
override def eql (that : Type ) = that match {
2183
2186
case that : SuperType => thistpe.eq(that.thistpe) && supertpe.eq(that.supertpe)
@@ -2198,7 +2201,7 @@ object Types {
2198
2201
abstract case class ConstantType (value : Constant ) extends CachedProxyType with SingletonType {
2199
2202
override def underlying (implicit ctx : Context ) = value.tpe
2200
2203
2201
- override def computeHash = doHash(value)
2204
+ override def computeHash ( bs : Binders ) = doHash(value)
2202
2205
}
2203
2206
2204
2207
final class CachedConstantType (value : Constant ) extends ConstantType (value)
@@ -2262,7 +2265,7 @@ object Types {
2262
2265
if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
2263
2266
else parent
2264
2267
2265
- override def computeHash = doHash(refinedName, refinedInfo, parent)
2268
+ override def computeHash ( bs : Binders ) = doHash(bs, refinedName, refinedInfo, parent)
2266
2269
2267
2270
override def eql (that : Type ) = that match {
2268
2271
case that : RefinedType =>
@@ -2326,7 +2329,7 @@ object Types {
2326
2329
refacc.apply(false , tp)
2327
2330
}
2328
2331
2329
- override def computeHash = doHash(parent)
2332
+ override def computeHash ( bs : Binders ) = doHash(bs, parent)
2330
2333
2331
2334
override def equals (that : Any ) = that match {
2332
2335
case that : RecType => parent == that.parent
@@ -2432,7 +2435,7 @@ object Types {
2432
2435
def derivedAndOrType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type =
2433
2436
derivedAndType(tp1, tp2)
2434
2437
2435
- override def computeHash = doHash(tp1, tp2)
2438
+ override def computeHash ( bs : Binders ) = doHash(bs, tp1, tp2)
2436
2439
2437
2440
override def eql (that : Type ) = that match {
2438
2441
case that : AndType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
@@ -2493,7 +2496,7 @@ object Types {
2493
2496
def derivedAndOrType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type =
2494
2497
derivedOrType(tp1, tp2)
2495
2498
2496
- override def computeHash = doHash(tp1, tp2)
2499
+ override def computeHash ( bs : Binders ) = doHash(bs, tp1, tp2)
2497
2500
2498
2501
override def eql (that : Type ) = that match {
2499
2502
case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
@@ -2559,7 +2562,7 @@ object Types {
2559
2562
def derivedExprType (resType : Type )(implicit ctx : Context ) =
2560
2563
if (resType eq this .resType) this else ExprType (resType)
2561
2564
2562
- override def computeHash = doHash(resType)
2565
+ override def computeHash ( bs : Binders ) = doHash(bs, resType)
2563
2566
2564
2567
override def eql (that : Type ) = that match {
2565
2568
case that : ExprType => resType.eq(that.resType)
@@ -2643,7 +2646,7 @@ object Types {
2643
2646
abstract class HKLambda extends CachedProxyType with LambdaType {
2644
2647
final override def underlying (implicit ctx : Context ) = resType
2645
2648
2646
- final override def computeHash = doHash(paramNames, resType, paramInfos)
2649
+ final override def computeHash ( bs : Binders ) = doHash(bs, paramNames, resType, paramInfos)
2647
2650
2648
2651
final override def equals (that : Any ) = that match {
2649
2652
case that : HKLambda =>
@@ -3119,12 +3122,13 @@ object Types {
3119
3122
def derivedAppliedType (tycon : Type , args : List [Type ])(implicit ctx : Context ): Type =
3120
3123
if ((tycon eq this .tycon) && (args eq this .args)) this
3121
3124
else tycon.appliedTo(args)
3125
+
3126
+ override def computeHash (bs : Binders ) = doHash(bs, tycon, args)
3127
+ override def eql (that : Type ) = this `eq` that // safe because applied types are hash-consed separately
3122
3128
}
3123
3129
3124
3130
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
3125
3131
myHash = hc
3126
- override def computeHash = unsupported(" computeHash" )
3127
- override def eql (that : Type ) = this eq that // safe because applied types are hash-consed separately
3128
3132
}
3129
3133
3130
3134
object AppliedType {
@@ -3140,6 +3144,8 @@ object Types {
3140
3144
type BT <: Type
3141
3145
val binder : BT
3142
3146
def copyBoundType (bt : BT ): Type
3147
+ override def identityHash (bs : Binders ) =
3148
+ if (bs == null ) super .identityHash(bs) else ???
3143
3149
}
3144
3150
3145
3151
abstract class ParamRef extends BoundType {
@@ -3153,7 +3159,7 @@ object Types {
3153
3159
else infos(paramNum)
3154
3160
}
3155
3161
3156
- override def computeHash = doHash(paramNum, binder.identityHash)
3162
+ override def computeHash ( bs : Binders ) = doHash(bs, paramNum, binder.identityHash(bs) )
3157
3163
3158
3164
override def equals (that : Any ) = that match {
3159
3165
case that : ParamRef => binder.eq(that.binder) && paramNum == that.paramNum
@@ -3210,7 +3216,7 @@ object Types {
3210
3216
3211
3217
// need to customize hashCode and equals to prevent infinite recursion
3212
3218
// between RecTypes and RecRefs.
3213
- override def computeHash = addDelta(binder.identityHash, 41 )
3219
+ override def computeHash ( bs : Binders ) = addDelta(binder.identityHash(bs) , 41 )
3214
3220
3215
3221
override def equals (that : Any ) = that match {
3216
3222
case that : RecThis => binder.eq(that.binder)
@@ -3231,7 +3237,7 @@ object Types {
3231
3237
override def underlying (implicit ctx : Context ) = info
3232
3238
def derivedSkolemType (info : Type )(implicit ctx : Context ) =
3233
3239
if (info eq this .info) this else SkolemType (info)
3234
- override def hashCode : Int = identityHash
3240
+ override def hashCode : Int = System .identityHashCode( this )
3235
3241
override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3236
3242
3237
3243
def withName (name : Name ): this .type = { myRepr = name; this }
@@ -3337,7 +3343,7 @@ object Types {
3337
3343
}
3338
3344
}
3339
3345
3340
- override def computeHash : Int = identityHash
3346
+ override def computeHash ( bs : Binders ) : Int = identityHash(bs)
3341
3347
override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3342
3348
3343
3349
override def toString = {
@@ -3412,7 +3418,7 @@ object Types {
3412
3418
if ((prefix eq this .prefix) && (classParents eq this .classParents) && (decls eq this .decls) && (selfInfo eq this .selfInfo)) this
3413
3419
else ClassInfo (prefix, cls, classParents, decls, selfInfo)
3414
3420
3415
- override def computeHash = doHash(cls, prefix)
3421
+ override def computeHash ( bs : Binders ) = doHash(bs, cls, prefix)
3416
3422
3417
3423
override def eql (that : Type ) = that match {
3418
3424
case that : ClassInfo =>
@@ -3495,7 +3501,7 @@ object Types {
3495
3501
case _ => super .| (that)
3496
3502
}
3497
3503
3498
- override def computeHash = doHash(lo, hi)
3504
+ override def computeHash ( bs : Binders ) = doHash(bs, lo, hi)
3499
3505
3500
3506
override def equals (that : Any ): Boolean = that match {
3501
3507
case that : TypeAlias => false
@@ -3518,7 +3524,7 @@ object Types {
3518
3524
def derivedTypeAlias (alias : Type )(implicit ctx : Context ) =
3519
3525
if (alias eq this .alias) this else TypeAlias (alias)
3520
3526
3521
- override def computeHash = doHash(alias)
3527
+ override def computeHash ( bs : Binders ) = doHash(bs, alias)
3522
3528
3523
3529
override def equals (that : Any ): Boolean = that match {
3524
3530
case that : TypeAlias => alias == that.alias
@@ -3577,7 +3583,7 @@ object Types {
3577
3583
def derivedJavaArrayType (elemtp : Type )(implicit ctx : Context ) =
3578
3584
if (elemtp eq this .elemType) this else JavaArrayType (elemtp)
3579
3585
3580
- override def computeHash = doHash(elemType)
3586
+ override def computeHash ( bs : Binders ) = doHash(bs, elemType)
3581
3587
3582
3588
override def eql (that : Type ) = that match {
3583
3589
case that : JavaArrayType => elemType.eq(that.elemType)
@@ -3595,12 +3601,12 @@ object Types {
3595
3601
/** Sentinel for "missing type" */
3596
3602
@ sharable case object NoType extends CachedGroundType {
3597
3603
override def exists = false
3598
- override def computeHash = hashSeed
3604
+ override def computeHash ( bs : Binders ) = hashSeed
3599
3605
}
3600
3606
3601
3607
/** Missing prefix */
3602
3608
@ sharable case object NoPrefix extends CachedGroundType {
3603
- override def computeHash = hashSeed
3609
+ override def computeHash ( bs : Binders ) = hashSeed
3604
3610
}
3605
3611
3606
3612
/** A common superclass of `ErrorType` and `TryDynamicCallSite`. Instances of this
@@ -3640,7 +3646,7 @@ object Types {
3640
3646
else if (! optBounds.exists) WildcardType
3641
3647
else WildcardType (optBounds.asInstanceOf [TypeBounds ])
3642
3648
3643
- override def computeHash = doHash(optBounds)
3649
+ override def computeHash ( bs : Binders ) = doHash(bs, optBounds)
3644
3650
3645
3651
override def eql (that : Type ) = that match {
3646
3652
case that : WildcardType => optBounds.eq(that.optBounds)
0 commit comments