SI-9072 Vector ++ concatenation of parallel collection cause inconsisten...#4259
SI-9072 Vector ++ concatenation of parallel collection cause inconsisten...#4259Ichoran merged 1 commit intoscala:2.11.xfrom
Conversation
|
LGTM but we should get the IDE build error under control before merging. (Not specific to this patch; everything's been failing on it lately.) |
|
Could you please expand the commit comment to briefly describe what was wrong with the code before? (e.g: "Should not side effect within a potentially parallel I'm auditing the rest of the collections for the same mistake. So far I've found: // /Users/jason/code/scala2/src/library/scala/collection/TraversableViewLike.scala:184
trait Appended[B >: A] extends Transformed[B] {
protected[this] val rest: GenTraversable[B]
def foreach[U](f: B => U) {
self foreach f
rest foreach f
}
final override protected[this] def viewIdentifier = "A"
}
// /Users/jason/code/scala2/src/library/scala/collection/TraversableViewLike.scala:139
trait Forced[B] extends Transformed[B] {
protected[this] val forced: GenSeq[B]
def foreach[U](f: B => U) = forced foreach f
final override protected[this] def viewIdentifier = "C"
} |
|
@retronym - Manual auditing sounds tedious. Maybe you're not doing it manually; e.g. you could deprecate foreach on GenTraversableLike and the other Gen-children; then the compiler should catch all uses. Anything outside collection.parallel is suspect. |
|
Excellent suggestion! I added a custom warning to flag any use of a higher order diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index d2931ff..2df03e2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1291,6 +1291,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
if (sym.isDeprecated && !currentOwner.ownerChain.exists(x => x.isDeprecated || x.hasBridgeAnnotation))
currentRun.reporting.deprecationWarning(pos, sym)
+ val isHigherOrderGenTraversableMethod = {
+ sym.hasTransOwner(CollectionPackage.moduleClass) && mexists(sym.paramss)(param => definitions.isFunctionType(param.info) && !param.isImplicit) && sym.owner.name.toString.matches("Gen[A-Z].*")
+ }
+ if (isHigherOrderGenTraversableMethod && currentClass.hasTransOwner(CollectionPackage.moduleClass) && !currentClass.hasTransOwner(CollectionParallelPackage.moduleClass) && !currentClass.name.toString.matches("Gen[A-Z].*")) {
+ reporter.warning(pos, "Use of higher order methods in GenTraversable et al not advisable from outside of scala.colllection.parallel")
+ }
+
// Similar to deprecation: check if the symbol is marked with @migration
// indicating it has changed semantics between versions.
if (sym.hasMigrationAnnotation && settings.Xmigration.value != NoScalaVersion) {
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 9f4ec3e..7e51f09 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -419,6 +419,8 @@ trait Definitions extends api.StandardDefinitions {
def elementType(container: Symbol, tp: Type): Type = elementExtract(container, tp)
// collections classes
+ lazy val CollectionPackage = getPackage("scala.collection")
+ lazy val CollectionParallelPackage = getPackage("scala.collection.parallel")
lazy val ConsClass = requiredClass[scala.collection.immutable.::[_]]
lazy val IteratorClass = requiredClass[scala.collection.Iterator[_]]
lazy val IterableClass = requiredClass[scala.collection.Iterable[_]]Results: Maybe checking for |
|
PLS REBUILD ALL |
|
(kitty-note-to-self: ignore 71918881) |
|
Merging as-is; the need to .seq is, sadly, rather common in the code, so there is not much benefit in having a comment here pointing it out. @retronym - did you file a ticket for the other spots (or fix them)? |
|
Argh, silly laptop touchpad. Didn't mean to close. |
SI-9072 Vector ++ concatenation of parallel collection cause inconsisten...
|
@retronym - Filed an issue for this, hopefully not a duplicate: https://issues.scala-lang.org/browse/SI-9126 @adriaanm - Not sure whether you intended me to merge this or to review it again (I already had, and nothing had really changed?). |
|
I meant to divide up the work of getting the four dozen or so pending PRs merged in due course. |
...t results