From 2634498cede2525b07c1e40fbad0f5ae0cf96fda Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 20 Jul 2015 10:36:53 +0200 Subject: Rename Apply -> hkApply Want to have a unique name for Apply, so that tests for higher-kinded types become cheaper. --- src/dotty/tools/dotc/core/Definitions.scala | 2 +- src/dotty/tools/dotc/core/StdNames.scala | 2 +- src/dotty/tools/dotc/core/TypeApplications.scala | 12 ++++++------ src/dotty/tools/dotc/core/TypeComparer.scala | 8 ++++---- src/dotty/tools/dotc/core/Types.scala | 4 ++-- src/dotty/tools/dotc/core/tasty/TreePickler.scala | 2 +- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 8 ++++---- src/dotty/tools/dotc/typer/Typer.scala | 7 ++++++- 9 files changed, 27 insertions(+), 22 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index fcd9ef224..03be776a0 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -528,7 +528,7 @@ class Definitions { val paramDecls = newScope for (i <- 0 until vcs.length) newTypeParam(cls, tpnme.lambdaArgName(i), varianceFlags(vcs(i)), paramDecls) - newTypeField(cls, tpnme.Apply, Covariant, 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 diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala index 52318a386..be2452428 100644 --- a/src/dotty/tools/dotc/core/StdNames.scala +++ b/src/dotty/tools/dotc/core/StdNames.scala @@ -311,7 +311,7 @@ object StdNames { val AnnotatedType: N = "AnnotatedType" val AppliedTypeTree: N = "AppliedTypeTree" - val Apply: N = "Apply" + val hkApply: N = "$apply" val ArrayAnnotArg: N = "ArrayAnnotArg" val Constant: N = "Constant" val ConstantType: N = "ConstantType" diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 12b540cf4..c09d6a2e0 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -227,7 +227,7 @@ class TypeApplications(val self: Type) extends AnyVal { // that fall through the hole. Not adding an #Apply typically manifests itself // with a <:< failure of two types that "look the same". An example is #779, // where compiling scala.immutable.Map gives a bounds violation. - TypeRef(res, tpnme.Apply) + TypeRef(res, tpnme.hkApply) else res } } @@ -235,8 +235,8 @@ class TypeApplications(val self: Type) extends AnyVal { /** Simplify a fully instantiated type of the form `LambdaX{... type Apply = T } # Apply` to `T`. */ def simplifyApply(implicit ctx: Context): Type = self match { - case self @ TypeRef(prefix, tpnme.Apply) if prefix.isInstantiatedLambda => - prefix.member(tpnme.Apply).info match { + case self @ TypeRef(prefix, tpnme.hkApply) if prefix.isInstantiatedLambda => + prefix.member(tpnme.hkApply).info match { case TypeAlias(alias) => alias case _ => self } @@ -541,7 +541,7 @@ class TypeApplications(val self: Type) extends AnyVal { else tp.subst(boundSyms, argRefs) substituted.bounds.withVariance(1) } - val res = RefinedType(lambda.typeRef, tpnme.Apply, substitutedRHS) + val res = RefinedType(lambda.typeRef, tpnme.hkApply, substitutedRHS) //println(i"lambda abstract $self wrt $boundSyms%, % --> $res") res } @@ -581,7 +581,7 @@ class TypeApplications(val self: Type) extends AnyVal { case TypeAlias(TypeRef(RefinedThis(rt), rname)) // TODO: Drop once hk applications have been updated if (rname == tparam.name) && (rt eq self) => etaCore(tp.parent, otherParams) - case TypeRef(TypeAlias(TypeRef(RefinedThis(rt), rname)), tpnme.Apply) + case TypeRef(TypeAlias(TypeRef(RefinedThis(rt), rname)), tpnme.hkApply) if (rname == tparam.name) && (rt eq self) => etaCore(tp.parent, otherParams) case _ => @@ -592,7 +592,7 @@ class TypeApplications(val self: Type) extends AnyVal { } } self match { - case self @ RefinedType(parent, tpnme.Apply) => + case self @ RefinedType(parent, tpnme.hkApply) => val lc = parent.LambdaClass(forcing = false) self.refinedInfo match { case TypeAlias(alias) if lc.exists => etaCore(alias, lc.typeParams.reverse) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index ea815f6c0..a8598ae44 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -471,7 +471,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { * continue with `T <:< U` if `inOrder` is true and `U <:< T` otherwise. */ def compareHK(projection: NamedType, other: Type, inOrder: Boolean) = - projection.name == tpnme.Apply && { + projection.name == tpnme.hkApply && { // @@@ rewrite val lambda = projection.prefix.LambdaClass(forcing = true) lambda.exists && !other.isLambda && other.testLifted(lambda.typeParams, @@ -480,7 +480,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { } /** The class symbols bounding the type of the `Apply` member of `tp` */ - private def classBounds(tp: Type) = tp.member(tpnme.Apply).info.classSymbols + private def classBounds(tp: Type) = tp.member(tpnme.hkApply).info.classSymbols /** Returns true iff either `tp11 <:< tp21` or `tp12 <:< tp22`, trying at the same time * to keep the constraint as wide as possible. Specifically, if @@ -633,9 +633,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { /** Does `tp` need to be eta lifted to be comparable to `target`? */ private def needsEtaLift(tp: Type, target: RefinedType): Boolean = { - //default.echo(i"needs eta $tp $target?", { + //default.echo(i"needs eta $tp $target?", { // @@@ rewrite val name = target.refinedName - (name.isLambdaArgName || (name eq tpnme.Apply)) && target.isLambda && + (name.isLambdaArgName || (name eq tpnme.hkApply)) && target.isLambda && tp.exists && !tp.isLambda //}) } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 9f2cc0f34..20b259db4 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -833,7 +833,7 @@ object Types { * * P { type T = String, type R = P{...}.T } # R --> String * - * (2) The refinement is a fully instantiated type lambda, and the projected name is "Apply". + * (2) The refinement is a fully instantiated type lambda, and the projected name is "$apply". * In this case the rhs of the apply is returned with all references to lambda argument types * substituted by their definitions. * @@ -869,7 +869,7 @@ object Types { else if (!pre.refinementRefersToThis) alias else alias match { case TypeRef(RefinedThis(`pre`), aliasName) => lookupRefined(aliasName) // (1) - case _ => if (name == tpnme.Apply) betaReduce(alias) else NoType // (2) + case _ => if (name == tpnme.hkApply) betaReduce(alias) else NoType // (2) } case _ => loop(pre.parent, resolved) } diff --git a/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/src/dotty/tools/dotc/core/tasty/TreePickler.scala index a23d59339..d50817b60 100644 --- a/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -176,7 +176,7 @@ class TreePickler(pickler: TastyPickler) { pickleNameAndSig(tpe.name, tpe.signature); pickleType(tpe.prefix) } case tpe: NamedType => - if (tpe.name == tpnme.Apply && tpe.prefix.argInfos.nonEmpty && tpe.prefix.isInstantiatedLambda) + if (tpe.name == tpnme.hkApply && tpe.prefix.argInfos.nonEmpty && tpe.prefix.isInstantiatedLambda) // instantiated lambdas are pickled as APPLIEDTYPE; #Apply will // be reconstituted when unpickling. pickleType(tpe.prefix) diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 68439846d..af33ce3c2 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -584,7 +584,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas * tp { name: T } */ def elimExistentials(boundSyms: List[Symbol], tp: Type)(implicit ctx: Context): Type = { - // Need to be careful not to run into cyclic references here (observed when + // Need to be careful not to run into cyclic references here (observed when // comiling t247.scala). That's why we avoiud taking `symbol` of a TypeRef // unless names match up. val isBound = (tp: Type) => { @@ -619,7 +619,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas case info => tp.derivedRefinedType(parent1, name, info) } - case tp @ TypeRef(pre, tpnme.Apply) if pre.isLambda => + case tp @ TypeRef(pre, tpnme.hkApply) => elim(pre) case _ => tp diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 70fab7e0f..a46665ec0 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -122,7 +122,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close } if (tp.isSafeLambda) { - val (prefix, body, bindings) = extractApply(tp) + val (prefix, body, bindings) = decomposeHKApply(tp) prefix match { case prefix: TypeRef if prefix.symbol.isLambdaTrait && body.exists => return typeLambdaText(prefix.symbol, body, bindings) @@ -184,9 +184,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { * without a prefix, because the latter print nicer. * */ - def extractApply(tp: Type): (Type, Type, List[(Name, Type)]) = tp.stripTypeVar match { + def decomposeHKApply(tp: Type): (Type, Type, List[(Name, Type)]) = tp.stripTypeVar match { case tp @ RefinedType(parent, name) => - if (name == tpnme.Apply) { + if (name == tpnme.hkApply) { // simplify arguments so that parameters just print HK$i and not // LambdaI{...}.HK$i val simplifyArgs = new TypeMap { @@ -199,7 +199,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } (parent, simplifyArgs(tp.refinedInfo.followTypeAlias), Nil) } else if (name.isLambdaArgName) { - val (prefix, body, argBindings) = extractApply(parent) + val (prefix, body, argBindings) = decomposeHKApply(parent) (prefix, body, (name, tp.refinedInfo) :: argBindings) } else (tp, NoType, Nil) case _ => diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index d35356a85..3f7e0b81c 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1434,7 +1434,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case Select(New(tpt), nme.CONSTRUCTOR) => tpt.tpe.dealias.argTypesLo case _ => Nil } - if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2 + if (typeArgs.isEmpty) { + //for ((pname, pbound) <- poly.paramNames.zip(poly.paramBounds)) + // if (pbound.hi.isSafeLambda) + // ctx.error(d"cannot infer argument for higher-kinded type parameter $pname", tree.pos) + typeArgs = constrained(poly, tree)._2 + } convertNewArray( adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original)) } -- cgit v1.2.3