diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-18 11:48:48 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-04-06 13:15:28 +0200 |
commit | c67217594bb40e1eab7e567c97bdf29ac0654864 (patch) | |
tree | d6f684b1854b5f869c98e444a558aee3878e02a2 /compiler/src/dotty/tools/dotc/core | |
parent | db4f7a19c9329d59da09a4de6b8476b4b6988cdf (diff) | |
download | dotty-c67217594bb40e1eab7e567c97bdf29ac0654864.tar.gz dotty-c67217594bb40e1eab7e567c97bdf29ac0654864.tar.bz2 dotty-c67217594bb40e1eab7e567c97bdf29ac0654864.zip |
Eliminate LambdaAbstract
Use fromParams instead.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
3 files changed, 28 insertions, 27 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 82b184dbc..eb3394082 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -272,25 +272,6 @@ class TypeApplications(val self: Type) extends AnyVal { self } - /** Lambda abstract `self` with given type parameters. Examples: - * - * type T[X] = U becomes type T = [X] -> U - * type T[X] >: L <: U becomes type T >: L <: ([X] -> U) - */ - def LambdaAbstract(tparams: List[TypeParamInfo])(implicit ctx: Context): Type = { - def expand(tp: Type) = PolyType/*HKTypeLambda*/.fromParams(tparams, tp) - if (tparams.isEmpty) self - else self match { - case self: TypeAlias => - self.derivedTypeAlias(expand(self.alias)) - case self @ TypeBounds(lo, hi) => - self.derivedTypeBounds( - if (lo.isRef(defn.NothingClass)) lo else expand(lo), - expand(hi)) - case _ => expand(self) - } - } - /** Convert a type constructor `TC` which has type parameters `T1, ..., Tn` * in a context where type parameters `U1,...,Un` are expected to * @@ -303,7 +284,7 @@ class TypeApplications(val self: Type) extends AnyVal { */ def EtaExpand(tparams: List[TypeSymbol])(implicit ctx: Context): Type = { val tparamsToUse = if (variancesConform(typeParams, tparams)) tparams else typeParamSymbols - self.appliedTo(tparams map (_.typeRef)).LambdaAbstract(tparamsToUse) + HKTypeLambda.fromParams(tparamsToUse, self.appliedTo(tparams map (_.typeRef))) //.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}") } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index a7401f6f9..4ba0a2924 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2566,12 +2566,11 @@ object Types { protected def paramName(param: ParamInfo.Of[N])(implicit ctx: Context): N = param.paramName - protected def paramInfo(param: ParamInfo.Of[N])(implicit ctx: Context): Type = - param.paramInfo - def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): LT = - apply(params.map(paramName))( - tl => params.map(param => tl.integrate(params, paramInfo(param)).asInstanceOf[PInfo]), + def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): Type = + if (params.isEmpty) resultType + else apply(params.map(paramName))( + tl => params.map(param => tl.integrate(params, param.paramInfo).asInstanceOf[PInfo]), tl => tl.integrate(params, resultType)) } @@ -2755,6 +2754,25 @@ object Types { override def paramName(param: ParamInfo.Of[TypeName])(implicit ctx: Context): TypeName = param.paramName.withVariance(param.paramVariance) + + /** Distributes Lambda inside type bounds. Examples: + * + * type T[X] = U becomes type T = [X] -> U + * type T[X] <: U becomes type T >: Nothign <: ([X] -> U) + * type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U) + */ + override def fromParams[PI <: ParamInfo.Of[TypeName]](params: List[PI], resultType: Type)(implicit ctx: Context): Type = { + def expand(tp: Type) = PolyType.fromParams(params, tp) //### + resultType match { + case rt: TypeAlias => + rt.derivedTypeAlias(expand(rt.alias)) + case rt @ TypeBounds(lo, hi) => + rt.derivedTypeBounds( + if (lo.isRef(defn.NothingClass)) lo else expand(lo), expand(hi)) + case rt => + expand(rt) + } + } } object PolyType extends TypeLambdaCompanion[PolyType] { diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 34cbf4677..cf99bb022 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -42,13 +42,15 @@ object Scala2Unpickler { /** Convert temp poly type to poly type and leave other types alone. */ def translateTempPoly(tp: Type)(implicit ctx: Context): Type = tp match { - case TempPolyType(tparams, restpe) => restpe.LambdaAbstract(tparams) // PolyType.fromParams(tparams, restpe) + case TempPolyType(tparams, restpe) => + (if (tparams.head.owner.isTerm) PolyType else HKTypeLambda) + .fromParams(tparams, restpe) case tp => tp } def addConstructorTypeParams(denot: SymDenotation)(implicit ctx: Context) = { assert(denot.isConstructor) - denot.info = denot.info.LambdaAbstract(denot.owner.typeParams) + denot.info = PolyType.fromParams(denot.owner.typeParams, denot.info) } /** Convert array parameters denoting a repeated parameter of a Java method |