From 0fde4b4902f81f9a020dbf460925596a276ab328 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 2 Dec 2015 10:56:49 +0100 Subject: Change hk naming scheme --- src/dotty/tools/dotc/core/Definitions.scala | 10 +++++----- src/dotty/tools/dotc/core/NameOps.scala | 15 +++++++++------ src/dotty/tools/dotc/core/StdNames.scala | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index 4556dd9d5..650cfe79c 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -642,9 +642,9 @@ class Definitions { * to be the type parameters of a higher-kided type). This is a class symbol that * would be generated by the following schema. * - * class LambdaXYZ extends Object with P1 with ... with Pn { - * type v_1 $hk$Arg0; ...; type v_N $hk$ArgN; - * type Apply + * trait LambdaXYZ extends Object with P1 with ... with Pn { + * type v_1 hk$0; ...; type v_N hk$N; + * type +$Apply * } * * Here: @@ -669,7 +669,7 @@ 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.hkArg(i), varianceFlags(vcs(i)), paramDecls) newTypeField(cls, tpnme.hkApply, Covariant, paramDecls) val parentTraitRefs = for (i <- 0 until vcs.length if vcs(i) != 0) @@ -679,7 +679,7 @@ class Definitions { } } - val traitName = tpnme.LambdaTraitName(vcs) + val traitName = tpnme.hkLambda(vcs) def createTrait = { val cls = newClassSymbol( diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 1a2646347..7dbd492b4 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -99,19 +99,22 @@ object NameOps { } /** Is this the name of a higher-kinded type parameter of a Lambda? */ - def isLambdaArgName = + def isHkArgName = name.length > 0 && - name.head == tpnme.LAMBDA_ARG_PREFIXhead && - name.startsWith(tpnme.LAMBDA_ARG_PREFIX) && { - val digits = name.drop(tpnme.LAMBDA_ARG_PREFIX.length) + name.head == tpnme.hkArgPrefixHead && + name.startsWith(tpnme.hkArgPrefix) && { + val digits = name.drop(tpnme.hkArgPrefixLength) digits.length <= 4 && digits.forall(_.isDigit) } /** The index of the higher-kinded type parameter with this name. * Pre: isLambdaArgName. */ - def LambdaArgIndex: Int = - name.drop(tpnme.LAMBDA_ARG_PREFIX.length).toString.toInt + def hkArgIndex: Int = + name.drop(tpnme.hkArgPrefixLength).toString.toInt + + def isLambdaTraitName(implicit ctx: Context): Boolean = + name.startsWith(tpnme.hkLambdaPrefix) /** If the name ends with $nn where nn are * all digits, strip the $ and the digits. diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala index e8cddd3d4..e2add1a52 100644 --- a/src/dotty/tools/dotc/core/StdNames.scala +++ b/src/dotty/tools/dotc/core/StdNames.scala @@ -173,8 +173,6 @@ 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_PREFIXhead: Char = LAMBDA_ARG_PREFIX.head final val AbstractFunction: N = "AbstractFunction" final val Any: N = "Any" @@ -314,7 +312,6 @@ object StdNames { val AnnotatedType: N = "AnnotatedType" val AppliedTypeTree: N = "AppliedTypeTree" - val hkApply: N = "$apply" val ArrayAnnotArg: N = "ArrayAnnotArg" val Constant: N = "Constant" val ConstantType: N = "ConstantType" @@ -322,7 +319,6 @@ object StdNames { val Flag : N = "Flag" val Ident: N = "Ident" val Import: N = "Import" - val LambdaPrefix: N = "Lambda$" val Literal: N = "Literal" val LiteralAnnotArg: N = "LiteralAnnotArg" val Modifiers: N = "Modifiers" @@ -530,9 +526,14 @@ object StdNames { val nothingRuntimeClass: N = "scala.runtime.Nothing$" val nullRuntimeClass: N = "scala.runtime.Null$" - val synthSwitch: N = "$synthSwitch" + val hkApply: N = "$Apply" + val hkArgPrefix: N = "$hk" + val hkLambdaPrefix: N = "Lambda$" + val hkArgPrefixHead: Char = hkArgPrefix.head + val hkArgPrefixLength: Int = hkArgPrefix.length + // unencoded operators object raw { final val AMP : N = "&" @@ -742,14 +743,13 @@ 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 - - final val Conforms = encode("<:<") + def hkLambda(vcs: List[Int]): TypeName = hkLambdaPrefix ++ vcs.map(varianceSuffix).mkString + def hkArg(n: Int): TypeName = hkArgPrefix ++ n.toString def varianceSuffix(v: Int): Char = varianceSuffixes.charAt(v + 1) - val varianceSuffixes = "NIP" + + final val Conforms = encode("<:<") } abstract class JavaNames[N <: Name] extends DefinedNames[N] { -- cgit v1.2.3