Skip to content

Commit

Permalink
Work around Scala parallel collections situation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eed3si9n committed Jan 10, 2021
1 parent cb4c1e7 commit f8c1582
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
12 changes: 12 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def commonBaseSettings: Seq[Setting[_]] = Def.settings(
crossScalaVersions := Seq(baseScalaVersion),
publishArtifact in Test := false,
fork in run := true,
libraryDependencies ++= {
if (autoScalaLibrary.value) List(silencerLib)
else Nil
},
)
def commonSettings: Seq[Setting[_]] =
commonBaseSettings :+
Expand Down Expand Up @@ -324,6 +328,10 @@ val logicProj = (project in file("internal") / "util-logic")
testedBaseSettings,
name := "Logic",
mimaSettings,
libraryDependencies ++= (scalaVersion.value match {
case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin))
case _ => List()
}),
)

// defines Java structures used across Scala versions, such as the API structures and relationships extracted by
Expand Down Expand Up @@ -613,6 +621,10 @@ lazy val scriptedSbtReduxProj = (project in file("scripted-sbt-redux"))
baseSettings,
name := "Scripted sbt Redux",
libraryDependencies ++= Seq(launcherInterface % "provided"),
libraryDependencies ++= (scalaVersion.value match {
case v if v.startsWith("2.12.") => List(compilerPlugin(silencerPlugin))
case _ => List()
}),
mimaSettings,
scriptedSbtReduxMimaSettings,
)
Expand Down
23 changes: 23 additions & 0 deletions main/src/main/scala/sbt/internal/CompatParColls.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/

package sbt.internal

// https://github.com/scala/scala-parallel-collections/issues/22
private[sbt] object CompatParColls {
@com.github.ghik.silencer.silent
val Converters = {
import Compat._
{
import scala.collection.parallel._
CollectionConverters
}
}
object Compat {
object CollectionConverters
}
}
8 changes: 7 additions & 1 deletion main/src/main/scala/sbt/internal/KeyIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ import sbt.librarymanagement.Configuration

object KeyIndex {
def empty: ExtendableKeyIndex = new KeyIndex0(emptyBuildIndex)
@com.github.ghik.silencer.silent
def apply(
known: Iterable[ScopedKey[_]],
projects: Map[URI, Set[String]],
configurations: Map[String, Seq[Configuration]]
): ExtendableKeyIndex =
): ExtendableKeyIndex = {
import sbt.internal.CompatParColls.Converters._
known.par.foldLeft(base(projects, configurations)) { _ add _ }
}
@com.github.ghik.silencer.silent
def aggregate(
known: Iterable[ScopedKey[_]],
extra: BuildUtil[_],
Expand All @@ -37,6 +41,7 @@ object KeyIndex {
* This was a significant serial bottleneck during project loading that we can work around by
* computing the aggregations in parallel and then bulk adding them to the index.
*/
import sbt.internal.CompatParColls.Converters._
val toAggregate = known.par.map {
case key if validID(key.key.label) =>
Aggregation.aggregate(key, ScopeMask(), extra, reverse = true)
Expand Down Expand Up @@ -92,6 +97,7 @@ object KeyIndex {
private[sbt] val emptyConfigIndex = new ConfigIndex(Map.empty, Map.empty, emptyAKeyIndex)
private[sbt] val emptyProjectIndex = new ProjectIndex(Map.empty)
private[sbt] val emptyBuildIndex = new BuildIndex(Map.empty)

}
import KeyIndex._

Expand Down
2 changes: 2 additions & 0 deletions main/src/main/scala/sbt/internal/server/Definition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private[sbt] object Definition {
result.future
}

@com.github.ghik.silencer.silent
def lspDefinition(
jsonDefinition: JValue,
requestId: String,
Expand Down Expand Up @@ -287,6 +288,7 @@ private[sbt] object Definition {
log.debug(s"symbol $sym")
analyses
.map { analyses =>
import sbt.internal.CompatParColls.Converters._
val locations = analyses.par.flatMap { analysis =>
val selectPotentials = textProcessor.potentialClsOrTraitOrObj(sym)
val classes =
Expand Down
2 changes: 2 additions & 0 deletions main/src/main/scala/sbt/nio/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ private[sbt] object Settings {
* @return a task definition that retrieves the input files and their file stamps scoped to the
* input key.
*/
@com.github.ghik.silencer.silent
private[sbt] def fileStamps(scopedKey: Def.ScopedKey[_]): Def.Setting[_] = {
import sbt.internal.CompatParColls.Converters._
val scope = scopedKey.scope
addTaskDefinition(Keys.inputFileStamps in scope := {
val cache = (unmanagedFileStampCache in scope).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ class ScriptedRunner {
instances: Int
) = run(baseDir, bufferLog, tests, logger, launchOpts, prescripted, prop, instances, true)

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

def runAll(toRun: GenSeq[ScriptedTests.TestRunner]): Unit =
def runAll(toRun: Seq[ScriptedTests.TestRunner]): Unit =
reportErrors(toRun.flatMap(test => test.apply().flatten))

def runAll(toRun: scala.collection.parallel.ParSeq[ScriptedTests.TestRunner]): Unit =
reportErrors(toRun.flatMap(test => test.apply().flatten).toList)

@deprecated("No longer used", "1.1.0")
def get(tests: Seq[String], baseDirectory: File, log: Logger): Seq[ScriptedTest] =
get(tests, baseDirectory, _ => true, log)
Expand Down

0 comments on commit f8c1582

Please sign in to comment.