@@ -1394,15 +1394,18 @@ object Types {
1394
1394
*/
1395
1395
def simplified (implicit ctx : Context ) = ctx.simplify(this , null )
1396
1396
1397
+ /** Equality used for hash-consing; uses `eq` on all recursive invocations.
1398
+ */
1399
+ def eql (that : Type ): Boolean = this .equals(that)
1400
+
1397
1401
/** customized hash code of this type.
1398
1402
* NotCached for uncached types. Cached types
1399
1403
* compute hash and use it as the type's hashCode.
1400
1404
*/
1401
1405
def hash : Int
1402
1406
1403
- /** Equality used for hash-consing; uses `eq` on all recursive invocations.
1404
- */
1405
- def eql (that : Type ): Boolean = this .equals(that)
1407
+ /** Compute hashcode relative to enclosing binders `bs` */
1408
+ def computeHash (bs : Binders ): Int
1406
1409
1407
1410
} // end Type
1408
1411
@@ -1440,34 +1443,33 @@ object Types {
1440
1443
private [this ] var myHash = HashUnknown
1441
1444
final def hash = {
1442
1445
if (myHash == HashUnknown ) {
1443
- myHash = computeHash
1446
+ myHash = computeHash( null )
1444
1447
assert(myHash != HashUnknown )
1445
1448
}
1446
1449
myHash
1447
1450
}
1448
1451
override final def hashCode =
1449
1452
if (hash == NotCached ) System .identityHashCode(this ) else hash
1450
- def computeHash : Int
1451
1453
}
1452
1454
1453
1455
/** Instances of this class are cached and are proxies. */
1454
1456
abstract class CachedProxyType extends TypeProxy with CachedType {
1455
1457
protected [this ] var myHash = HashUnknown
1456
1458
final def hash = {
1457
1459
if (myHash == HashUnknown ) {
1458
- myHash = computeHash
1460
+ myHash = computeHash( null )
1459
1461
assert(myHash != HashUnknown )
1460
1462
}
1461
1463
myHash
1462
1464
}
1463
1465
override final def hashCode =
1464
1466
if (hash == NotCached ) System .identityHashCode(this ) else hash
1465
- def computeHash : Int
1466
1467
}
1467
1468
1468
1469
/** Instances of this class are uncached and are not proxies. */
1469
1470
abstract class UncachedGroundType extends Type {
1470
1471
final def hash = NotCached
1472
+ final def computeHash (bs : Binders ) = NotCached
1471
1473
if (monitored) {
1472
1474
record(s " uncachable " )
1473
1475
record(s " uncachable: $getClass" )
@@ -1477,6 +1479,7 @@ object Types {
1477
1479
/** Instances of this class are uncached and are proxies. */
1478
1480
abstract class UncachedProxyType extends TypeProxy {
1479
1481
final def hash = NotCached
1482
+ final def computeHash (bs : Binders ) = NotCached
1480
1483
if (monitored) {
1481
1484
record(s " uncachable " )
1482
1485
record(s " uncachable: $getClass" )
@@ -2016,7 +2019,7 @@ object Types {
2016
2019
false
2017
2020
}
2018
2021
2019
- override def computeHash = unsupported( " computeHash " )
2022
+ override def computeHash ( bs : Binders ) = doHash(bs, designator, prefix )
2020
2023
2021
2024
override def eql (that : Type ) = this eq that // safe because named types are hash-consed separately
2022
2025
}
@@ -2140,7 +2143,7 @@ object Types {
2140
2143
// can happen in IDE if `cls` is stale
2141
2144
}
2142
2145
2143
- override def computeHash = doHash(tref)
2146
+ override def computeHash ( bs : Binders ) = doHash(bs, tref)
2144
2147
2145
2148
override def eql (that : Type ) = that match {
2146
2149
case that : ThisType => tref.eq(that.tref)
@@ -2168,7 +2171,7 @@ object Types {
2168
2171
if ((thistpe eq this .thistpe) && (supertpe eq this .supertpe)) this
2169
2172
else SuperType (thistpe, supertpe)
2170
2173
2171
- override def computeHash = doHash(thistpe, supertpe)
2174
+ override def computeHash ( bs : Binders ) = doHash(bs, thistpe, supertpe)
2172
2175
2173
2176
override def eql (that : Type ) = that match {
2174
2177
case that : SuperType => thistpe.eq(that.thistpe) && supertpe.eq(that.supertpe)
@@ -2189,7 +2192,7 @@ object Types {
2189
2192
abstract case class ConstantType (value : Constant ) extends CachedProxyType with SingletonType {
2190
2193
override def underlying (implicit ctx : Context ) = value.tpe
2191
2194
2192
- override def computeHash = doHash(value)
2195
+ override def computeHash ( bs : Binders ) = doHash(value)
2193
2196
}
2194
2197
2195
2198
final class CachedConstantType (value : Constant ) extends ConstantType (value)
@@ -2253,7 +2256,7 @@ object Types {
2253
2256
if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
2254
2257
else parent
2255
2258
2256
- override def computeHash = doHash(refinedName, refinedInfo, parent)
2259
+ override def computeHash ( bs : Binders ) = doHash(bs, refinedName, refinedInfo, parent)
2257
2260
2258
2261
override def eql (that : Type ) = that match {
2259
2262
case that : RefinedType =>
@@ -2317,7 +2320,7 @@ object Types {
2317
2320
refacc.apply(false , tp)
2318
2321
}
2319
2322
2320
- override def computeHash = doHash(parent)
2323
+ override def computeHash ( bs : Binders ) = doHash(bs, parent)
2321
2324
2322
2325
override def equals (that : Any ) = that match {
2323
2326
case that : RecType => parent == that.parent
@@ -2423,7 +2426,7 @@ object Types {
2423
2426
def derivedAndOrType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type =
2424
2427
derivedAndType(tp1, tp2)
2425
2428
2426
- override def computeHash = doHash(tp1, tp2)
2429
+ override def computeHash ( bs : Binders ) = doHash(bs, tp1, tp2)
2427
2430
2428
2431
override def eql (that : Type ) = that match {
2429
2432
case that : AndType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
@@ -2484,7 +2487,7 @@ object Types {
2484
2487
def derivedAndOrType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type =
2485
2488
derivedOrType(tp1, tp2)
2486
2489
2487
- override def computeHash = doHash(tp1, tp2)
2490
+ override def computeHash ( bs : Binders ) = doHash(bs, tp1, tp2)
2488
2491
2489
2492
override def eql (that : Type ) = that match {
2490
2493
case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
@@ -2550,7 +2553,7 @@ object Types {
2550
2553
def derivedExprType (resType : Type )(implicit ctx : Context ) =
2551
2554
if (resType eq this .resType) this else ExprType (resType)
2552
2555
2553
- override def computeHash = doHash(resType)
2556
+ override def computeHash ( bs : Binders ) = doHash(bs, resType)
2554
2557
2555
2558
override def eql (that : Type ) = that match {
2556
2559
case that : ExprType => resType.eq(that.resType)
@@ -2634,7 +2637,7 @@ object Types {
2634
2637
abstract class HKLambda extends CachedProxyType with LambdaType {
2635
2638
final override def underlying (implicit ctx : Context ) = resType
2636
2639
2637
- final override def computeHash = doHash(paramNames, resType, paramInfos)
2640
+ final override def computeHash ( bs : Binders ) = doHash(bs, paramNames, resType, paramInfos)
2638
2641
2639
2642
final override def equals (that : Any ) = that match {
2640
2643
case that : HKLambda =>
@@ -3110,12 +3113,13 @@ object Types {
3110
3113
def derivedAppliedType (tycon : Type , args : List [Type ])(implicit ctx : Context ): Type =
3111
3114
if ((tycon eq this .tycon) && (args eq this .args)) this
3112
3115
else tycon.appliedTo(args)
3116
+
3117
+ override def computeHash (bs : Binders ) = doHash(bs, tycon, args)
3118
+ override def eql (that : Type ) = this `eq` that // safe because applied types are hash-consed separately
3113
3119
}
3114
3120
3115
3121
final class CachedAppliedType (tycon : Type , args : List [Type ], hc : Int ) extends AppliedType (tycon, args) {
3116
3122
myHash = hc
3117
- override def computeHash = unsupported(" computeHash" )
3118
- override def eql (that : Type ) = this eq that // safe because applied types are hash-consed separately
3119
3123
}
3120
3124
3121
3125
object AppliedType {
@@ -3131,6 +3135,8 @@ object Types {
3131
3135
type BT <: Type
3132
3136
val binder : BT
3133
3137
def copyBoundType (bt : BT ): Type
3138
+ override def identityHash (bs : Binders ) =
3139
+ if (bs == null ) super .identityHash(bs) else ???
3134
3140
}
3135
3141
3136
3142
abstract class ParamRef extends BoundType {
@@ -3144,7 +3150,7 @@ object Types {
3144
3150
else infos(paramNum)
3145
3151
}
3146
3152
3147
- override def computeHash = doHash(paramNum, binder.identityHash)
3153
+ override def computeHash ( bs : Binders ) = doHash(bs, paramNum, binder.identityHash(bs) )
3148
3154
3149
3155
override def equals (that : Any ) = that match {
3150
3156
case that : ParamRef => binder.eq(that.binder) && paramNum == that.paramNum
@@ -3201,7 +3207,7 @@ object Types {
3201
3207
3202
3208
// need to customize hashCode and equals to prevent infinite recursion
3203
3209
// between RecTypes and RecRefs.
3204
- override def computeHash = addDelta(binder.identityHash, 41 )
3210
+ override def computeHash ( bs : Binders ) = addDelta(binder.identityHash(bs) , 41 )
3205
3211
3206
3212
override def equals (that : Any ) = that match {
3207
3213
case that : RecThis => binder.eq(that.binder)
@@ -3222,7 +3228,7 @@ object Types {
3222
3228
override def underlying (implicit ctx : Context ) = info
3223
3229
def derivedSkolemType (info : Type )(implicit ctx : Context ) =
3224
3230
if (info eq this .info) this else SkolemType (info)
3225
- override def hashCode : Int = identityHash
3231
+ override def hashCode : Int = System .identityHashCode( this )
3226
3232
override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3227
3233
3228
3234
def withName (name : Name ): this .type = { myRepr = name; this }
@@ -3328,7 +3334,7 @@ object Types {
3328
3334
}
3329
3335
}
3330
3336
3331
- override def computeHash : Int = identityHash
3337
+ override def computeHash ( bs : Binders ) : Int = identityHash(bs)
3332
3338
override def equals (that : Any ) = this .eq(that.asInstanceOf [AnyRef ])
3333
3339
3334
3340
override def toString = {
@@ -3403,7 +3409,7 @@ object Types {
3403
3409
if ((prefix eq this .prefix) && (classParents eq this .classParents) && (decls eq this .decls) && (selfInfo eq this .selfInfo)) this
3404
3410
else ClassInfo (prefix, cls, classParents, decls, selfInfo)
3405
3411
3406
- override def computeHash = doHash(cls, prefix)
3412
+ override def computeHash ( bs : Binders ) = doHash(bs, cls, prefix)
3407
3413
3408
3414
override def eql (that : Type ) = that match {
3409
3415
case that : ClassInfo =>
@@ -3486,7 +3492,7 @@ object Types {
3486
3492
case _ => super .| (that)
3487
3493
}
3488
3494
3489
- override def computeHash = doHash(lo, hi)
3495
+ override def computeHash ( bs : Binders ) = doHash(bs, lo, hi)
3490
3496
3491
3497
override def equals (that : Any ): Boolean = that match {
3492
3498
case that : TypeAlias => false
@@ -3509,7 +3515,7 @@ object Types {
3509
3515
def derivedTypeAlias (alias : Type )(implicit ctx : Context ) =
3510
3516
if (alias eq this .alias) this else TypeAlias (alias)
3511
3517
3512
- override def computeHash = doHash(alias)
3518
+ override def computeHash ( bs : Binders ) = doHash(bs, alias)
3513
3519
3514
3520
override def equals (that : Any ): Boolean = that match {
3515
3521
case that : TypeAlias => alias == that.alias
@@ -3568,7 +3574,7 @@ object Types {
3568
3574
def derivedJavaArrayType (elemtp : Type )(implicit ctx : Context ) =
3569
3575
if (elemtp eq this .elemType) this else JavaArrayType (elemtp)
3570
3576
3571
- override def computeHash = doHash(elemType)
3577
+ override def computeHash ( bs : Binders ) = doHash(bs, elemType)
3572
3578
3573
3579
override def eql (that : Type ) = that match {
3574
3580
case that : JavaArrayType => elemType.eq(that.elemType)
@@ -3586,12 +3592,12 @@ object Types {
3586
3592
/** Sentinel for "missing type" */
3587
3593
@ sharable case object NoType extends CachedGroundType {
3588
3594
override def exists = false
3589
- override def computeHash = hashSeed
3595
+ override def computeHash ( bs : Binders ) = hashSeed
3590
3596
}
3591
3597
3592
3598
/** Missing prefix */
3593
3599
@ sharable case object NoPrefix extends CachedGroundType {
3594
- override def computeHash = hashSeed
3600
+ override def computeHash ( bs : Binders ) = hashSeed
3595
3601
}
3596
3602
3597
3603
/** A common superclass of `ErrorType` and `TryDynamicCallSite`. Instances of this
@@ -3631,7 +3637,7 @@ object Types {
3631
3637
else if (! optBounds.exists) WildcardType
3632
3638
else WildcardType (optBounds.asInstanceOf [TypeBounds ])
3633
3639
3634
- override def computeHash = doHash(optBounds)
3640
+ override def computeHash ( bs : Binders ) = doHash(bs, optBounds)
3635
3641
3636
3642
override def eql (that : Type ) = that match {
3637
3643
case that : WildcardType => optBounds.eq(that.optBounds)
0 commit comments