aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-07-20 11:35:52 +0200
committerMartin Odersky <odersky@gmail.com>2015-09-18 18:10:39 +0200
commit31048ad571b8c917a4c67f48899babae0703cae2 (patch)
tree24d3f0d320ba96aaa7db40bb79bb29bfdae8fc1a /src/dotty
parent845a5d65796365454ceaaba48603afa07792f7e7 (diff)
downloaddotty-31048ad571b8c917a4c67f48899babae0703cae2.tar.gz
dotty-31048ad571b8c917a4c67f48899babae0703cae2.tar.bz2
dotty-31048ad571b8c917a4c67f48899babae0703cae2.zip
Rename of hk args HK$x -> hk$x
These are not user-accessible types, so no need to follow type convention and write in upper case. Also, rename occurrences of lambda to Lambda, to make clear we mean a type lambda.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala12
-rw-r--r--src/dotty/tools/dotc/core/NameOps.scala2
-rw-r--r--src/dotty/tools/dotc/core/StdNames.scala6
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala83
-rw-r--r--src/dotty/tools/dotc/core/Types.scala6
5 files changed, 27 insertions, 82 deletions
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index 03be776a0..a503a2d23 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -494,7 +494,7 @@ class Definitions {
/** The set of HigherKindedXYZ traits encountered so far */
def lambdaTraits: Set[Symbol] = myLambdaTraits
- private var lambdaTraitForVariances = mutable.Map[List[Int], ClassSymbol]()
+ private var LambdaTraitForVariances = mutable.Map[List[Int], ClassSymbol]()
/** The HigherKinded trait corresponding to symbols `boundSyms` (which are assumed
* to be the type parameters of a higher-kided type). This is a class symbol that
@@ -513,7 +513,7 @@ class Definitions {
* - for each positive or negative variance v_i there is a parent trait Pj which
* is the same as LambdaXYZ except that it has `I` in i-th position.
*/
- def lambdaTrait(vcs: List[Int]): ClassSymbol = {
+ def LambdaTrait(vcs: List[Int]): ClassSymbol = {
assert(vcs.nonEmpty)
def varianceFlags(v: Int) = v match {
@@ -527,17 +527,17 @@ class Definitions {
val cls = denot.asClass.classSymbol
val paramDecls = newScope
for (i <- 0 until vcs.length)
- newTypeParam(cls, tpnme.lambdaArgName(i), varianceFlags(vcs(i)), paramDecls)
+ newTypeParam(cls, tpnme.LambdaArgName(i), varianceFlags(vcs(i)), paramDecls)
newTypeField(cls, tpnme.hkApply, Covariant, paramDecls)
val parentTraitRefs =
for (i <- 0 until vcs.length if vcs(i) != 0)
- yield lambdaTrait(vcs.updated(i, 0)).typeRef
+ yield LambdaTrait(vcs.updated(i, 0)).typeRef
denot.info = ClassInfo(
ScalaPackageClass.thisType, cls, ObjectClass.typeRef :: parentTraitRefs.toList, paramDecls)
}
}
- val traitName = tpnme.lambdaTraitName(vcs)
+ val traitName = tpnme.LambdaTraitName(vcs)
def createTrait = {
val cls = newClassSymbol(
@@ -549,7 +549,7 @@ class Definitions {
cls
}
- lambdaTraitForVariances.getOrElseUpdate(vcs, createTrait)
+ LambdaTraitForVariances.getOrElseUpdate(vcs, createTrait)
}
// ----- primitive value class machinery ------------------------------------------
diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala
index bf5b68ce9..1a2646347 100644
--- a/src/dotty/tools/dotc/core/NameOps.scala
+++ b/src/dotty/tools/dotc/core/NameOps.scala
@@ -110,7 +110,7 @@ object NameOps {
/** The index of the higher-kinded type parameter with this name.
* Pre: isLambdaArgName.
*/
- def lambdaArgIndex: Int =
+ def LambdaArgIndex: Int =
name.drop(tpnme.LAMBDA_ARG_PREFIX.length).toString.toInt
/** If the name ends with $nn where nn are
diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala
index be2452428..7c73d95da 100644
--- a/src/dotty/tools/dotc/core/StdNames.scala
+++ b/src/dotty/tools/dotc/core/StdNames.scala
@@ -173,7 +173,7 @@ object StdNames {
final val WILDCARD_STAR: N = "_*"
final val REIFY_TREECREATOR_PREFIX: N = "$treecreator"
final val REIFY_TYPECREATOR_PREFIX: N = "$typecreator"
- final val LAMBDA_ARG_PREFIX: N = "HK$"
+ final val LAMBDA_ARG_PREFIX: N = "hk$"
final val LAMBDA_ARG_PREFIXhead: Char = LAMBDA_ARG_PREFIX.head
final val Any: N = "Any"
@@ -739,8 +739,8 @@ object StdNames {
def syntheticTypeParamNames(num: Int): List[TypeName] =
(0 until num).map(syntheticTypeParamName)(breakOut)
- def lambdaTraitName(vcs: List[Int]): TypeName = LambdaPrefix ++ vcs.map(varianceSuffix).mkString
- def lambdaArgName(n: Int) = LAMBDA_ARG_PREFIX ++ n.toString
+ def LambdaTraitName(vcs: List[Int]): TypeName = LambdaPrefix ++ vcs.map(varianceSuffix).mkString
+ def LambdaArgName(n: Int) = LAMBDA_ARG_PREFIX ++ n.toString
final val Conforms = encode("<:<")
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index ca2e7601b..75a0b9957 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -141,6 +141,16 @@ class TypeApplications(val self: Type) extends AnyVal {
def isInstantiatedLambda(implicit ctx: Context): Boolean =
isSafeLambda && typeParams.isEmpty
+ def isHK(implicit ctx: Context): Boolean = self.dealias match {
+ case self: TypeRef =>
+ self.info match {
+ case TypeBounds(_, hi) => hi.isHK
+ case _ => false
+ }
+ case RefinedType(_, name) => name == tpnme.hkApply || name.isLambdaArgName
+ case _ => false
+ }
+
/** Encode the type resulting from applying this type to given arguments */
final def appliedTo(args: List[Type])(implicit ctx: Context): Type = /*>|>*/ track("appliedTo") /*<|<*/ {
def matchParams(tp: Type, tparams: List[TypeSymbol], args: List[Type]): Type = args match {
@@ -187,7 +197,7 @@ class TypeApplications(val self: Type) extends AnyVal {
if (tsym.isClass || !tp.typeSymbol.isCompleting) original.typeParams
else {
ctx.warning(i"encountered F-bounded higher-kinded type parameters for $tsym; assuming they are invariant")
- defn.lambdaTrait(args map alwaysZero).typeParams
+ defn.LambdaTrait(args map alwaysZero).typeParams // @@@ can we force?
}
matchParams(tp, safeTypeParams, args)
}
@@ -450,70 +460,7 @@ class TypeApplications(val self: Type) extends AnyVal {
}
recur(self)
}
-/*
- /** Given a type alias
- *
- * type T[boundSyms] = p.C[targs]
- *
- * produce its equivalent right hand side RHS that makes no reference to the bound
- * symbols on the left hand side. I.e. the type alias can be replaced by
- *
- * type T = RHS
- *
- * There are two strategies how this is achieved.
- * 1st strategy: Applies if `C` is a class such that every bound symbol in `boundSyms`
- * appears as an argument in `targs`, and in the same order. Then the rewriting replaces
- * bound symbols by references to the parameters of class C. Example:
- *
- * Say we have:
- *
- * class Triple[type T1, type T2, type T3]
- * type A[X] = Triple[(X, X), X, String]
- *
- * Then this is rewritable, as `X` appears as second type argument to `Triple`.
- * Occurrences of `X` are rewritten to `this.T2` and the whole definition becomes:
- *
- * type A = Triple { type T1 = (this.T2, this.T2); type T3 = String }
- *
- * 2nd strategy: Used as a fallback if 1st strategy does not apply. It rewrites
- * the RHS to a typed lambda abstraction.
- */
- def parameterizeWith(boundSyms: List[Symbol])(implicit ctx: Context): Type = {
- def matchParams(bsyms: List[Symbol], tparams: List[Symbol], targs: List[Type],
- correspondingParamName: Map[Symbol, TypeName]): Type = {
- if (bsyms.isEmpty) {
- val correspondingNames = correspondingParamName.values.toSet
-
- def replacements(rt: RefinedType): List[Type] =
- for (sym <- boundSyms)
- yield TypeRef(RefinedThis(rt), correspondingParamName(sym))
-
- def rewrite(tp: Type): Type = tp match {
- case tp @ RefinedType(parent, name: TypeName) =>
- if (correspondingNames contains name) rewrite(parent)
- else RefinedType(
- rewrite(parent), name,
- rt => tp.refinedInfo.subst(boundSyms, replacements(rt)))
- case tp =>
- tp
- }
-
- rewrite(self)
- }
- else if (tparams.isEmpty || targs.isEmpty)
- LambdaAbstract(boundSyms)
- else if (bsyms.head == targs.head.typeSymbol)
- matchParams(bsyms.tail, tparams.tail, targs.tail,
- correspondingParamName + (bsyms.head -> tparams.head.name.asTypeName))
- else
- matchParams(bsyms, tparams.tail, targs.tail, correspondingParamName)
- }
- val cls = self.typeSymbol
- if (cls.isClass) matchParams(boundSyms, cls.typeParams, argInfos, Map())
- else LambdaAbstract(boundSyms)
- }
-*/
/** The typed lambda abstraction of this type `T` relative to `boundSyms`.
* This is:
*
@@ -532,18 +479,16 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
def LambdaAbstract(boundSyms: List[Symbol], cycleParanoid: Boolean = false)(implicit ctx: Context): Type = {
def expand(tp: Type) = {
- val lambda = defn.lambdaTrait(boundSyms.map(_.variance))
+ val lambda = defn.LambdaTrait(boundSyms.map(_.variance))
val substitutedRHS = (rt: RefinedType) => {
val argRefs = boundSyms.indices.toList.map(i =>
- RefinedThis(rt).select(tpnme.lambdaArgName(i)))
+ RefinedThis(rt).select(tpnme.LambdaArgName(i)))
val substituted =
if (cycleParanoid) new ctx.SafeSubstMap(boundSyms, argRefs).apply(tp)
else tp.subst(boundSyms, argRefs)
substituted.bounds.withVariance(1)
}
- val res = RefinedType(lambda.typeRef, tpnme.hkApply, substitutedRHS)
- //println(i"lambda abstract $self wrt $boundSyms%, % --> $res")
- res
+ RefinedType(lambda.typeRef, tpnme.hkApply, substitutedRHS)
}
self match {
case self @ TypeBounds(lo, hi) =>
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 20b259db4..4656b0629 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1865,8 +1865,8 @@ object Types {
case refinedInfo: TypeBounds if refinedInfo.variance != 0 && refinedName.isLambdaArgName =>
val cls = parent.LambdaClass(forcing = false)
if (cls.exists)
- assert(refinedInfo.variance == cls.typeParams.apply(refinedName.lambdaArgIndex).variance,
- s"variance mismatch for $this, $cls, ${cls.typeParams}, ${cls.typeParams.apply(refinedName.lambdaArgIndex).variance}, ${refinedInfo.variance}")
+ assert(refinedInfo.variance == cls.typeParams.apply(refinedName.LambdaArgIndex).variance,
+ s"variance mismatch for $this, $cls, ${cls.typeParams}, ${cls.typeParams.apply(refinedName.LambdaArgIndex).variance}, ${refinedInfo.variance}")
case _ =>
}
this
@@ -1882,7 +1882,7 @@ object Types {
this
else if ( refinedName.isLambdaArgName
//&& { println(s"deriving $refinedName $parent $underlyingTypeParams"); true }
- && refinedName.lambdaArgIndex < underlyingTypeParams.length
+ && refinedName.LambdaArgIndex < underlyingTypeParams.length
&& !parent.isLambda)
derivedRefinedType(parent.EtaExpand, refinedName, refinedInfo)
else