diff options
16 files changed, 113 insertions, 84 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 300bf833a8..47b50249c9 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -482,7 +482,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { BLOCK( VAL(sym) === qual0, - callAsReflective(mparams map (_.tpe), resType) + callAsReflective(mparams map tpeOfSymbol, resType) ) } } diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index eb3c965d7f..7b749afa2f 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -271,8 +271,11 @@ abstract class Erasure extends AddInterfaces poly + jsig(restpe) case MethodType(params, restpe) => - "("+(params map (_.tpe) map (jsig(_))).mkString+")"+ - (if (restpe.typeSymbol == UnitClass || sym0.isConstructor) VOID_TAG.toString else jsig(restpe)) + val buf = new StringBuffer("(") + params foreach (p => buf append jsig(p.tpe)) + buf append ")" + buf append (if (restpe.typeSymbol == UnitClass || sym0.isConstructor) VOID_TAG.toString else jsig(restpe)) + buf.toString case RefinedType(parent :: _, decls) => boxedSig(parent) diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 77ad65957d..7247770f4b 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -385,7 +385,7 @@ abstract class ExplicitOuter extends InfoTransform def makeGuardDef(vs: List[Symbol], guard: Tree) = { val gdname = unit.freshTermName("gd") val method = currentOwner.newMethod(gdname, tree.pos, SYNTHETIC) - val params = method newSyntheticValueParams vs.map(_.tpe) + val params = method newSyntheticValueParams vs.map(tpeOfSymbol) method setInfo new MethodType(params, BooleanClass.tpe) localTyper typed { diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index a34fc71b8f..f7fb17dee6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -181,8 +181,8 @@ trait Implicits { containsError(restpe) case NullaryMethodType(restpe) => containsError(restpe) - case MethodType(params, restpe) => - params.exists(_.tpe.isError) || containsError(restpe) + case mt @ MethodType(_, restpe) => + (mt.paramTypes exists typeIsError) || containsError(restpe) case _ => tp.isError } diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 9e324194e6..fc0f9370b4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -240,8 +240,8 @@ trait Infer { def normalize(tp: Type): Type = tp match { case mt @ MethodType(params, restpe) if mt.isImplicit => normalize(restpe) - case mt @ MethodType(params, restpe) if !mt.isDependentMethodType => - functionType(params map (_.tpe), normalize(restpe)) + case mt @ MethodType(_, restpe) if !mt.isDependentMethodType => + functionType(mt.paramTypes, normalize(restpe)) case NullaryMethodType(restpe) => normalize(restpe) case ExistentialType(tparams, qtpe) => @@ -747,8 +747,8 @@ trait Infer { alts exists (alt => isApplicable(undetparams, pre.memberType(alt), argtpes0, pt)) case ExistentialType(tparams, qtpe) => isApplicable(undetparams, qtpe, argtpes0, pt) - case MethodType(params, _) => - val formals = formalTypes(params map { _.tpe }, argtpes0.length, removeByName = false) + case mt @ MethodType(params, _) => + val formals = formalTypes(mt.paramTypes, argtpes0.length, removeByName = false) def tryTupleApply: Boolean = { // if 1 formal, 1 argtpe (a tuple), otherwise unmodified argtpes0 @@ -854,8 +854,8 @@ trait Infer { isAsSpecific(res, ftpe2) case mt: MethodType if mt.isImplicit => isAsSpecific(ftpe1.resultType, ftpe2) - case MethodType(params, _) if params.nonEmpty => - var argtpes = params map (_.tpe) + case mt @ MethodType(params, _) if params.nonEmpty => + var argtpes = mt.paramTypes if (isVarArgsList(params) && isVarArgsList(ftpe2.params)) argtpes = argtpes map (argtpe => if (isRepeatedParamType(argtpe)) argtpe.typeArgs.head else argtpe) @@ -864,8 +864,8 @@ trait Infer { isAsSpecific(PolyType(tparams, res), ftpe2) case PolyType(tparams, mt: MethodType) if mt.isImplicit => isAsSpecific(PolyType(tparams, mt.resultType), ftpe2) - case PolyType(_, MethodType(params, _)) if params.nonEmpty => - isApplicable(List(), ftpe2, params map (_.tpe), WildcardType) + case PolyType(_, (mt @ MethodType(params, _))) if params.nonEmpty => + isApplicable(List(), ftpe2, mt.paramTypes, WildcardType) // case NullaryMethodType(res) => // isAsSpecific(res, ftpe2) case ErrorType => @@ -1111,10 +1111,10 @@ trait Infer { */ def inferMethodInstance(fn: Tree, undetparams: List[Symbol], args: List[Tree], pt0: Type): List[Symbol] = fn.tpe match { - case MethodType(params0, _) => + case mt @ MethodType(params0, _) => try { val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0 - val formals = formalTypes(params0 map (_.tpe), args.length) + val formals = formalTypes(mt.paramTypes, args.length) val argtpes = actualTypes(args map (x => elimAnonymousClass(x.tpe.deconst)), formals.length) val restpe = fn.tpe.resultType(argtpes) @@ -1640,7 +1640,7 @@ trait Infer { else eligible filter { alt => // for functional values, the `apply` method might be overloaded val mtypes = followApply(alt.tpe) match { - case OverloadedType(_, alts) => alts map (_.tpe) + case OverloadedType(_, alts) => alts map tpeOfSymbol case t => t :: Nil } // Drop those that use a default; keep those that use vararg/tupling conversion. @@ -1777,7 +1777,7 @@ trait Infer { else if (sym.isOverloaded) { val xs = sym.alternatives val tparams = new AsSeenFromMap(pre, xs.head.owner) mapOver xs.head.typeParams - val bounds = tparams map (_.tpeHK) // see e.g., #1236 + val bounds = tparams map tpeHKOfSymbol // see e.g., #1236 val tpe = PolyType(tparams, OverloadedType(AntiPolyType(pre, bounds), xs)) (sym setInfo tpe, tpe) diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index 4f597f97c9..cdbdb82e9f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -41,7 +41,7 @@ trait MethodSynthesis { require(container.owner.isPackageClass, "Container must be a top-level class in a package: " + container) require(tparams.size == args.size, "Arguments must match type constructor arity: " + tparams + ", " + args) - appliedType(container, args map (_.tpe): _*) + appliedType(container, args map tpeOfSymbol: _*) } def companionType[T](implicit ct: CT[T]) = diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index 6eeba2b4bf..f69e5b6098 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala @@ -3294,7 +3294,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL // TODO: I don't think the binder's types can actually be different (due to checks in caseEquals) // if they do somehow manage to diverge, the lub might not be precise enough and we could get a type error // TODO: reuse name exactly if there's only one binder in binders - val binder = freshSym(binders.head.pos, lub(binders.map(_.tpe)), binders.head.name.toString) + val binder = freshSym(binders.head.pos, lub(binders.map(tpeOfSymbol)), binders.head.name.toString) // the patterns in same are equal (according to caseEquals) // we can thus safely pick the first one arbitrarily, provided we correct binding diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 9d0c5f400e..f87ca4997d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -941,9 +941,9 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R case TypeBounds(lo, hi) => validateVariance(lo, -variance) validateVariance(hi, variance) - case MethodType(formals, result) => + case mt @ MethodType(formals, result) => if (inRefinement) - validateVariances(formals map (_.tpe), -variance) + validateVariances(mt.paramTypes, -variance) validateVariance(result, variance) case NullaryMethodType(result) => validateVariance(result, variance) @@ -1677,7 +1677,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R tree case TypeApply(fn, args) => - checkBounds(tree, NoPrefix, NoSymbol, fn.tpe.typeParams, args map (_.tpe)) + checkBounds(tree, NoPrefix, NoSymbol, fn.tpe.typeParams, args map tpeOfTree) transformCaseApply(tree, ()) case x @ Apply(_, _) => diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 77c1bedc8e..5aa8e77347 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -393,7 +393,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val code = DefDef(newAcc, { val (receiver :: _) :: tail = newAcc.paramss val base: Tree = Select(Ident(receiver), sym) - val allParamTypes = mapParamss(sym)(_.tpe) + val allParamTypes = mapParamss(sym)(tpeOfSymbol) val args = map2(tail, allParamTypes)((params, tpes) => map2(params, tpes)(makeArg(_, receiver, _))) args.foldLeft(base)(Apply(_, _)) }) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 46fbaee20a..47e129206a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1309,7 +1309,7 @@ trait Typers extends Modes with Adaptations with Tags { def adaptToArguments(qual: Tree, name: Name, args: List[Tree], pt: Type, reportAmbiguous: Boolean, saveErrors: Boolean): Tree = { def doAdapt(restpe: Type) = //util.trace("adaptToArgs "+qual+", name = "+name+", argtpes = "+(args map (_.tpe))+", pt = "+pt+" = ") - adaptToMember(qual, HasMethodMatching(name, args map (_.tpe), restpe), reportAmbiguous, saveErrors) + adaptToMember(qual, HasMethodMatching(name, args map tpeOfTree, restpe), reportAmbiguous, saveErrors) if (pt != WildcardType) { silent(_ => doAdapt(pt)) match { case SilentResultValue(result) if result != qual => @@ -1437,7 +1437,7 @@ trait Typers extends Modes with Adaptations with Tags { val supertparams = if (supertpt.hasSymbol) supertpt.symbol.typeParams else List() var supertpe = supertpt.tpe if (!supertparams.isEmpty) - supertpe = PolyType(supertparams, appliedType(supertpe, supertparams map (_.tpeHK))) + supertpe = PolyType(supertparams, appliedType(supertpe, supertparams map tpeHKOfSymbol)) // A method to replace a super reference by a New in a supercall def transformSuperCall(scall: Tree): Tree = (scall: @unchecked) match { @@ -1871,7 +1871,7 @@ trait Typers extends Modes with Adaptations with Tags { val params = fn.tpe.params val args2 = if (params.isEmpty || !isRepeatedParamType(params.last.tpe)) args else args.take(params.length - 1) :+ EmptyTree - assert(sameLength(args2, params) || call.isErrorTyped, "mismatch " + clazz + " " + (params map (_.tpe)) + " " + args2)//debug + assert(sameLength(args2, params) || call.isErrorTyped, "mismatch " + clazz + " " + (params map tpeOfSymbol) + " " + args2)//debug (superConstr, args1 ::: args2) case Block(stats, expr) if !stats.isEmpty => decompose(stats.last) @@ -2005,7 +2005,7 @@ trait Typers extends Modes with Adaptations with Tags { case SilentResultValue(tpt) => val alias = enclClass.newAliasType(name.toTypeName, useCase.pos) val tparams = cloneSymbolsAtOwner(tpt.tpe.typeSymbol.typeParams, alias) - val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe))) + val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map tpeOfSymbol)) alias setInfo newInfo context.scope.enter(alias) case _ => @@ -2334,7 +2334,7 @@ trait Typers extends Modes with Adaptations with Tags { val (resTp, needAdapt) = if (opt.virtPatmat) ptOrLubPacked(casesTyped, pt) - else ptOrLub(casesTyped map (_.tpe), pt) + else ptOrLub(casesTyped map tpeOfTree, pt) val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, resTp)) @@ -2422,7 +2422,7 @@ trait Typers extends Modes with Adaptations with Tags { val match_ = methodBodyTyper.typedMatch(gen.mkUnchecked(selector), cases, mode, ptRes) val resTp = match_.tpe - val methFormals = paramSyms map (_.tpe) + val methFormals = paramSyms map tpeOfSymbol val parents = ( if (isPartial) parentsPartial(List(methFormals.head, resTp)) else addSerializable(abstractFunctionType(methFormals, resTp)) @@ -2588,7 +2588,7 @@ trait Typers extends Modes with Adaptations with Tags { // for (vparam <- vparams) { // checkNoEscaping.locals(context.scope, WildcardType, vparam.tpt); () // } - val formals = vparamSyms map (_.tpe) + val formals = vparamSyms map tpeOfSymbol val body1 = typed(fun.body, respt) val restpe = packedType(body1, fun.symbol).deconst.resultType val funtpe = typeRef(clazz.tpe.prefix, clazz, formals :+ restpe) @@ -3547,7 +3547,7 @@ trait Typers extends Modes with Adaptations with Tags { // Higher-kinded existentials are not yet supported, but this is // tpeHK for when they are: "if a type constructor is expected/allowed, // tpeHK must be called instead of tpe." - val typeParamTypes = typeParams map (_.tpeHK) + val typeParamTypes = typeParams map tpeHKOfSymbol def doSubst(info: Type) = info.subst(rawSyms, typeParamTypes) creator(typeParams map (_ modifyInfo doSubst), doSubst(tp)) @@ -3683,7 +3683,7 @@ trait Typers extends Modes with Adaptations with Tags { // lifted out of typed1 because it's needed in typedImplicit0 protected def typedTypeApply(tree: Tree, mode: Int, fun: Tree, args: List[Tree]): Tree = fun.tpe match { case OverloadedType(pre, alts) => - inferPolyAlternatives(fun, args map (_.tpe)) + inferPolyAlternatives(fun, args map tpeOfTree) val tparams = fun.symbol.typeParams //@M TODO: fun.symbol.info.typeParams ? (as in typedAppliedTypeTree) val args1 = if (sameLength(args, tparams)) { //@M: in case TypeApply we can't check the kind-arities of the type arguments, @@ -3703,7 +3703,7 @@ trait Typers extends Modes with Adaptations with Tags { typedTypeApply(tree, mode, fun setType fun.tpe.widen, args) case PolyType(tparams, restpe) if tparams.nonEmpty => if (sameLength(tparams, args)) { - val targs = args map (_.tpe) + val targs = args map tpeOfTree checkBounds(tree, NoPrefix, NoSymbol, tparams, targs, "") if (fun.symbol == Predef_classOf) typedClassOf(tree, args.head, true) @@ -4110,7 +4110,7 @@ trait Typers extends Modes with Adaptations with Tags { context.undetparams = cloneSymbols(tpt0.symbol.typeParams) notifyUndetparamsAdded(context.undetparams) TypeTree().setOriginal(tpt0) - .setType(appliedType(tpt0.tpe, context.undetparams map (_.tpeHK))) // @PP: tpeHK! #3343, #4018, #4347. + .setType(appliedType(tpt0.tpe, context.undetparams map tpeHKOfSymbol)) // @PP: tpeHK! #3343, #4018, #4347. } else tpt0 else tpt0 } @@ -4807,7 +4807,7 @@ trait Typers extends Modes with Adaptations with Tags { else { val decls = newScope //Console.println("Owner: " + context.enclClass.owner + " " + context.enclClass.owner.id) - val self = refinedType(parents1 map (_.tpe), context.enclClass.owner, decls, templ.pos) + val self = refinedType(parents1 map tpeOfTree, context.enclClass.owner, decls, templ.pos) newTyper(context.make(templ, self.typeSymbol, decls)).typedRefinement(templ) templ addAttachment CompoundTypeTreeOriginalAttachment(parents1, Nil) // stats are set elsewhere tree setType self @@ -4832,7 +4832,7 @@ trait Typers extends Modes with Adaptations with Tags { //@M! the polytype denotes the expected kind typedHigherKindedType(arg, mode, GenPolyType(tparam.typeParams, AnyClass.tpe)) } - val argtypes = args1 map (_.tpe) + val argtypes = args1 map tpeOfTree foreach2(args, tparams)((arg, tparam) => arg match { // note: can't use args1 in selector, because Bind's got replaced @@ -4985,7 +4985,7 @@ trait Typers extends Modes with Adaptations with Tags { val finalizer1 = if (finalizer.isEmpty) finalizer else typed(finalizer, UnitClass.tpe) - val (owntype, needAdapt) = ptOrLub(block1.tpe :: (catches1 map (_.tpe)), pt) + val (owntype, needAdapt) = ptOrLub(block1.tpe :: (catches1 map tpeOfTree), pt) if (needAdapt) { block1 = adapt(block1, mode, owntype) catches1 = catches1 map (adaptCase(_, mode, owntype)) diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 98d42b724c..14547123b0 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -759,7 +759,7 @@ trait Definitions extends api.StandardDefinitions { // java.lang.Object. Java also special cases the return type. lazy val Any_getClass = enterNewMethod(AnyClass, nme.getClass_, Nil, getMemberMethod(ObjectClass, nme.getClass_).tpe.resultType, DEFERRED) lazy val Any_isInstanceOf = newT1NullaryMethod(AnyClass, nme.isInstanceOf_, FINAL)(_ => booltype) - lazy val Any_asInstanceOf = newT1NullaryMethod(AnyClass, nme.asInstanceOf_, FINAL)(_.typeConstructor) + lazy val Any_asInstanceOf = newT1NullaryMethod(AnyClass, nme.asInstanceOf_, FINAL)(typeConstructorOfSymbol) // A type function from T => Class[U], used to determine the return // type of getClass calls. The returned type is: @@ -851,7 +851,7 @@ trait Definitions extends api.StandardDefinitions { lazy val Object_eq = enterNewMethod(ObjectClass, nme.eq, anyrefparam, booltype, FINAL) lazy val Object_ne = enterNewMethod(ObjectClass, nme.ne, anyrefparam, booltype, FINAL) lazy val Object_isInstanceOf = newT1NoParamsMethod(ObjectClass, nme.isInstanceOf_Ob, FINAL | SYNTHETIC)(_ => booltype) - lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(_.typeConstructor) + lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(typeConstructorOfSymbol) lazy val Object_synchronized = newPolyMethod(1, ObjectClass, nme.synchronized_, FINAL)(tps => (Some(List(tps.head.typeConstructor)), tps.head.typeConstructor) ) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 17f4669c29..15ca276b1a 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -11,6 +11,7 @@ import scala.collection.mutable.ListBuffer import util.Statistics import Flags._ import base.Attachments +import scala.annotation.tailrec trait Symbols extends api.Symbols { self: SymbolTable => import definitions._ @@ -1378,7 +1379,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** The value parameter sections of this symbol. */ def paramss: List[List[Symbol]] = info.paramss - + /** The least proper supertype of a class; includes all parent types * and refinement where needed. You need to compute that in a situation like this: * { @@ -2624,7 +2625,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => tpeCache = NoType val targs = if (phase.erasedTypes && this != ArrayClass) List() - else unsafeTypeParams map (_.typeConstructor) + else unsafeTypeParams map typeConstructorOfSymbol //@M! use typeConstructor to generate dummy type arguments, // sym.tpe should not be called on a symbol that's supposed to be a higher-kinded type // memberType should be used instead, that's why it uses tpeHK and not tpe @@ -3206,7 +3207,25 @@ trait Symbols extends api.Symbols { self: SymbolTable => def toList: List[TypeHistory] = this :: ( if (prev eq null) Nil else prev.toList ) } +// ----- Hoisted closures and convenience methods, for compile time reductions ------- + + private[scala] final val symbolIsPossibleInRefinement = (sym: Symbol) => sym.isPossibleInRefinement + private[scala] final val symbolIsNonVariant = (sym: Symbol) => sym.variance == 0 + private[scala] final val typeConstructorOfSymbol = (sym: Symbol) => sym.typeConstructor + private[scala] final val tpeOfSymbol = (sym: Symbol) => sym.tpe + private[scala] final val tpeHKOfSymbol = (sym: Symbol) => sym.tpeHK + + @tailrec private[scala] final + def allSymbolsHaveOwner(syms: List[Symbol], owner: Symbol): Boolean = syms match { + case sym :: rest => sym.owner == owner && allSymbolsHaveOwner(rest, owner) + case _ => true + } + + +// -------------- Statistics -------------------------------------------------------- + Statistics.newView("#symbols")(ids) + } object SymbolsStats { diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index b21a28eea8..8baed325fd 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1540,6 +1540,12 @@ trait Trees extends api.Trees { self: SymbolTable => sys.error("Not a LabelDef: " + t + "/" + t.getClass) } +// ----- Hoisted closures and convenience methods, for compile time reductions ------- + + private[scala] final val tpeOfTree = (tree: Tree) => tree.tpe + +// -------------- Classtags -------------------------------------------------------- + implicit val TreeTag = ClassTag[Tree](classOf[Tree]) implicit val TermTreeTag = ClassTag[TermTree](classOf[TermTree]) implicit val TypTreeTag = ClassTag[TypTree](classOf[TypTree]) diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index dd47ee2181..e031498684 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -363,7 +363,7 @@ trait Types extends api.Types { self: SymbolTable => * and all type parameters (if any) are invariant. */ def isFinalType = - typeSymbol.isFinal && (typeSymbol.typeParams forall (_.variance == 0)) + typeSymbol.isFinal && (typeSymbol.typeParams forall symbolIsNonVariant) /** Is this type completed (i.e. not a lazy type)? */ def isComplete: Boolean = true @@ -484,7 +484,7 @@ trait Types extends api.Types { self: SymbolTable => /** A list of placeholder types derived from the type parameters. * Used by RefinedType and TypeRef. */ - protected def dummyArgs: List[Type] = typeParams map (_.typeConstructor) + protected def dummyArgs: List[Type] = typeParams map typeConstructorOfSymbol /** For a (nullary) method or poly type, its direct result type, * the type itself for all other types. */ @@ -835,7 +835,7 @@ trait Types extends api.Types { self: SymbolTable => case (TypeRef(_, ArrayClass, List(arg1)), TypeRef(_, ArrayClass, List(arg2))) if arg2.typeSymbol.typeParams.nonEmpty => arg1 matchesPattern arg2 case (_, TypeRef(_, _, args)) => - val newtp = existentialAbstraction(args map (_.typeSymbol), that) + val newtp = existentialAbstraction(args map typeSymbolOfType, that) !(that =:= newtp) && (this <:< newtp) case _ => false @@ -1495,8 +1495,8 @@ trait Types extends api.Types { self: SymbolTable => } private def lowerString = if (emptyLowerBound) "" else " >: " + lo private def upperString = if (emptyUpperBound) "" else " <: " + hi - private def emptyLowerBound = lo.typeSymbolDirect eq NothingClass - private def emptyUpperBound = hi.typeSymbolDirect eq AnyClass + private def emptyLowerBound = typeIsNothing(lo) + private def emptyUpperBound = typeIsAny(hi) def isEmptyBounds = emptyLowerBound && emptyUpperBound // override def isNullable: Boolean = NullClass.tpe <:< lo; @@ -1706,7 +1706,7 @@ trait Types extends api.Types { self: SymbolTable => override def isHigherKinded = ( parents.nonEmpty && - (parents forall (_.isHigherKinded)) && + (parents forall typeIsHigherKinded) && !phase.erasedTypes ) @@ -1716,7 +1716,7 @@ trait Types extends api.Types { self: SymbolTable => //@M may result in an invalid type (references to higher-order args become dangling ) override def typeConstructor = - copyRefinedType(this, parents map (_.typeConstructor), decls) + copyRefinedType(this, parents map typeConstructorOfType, decls) final override def normalize: Type = if (phase.erasedTypes) normalizeImpl @@ -2540,7 +2540,7 @@ trait Types extends api.Types { self: SymbolTable => override def paramss: List[List[Symbol]] = params :: resultType.paramss - override def paramTypes = params map (_.tpe) + override def paramTypes = params map tpeOfSymbol override def boundSyms = resultType.boundSyms ++ params @@ -3240,7 +3240,7 @@ trait Types extends api.Types { self: SymbolTable => if (constr.instValid) constr.inst // get here when checking higher-order subtyping of the typevar by itself // TODO: check whether this ever happens? - else if (isHigherKinded) typeFun(params, applyArgs(params map (_.typeConstructor))) + else if (isHigherKinded) typeFun(params, applyArgs(params map typeConstructorOfSymbol)) else super.normalize ) override def typeSymbol = origin.typeSymbol @@ -3625,7 +3625,7 @@ trait Types extends api.Types { self: SymbolTable => val bounds = args map (TypeBounds upper _) foreach2(eparams, bounds)(_ setInfo _) - newExistentialType(eparams, typeRef(pre, sym, eparams map (_.tpe))) + newExistentialType(eparams, typeRef(pre, sym, eparams map tpeOfSymbol)) case _ => appliedType(tycon, args) } @@ -3862,8 +3862,8 @@ trait Types extends api.Types { self: SymbolTable => * guarding addLoBound/addHiBound somehow broke raw types so it * only guards against being created with them.] */ - private var lobounds = lo0 filterNot (_.typeSymbolDirect eq NothingClass) - private var hibounds = hi0 filterNot (_.typeSymbolDirect eq AnyClass) + private var lobounds = lo0 filterNot typeIsNothing + private var hibounds = hi0 filterNot typeIsAny private var numlo = numlo0 private var numhi = numhi0 private var avoidWidening = avoidWidening0 @@ -3919,8 +3919,8 @@ trait Types extends api.Types { self: SymbolTable => override def toString = { val boundsStr = { - val lo = loBounds filterNot (_.typeSymbolDirect eq NothingClass) - val hi = hiBounds filterNot (_.typeSymbolDirect eq AnyClass) + val lo = loBounds filterNot typeIsNothing + val hi = hiBounds filterNot typeIsAny val lostr = if (lo.isEmpty) Nil else List(lo.mkString(" >: (", ", ", ")")) val histr = if (hi.isEmpty) Nil else List(hi.mkString(" <: (", ", ", ")")) @@ -4281,7 +4281,7 @@ trait Types extends api.Types { self: SymbolTable => else try { expanded += sym val eparams = mapOver(typeParamsToExistentials(sym)) - existentialAbstraction(eparams, typeRef(apply(pre), sym, eparams map (_.tpe))) + existentialAbstraction(eparams, typeRef(apply(pre), sym, eparams map tpeOfSymbol)) } finally { expanded -= sym } @@ -6225,8 +6225,8 @@ trait Types extends api.Types { self: SymbolTable => */ private def lubList(ts: List[Type], depth: Int): List[Type] = { // Matching the type params of one of the initial types means dummies. - val initialTypeParams = ts map (_.typeParams) - def isHotForTs(xs: List[Type]) = initialTypeParams contains xs.map(_.typeSymbol) + val initialTypeParams = ts map typeParamsOfType + def isHotForTs(xs: List[Type]) = initialTypeParams contains (xs map typeSymbolOfType) def elimHigherOrderTypeParam(tp: Type) = tp match { case TypeRef(pre, sym, args) if args.nonEmpty && isHotForTs(args) => tp.typeConstructor @@ -6459,8 +6459,8 @@ trait Types extends api.Types { self: SymbolTable => val tparams1 = map2(tparams, matchingBounds(ts, tparams).transpose)((tparam, bounds) => tparam.cloneSymbol.setInfo(glb(bounds, depth))) PolyType(tparams1, lub0(matchingInstTypes(ts, tparams1))) - case ts @ MethodType(params, _) :: rest => - MethodType(params, lub0(matchingRestypes(ts, params map (_.tpe)))) + case ts @ (mt @ MethodType(params, _)) :: rest => + MethodType(params, lub0(matchingRestypes(ts, mt.paramTypes))) case ts @ NullaryMethodType(_) :: rest => NullaryMethodType(lub0(matchingRestypes(ts, Nil))) case ts @ TypeBounds(_, _) :: rest => @@ -6614,8 +6614,8 @@ trait Types extends api.Types { self: SymbolTable => val tparams1 = map2(tparams, matchingBounds(ts, tparams).transpose)((tparam, bounds) => tparam.cloneSymbol.setInfo(lub(bounds, depth))) PolyType(tparams1, glbNorm(matchingInstTypes(ts, tparams1), depth)) - case ts @ MethodType(params, _) :: rest => - MethodType(params, glbNorm(matchingRestypes(ts, params map (_.tpe)), depth)) + case ts @ (mt @ MethodType(params, _)) :: rest => + MethodType(params, glbNorm(matchingRestypes(ts, mt.paramTypes), depth)) case ts @ NullaryMethodType(_) :: rest => NullaryMethodType(glbNorm(matchingRestypes(ts, Nil), depth)) case ts @ TypeBounds(_, _) :: rest => @@ -6878,7 +6878,7 @@ trait Types extends api.Types { self: SymbolTable => */ private def matchingRestypes(tps: List[Type], pts: List[Type]): List[Type] = tps map { - case MethodType(params1, res) if (isSameTypes(params1 map (_.tpe), pts)) => + case mt @ MethodType(params1, res) if isSameTypes(mt.paramTypes, pts) => res case NullaryMethodType(res) if pts.isEmpty => res @@ -6992,29 +6992,30 @@ trait Types extends api.Types { self: SymbolTable => // ----- Hoisted closures and convenience methods, for compile time reductions ------- - private val typeIsNotNull = (tp: Type) => tp.isNotNull - private val symbolIsPossibleInRefinement = (sym: Symbol) => sym.isPossibleInRefinement - private val isTypeVar = (tp: Type) => tp.isInstanceOf[TypeVar] - private val typeContainsTypeVar = (tp: Type) => tp exists isTypeVar - private val typeIsNonClassType = (tp: Type) => tp.typeSymbolDirect.isNonClassType - private val typeIsExistentiallyBound = (tp: Type) => tp.typeSymbol.isExistentiallyBound - private val typeSymbolOfType = (tp: Type) => tp.typeSymbol - private val typeIsErroneous = (tp: Type) => tp.isErroneous - private val typeHasAnnotations = (tp: Type) => tp.annotations.nonEmpty - private val boundsContainType = (bounds: TypeBounds, tp: Type) => bounds containsType tp - private val typeListIsEmpty = (ts: List[Type]) => ts.isEmpty - private val typeIsSubTypeOfSerializable = (tp: Type) => tp <:< SerializableClass.tpe + private[scala] val typeIsNotNull = (tp: Type) => tp.isNotNull + private[scala] val isTypeVar = (tp: Type) => tp.isInstanceOf[TypeVar] + private[scala] val typeContainsTypeVar = (tp: Type) => tp exists isTypeVar + private[scala] val typeIsNonClassType = (tp: Type) => tp.typeSymbolDirect.isNonClassType + private[scala] val typeIsExistentiallyBound = (tp: Type) => tp.typeSymbol.isExistentiallyBound + private[scala] val typeIsErroneous = (tp: Type) => tp.isErroneous + private[scala] val typeIsError = (tp: Type) => tp.isError + private[scala] val typeHasAnnotations = (tp: Type) => tp.annotations.nonEmpty + private[scala] val boundsContainType = (bounds: TypeBounds, tp: Type) => bounds containsType tp + private[scala] val typeListIsEmpty = (ts: List[Type]) => ts.isEmpty + private[scala] val typeIsSubTypeOfSerializable = (tp: Type) => tp <:< SerializableClass.tpe + private[scala] val typeIsNothing = (tp: Type) => tp.typeSymbolDirect eq NothingClass + private[scala] val typeIsAny = (tp: Type) => tp.typeSymbolDirect eq AnyClass + private[scala] val typeIsHigherKinded = (tp: Type) => tp.isHigherKinded + + private[scala] val typeSymbolOfType = (tp: Type) => tp.typeSymbol + private[scala] val typeParamsOfType = (tp: Type) => tp.typeParams + private[scala] val typeConstructorOfType = (tp: Type) => tp.typeConstructor @tailrec private def typesContain(tps: List[Type], sym: Symbol): Boolean = tps match { case tp :: rest => (tp contains sym) || typesContain(rest, sym) case _ => false } - @tailrec private def allSymbolsHaveOwner(syms: List[Symbol], owner: Symbol): Boolean = syms match { - case sym :: rest => sym.owner == owner && allSymbolsHaveOwner(rest, owner) - case _ => true - } - // -------------- Classtags -------------------------------------------------------- implicit val AnnotatedTypeTag = ClassTag[AnnotatedType](classOf[AnnotatedType]) diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala index 9234ccca7b..dd515b2201 100644 --- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala +++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala @@ -677,7 +677,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ { val args = until(end, readTreeRef) if (fun.symbol.isOverloaded) { fun.setType(fun.symbol.info) - inferMethodAlternative(fun, args map (_.tpe), tpe) + inferMethodAlternative(fun, args map tpeOfTree, tpe) } Apply(fun, args) diff --git a/src/reflect/scala/reflect/internal/transform/Erasure.scala b/src/reflect/scala/reflect/internal/transform/Erasure.scala index 368d55a59c..cc5b5bb406 100644 --- a/src/reflect/scala/reflect/internal/transform/Erasure.scala +++ b/src/reflect/scala/reflect/internal/transform/Erasure.scala @@ -141,7 +141,7 @@ trait Erasure { if (restpe.typeSymbol == UnitClass) erasedTypeRef(UnitClass) // this replaces each typeref that refers to an argument // by the type `p.tpe` of the actual argument p (p in params) - else apply(mt.resultType(params map (_.tpe)))) + else apply(mt.resultType(mt.paramTypes))) case RefinedType(parents, decls) => apply(mergeParents(parents)) case AnnotatedType(_, atp, _) => @@ -220,7 +220,7 @@ trait Erasure { MethodType( cloneSymbolsAndModify(params, specialErasureAvoiding(clazz, _)), if (restpe.typeSymbol == UnitClass) erasedTypeRef(UnitClass) - else specialErasureAvoiding(clazz, (mt.resultType(params map (_.tpe))))) + else specialErasureAvoiding(clazz, (mt.resultType(mt.paramTypes)))) case TypeRef(pre, `clazz`, args) => typeRef(pre, clazz, List()) case _ => |