aboutsummaryrefslogtreecommitdiff
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
parentd9a37eaf5d36d772d59bca81237c19b3eb11db42 (diff)
downloaddotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.tar.gz
dotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.tar.bz2
dotty-a7ef4380d97a32e00d8ab23eeafa0bedfbc97838.zip
Simplified RefinedTypes, keeping only the unary variant.
-rw-r--r--src/dotty/tools/dotc/core/Substituters.scala84
-rw-r--r--src/dotty/tools/dotc/core/TypeComparers.scala10
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala22
-rw-r--r--src/dotty/tools/dotc/core/Types.scala161
4 files changed, 41 insertions, 236 deletions
diff --git a/src/dotty/tools/dotc/core/Substituters.scala b/src/dotty/tools/dotc/core/Substituters.scala
index a78b31571..a63465f2c 100644
--- a/src/dotty/tools/dotc/core/Substituters.scala
+++ b/src/dotty/tools/dotc/core/Substituters.scala
@@ -16,18 +16,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(subst(tp.prefix, from, to, map), tp.name)
case _: ThisType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- subst(tp.parent, from, to, map),
- tp.name1,
- subst(tp.info1, from, to, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- subst(tp.parent, from, to, map),
- tp.name1,
- subst(tp.info1, from, to, map),
- tp.name2,
- subst(tp.info2, from, to, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(subst(tp.parent, from, to, map), tp.name, subst(tp.info, from, to, map))
case _ =>
(if (map != null) map else new SubstBindingMap(from, to))
.mapOver(tp)
@@ -44,18 +34,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(subst1(tp.prefix, from, to, map), tp.name)
case _: ThisType | _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- subst1(tp.parent, from, to, map),
- tp.name1,
- subst1(tp.info1, from, to, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- subst1(tp.parent, from, to, map),
- tp.name1,
- subst1(tp.info1, from, to, map),
- tp.name2,
- subst1 (tp.info2, from, to, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(subst1(tp.parent, from, to, map), tp.name, subst1(tp.info, from, to, map))
case _ =>
(if (map != null) map else new Subst1Map(from, to))
.mapOver(tp)
@@ -74,18 +54,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(subst2(tp.prefix, from1, to1, from2, to2, map), tp.name)
case _: ThisType | _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- subst2(tp.parent, from1, to1, from2, to2, map),
- tp.name1,
- subst2(tp.info1, from1, to1, from2, to2, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- subst2(tp.parent, from1, to1, from2, to2, map),
- tp.name1,
- subst2(tp.info1, from1, to1, from2, to2, map),
- tp.name2,
- subst2(tp.info2, from1, to1, from2, to2, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(subst2(tp.parent, from1, to1, from2, to2, map), tp.name, subst2(tp.info, from1, to1, from2, to2, map))
case _ =>
(if (map != null) map else new Subst2Map(from1, to1, from2, to2))
.mapOver(tp)
@@ -109,18 +79,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(subst(tp.prefix, from, to, map), tp.name)
case _: ThisType | _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- subst(tp.parent, from, to, map),
- tp.name1,
- subst(tp.info1, from, to, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- subst(tp.parent, from, to, map),
- tp.name1,
- subst(tp.info1, from, to, map),
- tp.name2,
- subst(tp.info2, from, to, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(subst(tp.parent, from, to, map), tp.name, subst(tp.info, from, to, map))
case _ =>
(if (map != null) map else new SubstMap(from, to))
.mapOver(tp)
@@ -136,18 +96,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(substThis(tp.prefix, from, to, map), tp.name)
case _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- substThis(tp.parent, from, to, map),
- tp.name1,
- substThis(tp.info1, from, to, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- substThis(tp.parent, from, to, map),
- tp.name1,
- substThis(tp.info1, from, to, map),
- tp.name2,
- substThis(tp.info2, from, to, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(substThis(tp.parent, from, to, map), tp.name, substThis(tp.info, from, to, map))
case _ =>
(if (map != null) map else new SubstThisMap(from, to))
.mapOver(tp)
@@ -162,18 +112,8 @@ trait Substituters { this: Context =>
else tp.derivedNamedType(substThis(tp.prefix, from, to, map), tp.name)
case _: ThisType | _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
- substThis(tp.parent, from, to, map),
- tp.name1,
- substThis(tp.info1, from, to, map))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- substThis(tp.parent, from, to, map),
- tp.name1,
- substThis(tp.info1, from, to, map),
- tp.name2,
- substThis(tp.info2, from, to, map))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(substThis(tp.parent, from, to, map), tp.name, substThis(tp.info, from, to, map))
case _ =>
(if (map != null) map else new SubstRefinedThisMap(from, to))
.mapOver(tp)
diff --git a/src/dotty/tools/dotc/core/TypeComparers.scala b/src/dotty/tools/dotc/core/TypeComparers.scala
index 22ba680ca..be4c0b99c 100644
--- a/src/dotty/tools/dotc/core/TypeComparers.scala
+++ b/src/dotty/tools/dotc/core/TypeComparers.scala
@@ -117,17 +117,9 @@ object TypeComparers {
def thirdTry(tp1: Type, tp2: Type): Boolean = tp2 match {
case tp2: TypeRef =>
thirdTryRef(tp1, tp2)
- case tp2: RefinedType1 =>
- isSubType(tp1, tp2.parent) &&
- isSubType(tp1.member(tp2.name1).info, tp2.info1)
- case tp2: RefinedType2 =>
- isSubType(tp1, tp2.parent) &&
- isSubType(tp1.member(tp2.name1).info, tp2.info1) &&
- isSubType(tp1.member(tp2.name2).info, tp2.info2)
case tp2: RefinedType =>
isSubType(tp1, tp2.parent) &&
- ((tp2.names, tp2.infos).zipped forall ((name, info) =>
- isSubType(tp1.member(name).info, info)))
+ isSubType(tp1.member(tp2.name).info, tp2.info)
case AndType(tp21, tp22) =>
isSubType(tp1, tp21) && isSubType(tp1, tp22)
case OrType(tp21, tp22) =>
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 08d7c0cd6..25c8625ec 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -44,18 +44,11 @@ trait TypeOps { this: Context =>
toPrefix(pre, clazz, thisclazz)
case _: BoundType | NoPrefix =>
tp
- case tp: RefinedType1 =>
- tp.derivedRefinedType1(
+ case tp: RefinedType =>
+ tp.derivedRefinedType(
asSeenFrom(tp.parent, pre, clazz, theMap),
- tp.name1,
- asSeenFrom(tp.info1, pre, clazz, theMap))
- case tp: RefinedType2 =>
- tp.derivedRefinedType2(
- asSeenFrom(tp.parent, pre, clazz, theMap),
- tp.name1,
- asSeenFrom(tp.info1, pre, clazz, theMap),
- tp.name2,
- asSeenFrom(tp.info2, pre, clazz, theMap))
+ tp.name,
+ asSeenFrom(tp.info, pre, clazz, theMap))
case _ =>
(if (theMap != null) theMap else new AsSeenFromMap(pre, clazz))
.mapOver(tp)
@@ -73,11 +66,6 @@ trait TypeOps { this: Context =>
case OrType(l, r) => isAbstractIntersection(l) & isAbstractIntersection(r)
case _ => false
}
- def containsName(names: Set[Name], tp: RefinedType): Boolean = tp match {
- case tp: RefinedType1 => names contains tp.name1
- case tp: RefinedType2 => (names contains tp.name1) || (names contains tp.name2)
- case _ => tp.names exists (names contains)
- }
def test = {
tp match {
case ThisType(_) =>
@@ -85,7 +73,7 @@ trait TypeOps { this: Context =>
case tp: RefinedType =>
tp.parent.isVolatile ||
isAbstractIntersection(tp.parent) &&
- containsName(tp.abstractMemberNames(tp), tp)
+ (tp.abstractMemberNames(tp) contains tp.name)
case tp: TypeProxy =>
tp.underlying.isVolatile
case AndType(l, r) =>
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)