Skip to content

Commit

Permalink
Let phases themselves decide whether they have to do anything.
Browse files Browse the repository at this point in the history
Instead of having `Run.rootContext` hard-code the filtering.
  • Loading branch information
sjrd committed Dec 10, 2018
1 parent 660977c commit d222f20
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GenSJSIR extends Phase {
def phaseName: String = "genSJSIR"

def run(implicit ctx: Context): Unit = {
new JSCodeGen().run()
if (ctx.settings.scalajs.value)
new JSCodeGen().run()
}
}
19 changes: 1 addition & 18 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import collection.mutable
import dotty.tools.io.VirtualFile

import scala.util.control.NonFatal
import dotty.tools.backend.sjs

/** A compiler run. Exports various methods to compile source files */
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
Expand All @@ -42,23 +41,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
*/
protected[this] def rootContext(implicit ctx: Context): Context = {
ctx.initialize()(ctx)

val actualPhases = if (ctx.settings.scalajs.value) {
// Remove phases that Scala.js does not want
comp.phases.mapConserve(_.filter {
case _: transform.FunctionalInterfaces => false
case _ => true
}).filter(_.nonEmpty)
} else {
// Remove Scala.js-related phases
comp.phases.mapConserve(_.filter {
case _: sjs.GenSJSIR => false
case _ => true
}).filter(_.nonEmpty)
}

ctx.base.setPhasePlan(actualPhases)

ctx.base.setPhasePlan(comp.phases)
val rootScope = new MutableScope
val bootstrap = ctx.fresh
.setPeriod(Period(comp.nextRunId, FirstPhaseId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class FunctionalInterfaces extends MiniPhase {
val List(implParamTypes) = implType.paramInfoss
val implResultType = implType.resultType

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

0 comments on commit d222f20

Please sign in to comment.