aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 19:02:34 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:34:58 +0200
commitcdb4a1cb986f25eddf411dfc45aeb20dd994f7d5 (patch)
treeba9c96c271418ec09c4b39adad8ebdbf7b81f4fa /src/dotty/tools/dotc/core
parent5d0318681f8c368f04796da5dd11ee1c9fcbdbd0 (diff)
downloaddotty-cdb4a1cb986f25eddf411dfc45aeb20dd994f7d5.tar.gz
dotty-cdb4a1cb986f25eddf411dfc45aeb20dd994f7d5.tar.bz2
dotty-cdb4a1cb986f25eddf411dfc45aeb20dd994f7d5.zip
New type lambda scheme for hk types
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index 8ab5fbf02..2411e0bb2 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -15,8 +15,35 @@ import StdNames.tpnme
import util.Positions.Position
import config.Printers._
import collection.mutable
+ import dotty.tools.dotc.config.Config
import java.util.NoSuchElementException
+object TypeApplicationsNewHK {
+ import TypeApplications._
+
+ object TypeLambda {
+ def apply(argBindingFns: List[RefinedType => TypeBounds],
+ bodyFn: RefinedType => Type)(implicit ctx: Context): Type = {
+ val argNames = argBindingFns.indices.toList.map(tpnme.hkArg)
+ RefinedType.recursive(bodyFn, argNames, argBindingFns)
+ }
+
+ def unapply(tp: Type)(implicit ctx: Context): Option[(List[TypeBounds], Type)] = {
+ def decompose(t: Type, acc: List[TypeBounds]): (List[TypeBounds], Type) = t match {
+ case t @ RefinedType(p, rname, rinfo: TypeBounds)
+ if rname.isHkArgName && rinfo.isBinding =>
+ decompose(p, rinfo.bounds :: acc)
+ case _ =>
+ (acc, t)
+ }
+ decompose(tp, Nil) match {
+ case (Nil, _) => None
+ case x => Some(x)
+ }
+ }
+ }
+}
+
object TypeApplications {
/** Assert type is not a TypeBounds instance and return it unchanged */
@@ -51,6 +78,14 @@ object TypeApplications {
* [v1 X1: B1, ..., vn Xn: Bn] -> T
* ==>
* ([X_i := this.$hk_i] T) { type v_i $hk_i: (new)B_i }
+ *
+ * [X] -> List[X]
+ *
+ * List { type List$A = this.$hk_0 } { type $hk_0 }
+ *
+ * [X] -> X
+ *
+ * mu(this) this.$hk_0 & { type $hk_0 }
*/
object TypeLambda {
def apply(variances: List[Int],
@@ -388,9 +423,9 @@ class TypeApplications(val self: Type) extends AnyVal {
/** Replace references to type parameters with references to hk arguments `this.$hk_i`
* Care is needed not to cause cyclic reference errors, hence `SafeSubstMap`.
*/
- private[TypeApplications] def internalizeFrom[T <: Type](tparams: List[Symbol])(implicit ctx: Context): RefinedType => T =
+ def internalizeFrom[T <: Type](tparams: List[Symbol])(implicit ctx: Context): RefinedType => T =
(rt: RefinedType) =>
- new ctx.SafeSubstMap(tparams , argRefs(rt, tparams.length))
+ new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length))
.apply(self).asInstanceOf[T]
/** Lambda abstract `self` with given type parameters. Examples: