aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-27 16:06:41 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-27 19:27:10 +0100
commit3617102b51df4625cbe37f6a3f71caf64ddf7211 (patch)
tree126395f38546b865c0a8e4928dfce1ef68f072fe /src/dotty/tools/dotc/core/Types.scala
parentc476171d838c55bbfe36856e73a470e826748acc (diff)
downloaddotty-3617102b51df4625cbe37f6a3f71caf64ddf7211.tar.gz
dotty-3617102b51df4625cbe37f6a3f71caf64ddf7211.tar.bz2
dotty-3617102b51df4625cbe37f6a3f71caf64ddf7211.zip
Selective caching of SelectionProtos and ViewProtos
We cache SelectionProtos if their "compat" parameter is "NoViewsAllowed". We always cache ViewProtos. That's important for implicit search, because this enables eligible refs to be better cached. To make this work, we add a case to WildApprox which massages SelectionProtos so they also get noViewsAllowed in the compat parameter.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala43
1 files changed, 5 insertions, 38 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 4f740d2e5..63c26a6e7 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -961,8 +961,8 @@ object Types {
/** A trait for proto-types, used as expected types in typer */
trait ProtoType extends Type {
def isMatchedBy(tp: Type)(implicit ctx: Context): Boolean
- def fold[T](x: T, ta: TypeAccumulator[T]): T
- def map(tm: TypeMap): ProtoType
+ def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T
+ def map(tm: TypeMap)(implicit ctx: Context): ProtoType
}
/** Implementations of this trait cache the resukts of `narrow`. */
@@ -1491,7 +1491,7 @@ object Types {
extends MethodType(paramNames, paramTypes)(resultTypeExp) {
override def isJava = true
override def equals(that: Any) = super.equals(that) && that.isInstanceOf[JavaMethodType]
- override def computeHash = super.computeHash + 1
+ override def computeHash = addDelta(super.computeHash, 1)
override protected def prefixString = "JavaMethodType"
}
@@ -1499,7 +1499,7 @@ object Types {
extends MethodType(paramNames, paramTypes)(resultTypeExp) {
override def isImplicit = true
override def equals(that: Any) = super.equals(that) && that.isInstanceOf[ImplicitMethodType]
- override def computeHash = super.computeHash + 2
+ override def computeHash = addDelta(super.computeHash, 2)
override protected def prefixString = "ImplicitMethodType"
}
@@ -1612,7 +1612,7 @@ object Types {
def copyBoundType(bt: BT) = MethodParam(bt, paramNum)
// need to customize hashCode and equals to prevent infinite recursion for dep meth types.
- override def computeHash = avoidNotCached(System.identityHashCode(binder) + paramNum)
+ override def computeHash = addDelta(System.identityHashCode(binder), paramNum)
override def equals(that: Any) = that match {
case that: MethodParam =>
(this.binder eq that.binder) && this.paramNum == that.paramNum
@@ -2173,39 +2173,6 @@ object Types {
def apply(tp: Type) = tp
}
- /** Approximate occurrences of parameter types and uninstantiated typevars
- * by wildcard types.
- */
- class WildApprox(implicit ctx: Context) extends TypeMap {
- override def apply(tp: Type) = tp match {
- case PolyParam(pt, pnum) =>
- WildcardType(apply(pt.paramBounds(pnum)).bounds)
- case MethodParam(mt, pnum) =>
- WildcardType(TypeBounds.upper(apply(mt.paramTypes(pnum))))
- case tp: TypeVar =>
- val inst = tp.instanceOpt
- apply(inst orElse WildcardType(ctx.typerState.constraint.bounds(tp.origin)))
- case tp: AndType =>
- val tp1a = apply(tp.tp1)
- val tp2a = apply(tp.tp2)
- def wildBounds(tp: Type) =
- if (tp.isInstanceOf[WildcardType]) tp.bounds else TypeBounds.upper(tp)
- if (tp1a.isInstanceOf[WildcardType] || tp2a.isInstanceOf[WildcardType])
- WildcardType(wildBounds(tp1a) & wildBounds(tp2a))
- else
- tp.derivedAndType(tp1a, tp2a)
- case tp: OrType =>
- val tp1a = apply(tp.tp1)
- val tp2a = apply(tp.tp2)
- if (tp1a.isInstanceOf[WildcardType] || tp2a.isInstanceOf[WildcardType])
- WildcardType(tp1a.bounds | tp2a.bounds)
- else
- tp.derivedOrType(tp1a, tp2a)
- case _ =>
- mapOver(tp)
- }
- }
-
// ----- TypeAccumulators ----------------------------------------------------
abstract class TypeAccumulator[T](implicit ctx: Context) extends ((T, Type) => T) {