Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11041] Deprecate .zipped method on tuples #7025

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ trait MatchApproximation extends TreeAndTypeAnalysis with ScalaLogic with MatchT
// debug.patmat ("normalize subst: "+ normalize)

val okSubst = Substitution(unboundFrom.toList, unboundTo.toList) // it's important substitution does not duplicate trees here -- it helps to keep hash consing simple, anyway
pointsToBound ++= ((okSubst.from, okSubst.to).zipped filter { (f, t) => pointsToBound exists (sym => t.exists(_.symbol == sym)) })._1
pointsToBound ++= okSubst.from.lazyZip(okSubst.to).collect { case (f, t) if pointsToBound.exists(sym => t.exists(_.symbol == sym)) => f }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replacing filter with collect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code is filtering and then at the end, takes only the left iterable. I took liberty of replacing it with a collect which just collects the left elements when the predicate holds.

// debug.patmat("pointsToBound: "+ pointsToBound)

accumSubst >>= okSubst
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {

def emitVars = storedBinders.nonEmpty

private lazy val (stored, substed) = (subPatBinders, subPatRefs).zipped.partition{ case (sym, _) => storedBinders(sym) }
private lazy val (stored, substed) = subPatBinders.lazyZip(subPatRefs).partition{ case (sym, _) => storedBinders(sym) }

protected lazy val localSubstitution: Substitution = if (!emitVars) Substitution(subPatBinders, subPatRefs)
else {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Checkable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ trait Checkable {
if (tps1.size != tps2.size)
devWarning(s"Unequally sized type arg lists in propagateKnownTypes($from, $to): ($tps1, $tps2)")

(tps1, tps2).zipped foreach (_ =:= _)
tps1.lazyZip(tps2).foreach(_ =:= _)
// Alternate, variance respecting formulation causes
// neg/unchecked3.scala to fail (abstract types). TODO -
// figure it out. It seems there is more work to do if I
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,8 @@ trait ContextErrors {
private[scala] def NotWithinBoundsErrorMessage(prefix: String, targs: List[Type], tparams: List[Symbol], explaintypes: Boolean) = {
if (explaintypes) {
val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, targs).bounds)
(targs, bounds).zipped foreach ((targ, bound) => explainTypes(bound.lo, targ))
(targs, bounds).zipped foreach ((targ, bound) => explainTypes(targ, bound.hi))
()
targs.lazyZip(bounds).foreach((targ, bound) => explainTypes(bound.lo, targ))
targs.lazyZip(bounds).foreach((targ, bound) => explainTypes(targ, bound.hi))
}

prefix + "type arguments " + targs.mkString("[", ",", "]") +
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Infer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ trait Infer extends Checkable {
*/
def solvedTypes(tvars: List[TypeVar], tparams: List[Symbol], variances: List[Variance], upper: Boolean, depth: Depth): List[Type] = {
if (tvars.isEmpty) Nil else {
printTyping("solving for " + parentheses((tparams, tvars).zipped map ((p, tv) => s"${p.name}: $tv")))
printTyping("solving for " + parentheses(tparams.lazyZip(tvars).map((p, tv) => s"${p.name}: $tv")))
// !!! What should be done with the return value of "solve", which is at present ignored?
// The historical commentary says "no panic, it's good enough to just guess a solution,
// we'll find out later whether it works", meaning don't issue an error here when types
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,8 @@ abstract class RefChecks extends Transform {
reporter.error(tree0.pos, ex.getMessage())
if (settings.explaintypes) {
val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, argtps).bounds)
(argtps, bounds).zipped map ((targ, bound) => explainTypes(bound.lo, targ))
(argtps, bounds).zipped map ((targ, bound) => explainTypes(targ, bound.hi))
argtps.lazyZip(bounds).foreach((targ, bound) => explainTypes(bound.lo, targ))
argtps.lazyZip(bounds).foreach((targ, bound) => explainTypes(targ, bound.hi))
()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ trait TypeDiagnostics {
val params = req.typeConstructor.typeParams

if (foundArgs.nonEmpty && foundArgs.length == reqArgs.length) {
val relationships = (foundArgs, reqArgs, params).zipped map {
val relationships = foundArgs.lazyZip(reqArgs).lazyZip(params).map {
case (arg, reqArg, param) =>
def mkMsg(isSubtype: Boolean) = {
val op = if (isSubtype) "<:" else ">:"
Expand Down
43 changes: 22 additions & 21 deletions src/interactive/scala/tools/nsc/interactive/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1188,29 +1188,30 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
val enteredLowercaseSet = enteredS.toLowerCase().toSet
val allowSnake = !enteredS.contains('_')

(candidate: Name) => {
def candidateChunks = camelComponents(candidate.dropLocal.toString, allowSnake)
// Loosely based on IntelliJ's autocompletion: the user can just write everything in
// lowercase, as we'll let `isl` match `GenIndexedSeqLike` or `isLovely`.
def lenientMatch(entered: String, candidate: List[String], matchCount: Int): Boolean = {
candidate match {
case Nil => entered.isEmpty && matchCount > 0
case head :: tail =>
val enteredAlternatives = Set(entered, entered.capitalize)
val n = (head, entered).zipped.count {case (c, e) => c == e || (c.isUpper && c == e.toUpper)}
head.take(n).inits.exists(init =>
enteredAlternatives.exists(entered =>
lenientMatch(entered.stripPrefix(init), tail, matchCount + (if (init.isEmpty) 0 else 1))
{
candidate: Name =>
def candidateChunks = camelComponents(candidate.dropLocal.toString, allowSnake)
// Loosely based on IntelliJ's autocompletion: the user can just write everything in
// lowercase, as we'll let `isl` match `GenIndexedSeqLike` or `isLovely`.
def lenientMatch(entered: String, candidate: List[String], matchCount: Int): Boolean = {
candidate match {
case Nil => entered.isEmpty && matchCount > 0
case head :: tail =>
val enteredAlternatives = Set(entered, entered.capitalize)
val n = head.toIterable.lazyZip(entered).count {case (c, e) => c == e || (c.isUpper && c == e.toUpper)}
head.take(n).inits.exists(init =>
enteredAlternatives.exists(entered =>
lenientMatch(entered.stripPrefix(init), tail, matchCount + (if (init.isEmpty) 0 else 1))
)
)
)
}
}
}
val containsAllEnteredChars = {
// Trying to rule out some candidates quickly before the more expensive `lenientMatch`
val candidateLowercaseSet = candidate.toString.toLowerCase().toSet
enteredLowercaseSet.diff(candidateLowercaseSet).isEmpty
}
containsAllEnteredChars && lenientMatch(enteredS, candidateChunks, 0)
val containsAllEnteredChars = {
// Trying to rule out some candidates quickly before the more expensive `lenientMatch`
val candidateLowercaseSet = candidate.toString.toLowerCase().toSet
enteredLowercaseSet.diff(candidateLowercaseSet).isEmpty
}
containsAllEnteredChars && lenientMatch(enteredS, candidateChunks, 0)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/library/scala/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ object Predef extends LowPriorityImplicits {

// views --------------------------------------------------------------

@deprecated("Use xs.lazyZip(ys).", "2.13.0")
implicit def tuple2ToZippedOps[T1, T2](x: (T1, T2)): runtime.Tuple2Zipped.Ops[T1, T2] = new runtime.Tuple2Zipped.Ops(x)
@deprecated("Use xs.lazyZip(ys).lazyZip(zs).", "2.13.0")
implicit def tuple3ToZippedOps[T1, T2, T3](x: (T1, T2, T3)): runtime.Tuple3Zipped.Ops[T1, T2, T3] = new runtime.Tuple3Zipped.Ops(x)

// Not specialized anymore since 2.13 but we still need separate methods
Expand Down
4 changes: 4 additions & 0 deletions src/library/scala/runtime/Tuple2Zipped.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import scala.language.implicitConversions
* @define collectExample
* @define willNotTerminateInf
*/
@deprecated("Use scala.collection.LazyZip2.", "2.13.0")
trait ZippedIterable2[+El1, +El2] extends Any {
def iterator: Iterator[(El1, El2)]
def isEmpty: Boolean
}
@deprecated("Use scala.collection.LazyZip2.", "2.13.0")
object ZippedIterable2 {
implicit def zippedIterable2ToIterable[El1, El2](zz: ZippedIterable2[El1, El2]): Iterable[(El1, El2)] = {
new scala.collection.AbstractIterable[(El1, El2)] {
Expand All @@ -34,6 +36,7 @@ object ZippedIterable2 {
}
}

@deprecated("Use scala.collection.LazyZip2.", "2.13.0")
final class Tuple2Zipped[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2]](private val colls: (It1, It2)) extends AnyVal with ZippedIterable2[El1, El2] {
private def coll1 = colls._1
private def coll2 = colls._2
Expand Down Expand Up @@ -118,6 +121,7 @@ final class Tuple2Zipped[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2]](p
override def toString = s"($coll1, $coll2).zipped"
}

@deprecated("Use scala.collection.LazyZip2.", "2.13.0")
object Tuple2Zipped {
final class Ops[T1, T2](private val x: (T1, T2)) extends AnyVal {
def invert[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2], That]
Expand Down
4 changes: 4 additions & 0 deletions src/library/scala/runtime/Tuple3Zipped.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import scala.language.implicitConversions
* @define collectExample
* @define willNotTerminateInf
*/
@deprecated("Use scala.collection.LazyZip3.", "2.13.0")
trait ZippedIterable3[+El1, +El2, +El3] extends Any {
def iterator: Iterator[(El1, El2, El3)]
def isEmpty: Boolean
}
@deprecated("Use scala.collection.LazyZip3.", "2.13.0")
object ZippedIterable3 {
implicit def zippedIterable3ToIterable[El1, El2, El3](zz: ZippedIterable3[El1, El2, El3]): Iterable[(El1, El2, El3)] = {
new scala.collection.AbstractIterable[(El1, El2, El3)] {
Expand All @@ -32,6 +34,7 @@ object ZippedIterable3 {
}
}

@deprecated("Use scala.collection.LazyZip3.", "2.13.0")
final class Tuple3Zipped[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2], El3, It3 <: Iterable[El3]](private val colls: (It1, It2, It3))
extends AnyVal with ZippedIterable3[El1, El2, El3] {

Expand Down Expand Up @@ -129,6 +132,7 @@ final class Tuple3Zipped[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2], E
override def toString = s"($coll1, $coll2, $coll3).zipped"
}

@deprecated("Use scala.collection.LazyZip3.", "2.13.0")
object Tuple3Zipped {
final class Ops[T1, T2, T3](private val x: (T1, T2, T3)) extends AnyVal {
def invert[El1, It1 <: Iterable[El1], El2, It2 <: Iterable[El2], El3, It3 <: Iterable[El3], That]
Expand Down
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/BytecodeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class BytecodeTest {
println(s"Different member counts in $name1 and $name2")
false
}
else (ms1, ms2).zipped forall { (m1, m2) =>
else ms1.lazyZip(ms2).forall { (m1, m2) =>
val c1 = f(m1)
val c2 = f(m2).replaceAllLiterally(name2, name1)
if (c1 == c2)
Expand Down
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/CompilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class CompilerTest extends DirectTest {

override def extraSettings = "-usejavacp -d " + testOutput.path

def show() = (sources, units).zipped foreach check
def show() = sources.lazyZip(units).foreach(check)

// Override at least one of these...
def code = ""
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/TreeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ abstract class TreeGen {
val rhss = valeqs map { case ValEq(_, rhs) => rhs }
val defpat1 = makeBind(pat)
val defpats = pats map makeBind
val pdefs = (defpats, rhss).zipped flatMap mkPatDef
val pdefs = defpats.lazyZip(rhss).flatMap(mkPatDef)
val ids = (defpat1 :: defpats) map makeValue
val rhs1 = mkFor(
List(ValFrom(defpat1, rhs).setPos(t.pos)),
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ trait Trees extends api.Trees {

// Create a readable string describing a substitution.
private def substituterString(fromStr: String, toStr: String, from: List[Any], to: List[Any]): String = {
"subst[%s, %s](%s)".format(fromStr, toStr, (from, to).zipped map (_ + " -> " + _) mkString ", ")
"subst[%s, %s](%s)".format(fromStr, toStr, from.lazyZip(to).map(_ + " -> " + _).mkString(", "))
}

// NOTE: calls shallowDuplicate on trees in `to` to avoid problems when symbols in `from`
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/util/TableDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TableDef[T](_cols: Column[T]*) {

val headers = List(
headFormat.format(colNames: _*),
(colWidths, sepWidths).zipped map ((w1, w2) => "-" * w1 + " " * w2) mkString
colWidths.lazyZip(sepWidths).map((w1, w2) => "-" * w1 + " " * w2).mkString
)

def mkFormatString(sepf: Int => String): String =
Expand Down
2 changes: 1 addition & 1 deletion src/scaladoc/scala/tools/nsc/doc/html/HtmlTags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object HtmlTags {
def attribValues = productIterator.toList

def attribs: Seq[(String, String)] = {
(attribNames, attribValues).zipped.collect { case (k, v) if k != "elems" && v != null => (k, v.toString)}.toSeq
attribNames.lazyZip(attribValues).collect { case (k, v) if k != "elems" && v != null => (k, v.toString)}.toSeq
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/files/run/compiler-asSeenFrom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class CompilerTest extends DirectTest {

override def extraSettings = "-feature -usejavacp -d " + testOutput.path

def show() = (sources, units).zipped foreach check
def show() = sources.lazyZip(units) foreach check

// Override at least one of these...
def code = ""
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/t7096.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class CompilerTest extends DirectTest {

override def extraSettings = "-usejavacp -d " + testOutput.path

def show() = (sources, units).zipped foreach check
def show() = sources.lazyZip(units) foreach check

// Override at least one of these...
def code = ""
Expand Down
2 changes: 1 addition & 1 deletion test/junit/scala/collection/mutable/ArraySortingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ArraySortingTest {
java.util.Arrays.sort(test)
scala.util.Sorting.quickSort(cant)(CanOrder)
assert( test(6) == 1 )
assert( (test,cant).zipped.forall(_ == _.i) )
assert( test.toIterable.lazyZip(cant).forall(_ == _.i) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add lazyZip to ArrayOps so that users don’t have to convert it to an Iterable. We could do the same with StringOps, btw. I’ve created scala/bug#11063 for that. You don’t have to do it in that PR.

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BTypesFromClassfileTest extends BytecodeTesting {

def sameBTypes(fromSyms: Iterable[ClassBType], fromClassfiles: Iterable[ClassBType], checked: Set[InternalName]): Set[InternalName] = {
assert(fromSyms.size == fromClassfiles.size, s"\n$fromSyms\n$fromClassfiles")
(fromSyms, fromClassfiles).zipped.foldLeft(checked) {
fromSyms.lazyZip(fromClassfiles).foldLeft(checked) {
case (chk, (fromSym, fromClassfile)) => sameBType(fromSym, fromClassfile, chk)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InlineSourceMatcherTest extends BytecodeTesting {
val es = m.entries
assertEquals(es.length, expect.length)

for ((a, e) <- (es, expect).zipped) {
for ((a, e) <- es.lazyZip(expect)) {
assertEquals(a.pattern.pattern, e.regex)
assertEquals(a.negated, e.negated)
assertEquals(a.terminal, e.terminal)
Expand Down
32 changes: 12 additions & 20 deletions test/scalacheck/primitive-eqeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@ object PrimitiveEqEqTest extends Properties("==") {
def equalObjectsEqualHashcodes(x: Any, y: Any) = (x != y) || (x == y && x.## == y.##)

// ticket #2087
property("short/char") = forAll { (x: Short) => {
val ch: Char = x.toChar
(x == ch) == (ch == x)
}
property("short/char") = forAll { x: Short =>
val ch: Char = x.toChar
(x == ch) == (ch == x)
}

property("symmetry") = forAll { (x: AnyVal, y: AnyVal) => (x == y) == (y == x) }
property("transitivity") = forAll { (x: AnyVal, y: AnyVal, z: AnyVal) => x != y || y != z || x == z }

property("##") = forAll {
(x: Short) => {
val anyvals = List(x.toByte, x.toChar, x, x.toInt, x.toLong, x.toFloat, x.toDouble, BigInt(x), BigDecimal(x))
val shortAndLarger = anyvals drop 2
property("##") = forAll { x: Short =>
val anyvals = List(x.toByte, x.toChar, x, x.toInt, x.toLong, x.toFloat, x.toDouble, BigInt(x), BigDecimal(x))
val shortAndLarger = anyvals drop 2

val result = (
((anyvals, anyvals).zipped forall equalObjectsEqualHashcodes) &&
((shortAndLarger, shortAndLarger).zipped forall (_ == _)) &&
((shortAndLarger, shortAndLarger).zipped forall ((x, y) => (x: Any) == (y: Any)))
)
result
}
(anyvals.lazyZip(anyvals) forall equalObjectsEqualHashcodes) &&
(shortAndLarger.lazyZip(shortAndLarger) forall (_ == _)) &&
(shortAndLarger.lazyZip(shortAndLarger) forall ((x, y) => (x: Any) == (y: Any)))
}
property("## 2") = forAll {
(dv: Double) => {
val fv = dv.toFloat
(fv != dv) || (fv.## == dv.##)
}
property("## 2") = forAll { dv: Double =>
val fv = dv.toFloat
(fv != dv) || (fv.## == dv.##)
}
}