Skip to content

Avoid creating ScalaInstance when not used #6556

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

Merged
merged 4 commits into from
May 28, 2019
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
1 change: 1 addition & 0 deletions sbt-dotty/sbt-test/sbt-dotty/scala2/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ThisBuild / scalaVersion := "2.12.8"
1 change: 1 addition & 0 deletions sbt-dotty/sbt-test/sbt-dotty/scala2/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hello
/** Hello, world! */
object Hello {
def main(args: Array[String]): Unit = {
println("Hello Scala 2")
}
}
2 changes: 2 additions & 0 deletions sbt-dotty/sbt-test/sbt-dotty/scala2/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> run
> doc
13 changes: 6 additions & 7 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ object DottyPlugin extends AutoPlugin {
}
)

// https://github.com/sbt/sbt/issues/3110
val Def = sbt.Def
override def projectSettings: Seq[Setting[_]] = {
Seq(
isDotty := scalaVersion.value.startsWith("0."),
Expand Down Expand Up @@ -293,13 +295,10 @@ object DottyPlugin extends AutoPlugin {
allJars
)
}
else Def.task {
// This should really be `old` with `val old = scalaInstance.value`
// above, except that this would force the original definition of the
// `scalaInstance` task to be computed when `isDotty` is true, which
// would fail because `managedScalaInstance` is false.
Defaults.scalaInstanceTask.value
}
else
// This dereferences the Initialize graph, but keeps the Task unevaluated,
// so its effect gets fired only when isDotty.value evaluates to false. yay monad.
Def.valueStrict { scalaInstance.taskValue }
}.value,

// Because managedScalaInstance is false, sbt won't add the standard library to our dependencies for us
Expand Down