Skip to content

Commit f8c1582

Browse files
committed
Work around Scala parallel collections situation
Ref scala/scala-parallel-collections#22 Parallel collection got split off without source-compatible library, so apparently we need to roll our own compat hack, which causes import not used, so it needs to be paired with silencer.
1 parent cb4c1e7 commit f8c1582

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

build.sbt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def commonBaseSettings: Seq[Setting[_]] = Def.settings(
105105
crossScalaVersions := Seq(baseScalaVersion),
106106
publishArtifact in Test := false,
107107
fork in run := true,
108+
libraryDependencies ++= {
109+
if (autoScalaLibrary.value) List(silencerLib)
110+
else Nil
111+
},
108112
)
109113
def commonSettings: Seq[Setting[_]] =
110114
commonBaseSettings :+
@@ -324,6 +328,10 @@ val logicProj = (project in file("internal") / "util-logic")
324328
testedBaseSettings,
325329
name := "Logic",
326330
mimaSettings,
331+
libraryDependencies ++= (scalaVersion.value match {
332+
case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin))
333+
case _ => List()
334+
}),
327335
)
328336

329337
// defines Java structures used across Scala versions, such as the API structures and relationships extracted by
@@ -613,6 +621,10 @@ lazy val scriptedSbtReduxProj = (project in file("scripted-sbt-redux"))
613621
baseSettings,
614622
name := "Scripted sbt Redux",
615623
libraryDependencies ++= Seq(launcherInterface % "provided"),
624+
libraryDependencies ++= (scalaVersion.value match {
625+
case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin))
626+
case _ => List()
627+
}),
616628
mimaSettings,
617629
scriptedSbtReduxMimaSettings,
618630
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* sbt
3+
* Copyright 2011 - 2018, Lightbend, Inc.
4+
* Copyright 2008 - 2010, Mark Harrah
5+
* Licensed under Apache License 2.0 (see LICENSE)
6+
*/
7+
8+
package sbt.internal
9+
10+
// https://github.com/scala/scala-parallel-collections/issues/22
11+
private[sbt] object CompatParColls {
12+
@com.github.ghik.silencer.silent
13+
val Converters = {
14+
import Compat._
15+
{
16+
import scala.collection.parallel._
17+
CollectionConverters
18+
}
19+
}
20+
object Compat {
21+
object CollectionConverters
22+
}
23+
}

main/src/main/scala/sbt/internal/KeyIndex.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ import sbt.librarymanagement.Configuration
1717

1818
object KeyIndex {
1919
def empty: ExtendableKeyIndex = new KeyIndex0(emptyBuildIndex)
20+
@com.github.ghik.silencer.silent
2021
def apply(
2122
known: Iterable[ScopedKey[_]],
2223
projects: Map[URI, Set[String]],
2324
configurations: Map[String, Seq[Configuration]]
24-
): ExtendableKeyIndex =
25+
): ExtendableKeyIndex = {
26+
import sbt.internal.CompatParColls.Converters._
2527
known.par.foldLeft(base(projects, configurations)) { _ add _ }
28+
}
29+
@com.github.ghik.silencer.silent
2630
def aggregate(
2731
known: Iterable[ScopedKey[_]],
2832
extra: BuildUtil[_],
@@ -37,6 +41,7 @@ object KeyIndex {
3741
* This was a significant serial bottleneck during project loading that we can work around by
3842
* computing the aggregations in parallel and then bulk adding them to the index.
3943
*/
44+
import sbt.internal.CompatParColls.Converters._
4045
val toAggregate = known.par.map {
4146
case key if validID(key.key.label) =>
4247
Aggregation.aggregate(key, ScopeMask(), extra, reverse = true)
@@ -92,6 +97,7 @@ object KeyIndex {
9297
private[sbt] val emptyConfigIndex = new ConfigIndex(Map.empty, Map.empty, emptyAKeyIndex)
9398
private[sbt] val emptyProjectIndex = new ProjectIndex(Map.empty)
9499
private[sbt] val emptyBuildIndex = new BuildIndex(Map.empty)
100+
95101
}
96102
import KeyIndex._
97103

main/src/main/scala/sbt/internal/server/Definition.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ private[sbt] object Definition {
259259
result.future
260260
}
261261

262+
@com.github.ghik.silencer.silent
262263
def lspDefinition(
263264
jsonDefinition: JValue,
264265
requestId: String,
@@ -287,6 +288,7 @@ private[sbt] object Definition {
287288
log.debug(s"symbol $sym")
288289
analyses
289290
.map { analyses =>
291+
import sbt.internal.CompatParColls.Converters._
290292
val locations = analyses.par.flatMap { analysis =>
291293
val selectPotentials = textProcessor.potentialClsOrTraitOrObj(sym)
292294
val classes =

main/src/main/scala/sbt/nio/Settings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ private[sbt] object Settings {
269269
* @return a task definition that retrieves the input files and their file stamps scoped to the
270270
* input key.
271271
*/
272+
@com.github.ghik.silencer.silent
272273
private[sbt] def fileStamps(scopedKey: Def.ScopedKey[_]): Def.Setting[_] = {
274+
import sbt.internal.CompatParColls.Converters._
273275
val scope = scopedKey.scope
274276
addTaskDefinition(Keys.inputFileStamps in scope := {
275277
val cache = (unmanagedFileStampCache in scope).value

scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ class ScriptedRunner {
482482
instances: Int
483483
) = run(baseDir, bufferLog, tests, logger, launchOpts, prescripted, prop, instances, true)
484484

485+
@com.github.ghik.silencer.silent
485486
private[this] def run(
486487
baseDir: File,
487488
bufferLog: Boolean,
@@ -510,7 +511,8 @@ class ScriptedRunner {
510511
val scriptedRunners =
511512
runner.batchScriptedRunner(scriptedTests, addTestFile, groupCount, prop, logger)
512513
if (parallelExecution && instances > 1) {
513-
val parallelRunners = scriptedRunners.toParArray
514+
import sbt.internal.CompatParColls.Converters._
515+
val parallelRunners = scriptedRunners.toArray.par
514516
parallelRunners.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(instances))
515517
runAll(parallelRunners)
516518
} else {
@@ -544,9 +546,12 @@ class ScriptedRunner {
544546
private def reportErrors(errors: GenSeq[String]): Unit =
545547
if (errors.nonEmpty) sys.error(errors.mkString("Failed tests:\n\t", "\n\t", "\n")) else ()
546548

547-
def runAll(toRun: GenSeq[ScriptedTests.TestRunner]): Unit =
549+
def runAll(toRun: Seq[ScriptedTests.TestRunner]): Unit =
548550
reportErrors(toRun.flatMap(test => test.apply().flatten))
549551

552+
def runAll(toRun: scala.collection.parallel.ParSeq[ScriptedTests.TestRunner]): Unit =
553+
reportErrors(toRun.flatMap(test => test.apply().flatten).toList)
554+
550555
@deprecated("No longer used", "1.1.0")
551556
def get(tests: Seq[String], baseDirectory: File, log: Logger): Seq[ScriptedTest] =
552557
get(tests, baseDirectory, _ => true, log)

0 commit comments

Comments
 (0)