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

Add -Ybackend-parallelism and -release #76

Merged
merged 1 commit into from
May 6, 2022
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 @@ -28,6 +28,7 @@ object ScalaVersion {
val V2_11_11 = ScalaVersion(2, 11, 11)
val V2_12_0 = ScalaVersion(2, 12, 0)
val V2_12_2 = ScalaVersion(2, 12, 2)
val V2_12_5 = ScalaVersion(2, 12, 5)
val V2_13_0 = ScalaVersion(2, 13, 0)
val V2_13_2 = ScalaVersion(2, 13, 2)
val V2_13_3 = ScalaVersion(2, 13, 3)
Expand Down
37 changes: 36 additions & 1 deletion src/main/scala/io/github/davidgregory084/ScalacOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ trait ScalacOptions {
val feature =
new ScalacOption(List("-feature"))

/** Compile for a specific version of the Java platform. Supported targets: 8, 9, ..., 17, 18.
*
* The release flag is supported only on JDK 9 and above, since it relies on the functionality
* provided in [[http://openjdk.java.net/jeps/247 JEP-247: Compile for Older Platform Versions]].
*/
def release(version: String) =
new ScalacOption(List("-release", version), version => version > V2_12_5)
Comment on lines +47 to +48
Copy link
Member

Choose a reason for hiding this comment

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

Note this flag has been renamed to -java-output-version in 3.1.2 as of scala/scala3#14606.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah cool, I will spend some time next week to understand everything that has happened there. It looks like they have left the old names in as aliases luckily.


/** Enable features that will be available in a future version of Scala, for purposes of early
* migration and alpha testing.
*/
Expand Down Expand Up @@ -344,6 +352,15 @@ trait ScalacOptions {
def privateOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
new ScalacOption(List(s"-Y$name"), isSupported)

/** Private options (-Y)
*/
def privateOption(
name: String,
additionalTokens: List[String],
isSupported: ScalaVersion => Boolean
) =
new ScalacOption(s"-Y$name" :: additionalTokens, isSupported)

/** Produce an error if an argument list is modified to match the receiver.
*/
val privateNoAdaptedArgs =
Expand All @@ -357,13 +374,31 @@ trait ScalacOptions {

/** Enables support for higher order unification in type constructor inference.
*
* Initially provided as a compiler option in the 2.12.x series to fix the infamous [[https://github.com/scala/bug/issues/2712 SI-2712]].
* Initially provided as a compiler option in the 2.12.x series to fix the infamous
* [[https://github.com/scala/bug/issues/2712 SI-2712]].
*
* Enabled by default in 2.13.0+ and no longer accepted by the compiler as an option.
*/
val privatePartialUnification =
privateOption("partial-unification", version => version.isBetween(V2_11_11, V2_13_0))

/** Configures the number of worker threads for the compiler backend.
*
* As of 2.12.5 the compiler can serialize bytecode, perform method-local optimisations and write
* class files in parallel.
*
* @param threads
* the number of worker threads. Default: 8, or the value returned by
* [[java.lang.Runtime#availableProcessors]] if fewer than 8.
*/
def privateBackendParallelism(
threads: Int = math.min(Runtime.getRuntime.availableProcessors, 8)
) = privateOption(
"backend-parallelism",
List(threads.toString),
version => version.isBetween(V2_12_5, V3_0_0)
)

/** Private warning options (-Ywarn)
*/
def privateWarnOption(name: String, isSupported: ScalaVersion => Boolean = _ => true) =
Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/io/github/davidgregory084/TpolecatPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ object TpolecatPlugin extends AutoPlugin {
override def projectSettings: Seq[Setting[_]] = Seq(
Def.derive(
scalacOptions := {
val previous = scalacOptions.value
val scalaV = scalaVersion.value
val filters = scalacOptionsFor(scalaV, tpolecatExcludeOptions.value).toSet
val newOptions = scalacOptionsFor(scalaV, tpolecatScalacOptions.value)
(previous ++ newOptions).filterNot(filters).distinct
val pluginOptions = tpolecatScalacOptions.value
val pluginExcludes = tpolecatExcludeOptions.value
val selectedOptions = pluginOptions.diff(pluginExcludes)
scalacOptionsFor(scalaVersion.value, selectedOptions)
}
),
Def.derive(
Expand Down
32 changes: 17 additions & 15 deletions src/sbt-test/sbt-tpolecat/scalacOptions/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ tpolecatDevModeOptions ++= Set(
ScalacOptions.source3Migration
)

tpolecatReleaseModeOptions ++= ScalacOptions.optimizerOptions("**")
tpolecatReleaseModeOptions ++= {
ScalacOptions.optimizerOptions("**") +
ScalacOptions.release("8") +
ScalacOptions.privateBackendParallelism(8)
}

val Scala211Options =
Seq(
Expand Down Expand Up @@ -225,17 +229,25 @@ TaskKey[Unit]("checkReleaseMode") := {
"-Xfatal-warnings",
"-opt:l:method",
"-opt:l:inline",
"-opt-inline-from:**"
"-opt-inline-from:**",
"-release",
"8",
"-Ybackend-parallelism",
"8"
)
case Scala213 =>
Scala213Options ++ Seq(
"-Xfatal-warnings",
"-opt:l:method",
"-opt:l:inline",
"-opt-inline-from:**"
"-opt-inline-from:**",
"-release",
"8",
"-Ybackend-parallelism",
"8"
)
case Scala30 => Scala30Options ++ Seq("-Xfatal-warnings")
case Scala31 => Scala31Options ++ Seq("-Xfatal-warnings")
case Scala30 => Scala30Options ++ Seq("-Xfatal-warnings", "-release", "8")
case Scala31 => Scala31Options ++ Seq("-Xfatal-warnings", "-release", "8")
}

val actualOptions = scalacOptions.value
Expand Down Expand Up @@ -266,13 +278,3 @@ TaskKey[Unit]("checkThisProjectScalacOptions") := {
val options = (Compile / scalacOptions).value
assert(options.contains("non-existent-key"), "Scope ThisProject was ignored")
}

addCommandAlias(
"addScalacOptionsToThisBuild",
"set ThisBuild / scalacOptions += \"non-existent-key-2\""
)

TaskKey[Unit]("checkThisBuildScalacOptions") := {
val options = (Compile / scalacOptions).value
assert(options.contains("non-existent-key-2"), "Scope ThisBuild was ignored")
}
5 changes: 1 addition & 4 deletions src/sbt-test/sbt-tpolecat/scalacOptions/test
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
> +compile
# Check console options
> +checkConsoleScalacOptions
# Check ThisProject
# Check user can still append their own scalacOptions
> addScalacOptionsToThisProject
> +checkThisProjectScalacOptions
# Check ThisBuild
> addScalacOptionsToThisBuild
> +checkThisBuildScalacOptions