summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/TraversableViewLike.scala
Commit message (Collapse)AuthorAgeFilesLines
* SI-8691 SeqView throws exception when prepending a collectionRex Kerr2014-12-061-4/+18
| | | | | | | | Prepend was throwing segfaults as it was handled differently from Append. This brings the two into line with each other. There are various optimizations that could be applied that have not been, however, such as intercepting sequential prepends and generating one multi-prepend instead of nested single-element prepends. Unit test added to verify minimally that bug is gone.
* Merge pull request #3191 from retronym/ticket/deprecate-par-viewJason Zaugg2013-12-061-17/+99
|\ | | | | Remove parallel collection views and, with them, Gen*View
| * Removes Gen*View and Par*ViewJason Zaugg2013-11-261-17/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - code that used to be inherited in *View is now inlined - the `view` methods on `ParIteratoa` and `ParSeq` now convert to sequential collections, and are deprecated asking the user to do this explicitly in the future. Should be largely source compatible with 2.10.x, on the assumption that the removed classes, while being public, were internal implementation details. A few tests used now-removed classes to demonstrate compiler crashes. I managed to confirm that after my decoupling, t4365 still exercises the bug: % qbin/scalac test/files/pos/t4365/*.scala warning: there were 2 deprecation warning(s); re-run with -deprecation for details one warning found % scalac-hash 7b4e450 test/files/pos/t4365/*.scala warning: there were 2 deprecation warning(s); re-run with -deprecation for details one warning found % scalac-hash 7b4e450~1 test/files/pos/t4365/*.scala 2<&1 | grep -i wrong error: something is wrong: cannot make sense of type application something is wrong: cannot make sense of type application something is wrong: cannot make sense of type application I didn't manage to do the same for specializes-sym-crash.scala, and instead just made it compile.
* | SI-4332 Plugs the gaps in viewsJason Zaugg2013-11-261-0/+13
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These currently result in runtime errors: scala> List(1).view.distinct.force java.lang.UnsupportedOperationException: SeqView(...).newBuilder scala> List(1).view.inits.toList java.lang.UnsupportedOperationException: SeqView(...).newBuilder Two tests are enclosed: 1. reflect on the views to make any method that returns `Repr` is overriden in `*ViewLike`. This guards against new additions to the collections API. 2. exercise the newly added overrides Some care is needed with `tail`, we must re-override it in `mutable.IndexedSeqView` to be explicit about the end point of the slice, because the `IndexedSeqView#Sliced` defines length in terms of that. (Higher up the chain, it is just `iterator.size`, that's why `SeqView#tail` just sets up a slice from `1 to Int.MaxValue`.) Parallel collections views are not touched, as these are likely to be deprecated or removed shortly. Before this change, the test reported the following. Not all of these methods were buggy. For instance, `sortBy`, `sortWith` are implemented in terms of `sorted` which was implemented in `SeqViewLike`. Even in those cases, I have opted to override the methods in the `ViewLike` to guard against changes in the base class implementation and to simplify the rules in the test. ====================================================================== Checking scala.collection.TraversableView ====================================================================== trait TraversableLike ---------------------------------------------------------------------- def filterNot(p: A => Boolean): Repr def inits: Iterator[Repr] def tails: Iterator[Repr] override def tail: Repr ====================================================================== Checking scala.collection.IterableView ====================================================================== trait IterableLike ---------------------------------------------------------------------- def dropRight(n: Int): Repr def sliding(size: Int): Iterator[Repr] def takeRight(n: Int): Repr trait TraversableLike ---------------------------------------------------------------------- def filterNot(p: A => Boolean): Repr def inits: Iterator[Repr] def tails: Iterator[Repr] override def tail: Repr ====================================================================== Checking scala.collection.SeqView ====================================================================== trait IterableLike ---------------------------------------------------------------------- def dropRight(n: Int): Repr def sliding(size: Int): Iterator[Repr] def takeRight(n: Int): Repr trait SeqLike ---------------------------------------------------------------------- def combinations(n: Int): Iterator[Repr] def distinct: Repr def permutations: Iterator[Repr] def sortBy[B](f: A => B)(implicit ord: scala.math.Ordering[B]): Repr def sortWith(lt: (A, A) => Boolean): Repr trait TraversableLike ---------------------------------------------------------------------- def filterNot(p: A => Boolean): Repr def inits: Iterator[Repr] def tails: Iterator[Repr] override def tail: Repr ====================================================================== Checking scala.collection.mutable.IndexedSeqView ====================================================================== trait IndexedSeqOptimized ---------------------------------------------------------------------- override def dropRight(n: Int): Repr override def tail: Repr override def takeRight(n: Int): Repr trait IterableLike ---------------------------------------------------------------------- def sliding(size: Int): Iterator[Repr] trait SeqLike ---------------------------------------------------------------------- def combinations(n: Int): Iterator[Repr] def distinct: Repr def permutations: Iterator[Repr] def sortBy[B](f: A => B)(implicit ord: scala.math.Ordering[B]): Repr def sortWith(lt: (A, A) => Boolean): Repr trait TraversableLike ---------------------------------------------------------------------- def filterNot(p: A => Boolean): Repr def inits: Iterator[Repr] def tails: Iterator[Repr] ====================================================================== Checking scala.collection.immutable.StreamView ====================================================================== trait IterableLike ---------------------------------------------------------------------- def dropRight(n: Int): Repr def sliding(size: Int): Iterator[Repr] def takeRight(n: Int): Repr trait SeqLike ---------------------------------------------------------------------- def combinations(n: Int): Iterator[Repr] def distinct: Repr def permutations: Iterator[Repr] def sortBy[B](f: A => B)(implicit ord: scala.math.Ordering[B]): Repr def sortWith(lt: (A, A) => Boolean): Repr trait TraversableLike ---------------------------------------------------------------------- def filterNot(p: A => Boolean): Repr def inits: Iterator[Repr] def tails: Iterator[Repr] override def tail: Repr
* Cull extraneous whitespace.Paul Phillips2013-09-181-2/+0
| | | | | | | | | | | | | | | | | | | | | One last flurry with the broom before I leave you slobs to code in your own filth. Eliminated all the trailing whitespace I could manage, with special prejudice reserved for the test cases which depended on the preservation of trailing whitespace. Was reminded I cannot figure out how to eliminate the trailing space on the "scala> " prompt in repl transcripts. At least reduced the number of such empty prompts by trimming transcript code on the way in. Routed ConsoleReporter's "printMessage" through a trailing whitespace stripping method which might help futureproof against the future of whitespace diseases. Deleted the up-to-40 lines of trailing whitespace found in various library files. It seems like only yesterday we performed whitespace surgery on the whole repo. Clearly it doesn't stick very well. I suggest it would work better to enforce a few requirements on the way in.
* Absolutized paths involving the scala package.Paul Phillips2013-05-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Confusing, now-it-happens now-it-doesn't mysteries lurk in the darkness. When scala packages are declared like this: package scala.collection.mutable Then paths relative to scala can easily be broken via the unlucky presence of an empty (or nonempty) directory. Example: // a.scala package scala.foo class Bar { new util.Random } % scalac ./a.scala % mkdir util % scalac ./a.scala ./a.scala:4: error: type Random is not a member of package util new util.Random ^ one error found There are two ways to play defense against this: - don't use relative paths; okay sometimes, less so others - don't "opt out" of the scala package This commit mostly pursues the latter, with occasional doses of the former. I created a scratch directory containing these empty directories: actors annotation ant api asm beans cmd collection compat concurrent control convert docutil dtd duration event factory forkjoin generic hashing immutable impl include internal io logging macros man1 matching math meta model mutable nsc parallel parsing partest persistent process pull ref reflect reify remote runtime scalap scheduler script swing sys text threadpool tools transform unchecked util xml I stopped when I could compile the main src directories even with all those empties on my classpath.
* Merge branch 'merge-2.10.wip-x' into merge-2.10.x-masterPaul Phillips2012-11-231-9/+0
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * merge-2.10.wip-x: (24 commits) SI-6023 reify abstract vals Removing controversial `either` method from Futures API. SI-6695 Test case for fixed Array match bug adds comments to standard attachments SI-6673 fixes macro problems with eta expansions Restore the opimization apparently lost after merge. SI-6624 set info of case pattern binder to help find case field accessors Scaladoc update for collection.mutable.MultiMap SI-6663: don't ignore type parameter on selectDynamic invocation SI-6551: don't insert apply call in polymorphic expression. SI-6634 Fixes data corruption issue in ListBuffer#remove Fixes SI-6628, Revert "Fix for view isEmpty." SI-6661 - Remove obsolete implicit parameter of scala.concurrent.promise method Fixes SI-6150 - backport to 2.10.x branch. SI-5330, SI-6014 deal with existential self-type Fixes SI-6559 - StringContext not using passed in escape function. SI-6648 copyAttrs must preserve TypeTree#wasEmpty Fix raw string interpolator: string parts which were after the first argument were still escaped sane printing of renamed imports SI-6440 Address regressions around MissingRequirementError ... Conflicts: src/library/scala/collection/generic/IndexedSeqFactory.scala src/library/scala/collection/mutable/ListBuffer.scala src/reflect/scala/reflect/internal/Symbols.scala src/reflect/scala/reflect/internal/Types.scala test/files/run/t6150.scala
| * Fixes SI-6628, Revert "Fix for view isEmpty."Paul Phillips2012-11-151-11/+2
| | | | | | | | | | | | This reverts commit caf7eb6b56817fd1e1fbc1cf017f30e6f94c6bea. I don't have a better idea right now than wholesale reversion.
* | Remove unused imports in library.Paul Phillips2012-11-191-1/+0
|/
* Brings all copyrights (in comments) up-to-date, from 2011/12 to 2013Heather Miller2012-11-021-1/+1
|
* Eliminate breaking relative names in source.Paul Phillips2012-09-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These things are killing me. Constructions like package scala.foo.bar.baz import foo.Other DO NOT WORK in general. Such files are not really in the "scala" package, because it is not declared package scala package foo.bar.baz And there is a second problem: using a relative path name means compilation will fail in the presence of a directory of the same name, e.g. % mkdir reflect % scalac src/reflect/scala/reflect/internal/util/Position.scala src/reflect/scala/reflect/internal/util/Position.scala:9: error: object ClassTag is not a member of package reflect import reflect.ClassTag ^ src/reflect/scala/reflect/internal/util/Position.scala:10: error: object base is not a member of package reflect import reflect.base.Attachments ^ As a rule, do not use relative package paths unless you have explicitly imported the path to which you think you are relative. Better yet, don't use them at all. Unfortunately they mostly work because scala variously thinks everything scala.* is in the scala package and/or because you usually aren't bootstrapping and it falls through to an existing version of the class already on the classpath. Making the paths explicit is not a complete solution - in particular, we remain enormously vulnerable to any directory or package called "scala" which isn't ours - but it greatly limts the severity of the problem.
* Fix for view isEmpty.Paul Phillips2012-08-131-2/+11
| | | | | | | | | | Views have been inheriting the very inefficient isEmpty from Traversable, and since isEmpty is not specifically forwarded to the underlying collections, views miss out on all the important optimizations in those collections which tend to be implemented via method override. Not to mention, they miss out on correctness, because calling foreach has a habit of forcing the first element of the view.
* Fix SI-5971.Aleksandar Prokopec2012-06-271-1/+1
| | | | | | | | | When using `AbstractTransformed` abstract inner class in views in order to force generating bridges, one must take care to push the corresponding collection trait (such as `Iterable` or `Seq`) as far as possible to the left in the linearization order -- otherwise, overridden methods from these traits can override the already overridden methods in view. This was the case with `takeWhile`.
* Fixes SI-5201. Adds flatten to TraversableViewLike.Josh Suereth2012-05-081-0/+2
| | | | | | | | | Note: This commit exposes a pretty rich type on flatten in views. HOWEVER, because we don't capture the higher kinded type of the underlying collection, it makes returning a more minimal type pretty dang hard. I can imagine a very breaking and painful change of capturing the underling collection as a higher-kinded type as well as the current view type in a *ViewLike.scala. I hope this kind of issue, along with others, drives a rethink of our view API design.
* Fixes si-5656.Aleksandar Prokopec2012-05-041-5/+13
|
* Enabling postfix ops feature warning, and working on libs to avoid them.Martin Odersky2012-04-121-1/+1
|
* Various improvements to SIP 18 diagnostics. Made scala library and compiler ↵Martin Odersky2012-04-121-0/+1
| | | | feature clean.
* unzip(3) on view now returns view.Josh Suereth2011-12-181-0/+6
| | | | | | | | * Added unzip and unzip3 to TraversableViewLike * Added partest tests for unzip on views returning specific collection types. Closes SI-5053 Review by @paulp
* Migration message and version cleanupSimon Ochsenreither2011-12-071-4/+1
| | | | | | | | | | The @migration annotation can now be used like @deprecation. Old syntax is still supported, but deprecated. Improve wording and consistency of migration messages, migration warnings also print the version in which the change occurred now. Partially fixes SI-4990.
* Dropped about 1.5 Mb off scala-library.jar.Paul Phillips2011-11-071-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit and the two subsequent commits were contributed by: Todd Vierling <tv@duh.org>. I combined some commits and mangled his commit messages, but all the credit is his. This pursues the same approach to classfile reduction seen in r19989 when AbstractFunctionN was introduced, but applies it to the collections. Thanks to -Xlint it's easy to verify that the private types don't escape. Design considerations as articulated by Todd: * Don't necessarily create concrete types for _everything_. Where a subtrait only provides a few additional methods, don't bother; instead, use the supertrait's concrete class and retain the "with". For example, "extends AbstractSeq[A] with LinearSeq[A]". * Examine all classes with .class file size greater than 10k. Named classes and class names ending in $$anon$<num> are candidates for analysis. * If a return type is currently inferred where an anon subclass would be returned, make the return type explicit. Don't allow the library-private abstract classes to leak into the public namespace [and scaladoc].
* Views using methods implemented in terms of isE...Paul Phillips2011-06-131-0/+21
| | | | | | | | | | | | | | | Views using methods implemented in terms of isEmpty (in particular, headOption and lastOption) were traversing the collection twice up to the nonEmpty element, because "if (isEmpty) None else Some(head)" means calling isEmpty separately from head. I overrode those methods in TraversableViewLike to avoid the second traversal. This leaves at least init and tail still in that boat, but they were getting too involved. How do I say "review by pool of reviewers", who can help set that up? In the meantime no review.
* Fix for wrong results from groupBy on views.Paul Phillips2011-06-121-1/+1
|
* Fix for view+groupBy closes #4558, no review.Paul Phillips2011-05-141-3/+5
|
* Refactoring the collections api to support diff...Aleksandar Pokopec2011-04-131-109/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactoring the collections api to support differentiation between referring to a sequential collection and a parallel collection, and to support referring to both types of collections. New set of traits Gen* are now superclasses of both their * and Par* subclasses. For example, GenIterable is a superclass of both Iterable and ParIterable. Iterable and ParIterable are not in a subclassing relation. The new class hierarchy is illustrated below (simplified, not all relations and classes are shown): TraversableOnce --> GenTraversableOnce ^ ^ | | Traversable --> GenTraversable ^ ^ | | Iterable --> GenIterable <-- ParIterable ^ ^ ^ | | | Seq --> GenSeq <-- ParSeq (the *Like, *View and *ViewLike traits have a similar hierarchy) General views extract common view functionality from parallel and sequential collections. This design also allows for more flexible extensions to the collections framework. It also allows slowly factoring out common functionality up into Gen* traits. From now on, it is possible to write this: import collection._ val p = parallel.ParSeq(1, 2, 3) val g: GenSeq[Int] = p // meaning a General Sequence val s = g.seq // type of s is Seq[Int] for (elem <- g) { // do something without guarantees on sequentiality of foreach // this foreach may be executed in parallel } for (elem <- s) { // do something with a guarantee that foreach is executed in order, sequentially } for (elem <- p) { // do something concurrently, in parallel } This also means that some signatures had to be changed. For example, method `flatMap` now takes `A => GenTraversableOnce[B]`, and `zip` takes a `GenIterable[B]`. Also, there are mutable & immutable Gen* trait variants. They have generic companion functionality.
* Addressing most of the warnings revealed by the...Paul Phillips2011-03-301-4/+4
| | | | | | Addressing most of the warnings revealed by the patch to warn about unknown scaladoc variables. Updated and reran genprod. No review.
* A patch for views. Most relevant change:Paul Phillips2011-03-111-75/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Almost all view classes now list parents like trait Appended[B >: A] extends super.Appended[B] with Transformed[B] instead of the former trait Appended[B >: A] extends Transformed[B] with super.Appended[B] because as it was, the implementation of foreach in TraversableViewLike#Transformed was repeatedly trumping overrides found in e.g. IterableLike. This change was not without its own consequences, and much of the rest of the patch is dealing with that. A more general issue is clearly revealed here: there is no straightforward way to deal with trait composition and overrides when some methods should prefer B over A and some the reverse. (It's more like A through Z in this case.) That closes #4279, with some views being five orders of magnitude slower than necessary. There is a test that confirms they'll stay performance neighbors. In the view classes (Zipped, Mapped, etc.) I attended to them with comb and brush until they were reasonably consistent. I only use "override" where necessary and throw in some "final" in the interests of trying to anchor the composition outcome. I also switched the newSliced, newZipped, etc. methods to use early init syntax since a number have abstract vals and I found at least one bug originating with uninitialized access. There was a piece of a parallel collections scalacheck test failing, which I disabled out of expedience - am emailing prokopec. There is plenty of work left to do but paulp must get back to other 2.9 issues. This is the Zurich->SF airplane patch. No review.
* Made mkString work correctly on views.Paul Phillips2011-02-251-0/+10
| | | | | about how to obtain a String and how not to. Closes #4297, no review.
* Merge branch 'work'Aleksandar Pokopec2011-01-261-0/+5
| | | | | | Conflicts: src/library/scala/concurrent/SyncVar.scala
* Updated copyright notices to 2011Antonio Cunei2011-01-201-1/+1
|
* The initial implementation of TraversableOnce c...Paul Phillips2010-11-291-3/+3
| | | | | | | | | | | | | | | | | | The initial implementation of TraversableOnce could not supply concrete methods or even signatures for map and flatMap because they have different signatures in Iterator and TraversableLike. But we can take another approach which works out as nicely: 1) Create implicits which install those methods and flatten on TraversableOnce instances. 2) Generalize the signatures of flatten and flatMap to work with A => TraversableOnce[B] instead of A => Traversable[B]. And voila, you can mix and match Iterators and Traversables in a for comprehension, map, flatMap, and flatten, without the tedious process of sprinkling .iterator or .toList around to appease the compiler. No review.
* Refactorings to make iterators required by task...Aleksandar Pokopec2010-09-171-0/+1
| | | | | | Refactorings to make iterators required by task objects less restricted. No review
* Overrode addString in TraversableViewLike.Paul Phillips2010-09-161-0/+3
| | | | | | | | | | | | | | | the Transform-derived traits within view resisted evaluating the entire sequence on a toString call, but the original view returned from a call to .view did not. This has a particularly bad result in the case of Stream, as for instance: Stream from 1 view would enter infiniteloopiland in the repl despite the fact that it should be doubly resistant to eager evaluation. Review by prokopec.
* first part of r22260Antonio Cunei2010-06-161-1/+1
|
* temporarily reversing r22260; will be shortly r...Antonio Cunei2010-06-161-1/+1
| | | | | | temporarily reversing r22260; will be shortly re-committed in two separate portions.
* Changed groupBy to return immutable.Map.Paul Phillips2010-06-131-1/+1
|
* Fixed problem discovered by Paul that views do ...Martin Odersky2010-06-061-0/+1
| | | | | | Fixed problem discovered by Paul that views do not support a filter in for expressions. review by extempore.
* Removed more than 3400 svn '$Id' keywords and r...Antonio Cunei2010-05-121-1/+0
| | | | | Removed more than 3400 svn '$Id' keywords and related junk.
* Updated documentationMartin Odersky2010-04-091-11/+23
|
* Rearranging IndexedSeq/LinearSeq and related workMartin Odersky2010-04-051-0/+1
|
* TraversableOnce. Review by odersky.Paul Phillips2010-03-271-4/+2
|
* Renamed partialMap to collect.Paul Phillips2010-03-241-1/+1
| | | | | | | | | method on Iterator called collect which I had to remove, because if the method is overloaded it puts a bullet in the type inference, an intolerable result for a function which takes a partial function as its argument. I don't think there's much chance of confusion, but I put a migration warning on collect just in case. No review.
* Spring cleaning of collection libraries.Martin Odersky2010-03-191-8/+45
| | | | | | If people think some operations can be more lazy, please provide patches/do changes. Also brought proxies and forwarders into line.
* Reverts r20311 since I'm not seeing what's goin...Paul Phillips2010-01-131-7/+16
| | | | | | Reverts r20311 since I'm not seeing what's going on in #2876 and the optimization can wait.
* Created team of private[collection] abstract cl...Paul Phillips2009-12-231-16/+7
| | | | | | | | | | | | Created team of private[collection] abstract classes and traits in scala.collection.views. Factored boilerplate and base Transformed traits out of *ViewLike classes. Executive summary and motivation: 4812029 Dec 23 09:47 scala-library.jar // before 4604150 Dec 23 09:24 scala-library.jar // after Direct size savings of 4.5%. Review by odersky.
* Updated copyright notices to 2010Antonio Cunei2009-12-071-1/+1
|
* More world-shaking deprecation work.Paul Phillips2009-11-201-2/+1
| | | | | | | object, updating some @deprecated messages to give realistic alternatives, properly resolving the semantic mismatch between List.-- and diff, its once-recommended but inequivalent alternative.
* Fixed #1342.Martin Odersky2009-10-281-4/+3
|
* renamed BuilderFactory[El, To, From] -> CanBuil...Adriaan Moors2009-10-211-6/+6
| | | | | | | | | | | | | | | | | | | | | renamed BuilderFactory[El, To, From] -> CanBuildFrom[From, El, To] and added apply() overload to create collections from scratch generically added def apply() overload to BuilderFactory so that we can also create collections from scratch generically (see test test/files/pos/collectGenericCC.scala) renaming: - BuilderFactory[El, To, From] -> CanBuildFrom[From, El, To] bulk type-param reordering using: s/CanBuildFrom\[\s*([^,()\s]*)\s*,(\s+[^\s,()]*)\s*,\s+([^\s,()]*)\s*\]/CanBuildFrom[$3, $1,$2]/ some argument lists got mixed up because they contained 4 comma's... - builderFactory -> canBuildFrom removed explicit implicit value in DocDriver that was renamed renamed collection/generic/BuilderFactory.scala -> collection/generic/CanBuildFrom.scala tested with clean build using ant strap.done -- everything went well on my machine
* reverted immutable.Vector because it gave rando...Martin Odersky2009-10-121-1/+1
| | | | | | reverted immutable.Vector because it gave random build errors on my machine. Fixed various tickets, updated test and check files.
* Collections refactoring.Martin Odersky2009-09-251-0/+179