diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 0050d08f1b..4b1f1efee4 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -9,8 +9,6 @@ package transform import scala.tools.nsc.symtab.Flags import scala.collection.{ mutable, immutable } -import scala.language.postfixOps -import scala.language.existentials import scala.annotation.tailrec /** Specialize code on types. @@ -168,7 +166,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { /** Reduce the given environment to contain mappings only for type variables in tps. */ def restrict(env: TypeEnv, tps: immutable.Set[Symbol]): TypeEnv = - env filterKeys tps toMap + env.filterKeys(tps).toMap /** Is the given environment a valid specialization for sym? * It is valid if each binding is from a @specialized type parameter in sym (or its owner) @@ -367,7 +365,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { } ) - lazy val specializableTypes = ScalaValueClasses map (_.tpe) sorted + lazy val specializableTypes = ScalaValueClasses.map(_.tpe).sorted /** If the symbol is the companion of a value class, the value class. * Otherwise, AnyRef. @@ -386,7 +384,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { val types = if (!sym.isSpecialized) Nil // no @specialized Annotation else - specializedOn(sym) map (s => specializesClass(s).tpe) sorted + specializedOn(sym).map(s => specializesClass(s).tpe).sorted if (isBoundedGeneric(sym.tpe) && (types contains AnyRefClass)) reporter.warning(sym.pos, sym + " is always a subtype of " + AnyRefTpe + ".") @@ -474,7 +472,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case ExistentialType(_, res) => specializedTypeVars(res) case AnnotatedType(_, tp) => specializedTypeVars(tp) case TypeBounds(lo, hi) => specializedTypeVars(lo :: hi :: Nil) - case RefinedType(parents, _) => parents flatMap specializedTypeVars toSet + case RefinedType(parents, _) => parents.flatMap(specializedTypeVars).toSet case _ => immutable.Set.empty } @@ -861,7 +859,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { if (unusedStvars.length == 1) "is" else "are") ) unusedStvars foreach (_ removeAnnotation SpecializedClass) - specializingOn = specializingOn filterNot (unusedStvars contains) + specializingOn = specializingOn filterNot (unusedStvars contains _) } for (env0 <- specializations(specializingOn) if needsSpecialization(env0, sym)) yield { // !!! Can't this logic be structured so that the new symbol's name is @@ -1021,7 +1019,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case (NoSymbol, _) => if (overriding.isSuperAccessor) { val alias = overriding.alias - debuglog("checking special overload for super accessor: %s, alias for %s".format(overriding.fullName, alias.fullName)) + debuglog(s"checking special overload for super accessor: ${overriding.fullName}, alias for ${alias.fullName}") needsSpecialOverride(alias) match { case nope @ (NoSymbol, _) => None case (overridden, env) => @@ -1043,7 +1041,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { param.name = overriding.paramss(i)(j).name // SI-6555 Retain the parameter names from the subclass. } } - debuglog("specialized overload %s for %s in %s: %s".format(om, overriding.name.decode, pp(env), om.info)) + debuglog(s"specialized overload $om for ${overriding.name.decode} in ${pp(env)}: ${om.info}") if (overriding.isAbstractOverride) om.setFlag(ABSOVERRIDE) typeEnv(om) = env addConcreteSpecMethod(overriding) @@ -1092,7 +1090,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { */ private def unify(tp1: Type, tp2: Type, env: TypeEnv, strict: Boolean, tparams: Boolean = false): TypeEnv = (tp1, tp2) match { case (TypeRef(_, sym1, _), _) if sym1.isSpecialized => - debuglog("Unify " + tp1 + ", " + tp2) + debuglog(s"Unify $tp1, $tp2") if (isPrimitiveValueClass(tp2.typeSymbol) || isSpecializedAnyRefSubtype(tp2, sym1)) env + ((sym1, tp2)) else if (isSpecializedAnyRefSubtype(tp2, sym1)) @@ -1103,20 +1101,20 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { env case (TypeRef(_, sym1, args1), TypeRef(_, sym2, args2)) => if (args1.nonEmpty || args2.nonEmpty) - debuglog("Unify types " + tp1 + " and " + tp2) + debuglog(s"Unify types $tp1 and $tp2") if (strict && args1.length != args2.length) unifyError(tp1, tp2) val e = unify(args1, args2, env, strict) - if (e.nonEmpty) debuglog("unified to: " + e) + if (e.nonEmpty) debuglog(s"unified to: $e") e case (TypeRef(_, sym1, _), _) if sym1.isTypeParameterOrSkolem => env case (MethodType(params1, res1), MethodType(params2, res2)) => if (strict && params1.length != params2.length) unifyError(tp1, tp2) - debuglog("Unify methods " + tp1 + " and " + tp2) + debuglog(s"Unify methods $tp1 and $tp2") unify(res1 :: (params1 map (_.tpe)), res2 :: (params2 map (_.tpe)), env, strict) case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => - debuglog("Unify polytypes " + tp1 + " and " + tp2) + debuglog(s"Unify polytypes $tp1 and $tp2") if (strict && tparams1.length != tparams2.length) unifyError(tp1, tp2) else if (tparams && tparams1.length == tparams2.length) @@ -1134,7 +1132,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case (ExistentialType(_, res1), _) => unify(tp2, res1, env, strict) case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) => unify(List(lo1, hi1), List(lo2, hi2), env, strict) case _ => - debuglog("don't know how to unify %s [%s] with %s [%s]".format(tp1, tp1.getClass, tp2, tp2.getClass)) + debuglog(s"don't know how to unify $tp1 [${tp1.getClass}] with $tp2 [${tp2.getClass}]") env } @@ -1144,9 +1142,9 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { if (!strict) unify(args._1, args._2, env, strict) else { val nenv = unify(args._1, args._2, emptyEnv, strict) - if (env.keySet intersect nenv.keySet isEmpty) env ++ nenv + if (env.keySet.intersect(nenv.keySet).isEmpty) env ++ nenv else { - debuglog("could not unify: u(" + args._1 + ", " + args._2 + ") yields " + nenv + ", env: " + env) + debuglog(s"could not unify: u(${args._1}, ${args._2}) yields $nenv, env: $env") unifyError(tp1, tp2) } } @@ -1242,7 +1240,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { env forall { case (tvar, tpe) => matches(tvar.info.bounds.lo, tpe) && matches(tpe, tvar.info.bounds.hi) || { if (warnings) - reporter.warning(tvar.pos, "Bounds prevent specialization of " + tvar) + reporter.warning(tvar.pos, s"Bounds prevent specialization of $tvar") debuglog("specvars: " + tvar.info.bounds.lo + ": " + @@ -1373,7 +1371,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { sym, currentClass, sym.owner.enclClass, isAccessible(sym), nme.isLocalName(sym.name)) ) if (shouldMakePublic(sym) && !isAccessible(sym)) { - debuglog("changing private flag of " + sym) + debuglog(s"changing private flag of $sym") sym.makeNotPrivate(sym.owner) } super.transform(tree) @@ -1428,10 +1426,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { (treeType =:= memberType) || { // anyref specialization memberType match { case PolyType(_, resTpe) => - debuglog("Conformance for anyref - polytype with result type: " + resTpe + " and " + treeType + "\nOrig. sym.: " + origSymbol) + debuglog(s"Conformance for anyref - polytype with result type: $resTpe and $treeType\nOrig. sym.: $origSymbol") try { val e = unify(origSymbol.tpe, memberType, emptyEnv, true) - debuglog("obtained env: " + e) + debuglog(s"obtained env: $e") e.keySet == env.keySet } catch { case _: Throwable => @@ -1531,7 +1529,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { ) val tree1 = gen.mkTypeApply(specTree, residualTargs) - debuglog("rewrote " + tree + " to " + tree1) + debuglog(s"rewrote $tree to $tree1") localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method } @@ -1539,7 +1537,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { tree match { case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => def transformNew = { - debuglog("Attempting to specialize new %s(%s)".format(tpt, args.mkString(", "))) + debuglog(s"Attempting to specialize new $tpt(${args.mkString(", ")})") val found = specializedType(tpt.tpe) if (found.typeSymbol ne tpt.tpe.typeSymbol) { // the ctor can be specialized val inst = New(found, transformTrees(args): _*) |