diff options
author | Martin Odersky <odersky@gmail.com> | 2015-01-10 18:17:49 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-01-10 18:17:49 +0100 |
commit | 1d8c014a0a7872120df2b46e1a7e305c98f5b4c5 (patch) | |
tree | 2ff19268e81e094a619b345ec327345907d6c46e | |
parent | 97aced07f273a31be69fd771a4e900a8e0cfa43a (diff) | |
download | dotty-1d8c014a0a7872120df2b46e1a7e305c98f5b4c5.tar.gz dotty-1d8c014a0a7872120df2b46e1a7e305c98f5b4c5.tar.bz2 dotty-1d8c014a0a7872120df2b46e1a7e305c98f5b4c5.zip |
Rename RefinedThis -> SkolemType
Also, make binder type of SkolemType refer to arbitrary type,
not necessarily RefinedType.
-rw-r--r-- | src/dotty/tools/dotc/core/Substituters.scala | 22 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeApplications.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 43 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 | ||||
-rw-r--r-- | tests/pos/Patterns.scala | 2 |
8 files changed, 40 insertions, 47 deletions
diff --git a/src/dotty/tools/dotc/core/Substituters.scala b/src/dotty/tools/dotc/core/Substituters.scala index 76264519f..b45522bf9 100644 --- a/src/dotty/tools/dotc/core/Substituters.scala +++ b/src/dotty/tools/dotc/core/Substituters.scala @@ -179,23 +179,21 @@ trait Substituters { this: Context => .mapOver(tp) } - // !!! TODO remove once we are sure new RefinedThis scheme works and we drop the ref to - // the target type from RefinedThis. - final def substThis0(tp: Type, from: RefinedType, to: Type, theMap: SubstRefinedThisMap0): Type = + final def substSkolem(tp: Type, from: Type, to: Type, theMap: SubstSkolemMap): Type = tp match { - case tp @ RefinedThis(rt) => - if (rt eq from) to else tp + case tp @ SkolemType(binder) => + if (binder eq from) to else tp case tp: NamedType => if (tp.currentSymbol.isStatic) tp - else tp.derivedSelect(substThis0(tp.prefix, from, to, theMap)) + else tp.derivedSelect(substSkolem(tp.prefix, from, to, theMap)) case _: ThisType | _: BoundType | NoPrefix => tp case tp: RefinedType => - tp.derivedRefinedType(substThis0(tp.parent, from, to, theMap), tp.refinedName, substThis0(tp.refinedInfo, from, to, theMap)) + tp.derivedRefinedType(substSkolem(tp.parent, from, to, theMap), tp.refinedName, substSkolem(tp.refinedInfo, from, to, theMap)) case tp: TypeAlias => - tp.derivedTypeAlias(substThis0(tp.alias, from, to, theMap)) + tp.derivedTypeAlias(substSkolem(tp.alias, from, to, theMap)) case _ => - (if (theMap != null) theMap else new SubstRefinedThisMap0(from, to)) + (if (theMap != null) theMap else new SubstSkolemMap(from, to)) .mapOver(tp) } @@ -224,7 +222,7 @@ trait Substituters { this: Context => case tp: NamedType => if (tp.currentSymbol.isStatic) tp else tp.derivedSelect(substParams(tp.prefix, from, to, theMap)) - case _: ThisType | NoPrefix | _: RefinedThis => + case _: ThisType | NoPrefix | _: SkolemType => tp case tp: RefinedType => tp.derivedRefinedType(substParams(tp.parent, from, to, theMap), tp.refinedName, substParams(tp.refinedInfo, from, to, theMap)) @@ -268,8 +266,8 @@ trait Substituters { this: Context => def apply(tp: Type): Type = substThis(tp, from, to, this) } - final class SubstRefinedThisMap0(from: RefinedType, to: Type) extends DeepTypeMap { - def apply(tp: Type): Type = substThis0(tp, from, to, this) + final class SubstSkolemMap(from: Type, to: Type) extends DeepTypeMap { + def apply(tp: Type): Type = substSkolem(tp, from, to, this) } final class SubstParamMap(from: ParamType, to: Type) extends DeepTypeMap { diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index b29022281..e59c60959 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -373,9 +373,9 @@ class TypeApplications(val self: Type) extends AnyVal { case _ => firstBaseArgInfo(defn.SeqClass) } - def containsRefinedThis(target: Type)(implicit ctx: Context): Boolean = { + def containsSkolemType(target: Type)(implicit ctx: Context): Boolean = { def recur(tp: Type): Boolean = tp.stripTypeVar match { - case RefinedThis(tp) => + case SkolemType(tp) => tp eq target case tp: NamedType => tp.info match { @@ -432,7 +432,7 @@ class TypeApplications(val self: Type) extends AnyVal { def replacements(rt: RefinedType): List[Type] = for (sym <- boundSyms) - yield TypeRef(RefinedThis(rt), correspondingParamName(sym)) + yield TypeRef(SkolemType(rt), correspondingParamName(sym)) def rewrite(tp: Type): Type = tp match { case tp @ RefinedType(parent, name: TypeName) => @@ -475,7 +475,7 @@ class TypeApplications(val self: Type) extends AnyVal { val lambda = defn.lambdaTrait(boundSyms.map(_.variance)) val substitutedRHS = (rt: RefinedType) => { val argRefs = boundSyms.indices.toList.map(i => - RefinedThis(rt).select(tpnme.lambdaArgName(i))) + SkolemType(rt).select(tpnme.lambdaArgName(i))) tp.subst(boundSyms, argRefs).bounds.withVariance(1) } val res = RefinedType(lambda.typeRef, tpnme.Apply, substitutedRHS) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 8a810741a..ef0ac627f 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -258,9 +258,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi } } comparePolyParam - case RefinedThis(rt1) => + case SkolemType(binder1) => tp2 match { - case RefinedThis(rt2) if rt1 == rt2 => true + case SkolemType(binder2) if binder1 == binder2 => true case _ => thirdTry(tp1, tp2) } case tp1: BoundType => @@ -525,7 +525,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi try { def rebindNeeded = tp2.refinementRefersToThis val base = if (rebindNeeded) ensureSingleton(tp1) else tp1 - val rinfo2 = if (rebindNeeded) tp2.refinedInfo.substThis0(tp2, base) else tp2.refinedInfo + val rinfo2 = if (rebindNeeded) tp2.refinedInfo.substSkolem(tp2, base) else tp2.refinedInfo def qualifies(m: SingleDenotation) = isSubType(m.info, rinfo2) def memberMatches(mbr: Denotation): Boolean = mbr match { // inlined hasAltWith for performance case mbr: SingleDenotation => qualifies(mbr) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 933f56cb4..c476a8be9 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -49,7 +49,7 @@ object Types { * | | +--- SuperType * | | +--- ConstantType * | | +--- MethodParam - * | | +--- RefinedThis + * | | +--- SkolemType * | +- PolyParam * | +- RefinedType * | +- TypeBounds @@ -437,7 +437,7 @@ object Types { def goRefined(tp: RefinedType) = { val pdenot = go(tp.parent) val rinfo = - if (tp.refinementRefersToThis) tp.refinedInfo.substThis0(tp, pre) + if (tp.refinementRefersToThis) tp.refinedInfo.substSkolem(tp, pre) else tp.refinedInfo if (name.isTypeName) { // simplified case that runs more efficiently val jointInfo = if (rinfo.isAlias) rinfo else pdenot.info & rinfo @@ -774,13 +774,13 @@ object Types { case TypeAlias(tp) => if (!pre.refinementRefersToThis) tp else tp match { - case TypeRef(RefinedThis(`pre`), alias) => lookupRefined(alias) + case TypeRef(SkolemType(`pre`), alias) => lookupRefined(alias) case _ => NoType } case _ => loop(pre.parent) } - case RefinedThis(rt) => - rt.lookupRefined(name) + case SkolemType(binder) => + binder.lookupRefined(name) case pre: WildcardType => WildcardType case _ => @@ -940,9 +940,9 @@ object Types { final def substThisUnlessStatic(cls: ClassSymbol, tp: Type)(implicit ctx: Context): Type = if (cls.isStaticOwner) this else ctx.substThis(this, cls, tp, null) - /** Substitute all occurrences of `RefinedThis(rt)` by `tp` !!! TODO remove */ - final def substThis0(rt: RefinedType, tp: Type)(implicit ctx: Context): Type = - ctx.substThis0(this, rt, tp, null) + /** Substitute all occurrences of `SkolemType(binder)` by `tp` */ + final def substSkolem(binder: Type, tp: Type)(implicit ctx: Context): Type = + ctx.substSkolem(this, binder, tp, null) /** Substitute a bound type by some other type */ final def substParam(from: ParamType, to: Type)(implicit ctx: Context): Type = @@ -1334,7 +1334,7 @@ object Types { * to an (unbounded) wildcard type. * * (2) Reduce a type-ref `T { X = U; ... } # X` to `U` - * provided `U` does not refer with a RefinedThis to the + * provided `U` does not refer with a SkolemType to the * refinement type `T { X = U; ... }` */ def reduceProjection(implicit ctx: Context): Type = { @@ -1743,7 +1743,7 @@ object Types { def refinementRefersToThis(implicit ctx: Context): Boolean = { if (!refinementRefersToThisKnown) { - refinementRefersToThisCache = refinedInfo.containsRefinedThis(this) + refinementRefersToThisCache = refinedInfo.containsSkolemType(this) refinementRefersToThisKnown = true } refinementRefersToThisCache @@ -1779,7 +1779,7 @@ object Types { derivedRefinedType(parent.EtaExpand, refinedName, refinedInfo) else if (false) RefinedType(parent, refinedName, refinedInfo) - else RefinedType(parent, refinedName, rt => refinedInfo.substThis0(this, RefinedThis(rt))) + else RefinedType(parent, refinedName, rt => refinedInfo.substSkolem(this, SkolemType(rt))) } override def equals(that: Any) = that match { @@ -2109,10 +2109,10 @@ object Types { } } - // ----- Bound types: MethodParam, PolyParam, RefinedThis -------------------------- + // ----- Bound types: MethodParam, PolyParam, SkolemType -------------------------- abstract class BoundType extends CachedProxyType with ValueType { - type BT <: BindingType + type BT <: Type def binder: BT // Dotty deviation: copyBoundType was copy, but // dotty generates copy methods always automatically, and therefore @@ -2175,25 +2175,20 @@ object Types { override def computeHash = doHash(paramNum, binder) } - /** A reference to the `this` of an enclosing refined type. - * @param binder The refinement type referred to the RefinedThis when - * it was created. - * @param level The number of enclosing refined types between - * the `this` reference and its target. - */ - case class RefinedThis(binder: RefinedType) extends BoundType with SingletonType { - type BT = RefinedType + /** A skolem type reference with underlying type `binder`. */ + case class SkolemType(binder: Type) extends BoundType with SingletonType { + type BT = Type override def underlying(implicit ctx: Context) = binder - def copyBoundType(bt: BT) = RefinedThis(bt) + def copyBoundType(bt: BT) = SkolemType(bt) // need to customize hashCode and equals to prevent infinite recursion for // refinements that refer to the refinement type via this override def computeHash = addDelta(binder.identityHash, 41) override def equals(that: Any) = that match { - case that: RefinedThis => this.binder eq that.binder + case that: SkolemType => this.binder eq that.binder case _ => false } - override def toString = s"RefinedThis(${binder.hashCode})" + override def toString = s"SkolemType(${binder.hashCode})" } // ------------ Type variables ---------------------------------------- diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 62ad39c07..894ad8f80 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -662,7 +662,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: else { def addRefinement(tp: Type, sym: Symbol) = { def subst(info: Type, rt: RefinedType) = - if (clazz.isClass) info.substThis(clazz.asClass, RefinedThis(rt)) + if (clazz.isClass) info.substThis(clazz.asClass, SkolemType(rt)) else info // turns out some symbols read into `clazz` are not classes, not sure why this is the case. RefinedType(tp, sym.name, subst(sym.info, _)) } diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 77a308bba..e86539d6c 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -207,7 +207,7 @@ class PlainPrinter(_ctx: Context) extends Printer { toText(value) case MethodParam(mt, idx) => nameString(mt.paramNames(idx)) - case sk: RefinedThis => + case sk: SkolemType => sk.binder match { case rt: RefinedType => s"${nameString(rt.typeSymbol)}{...}.this" case _ => "<skolem>" diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 0ff47b36d..9958b3b64 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -791,7 +791,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit checkRefinementNonCyclic(refinement, refineCls, seen) val rsym = refinement.symbol val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info - RefinedType(parent, rsym.name, rt => rinfo.substThis(refineCls, RefinedThis(rt))) + RefinedType(parent, rsym.name, rt => rinfo.substThis(refineCls, SkolemType(rt))) // todo later: check that refinement is within bounds } val res = cpy.RefinedTypeTree(tree)(tpt1, refinements1) withType diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala index 54c4d8ab2..e443c2ab5 100644 --- a/tests/pos/Patterns.scala +++ b/tests/pos/Patterns.scala @@ -6,7 +6,7 @@ object Patterns { private def rebase(tp: NamedType): Type = { def rebaseFrom(prefix: Type): Type = ??? tp.prefix match { - case RefinedThis(rt) => rebaseFrom(rt) + case SkolemType(rt) => rebaseFrom(rt) case pre: ThisType => rebaseFrom(pre) case _ => tp } |