aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-18 11:48:48 +0100
committerMartin Odersky <odersky@gmail.com>2017-04-06 13:15:28 +0200
commitc67217594bb40e1eab7e567c97bdf29ac0654864 (patch)
treed6f684b1854b5f869c98e444a558aee3878e02a2 /compiler/src/dotty/tools/dotc/core
parentdb4f7a19c9329d59da09a4de6b8476b4b6988cdf (diff)
downloaddotty-c67217594bb40e1eab7e567c97bdf29ac0654864.tar.gz
dotty-c67217594bb40e1eab7e567c97bdf29ac0654864.tar.bz2
dotty-c67217594bb40e1eab7e567c97bdf29ac0654864.zip
Eliminate LambdaAbstract
Use fromParams instead.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeApplications.scala21
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala28
-rw-r--r--compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala6
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