Skip to content

Commit d222f20

Browse files
committed
Let phases themselves decide whether they have to do anything.
Instead of having `Run.rootContext` hard-code the filtering.
1 parent 660977c commit d222f20

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class GenSJSIR extends Phase {
99
def phaseName: String = "genSJSIR"
1010

1111
def run(implicit ctx: Context): Unit = {
12-
new JSCodeGen().run()
12+
if (ctx.settings.scalajs.value)
13+
new JSCodeGen().run()
1314
}
1415
}

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import collection.mutable
2727
import dotty.tools.io.VirtualFile
2828

2929
import scala.util.control.NonFatal
30-
import dotty.tools.backend.sjs
3130

3231
/** A compiler run. Exports various methods to compile source files */
3332
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
@@ -42,23 +41,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
4241
*/
4342
protected[this] def rootContext(implicit ctx: Context): Context = {
4443
ctx.initialize()(ctx)
45-
46-
val actualPhases = if (ctx.settings.scalajs.value) {
47-
// Remove phases that Scala.js does not want
48-
comp.phases.mapConserve(_.filter {
49-
case _: transform.FunctionalInterfaces => false
50-
case _ => true
51-
}).filter(_.nonEmpty)
52-
} else {
53-
// Remove Scala.js-related phases
54-
comp.phases.mapConserve(_.filter {
55-
case _: sjs.GenSJSIR => false
56-
case _ => true
57-
}).filter(_.nonEmpty)
58-
}
59-
60-
ctx.base.setPhasePlan(actualPhases)
61-
44+
ctx.base.setPhasePlan(comp.phases)
6245
val rootScope = new MutableScope
6346
val bootstrap = ctx.fresh
6447
.setPeriod(Period(comp.nextRunId, FirstPhaseId))

compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class FunctionalInterfaces extends MiniPhase {
3333
val List(implParamTypes) = implType.paramInfoss
3434
val implResultType = implType.resultType
3535

36-
if (defn.isSpecializableFunction(cls, implParamTypes, implResultType)) {
36+
if (defn.isSpecializableFunction(cls, implParamTypes, implResultType) &&
37+
!ctx.settings.scalajs.value) { // never do anything for Scala.js, but do this test as late as possible not to slow down Scala/JVM
3738
val names = ctx.atPhase(ctx.erasurePhase) {
3839
implicit ctx => cls.typeParams.map(_.name)
3940
}

0 commit comments

Comments
 (0)