aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-26 13:11:38 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-26 18:52:33 +0100
commit5b69fbbe68705ece7d892cbda555191853f1c5be (patch)
treedb3e2511d017f8ad05f7442459cb171edefdd217
parentf7e79bfbdef1123273d5f872572a6a6d55a2cd81 (diff)
downloaddotty-5b69fbbe68705ece7d892cbda555191853f1c5be.tar.gz
dotty-5b69fbbe68705ece7d892cbda555191853f1c5be.tar.bz2
dotty-5b69fbbe68705ece7d892cbda555191853f1c5be.zip
Refactored RefinedTypes to favor the case where refinedInfo is independent of type itself.
-rw-r--r--src/dotty/tools/dotc/core/Types.scala23
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala2
2 files changed, 17 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index f0385c08e..0cda02a6e 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -962,7 +962,10 @@ object Types {
if (tp.hash == NotCached) {
record("uncached-types")
record(s"uncached: ${tp.getClass}")
- } else record("cached-types")
+ } else {
+ record("cached-types")
+ record(s"cached: ${tp.getClass}")
+ }
if (tp.hash == NotCached) tp
else ctx.uniques.findEntryOrUpdate(tp).asInstanceOf[T]
} /* !!! DEBUG
@@ -1348,10 +1351,10 @@ object Types {
* @param infoFn: A function that produces the info of the refinement declaration,
* given the refined type itself.
*/
- abstract case class RefinedType(parent: Type, refinedName: Name)(infoFn: RefinedType => Type)
+ abstract case class RefinedType(parent: Type, refinedName: Name)
extends CachedProxyType with BindingType with ValueType {
- val refinedInfo: Type = infoFn(this)
+ val refinedInfo: Type
override def underlying(implicit ctx: Context) = parent
@@ -1393,18 +1396,24 @@ object Types {
override def toString = s"RefinedType($parent, $refinedName, $refinedInfo)"
}
- class CachedRefinedType(parent: Type, refinedName: Name, infoFn: RefinedType => Type) extends RefinedType(parent, refinedName)(infoFn)
+ class CachedRefinedType(parent: Type, refinedName: Name, infoFn: RefinedType => Type) extends RefinedType(parent, refinedName) {
+ val refinedInfo = infoFn(this)
+ }
+
+ class DirectRefinedType(parent: Type, refinedName: Name, override val refinedInfo: Type) extends RefinedType(parent, refinedName)
object RefinedType {
def make(parent: Type, names: List[Name], infoFns: List[RefinedType => Type])(implicit ctx: Context): Type =
if (names.isEmpty) parent
else make(RefinedType(parent, names.head, infoFns.head), names.tail, infoFns.tail)
- def apply(parent: Type, name: Name, infoFn: RefinedType => Type)(implicit ctx: Context): RefinedType =
+ def apply(parent: Type, name: Name, infoFn: RefinedType => Type)(implicit ctx: Context): RefinedType = {
unique(new CachedRefinedType(parent, name, infoFn))
+ }
- def apply(parent: Type, name: Name, info: Type)(implicit ctx: Context): RefinedType =
- apply(parent, name, scala.Function.const(info): (RefinedType => Type))
+ def apply(parent: Type, name: Name, info: Type)(implicit ctx: Context): RefinedType = {
+ unique(new DirectRefinedType(parent, name, info))
+ }
}
// --- AndType/OrType ---------------------------------------------------------------
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index d815d369d..3ef9f42a6 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -73,7 +73,7 @@ object Inferencing {
* [ ].name: proto
*/
class SelectionProto(val name: Name, proto: Type, compat: Compatibility)
- extends RefinedType(WildcardType, name)(_ => proto) with ProtoType {
+ extends DirectRefinedType(WildcardType, name, proto) with ProtoType {
override def isMatchedBy(tp1: Type)(implicit ctx: Context) =
name == nme.WILDCARD || {
val mbr = tp1.member(name)