diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-19 20:31:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-19 20:31:46 +0000 |
commit | 04a99160c27257565438b58e814c885283521358 (patch) | |
tree | 55696ed37c7172f2938fe4f212949cee28dc1728 | |
parent | 1e1c87c234826279a58c97bc5124f2e76ab58dce (diff) | |
download | scala-04a99160c27257565438b58e814c885283521358.tar.gz scala-04a99160c27257565438b58e814c885283521358.tar.bz2 scala-04a99160c27257565438b58e814c885283521358.zip |
Deprecation patrol exercises the new capabiliti...
Deprecation patrol exercises the new capabilities in Tuple2.zipped among
other exciting no-ops.
21 files changed, 125 insertions, 133 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala b/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala index ab32e69944..31abf6c18a 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala @@ -152,7 +152,7 @@ abstract class Checkers { else { if (s1.length != s2.length) throw new CheckerError("Incompatible stacks: " + s1 + " and " + s2 + " in " + method + " at entry to block: " + bl); - new TypeStack(List.map2(s1.types, s2.types) (lub)) + new TypeStack((s1.types, s2.types).zipped map lub) } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala index 6e7a81ac1e..eef1863374 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala @@ -18,7 +18,7 @@ trait TypeStacks { self: ICodes => import opcodes._ import global.{Symbol, Type, definitions} - /* This class simulates the type of the opperand + /* This class simulates the type of the operand * stack of the ICode. */ type Rep = List[TypeKind] @@ -71,20 +71,22 @@ trait TypeStacks { self: ICodes => def apply(n: Int): TypeKind = types(n) /** - * A TypeStack aggress with another one if they have the same + * A TypeStack agrees with another one if they have the same * length and each type kind agrees position-wise. Two * types agree if one is a subtype of the other. */ def agreesWith(other: TypeStack): Boolean = (types.length == other.types.length) && - List.forall2(types, other.types) ((t1, t2) => t1 <:< t2 || t2 <:< t1) + ((types, other.types).zipped forall ((t1, t2) => t1 <:< t2 || t2 <:< t1)) /* This method returns a String representation of the stack */ override def toString() = types.mkString("\n", "\n", "\n") - override def equals(other: Any): Boolean = - other.isInstanceOf[TypeStack] && - List.forall2(other.asInstanceOf[TypeStack].types, types)((a, b) => a == b) + override def hashCode() = types.hashCode() + override def equals(other: Any): Boolean = other match { + case x: TypeStack => x.types sameElements types + case _ => false + } } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala index f33d7fae39..fe114e3faa 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala @@ -66,8 +66,8 @@ abstract class CopyPropagation { if ((other eq bottom) || (this eq bottom)) (this eq other) else { - this.bindings == other.bindings && - List.forall2(this.stack, other.stack) { (a, b) => a == b } + (this.bindings == other.bindings) && + ((this.stack, other.stack).zipped forall (_ == _)) } } @@ -249,6 +249,11 @@ abstract class CopyPropagation { import opcodes._ + private def retain[A, B](map: Map[A, B])(p: (A, B) => Boolean) = { + for ((k, v) <- map ; if !p(k, v)) map -= k + map + } + /** Abstract interpretation for one instruction. */ def interpret(in: copyLattice.Elem, i: Instruction): copyLattice.Elem = { var out = in.dup @@ -458,7 +463,7 @@ abstract class CopyPropagation { */ final def cleanReferencesTo(s: copyLattice.State, target: Location) { def cleanRecord(r: Record): Record = { - r.bindings retain { (loc, value) => + retain(r.bindings) { (loc, value) => (value match { case Deref(loc1) if (loc1 == target) => false case Boxed(loc1) if (loc1 == target) => false @@ -478,7 +483,7 @@ abstract class CopyPropagation { case _ => v }} - s.bindings retain { (loc, value) => + retain(s.bindings) { (loc, value) => (value match { case Deref(loc1) if (loc1 == target) => false case Boxed(loc1) if (loc1 == target) => false @@ -531,12 +536,12 @@ abstract class CopyPropagation { } state.stack = state.stack map { v => v match { case Record(cls, bindings) => - bindings.retain { (sym: Symbol, v: Value) => shouldRetain(sym) } + retain(bindings) { (sym, _) => shouldRetain(sym) } Record(cls, bindings) case _ => v }} - state.bindings retain {(loc, value) => + retain(state.bindings) { (loc, value) => value match { case Deref(Field(rec, sym)) => shouldRetain(sym) case Boxed(Field(rec, sym)) => shouldRetain(sym) diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala index 65065fe0d1..1c714cbd5d 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala @@ -43,19 +43,19 @@ abstract class ReachingDefinitions { else if (bottom == b) a else { val locals = a.vars ++ b.vars - val stack = if (a.stack == Nil) - b.stack - else if (b.stack == Nil) a.stack - else List.map2(a.stack, b.stack) (_ ++ _) - - val res = IState(locals, stack) - -// Console.println("\tlub2: " + a + ", " + b) -// Console.println("\tis: " + res) - -// if (res._1 eq bottom._1) (new ListSet[Definition], Nil) -// else res - res + val stack = + if (a.stack == Nil) b.stack + else if (b.stack == Nil) a.stack + else (a.stack, b.stack).zipped map (_ ++ _) + + IState(locals, stack) + + // val res = IState(locals, stack) + // Console.println("\tlub2: " + a + ", " + b) + // Console.println("\tis: " + res) + // if (res._1 eq bottom._1) (new ListSet[Definition], Nil) + // else res + // res } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala index fc097956a8..eecae5e578 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala @@ -53,7 +53,7 @@ abstract class TypeFlowAnalysis { else { // if (s1.length != s2.length) // throw new CheckerError("Incompatible stacks: " + s1 + " and " + s2); - new TypeStack(List.map2(s1.types, s2.types) (icodes.lub)) + new TypeStack((s1.types, s2.types).zipped map icodes.lub) } } } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index acc9aafa80..9abd29cd0a 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -47,7 +47,8 @@ abstract class GenJVM extends SubComponent { override def run { if (settings.debug.value) inform("[running phase " + name + " on icode]") if (settings.Xdce.value) - icodes.classes.retain { (sym: Symbol, cls: IClass) => !inliner.isClosureClass(sym) || deadCode.liveClosures(sym) } + for ((sym, cls) <- icodes.classes ; if inliner.isClosureClass(sym) && !deadCode.liveClosures(sym)) + icodes.classes -= sym classes.valuesIterator foreach apply } @@ -505,7 +506,7 @@ abstract class GenJVM extends SubComponent { val innerClassesAttr = jclass.getInnerClasses() // sort them so inner classes succeed their enclosing class // to satisfy the Eclipse Java compiler - for (innerSym <- innerClasses.toList.sort(_.name.length < _.name.length)) { + for (innerSym <- innerClasses.toList sortBy (_.name.length)) { var outerName = javaName(innerSym.rawowner) // remove the trailing '$' if (outerName.endsWith("$") && isTopLevelModule(innerSym.rawowner)) diff --git a/src/compiler/scala/tools/nsc/dependencies/Changes.scala b/src/compiler/scala/tools/nsc/dependencies/Changes.scala index 80a068dcdf..3c6184bc24 100644 --- a/src/compiler/scala/tools/nsc/dependencies/Changes.scala +++ b/src/compiler/scala/tools/nsc/dependencies/Changes.scala @@ -92,15 +92,9 @@ abstract class Changes { tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType]) case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => - (tparams1.length == tparams2.length && - List.forall2(tparams1, tparams2) - ((p1, p2) => sameType(p1.info, p2.info)) && - sameType(res1, res2)) + sameTypeParams(tparams1, tparams2) && sameType(res1, res2) case (ExistentialType(tparams1, res1), ExistentialType(tparams2, res2)) => - (tparams1.length == tparams2.length && - List.forall2(tparams1, tparams2) - ((p1, p2) => sameType(p1.info, p2.info)) && - sameType(res1, res2)) + sameTypeParams(tparams1, tparams2) && sameType(res1, res2) case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) => sameType(lo1, lo2) && sameType(hi1, hi2) case (BoundedWildcardType(bounds), _) => @@ -133,9 +127,11 @@ abstract class Changes { ((tp1n ne tp1) || (tp2n ne tp2)) && sameType(tp1n, tp2n) } + private def sameTypeParams(tparams1: List[Symbol], tparams2: List[Symbol]) = + sameTypes(tparams1 map (_.info), tparams2 map (_.info)) + def sameTypes(tps1: List[Type], tps2: List[Type]): Boolean = - (tps1.length == tps2.length - && List.forall2(tps1, tps2)(sameType)) + (tps1.length == tps2.length) && ((tps1, tps2).zipped forall sameType) /** Return the list of changes between 'from' and 'to'. */ diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 710311a627..acd8130314 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -477,7 +477,7 @@ trait ParallelMatching extends ast.TreeDSL // @todo: equals test for same constant class MixEquals(val pmatch: PatternMatch, val rest: Rep) extends RuleApplication { private lazy val labelBody = - remake(List.map2(rest.rows.tail, pmatch.tail)(_ insert _)).toTree + remake((rest.rows.tail, pmatch.tail).zipped map (_ insert _)).toTree private lazy val rhs = decodedEqualsType(head.tpe) match { diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 3171a13454..99877e31b3 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -2861,9 +2861,8 @@ A type's typeSymbol should never be inspected directly. val clonedSyms = origSyms map (_.cloneSymbol) val clonedInfos = clonedSyms map (_.info.substSym(origSyms, clonedSyms)) val transformedInfos = clonedInfos mapConserve (this) - List.map2(clonedSyms, transformedInfos) { - ((newSym, newInfo) => newSym.setInfo(newInfo)) - } + (clonedSyms, transformedInfos).zipped map (_ setInfo _) + clonedSyms } } @@ -3845,12 +3844,12 @@ A type's typeSymbol should never be inspected directly. case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => // assert((tparams1 map (_.typeParams.length)) == (tparams2 map (_.typeParams.length))) (tparams1.length == tparams2.length && - List.forall2(tparams1, tparams2) + (tparams1, tparams2).zipped.forall ((p1, p2) => p1.info =:= p2.info.substSym(tparams2, tparams1)) && //@M looks like it might suffer from same problem as #2210 res1 =:= res2.substSym(tparams2, tparams1)) case (ExistentialType(tparams1, res1), ExistentialType(tparams2, res2)) => (tparams1.length == tparams2.length && - List.forall2(tparams1, tparams2) + (tparams1, tparams2).zipped.forall ((p1, p2) => p1.info =:= p2.info.substSym(tparams2, tparams1)) && //@M looks like it might suffer from same problem as #2210 res1 =:= res2.substSym(tparams2, tparams1)) case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) => @@ -3891,8 +3890,7 @@ A type's typeSymbol should never be inspected directly. * types? */ def isSameTypes(tps1: List[Type], tps2: List[Type]): Boolean = - tps1.length == tps2.length && - List.forall2(tps1, tps2)((tp1, tp2) => tp1 =:= tp2) + tps1.length == tps2.length && ((tps1, tps2).zipped forall (_ =:= _)) private var pendingSubTypes = new collection.mutable.HashSet[SubTypePair] private var basetypeRecursions: Int = 0 @@ -3974,16 +3972,16 @@ A type's typeSymbol should never be inspected directly. tparams1.length == tparams2.length && { if(tparams1.isEmpty) res1 <:< res2 // fast-path: monomorphic nullary method type else if(tparams1.head.owner.isMethod) { // fast-path: polymorphic method type -- type params cannot be captured - List.forall2(tparams1, tparams2)((p1, p2) => - p2.info.substSym(tparams2, tparams1) <:< p1.info) && + ((tparams1, tparams2).zipped forall ((p1, p2) => + p2.info.substSym(tparams2, tparams1) <:< p1.info)) && res1 <:< res2.substSym(tparams2, tparams1) } else { // normalized higher-kinded type //@M for an example of why we need to generate fresh symbols, see neg/tcpoly_ticket2101.scala val tpsFresh = cloneSymbols(tparams1) // @M cloneSymbols(tparams2) should be equivalent -- TODO: check - (List.forall2(tparams1, tparams2)((p1, p2) => - p2.info.substSym(tparams2, tpsFresh) <:< p1.info.substSym(tparams1, tpsFresh)) && - res1.substSym(tparams1, tpsFresh) <:< res2.substSym(tparams2, tpsFresh)) + ((tparams1, tparams2).zipped forall ((p1, p2) => + p2.info.substSym(tparams2, tpsFresh) <:< p1.info.substSym(tparams1, tpsFresh))) && + res1.substSym(tparams1, tpsFresh) <:< res2.substSym(tparams2, tpsFresh) //@M the forall in the previous test could be optimised to the following, // but not worth the extra complexity since it only shaves 1s from quick.comp @@ -4200,8 +4198,7 @@ A type's typeSymbol should never be inspected directly. * of `tps2'? */ def isSubTypes(tps1: List[Type], tps2: List[Type]): Boolean = - tps1.length == tps2.length && - List.forall2(tps1, tps2)((tp1, tp2) => tp1 <:< tp2) + tps1.length == tps2.length && ((tps1, tps2).zipped forall (_ <:< _)) /** Does type `tp' implement symbol `sym' with same or * stronger type? Exact only if `sym' is a member of some @@ -4262,11 +4259,11 @@ A type's typeSymbol should never be inspected directly. /** Are `tps1' and `tps2' lists of pairwise equivalent types? */ private def matchingParams(tps1: List[Type], tps2: List[Type], tps1isJava: Boolean, tps2isJava: Boolean): Boolean = - tps1.length == tps2.length && - List.forall2(tps1, tps2)((tp1, tp2) => + (tps1.length == tps2.length) && + ((tps1, tps2).zipped forall ((tp1, tp2) => (tp1 =:= tp2) || tps1isJava && tp2.typeSymbol == ObjectClass && tp1.typeSymbol == AnyClass || - tps2isJava && tp1.typeSymbol == ObjectClass && tp2.typeSymbol == AnyClass) + tps2isJava && tp1.typeSymbol == ObjectClass && tp2.typeSymbol == AnyClass)) /** like map2, but returns list `xs' itself - instead of a copy - if function * `f' maps all elements to themselves. @@ -4356,7 +4353,7 @@ A type's typeSymbol should never be inspected directly. */ def isWithinBounds(pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type]): Boolean = { val bounds = instantiatedBounds(pre, owner, tparams, targs) - !(List.map2(bounds, targs)((bound, targ) => bound containsType targ) contains false) + (bounds, targs).zipped forall (_ containsType _) } def instantiatedBounds(pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type]): List[TypeBounds] = @@ -4514,7 +4511,7 @@ A type's typeSymbol should never be inspected directly. case List(t) => t case ts @ PolyType(tparams, _) :: _ => PolyType( - List.map2(tparams, matchingBounds(ts, tparams).transpose) + (tparams, matchingBounds(ts, tparams).transpose).zipped map ((tparam, bounds) => tparam.cloneSymbol.setInfo(glb(bounds, depth))), lub0(matchingInstTypes(ts, tparams))) case ts @ MethodType(params, _) :: rest => @@ -4542,8 +4539,7 @@ A type's typeSymbol should never be inspected directly. if (syms contains NoSymbol) NoSymbol else { val symtypes = - (List.map2(narrowts, syms) - ((t, sym) => t.memberInfo(sym).substThis(t.typeSymbol, lubThisType))); + (narrowts, syms).zipped map ((t, sym) => t.memberInfo(sym).substThis(t.typeSymbol, lubThisType)) if (proto.isTerm) // possible problem: owner of info is still the old one, instead of new refinement class proto.cloneSymbol(lubRefined.typeSymbol).setInfo(lub(symtypes, decr(depth))) else if (symtypes.tail forall (symtypes.head =:=)) @@ -4615,7 +4611,7 @@ A type's typeSymbol should never be inspected directly. case List(t) => t case ts @ PolyType(tparams, _) :: _ => PolyType( - List.map2(tparams, matchingBounds(ts, tparams).transpose) + (tparams, matchingBounds(ts, tparams).transpose).zipped map ((tparam, bounds) => tparam.cloneSymbol.setInfo(lub(bounds, depth))), glb0(matchingInstTypes(ts, tparams))) case ts @ MethodType(params, _) :: rest => diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala index 16c5f8754d..b2f9489480 100644 --- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala +++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala @@ -94,10 +94,11 @@ abstract class LazyVals extends Transform with ast.TreeDSL { } val bmps = bitmaps(methSym) map (ValDef(_, ZERO)) + def isMatch(params: List[Ident]) = (params.tail, methSym.tpe.paramTypes).zipped forall (_.tpe == _) + if (bmps.isEmpty) rhs else rhs match { case Block(assign, l @ LabelDef(name, params, rhs1)) - if (name.toString.equals("_" + methSym.name) - && List.forall2(params.tail, methSym.tpe.paramTypes) { (ident, tpe) => ident.tpe == tpe }) => + if name.toString == ("_" + methSym.name) && isMatch(params) => val sym = l.symbol Block(assign, treeCopy.LabelDef(l, name, params, typed(prependStats(bmps, rhs1)))) diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 93cb5baefa..3e4cbf8f24 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -344,12 +344,7 @@ abstract class TailCalls extends Transform typed(t) } - private def isSameTypes(ts1: List[Symbol], ts2: List[Symbol]): Boolean = { - def isSameType(t1: Symbol, t2: Symbol) = { - t1 == t2 - } - List.forall2(ts1, ts2)(isSameType) - } + private def isSameTypes(ts1: List[Symbol], ts2: List[Symbol]) = ts1 sameElements ts2 /** Returns <code>true</code> if the fun tree refers to the same method as * the one saved in <code>ctx</code>. diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 67c963acf5..8f49d469f4 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -467,7 +467,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { case _ => args } - List.map2(formals, args1) { (formal, arg) => + (formals, args1).zipped map { (formal, arg) => if (formal.typeSymbol != ByNameParamClass) { arg } else if (isByNameRef(arg)) { diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index 7d75994ef3..375dd5a4a5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -20,12 +20,13 @@ trait EtaExpansion { self: Analyzer => import global._ object etaExpansion { + private def isMatch(vparam: ValDef, arg: Tree) = arg match { + case Ident(name) => vparam.name == name + case _ => false + } + def unapply(tree: Tree): Option[(List[ValDef], Tree, List[Tree])] = tree match { - case Function(vparams, Apply(fn, args)) - if (List.forall2(vparams, args) { - case (vparam, Ident(name)) => vparam.name == name - case _ => false - }) => + case Function(vparams, Apply(fn, args)) if (vparams, args).zipped forall isMatch => Some((vparams, fn, args)) case _ => None diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 69407ef0f1..a4b164edfe 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -404,7 +404,7 @@ trait Infer { val l = args.length - 1 l == formals.length && sym == FunctionClass(l) && - List.forall2(args, formals) (isPlausiblySubType) && + ((args, formals).zipped forall isPlausiblySubType) && isPlausiblySubType(tp.resultApprox, args.last) } case _ => @@ -458,7 +458,7 @@ trait Infer { def isCoercible(tp: Type, pt: Type): Boolean = false def isCompatibleArgs(tps: List[Type], pts: List[Type]): Boolean = - List.map2(tps, pts)((tp, pt) => isCompatibleArg(tp, pt)) forall (x => x) + (tps, pts).zipped forall isCompatibleArg /* -- Type instantiation------------------------------------------------ */ @@ -562,7 +562,7 @@ trait Infer { } val tvars = tparams map freshVar if (isConservativelyCompatible(restpe.instantiateTypeParams(tparams, tvars), pt)) - List.map2(tparams, tvars) ((tparam, tvar) => + (tparams, tvars).zipped map ((tparam, tvar) => instantiateToBound(tvar, varianceInTypes(formals)(tparam))) else tvars map (tvar => WildcardType) @@ -582,7 +582,7 @@ trait Infer { @inline def notCovariantIn(tparam: Symbol, restpe: Type) = (varianceInType(restpe)(tparam) & COVARIANT) == 0 // tparam occurred non-covariantly (in invariant or contravariant position) - List.map2(tparams, targs) {(tparam, targ) => + (tparams, targs).zipped map { (tparam, targ) => if (targ.typeSymbol == NothingClass && (restpe == WildcardType || notCovariantIn(tparam, restpe))) { uninstantiated += tparam tparam.tpeHK //@M tparam.tpe was wrong: we only want the type constructor, @@ -659,7 +659,7 @@ trait Infer { if (!isFullyDefined(tvar)) tvar.constr.inst = NoType // Then define remaining type variables from argument types. - List.map2(argtpes, formals) {(argtpe, formal) => + (argtpes, formals).zipped map { (argtpe, formal) => //@M isCompatible has side-effect: isSubtype0 will register subtype checks in the tvar's bounds if (!isCompatibleArg(argtpe.deconst.instantiateTypeParams(tparams, tvars), formal.instantiateTypeParams(tparams, tvars))) { @@ -1032,8 +1032,8 @@ trait Infer { (tparams map (_.defString)).mkString("[", ",", "]")) if (settings.explaintypes.value) { val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, targs).bounds) - List.map2(targs, bounds)((targ, bound) => explainTypes(bound.lo, targ)) - List.map2(targs, bounds)((targ, bound) => explainTypes(targ, bound.hi)) + (targs, bounds).zipped foreach ((targ, bound) => explainTypes(bound.lo, targ)) + (targs, bounds).zipped foreach ((targ, bound) => explainTypes(targ, bound.hi)) () } } diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 773b2cf561..d36d68163f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -223,7 +223,7 @@ trait NamesDefaults { self: Analyzer => */ def argValDefs(args: List[Tree], paramTypes: List[Type], blockTyper: Typer): List[ValDef] = { val context = blockTyper.context - val symPs = List.map2(args, paramTypes)((arg, tpe) => { + val symPs = (args, paramTypes).zipped map ((arg, tpe) => { val byName = tpe.typeSymbol == ByNameParamClass val s = context.owner.newValue(arg.pos, unit.fresh.newName(arg.pos, "x$")) val valType = if (byName) functionType(List(), arg.tpe) @@ -231,7 +231,7 @@ trait NamesDefaults { self: Analyzer => s.setInfo(valType) (context.scope.enter(s), byName) }) - List.map2(symPs, args)((symP, arg) => { + (symPs, args).zipped map ((symP, arg) => { val (sym, byName) = symP // resetAttrs required for #2290. given a block { val x = 1; x }, when wrapping into a function // () => { val x = 1; x }, the owner of symbol x must change (to the apply method of the function). @@ -270,7 +270,7 @@ trait NamesDefaults { self: Analyzer => reorderArgsInv(formals, argPos), blockTyper) // refArgs: definition-site order again - val refArgs = List.map2(reorderArgs(valDefs, argPos), formals)((vDef, tpe) => { + val refArgs = (reorderArgs(valDefs, argPos), formals).zipped map ((vDef, tpe) => { val ref = gen.mkAttributedRef(vDef.symbol) atPos(vDef.pos.focus) { // for by-name parameters, the local value is a nullary function returning the argument diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 3b49d22f0e..916ed69b67 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -888,8 +888,8 @@ abstract class RefChecks extends InfoTransform { unit.error(pos, ex.getMessage()); if (settings.explaintypes.value) { val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, argtps).bounds) - List.map2(argtps, bounds)((targ, bound) => explainTypes(bound.lo, targ)) - List.map2(argtps, bounds)((targ, bound) => explainTypes(targ, bound.hi)) + (argtps, bounds).zipped map ((targ, bound) => explainTypes(bound.lo, targ)) + (argtps, bounds).zipped map ((targ, bound) => explainTypes(targ, bound.hi)) () } } @@ -899,9 +899,7 @@ abstract class RefChecks extends InfoTransform { val clazz = pat.tpe.typeSymbol; clazz == seltpe.typeSymbol && clazz.isClass && (clazz hasFlag CASE) && - List.forall2( - args, - clazz.primaryConstructor.tpe.asSeenFrom(seltpe, clazz).paramTypes)(isIrrefutable) + ((args, clazz.primaryConstructor.tpe.asSeenFrom(seltpe, clazz).paramTypes).zipped forall isIrrefutable) case Typed(pat, tpt) => seltpe <:< tpt.tpe case Ident(nme.WILDCARD) => diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index b80a782e36..fe2b1fd7ca 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -54,11 +54,11 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } */ private def transformArgs(args: List[Tree], formals: List[Type]) = - List.map2(args, formals){ (arg, formal) => + ((args, formals).zipped map { (arg, formal) => if (formal.typeSymbol == definitions.ByNameParamClass) withInvalidOwner { checkPackedConforms(transform(arg), formal.typeArgs.head) } else transform(arg) - } ::: + }) ::: (args drop formals.length map transform) private def checkPackedConforms(tree: Tree, pt: Type): Tree = { @@ -290,7 +290,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val obj = protAcc.paramss.head.head // receiver protAcc.paramss.tail.zip(allParamTypes(sym.tpe)).foldLeft(Select(Ident(obj), sym): Tree) ( (fun, pvparams) => { - Apply(fun, (List.map2(pvparams._1, pvparams._2) { (v, origTpe) => makeArg(v, obj, origTpe) } )) + Apply(fun, (pvparams._1, pvparams._2).zipped map (makeArg(_, obj, _))) }) }) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1ddc3b9116..a6d4230969 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1141,7 +1141,7 @@ trait Typers { self: Analyzer => if (!supertparams.isEmpty) error(supertpt.pos, "missing type arguments") } - List.map2(cstats1, treeInfo.preSuperFields(templ.body)) { + (cstats1, treeInfo.preSuperFields(templ.body)).zipped map { (ldef, gdef) => gdef.tpt.tpe = ldef.symbol.tpe } case _ => @@ -1573,7 +1573,7 @@ trait Typers { self: Analyzer => if (!superClazz.hasFlag(JAVA)) { val superParamAccessors = superClazz.constrParamAccessors if (superParamAccessors.length == superArgs.length) { - List.map2(superParamAccessors, superArgs) { (superAcc, superArg) => + (superParamAccessors, superArgs).zipped map { (superAcc, superArg) => superArg match { case Ident(name) => if (vparamss.exists(_.exists(_.symbol == superArg.symbol))) { @@ -1924,7 +1924,7 @@ trait Typers { self: Analyzer => if (fun.vparams.length != argpts.length) errorTree(fun, "wrong number of parameters; expected = " + argpts.length) else { - val vparamSyms = List.map2(fun.vparams, argpts) { (vparam, argpt) => + val vparamSyms = (fun.vparams, argpts).zipped map { (vparam, argpt) => if (vparam.tpt.isEmpty) { vparam.tpt.tpe = if (isFullyDefined(argpt)) argpt @@ -2101,13 +2101,13 @@ trait Typers { self: Analyzer => val losym = tparam.info.bounds.lo.typeSymbol losym != NothingClass && losym != NullClass } - List.exists2(formals, args) { + (formals, args).zipped exists { case (formal, Function(vparams, _)) => (vparams exists (_.tpt.isEmpty)) && vparams.length <= MaxFunctionArity && (formal baseType FunctionClass(vparams.length) match { case TypeRef(_, _, formalargs) => - List.exists2(formalargs, vparams) ((formalarg, vparam) => + (formalargs, vparams).zipped.exists ((formalarg, vparam) => vparam.tpt.isEmpty && (tparams exists (formalarg contains))) && (tparams forall isLowerBounded) case _ => @@ -2336,7 +2336,7 @@ trait Typers { self: Analyzer => } else { assert((mode & PATTERNmode) == 0); // this case cannot arise for patterns val lenientTargs = protoTypeArgs(tparams, formals, mt.resultApprox, pt) - val strictTargs = List.map2(lenientTargs, tparams)((targ, tparam) => + val strictTargs = (lenientTargs, tparams).zipped map ((targ, tparam) => if (targ == WildcardType) tparam.tpe else targ) //@M TODO: should probably be .tpeHK def typedArgToPoly(arg: Tree, formal: Type): Tree = { val lenientPt = formal.instantiateTypeParams(tparams, lenientTargs) @@ -2348,7 +2348,7 @@ trait Typers { self: Analyzer => } arg1 } - val args1 = List.map2(args, formals)(typedArgToPoly) + val args1 = (args, formals).zipped map typedArgToPoly if (args1 exists (_.tpe.isError)) setError(tree) else { if (settings.debug.value) log("infer method inst "+fun+", tparams = "+tparams+", args = "+args1.map(_.tpe)+", pt = "+pt+", lobounds = "+tparams.map(_.tpe.bounds.lo)+", parambounds = "+tparams.map(_.info));//debug @@ -3609,7 +3609,7 @@ trait Typers { self: Analyzer => // @M! added the latter condition appliedType(tpt1.tpe, argtypes) else tpt1.tpe.instantiateTypeParams(tparams, argtypes) - List.map2(args, tparams) { (arg, tparam) => arg match { + (args, tparams).zipped map { (arg, tparam) => arg match { // note: can't use args1 in selector, because Bind's got replaced case Bind(_, _) => if (arg.symbol.isAbstractType) @@ -3693,7 +3693,7 @@ trait Typers { self: Analyzer => case UnApply(fun, args) => val fun1 = typed(fun) val tpes = formalTypes(unapplyTypeList(fun.symbol, fun1.tpe), args.length) - val args1 = List.map2(args, tpes)(typedPattern(_, _)) + val args1 = (args, tpes).zipped map (typedPattern(_, _)) treeCopy.UnApply(tree, fun1, args1) setType pt case ArrayValue(elemtpt, elems) => diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 3287204c58..4eb2d4ccf1 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -306,7 +306,7 @@ sealed abstract class List[+A] extends LinearSeq[A] * @return this list without the elements of the given list * <code>that</code>. */ - @deprecated("use `diff' instead") + @deprecated("use `list1.toSet -- list2` instead") def -- [B >: A](that: List[B]): List[B] = { val b = new ListBuffer[B] var these = this @@ -324,7 +324,7 @@ sealed abstract class List[+A] extends LinearSeq[A] * @return this list without occurrences of the given object * <code>x</code>. */ - @deprecated("use `diff' instead") + @deprecated("use `filterNot (_ == x)` instead") def - [B >: A](x: B): List[B] = { val b = new ListBuffer[B] var these = this @@ -360,13 +360,13 @@ sealed abstract class List[+A] extends LinearSeq[A] var left2 = l2 while (!left1.isEmpty && !left2.isEmpty) { - if(lt(left1.head, left2.head)) { - res += left1.head - left1 = left1.tail - } else { - res += left2.head - left2 = left2.tail - } + if(lt(left1.head, left2.head)) { + res += left1.head + left1 = left1.tail + } else { + res += left2.head + left2 = left2.tail + } } res ++= left1 @@ -382,12 +382,12 @@ sealed abstract class List[+A] extends LinearSeq[A] var left = lst while (!left.isEmpty) { - res1 += left.head - left = left.tail - if (!left.isEmpty) { - res2 += left.head - left = left.tail - } + res1 += left.head + left = left.tail + if (!left.isEmpty) { + res2 += left.head + left = left.tail + } } (res1.toList, res2.toList) @@ -397,15 +397,15 @@ sealed abstract class List[+A] extends LinearSeq[A] /** Merge-sort the specified list */ def ms(lst: List[A]): List[A] = lst match { - case Nil => lst - case x :: Nil => lst - case x :: y :: Nil => - if (lt(x,y)) - lst - else - y :: x :: Nil - - case lst => + case Nil => lst + case x :: Nil => lst + case x :: y :: Nil => + if (lt(x,y)) + lst + else + y :: x :: Nil + + case lst => val (l1, l2) = split(lst) val l1s = ms(l1) val l2s = ms(l2) diff --git a/src/library/scala/reflect/Print.scala b/src/library/scala/reflect/Print.scala index ab9ffdc99b..5b773e69b4 100644 --- a/src/library/scala/reflect/Print.scala +++ b/src/library/scala/reflect/Print.scala @@ -103,11 +103,8 @@ object Print extends Function1[Any, String] { case reflect.MethodType(formals, resultType) => formals.map(Print).mkString("(", ", ", ")") + " => " + Print(resultType) case reflect.PolyType(typeParams, typeBounds, resultType) => - (List.map2(typeParams, typeBounds) - ((tp, tb) => "[" + Print(tb._1) + " :> " + Print(tp) + " :> " + Print(tb._2) + "]")). - mkString("[", ", ", "]") + " -> " + Print(resultType) - // val z = (typeParams, typeBounds).zip map { case (tp, tb) => "[" + Print(tb._1) + " :> " + Print(tp) + " :> " + Print(tb._2) + "]" } - // z.mkString("[", ", ", "]") + " -> " + Print(resultType) + val z = (typeParams, typeBounds).zip map { case (tp, tb) => "[" + Print(tb._1) + " :> " + Print(tp) + " :> " + Print(tb._2) + "]" } + z.mkString("[", ", ", "]") + " -> " + Print(resultType) case _ => "???" } diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala index 641950f7b9..ec02009728 100644 --- a/src/partest/scala/tools/partest/nest/Worker.scala +++ b/src/partest/scala/tools/partest/nest/Worker.scala @@ -82,7 +82,7 @@ class Worker(val fileManager: FileManager) extends Actor { file.getAbsolutePath.substring(filesPathLen) } } - NestUI.normal("[...]"+name+List.toString(List.fill(totalWidth-name.length)(' ')), printer) + NestUI.normal("[...]"+name+(List.fill(totalWidth-name.length)(' ')).mkString, printer) } def printInfoEnd(success: Boolean, printer: PrintWriter) { |