aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-01-27 14:55:17 +0100
committerMartin Odersky <odersky@gmail.com>2013-01-27 14:55:17 +0100
commita7ef4380d97a32e00d8ab23eeafa0bedfbc97838 (patch)
tree03b8f133de95dbff549e6da9f293441bf369041f /src/dotty/tools/dotc/core/Types.scala
parentd9a37eaf5d36d772d59bca81237c19b3eb11db42 (diff)
downloaddotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.tar.gz
dotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.tar.bz2
dotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.zip
Simplified RefinedTypes, keeping only the unary variant.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala161
1 files changed, 23 insertions, 138 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index d55afcca6..ee9e881ad 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -109,17 +109,10 @@ object Types {
final def memberNames(pre: Type, keepOnly: NameFilter)(implicit ctx: Context): Set[Name] = this match {
case tp: ClassInfo =>
tp.classd.memberNames(keepOnly) filter (keepOnly(pre, _))
- case tp: RefinedType1 =>
- var ns = tp.parent.memberNames(pre, keepOnly)
- if (keepOnly(pre, tp.name1)) ns += tp.name1
- ns
- case tp: RefinedType2 =>
+ case tp: RefinedType =>
var ns = tp.parent.memberNames(pre, keepOnly)
- if (keepOnly(pre, tp.name1)) ns += tp.name1
- if (keepOnly(pre, tp.name2)) ns += tp.name2
+ if (keepOnly(pre, tp.name)) ns += tp.name
ns
- case tp: RefinedTypeN =>
- tp.parent.memberNames(pre, keepOnly) ++ (tp.names filter (keepOnly(pre, _))).toSet
case tp: AndType =>
tp.tp1.memberNames(pre, keepOnly) | tp.tp2.memberNames(pre, keepOnly)
case tp: OrType =>
@@ -278,10 +271,8 @@ object Types {
final def nonPrivateDecl(name: Name)(implicit ctx: Context): Denotation =
findDecl(name, this, Flags.Private)
- /** The non-private declaration of this type with given name */
+ /** The non-private class member declaration of this type with given name */
final def findDecl(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = this match {
- case tp: RefinedType =>
- tp.findDecl(name, pre)
case tp: ClassInfo =>
tp.classd.decls
.denotsNamed(name)
@@ -308,11 +299,11 @@ object Types {
*/
final def findMember(name: Name, pre: Type, excluded: FlagSet)(implicit ctx: Context): Denotation = this match {
case tp: RefinedType =>
- val denot = tp.findDecl(name, pre)
- if ((denot.symbol is TypeParam) && denot.info.isAliasTypeBounds)
- denot
+ val pdenot = tp.parent.findMember(name, pre, excluded)
+ if (name eq tp.name)
+ pdenot & new JointRefDenotation(NoSymbol, tp.info.substThis(tp, pre), Period.allInRun(ctx.runId))
else
- tp.parent.findMember(name, pre, excluded | Flags.Private) & denot
+ pdenot
case tp: TypeProxy =>
tp.underlying.findMember(name, pre, excluded)
case tp: ClassInfo =>
@@ -469,12 +460,6 @@ object Types {
finishHash(hashing.mix(seed, elemHash), arity + 1, tp2)
}
- private def finishHash(seed: Int, arity: Int, tp1: Type, tp2: Type, tp3: Type): Int = {
- val elemHash = tp1.hash
- if (elemHash == NotCached) return NotCached
- finishHash(hashing.mix(seed, elemHash), arity + 1, tp2, tp3)
- }
-
private def finishHash(seed: Int, arity: Int, tps: List[Type]): Int = {
var h = seed
var xs = tps
@@ -516,9 +501,6 @@ object Types {
protected def doHash(x1: Any, tp2: Type, tps3: List[Type]): Int =
finishHash(hashing.mix(hashSeed, x1.hashCode), 1, tp2, tps3)
- protected def doHash(x1: Any, x2: Any, tp3: Type, tp4: Type, tp5: Type) =
- finishHash(hashing.mix(hashing.mix(hashSeed, x1.hashCode), x2.hashCode), 2, tp3, tp4, tp5)
-
} // end Type
/** A marker trait for cached types */
@@ -720,113 +702,28 @@ object Types {
// --- Refined Type ---------------------------------------------------------
- abstract case class RefinedType(parent: Type) extends CachedProxyType with BindingType {
+ abstract case class RefinedType(parent: Type, name: Name)(infof: RefinedType => Type) extends CachedProxyType with BindingType {
- override def underlying(implicit ctx: Context) = parent
-
- def derivedRefinedType(parent: Type, names: List[Name], infos: List[Type])(implicit ctx: Context): RefinedType =
- if ((parent eq this.parent) && (names eq this.names) && (infos eq this.infos)) this
- else
- RefinedType(parent, names, infos map (info => (rt: RefinedType) => info.subst(this, rt)))
-
- def names: List[Name]
-
- def infos: List[Type]
+ val info: Type = infof(this)
- def info(name: Name): Type
+ override def underlying(implicit ctx: Context) = parent
- // needed???
- //def refine(tp: Type)(implicit ctx: Context): Type
+ def derivedRefinedType(parent: Type, name: Name, info: Type)(implicit ctx: Context): RefinedType =
+ if ((parent eq this.parent) && (name eq this.name) && (info eq this.info)) this
+ else RefinedType(parent, name, rt => info.substThis(this, RefinedThis(rt)))
- def findDecl(name: Name, pre: Type)(implicit ctx: Context): Denotation = {
- val tpe = info(name)
- if (tpe == NoType) NoDenotation
- else new JointRefDenotation(NoSymbol, tpe.substThis(this, pre), Period.allInRun(ctx.runId))
- }
+ override def computeHash = doHash(name, info, parent)
}
- object RefinedType {
+ class CachedRefinedType(parent: Type, name: Name, infof: RefinedType => Type) extends RefinedType(parent, name)(infof)
+ object RefinedType {
def make(parent: Type, names: List[Name], infofs: List[RefinedType => Type])(implicit ctx: Context): Type =
if (names.isEmpty) parent
- else apply(parent, names, infofs)
+ else make(RefinedType(parent, names.head, infofs.head), names.tail, infofs.tail)
- def apply(parent: Type, names: List[Name], infofs: List[RefinedType => Type])(implicit ctx: Context): RefinedType =
- names.length match {
- case 1 => apply(parent, names.head, infofs.head)
- case 2 => apply(parent, names.head, infofs.head, names.tail.head, infofs.tail.head)
- case _ => unique(new RefinedTypeN(parent, names, infofs))
- }
-
- def apply(parent: Type, name1: Name, infof1: RefinedType => Type)(implicit ctx: Context): RefinedType1 =
- unique(new RefinedType1(parent, name1, infof1))
-
- def apply(parent: Type, name1: Name, infof1: RefinedType => Type, name2: Name, infof2: RefinedType => Type)(implicit ctx: Context): RefinedType2 =
- unique(new RefinedType2(parent, name1, infof1, name2, infof2))
- }
-
- class RefinedType1(parent: Type, val name1: Name, infof1: RefinedType => Type) extends RefinedType(parent) {
- val info1 = infof1(this)
- def names = name1 :: Nil
- def infos = info1 :: Nil
- def info(name: Name) =
- if (name == name1) info1
- else NoType
- def derivedRefinedType1(parent: Type, name1: Name, info1: Type)(implicit ctx: Context): RefinedType1 =
- if ((parent eq this.parent) && (name1 eq this.name1) && (info1 eq this.info1)) this
- else RefinedType(parent, name1, rt => info1.substThis(this, RefinedThis(rt)))
-
- /*def refine(parent: Type)(implicit ctx: Context) =
- if (parent.nonPrivateMember(name1).exists)
- derivedRefinedType1(parent, name1, info1)
- else parent*/
-
- override def computeHash = doHash(name1, info1, parent)
- }
-
- class RefinedType2(parent: Type, val name1: Name, infof1: RefinedType => Type, val name2: Name, infof2: RefinedType => Type) extends RefinedType(parent) {
- val info1 = infof1(this)
- val info2 = infof2(this)
- def names = name1 :: name2 :: Nil
- def infos = info1 :: info2 :: Nil
- def info(name: Name) =
- if (name == name1) info1
- else if (name == name2) info2
- else NoType
-
- def derivedRefinedType2(parent: Type, name1: Name, info1: Type, name2: Name, info2: Type)(implicit ctx: Context): RefinedType2 =
- if ((parent eq this.parent) && (name1 eq this.name1) && (info1 eq this.info1) && (name2 eq this.name2) && (info2 eq this.info2)) this
- else RefinedType(parent, name1, rt => info1.substThis(this, RefinedThis(rt)), name2, rt => info2.substThis(this, RefinedThis(rt)))
-
- /*def refine(parent: Type)(implicit ctx: Context) =
- if (parent.nonPrivateMember(name1).exists ||
- parent.nonPrivateMember(name2).exists)
- derivedRefinedType2(parent, name1, info1, name2, info2)
- else parent*/
-
- override def computeHash = doHash(name1, name2, info1, info2, parent)
- }
-
- class RefinedTypeN(parent: Type, val names: List[Name], infofs: List[RefinedType => Type]) extends RefinedType(parent) {
- val infos = infofs map (_(this))
-
- def info(name: Name): Type = {
- var ns = names
- var is = infos
- while (ns.nonEmpty) {
- if (ns.head == name) return is.head
- ns = ns.tail
- is = is.tail
- }
- NoType
- }
-
- /*def refine(parent: Type)(implicit ctx: Context) =
- if (names exists (parent.nonPrivateMember(_).exists))
- derivedRefinedType(parent, names, infos)
- else parent*/
-
- override def computeHash = doHash(names, parent, infos)
+ def apply(parent: Type, name: Name, infof: RefinedType => Type)(implicit ctx: Context): RefinedType =
+ unique(new CachedRefinedType(parent, name, infof))
}
// --- AndType/OrType ---------------------------------------------------------------
@@ -1104,14 +1001,8 @@ object Types {
case _: ThisType
| _: BoundType => tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(this(tp.parent), tp.name1, this(tp.info1))
-
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(this(tp.parent), tp.name1, this(tp.info1), tp.name2, this(tp.info2))
-
- case tp: RefinedTypeN =>
- tp.derivedRefinedType(this(tp.parent), tp.names, tp.infos mapConserve this)
+ case tp: RefinedType =>
+ tp.derivedRefinedType(this(tp.parent), tp.name, this(tp.info))
case tp @ PolyType(pnames) =>
tp.derivedPolyType(
@@ -1174,14 +1065,8 @@ object Types {
case _: ThisType
| _: BoundType => x
- case tp: RefinedType1 =>
- this(this(x, tp.parent), tp.info1)
-
- case tp: RefinedType2 =>
- this(this(this(x, tp.parent), tp.info1), tp.info2)
-
- case tp: RefinedTypeN =>
- (this(x, tp.parent) /: tp.infos)(apply)
+ case tp: RefinedType =>
+ this(this(x, tp.parent), tp.info)
case tp @ PolyType(pnames) =>
this((x /: tp.paramBounds)(this), tp.resultType)