Skip to content

Commit e0dbba6

Browse files
authored
Merge pull request #6556 from eed3si9n/wip/taskdyn
Avoid creating ScalaInstance when not used
2 parents 2e54624 + fb99391 commit e0dbba6

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ThisBuild / scalaVersion := "2.12.8"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package hello
2+
/** Hello, world! */
3+
object Hello {
4+
def main(args: Array[String]): Unit = {
5+
println("Hello Scala 2")
6+
}
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> run
2+
> doc

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ object DottyPlugin extends AutoPlugin {
148148
}
149149
)
150150

151+
// https://github.com/sbt/sbt/issues/3110
152+
val Def = sbt.Def
151153
override def projectSettings: Seq[Setting[_]] = {
152154
Seq(
153155
isDotty := scalaVersion.value.startsWith("0."),
@@ -299,13 +301,10 @@ object DottyPlugin extends AutoPlugin {
299301
allJars
300302
)
301303
}
302-
else Def.task {
303-
// This should really be `old` with `val old = scalaInstance.value`
304-
// above, except that this would force the original definition of the
305-
// `scalaInstance` task to be computed when `isDotty` is true, which
306-
// would fail because `managedScalaInstance` is false.
307-
Defaults.scalaInstanceTask.value
308-
}
304+
else
305+
// This dereferences the Initialize graph, but keeps the Task unevaluated,
306+
// so its effect gets fired only when isDotty.value evaluates to false. yay monad.
307+
Def.valueStrict { scalaInstance.taskValue }
309308
}.value,
310309

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

0 commit comments

Comments
 (0)