diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-17 15:08:59 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-06 13:15:28 +0200 |
commit | 5fe6f54de36224974bdd3a9169f899f6df25971e (patch) | |
tree | af7d433304a4b35c38f1c2cccecee240353ffadc | |
parent | 700e7ac6658a1d699502c94141091012d18519c4 (diff) | |
download | dotty-5fe6f54de36224974bdd3a9169f899f6df25971e.tar.gz dotty-5fe6f54de36224974bdd3a9169f899f6df25971e.tar.bz2 dotty-5fe6f54de36224974bdd3a9169f899f6df25971e.zip |
Eliminate ParamType
Replace with ParamRef
5 files changed, 12 insertions, 18 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Substituters.scala b/compiler/src/dotty/tools/dotc/core/Substituters.scala index 23683608a..d565ec229 100644 --- a/compiler/src/dotty/tools/dotc/core/Substituters.scala +++ b/compiler/src/dotty/tools/dotc/core/Substituters.scala @@ -196,7 +196,7 @@ trait Substituters { this: Context => .mapOver(tp) } - final def substParam(tp: Type, from: ParamType, to: Type, theMap: SubstParamMap): Type = + final def substParam(tp: Type, from: ParamRef, to: Type, theMap: SubstParamMap): Type = tp match { case tp: BoundType => if (tp == from) to else tp @@ -216,7 +216,7 @@ trait Substituters { this: Context => final def substParams(tp: Type, from: BindingType, to: List[Type], theMap: SubstParamsMap): Type = tp match { - case tp: ParamType => + case tp: ParamRef => if (tp.binder == from) to(tp.paramNum) else tp case tp: NamedType => if (tp.currentSymbol.isStatic) tp @@ -269,7 +269,7 @@ trait Substituters { this: Context => def apply(tp: Type): Type = substRecThis(tp, from, to, this) } - final class SubstParamMap(from: ParamType, to: Type) extends DeepTypeMap { + final class SubstParamMap(from: ParamRef, to: Type) extends DeepTypeMap { def apply(tp: Type) = substParam(tp, from, to, this) } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 074d2e1fb..217e5e351 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1199,7 +1199,7 @@ object Types { ctx.substRecThis(this, binder, tp, null) /** Substitute a bound type by some other type */ - final def substParam(from: ParamType, to: Type)(implicit ctx: Context): Type = + final def substParam(from: ParamRef, to: Type)(implicit ctx: Context): Type = ctx.substParam(this, from, to, null) /** Substitute bound types by some other types */ @@ -2411,8 +2411,6 @@ object Types { type PInfo = Type type This <: TermLambda - def paramNames: List[TermName] - override def resultType(implicit ctx: Context): Type = if (dependencyStatus == FalseDeps) { // dealias all false dependencies val dealiasMap = new TypeMap { @@ -2831,7 +2829,7 @@ object Types { unique(new CachedHKApply(tycon, args)).checkInst } - // ----- Bound types: MethodParam, TypeParamRef -------------------------- + // ----- BoundTypes: ParamRef, RecThis ---------------------------------------- abstract class BoundType extends CachedProxyType with ValueType { type BT <: Type @@ -2839,13 +2837,9 @@ object Types { def copyBoundType(bt: BT): Type } - abstract class ParamType extends BoundType { - def paramNum: Int - def paramName: Name - } - - abstract class ParamRef extends ParamType { + abstract class ParamRef extends BoundType { type BT <: LambdaType + def paramNum: Int def paramName: binder.ThisName = binder.paramNames(paramNum) override def underlying(implicit ctx: Context): Type = { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 0b361f1f4..d712b913b 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -260,14 +260,14 @@ class TreePickler(pickler: TastyPickler) { writeByte(METHODtype) pickleMethodic(tpe.resultType, tpe.paramNames, tpe.paramInfos) case tpe: TypeParamRef => - if (!pickleParamType(tpe)) + if (!pickleParamRef(tpe)) // TODO figure out why this case arises in e.g. pickling AbstractFileReader. ctx.typerState.constraint.entry(tpe) match { case TypeBounds(lo, hi) if lo eq hi => pickleNewType(lo, richTypes) case _ => assert(false, s"orphan poly parameter: $tpe") } case tpe: TermParamRef => - assert(pickleParamType(tpe), s"orphan method parameter: $tpe") + assert(pickleParamRef(tpe), s"orphan method parameter: $tpe") case tpe: LazyRef => pickleType(tpe.ref) }} catch { @@ -289,7 +289,7 @@ class TreePickler(pickler: TastyPickler) { } } - def pickleParamType(tpe: ParamType)(implicit ctx: Context): Boolean = { + def pickleParamRef(tpe: ParamRef)(implicit ctx: Context): Boolean = { val binder = pickledTypes.get(tpe.binder) val pickled = binder != null if (pickled) { diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 89e935bd5..dd060ea09 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -460,7 +460,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder new api.Annotated(apiType(tpe), Array(apiAnnotation(annot))) case tp: ThisType => apiThis(tp.cls) - case tp: ParamType => + case tp: ParamRef => // TODO: Distinguishing parameters based on their names alone is not enough, // the binder is also needed (at least for type lambdas). new api.ParameterRef(tp.paramName.toString) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index dde037938..ebb5b605b 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -296,7 +296,7 @@ class TreeChecker extends Phase with SymTransformer { definedBinders += tp mapOver(tp) definedBinders -= tp - case tp: ParamType => + case tp: ParamRef => assert(definedBinders.contains(tp.binder), s"orphan param: $tp") case tp: TypeVar => apply(tp.underlying) |