8000 Squash: CheckingPhase is the *previous* phase now. · scala-js/scala-js@b341cc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit b341cc9

Browse files
committed
Squash: CheckingPhase is the *previous* phase now.
1 parent cb01bde commit b341cc9

File tree

12 files changed

+48
-58
lines changed

12 files changed

+48
-58
lines changed

linker/shared/src/main/scala/org/scalajs/linker/analyzer/InfoLoader.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ private[analyzer] object InfoLoader {
8080
if (!version.sameVersion(newVersion)) {
8181
version = newVersion
8282
info = irLoader.loadClassDef(className).map { tree =>
83-
for (nextPhase <- checkIRFor) {
84-
val errorCount = ClassDefChecker.check(tree, nextPhase, logger)
83+
for (previousPhase <- checkIRFor) {
84+
val errorCount = ClassDefChecker.check(tree, previousPhase, logger)
8585
if (errorCount != 0) {
86-
if (nextPhase == CheckingPhase.BaseLinker) {
86+
if (previousPhase == CheckingPhase.Compiler) {
8787
throw new LinkingException(
8888
s"There were $errorCount ClassDef checking errors.")
8989
} else {

linker/shared/src/main/scala/org/scalajs/linker/checker/CheckingPhase.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
package org.scalajs.linker.checker
1414

15-
/** A phase *before which* we are checking IR for.
15+
/** A phase *after which* we are checking IR.
1616
*
1717
* When checking IR (with `ClassDefChecker` or `IRChecker`), different nodes
1818
* and transients are allowed between different phases. The `CheckingPhase`
19-
* records the *next* phase to run after the check. We are therefore checking
20-
* that the IR is a valid *input* to the target phase.
19+
* records the *previous* phase to run before the check. We are therefore
20+
* checking that the IR is a valid *output* to the target phase.
2121
*/
2222
sealed abstract class CheckingPhase
2323

2424
object CheckingPhase {
25+
case object Compiler extends CheckingPhase
2526
case object BaseLinker extends CheckingPhase
2627
case object Optimizer extends CheckingPhase
27-
case object Emitter extends CheckingPhase
2828
}

linker/shared/src/main/scala/org/scalajs/linker/checker/ClassDefChecker.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ import org.scalajs.linker.standard.LinkedClass
2828

2929
/** Checker for the validity of the IR. */
3030
private final class ClassDefChecker(classDef: ClassDef,
31-
nextPhase: CheckingPhase, reporter: ErrorReporter) {
31+
previousPhase: CheckingPhase, reporter: ErrorReporter) {
3232
import ClassDefChecker._
3333

3434
import reporter.reportError
3535

36-
private val featureSet = FeatureSet.supportedBy(nextPhase)
36+
private val featureSet = FeatureSet.allowedAfter(previousPhase)
3737

3838
private[this] val isJLObject = classDef.name.name == ObjectClass
3939

@@ -1037,13 +1037,13 @@ object ClassDefChecker {
10371037
*
10381038
* @return Count of IR checking errors (0 in case of success)
10391039
*/
1040-
def check(classDef: ClassDef, nextPhase: CheckingPhase, logger: Logger): Int = {
1040+
def check(classDef: ClassDef, previousPhase: CheckingPhase, logger: Logger): Int = {
10411041
val reporter = new LoggerErrorReporter(logger)
1042-
new ClassDefChecker(classDef, nextPhase, reporter).checkClassDef()
1042+
new ClassDefChecker(classDef, previousPhase, reporter).checkClassDef()
10431043
reporter.errorCount
10441044
}
10451045

1046-
def check(linkedClass: LinkedClass, nextPhase: CheckingPhase, logger: Logger): Int = {
1046+
def check(linkedClass: LinkedClass, previousPhase: CheckingPhase, logger: Logger): Int = {
10471047
// Rebuild a ClassDef out of the LinkedClass
10481048
import linkedClass._
10491049
implicit val pos = linkedClass.pos
@@ -1064,7 +1064,7 @@ object ClassDefChecker {
10641064
topLevelExportDefs = Nil
10651065
)(optimizerHints)
10661066

1067-
check(classDef, nextPhase, logger)
1067+
check(classDef, previousPhase, logger)
10681068
}
10691069

10701070
private class Env(

linker/shared/src/main/scala/org/scalajs/linker/checker/FeatureSet.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ private[checker] object FeatureSet {
6969
private val Optimized =
7070
OptimizedTransients | Records | RelaxedCtorBodies
7171

72-
/** The set of features supported (as input) by the given phase. */
73-
def supportedBy(phase: CheckingPhase): FeatureSet = phase match {
74-
case BaseLinker => Empty
75-
case Optimizer => Linked
76-
case Emitter => Linked | Optimized
72+
/** The set of features allowed as output of the given phase. */
73+
def allowedAfter(phase: CheckingPhase): FeatureSet = phase match {
74+
case Compiler => Empty
75+
case BaseLinker => Linked
76+
case Optimizer => Linked | Optimized
7777
}
7878
}

linker/shared/src/main/scala/org/scalajs/linker/checker/IRChecker.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import org.scalajs.linker.checker.ErrorReporter._
2929

3030
/** Checker for the validity of the IR. */
3131
private final class IRChecker(unit: LinkingUnit, reporter: ErrorReporter,
32-
nextPhase: CheckingPhase) {
32+
previousPhase: CheckingPhase) {
3333

3434
import IRChecker._
3535
import reporter.reportError
3636

37-
private val featureSet = FeatureSet.supportedBy(nextPhase)
37+
private val featureSet = FeatureSet.allowedAfter(previousPhase)
3838

3939
private val classes: mutable.Map[ClassName, CheckedClass] = {
4040
val tups = for (classDef <- unit.classDefs) yield {
@@ -928,9 +928,9 @@ object IRChecker {
928928
*
929929
* @return Count of IR checking errors (0 in case of success)
930930
*/
931-
def check(unit: LinkingUnit, logger: Logger, nextPhase: CheckingPhase): Int = {
931+
def check(unit: LinkingUnit, logger: Logger, previousPhase: CheckingPhase): Int = {
932932
val reporter = new LoggerErrorReporter(logger)
933-
new IRChecker(unit, reporter, nextPhase).check()
933+
new IRChecker(unit, reporter, previousPhase).check()
934934
reporter.errorCount
935935
}
936936
}

linker/shared/src/main/scala/org/scalajs/linker/frontend/BaseLinker.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ import Analysis._
3232
/** Links the information from [[interface.IRFile IRFile]]s into
3333
* [[standard.LinkedClass LinkedClass]]es. Does a dead code elimination pass.
3434
*/
35-
final class BaseLinker(config: CommonPhaseConfig, checkIRFor: Option[CheckingPhase]) {
35+
final class BaseLinker(config: CommonPhaseConfig, checkIR: Boolean) {
3636
import BaseLinker._
3737

3838
private val irLoader = new FileIRLoader
3939
private val analyzer = {
40-
// Irrespective of the next phase, the analyzer checks IR as *input* to the BaseLinker
41-
val checkIRForMe = checkIRFor.map(_ => CheckingPhase.BaseLinker)
42-
new Analyzer(config, initial = true, checkIRFor = checkIRForMe, failOnError = true, irLoader)
40+
val checkIRFor = Some(CheckingPhase.Compiler).filter(_ => checkIR)
41+
new Analyzer(config, initial = true, checkIRFor, failOnError = true, irLoader)
4342
}
4443
private val methodSynthesizer = new MethodSynthesizer(irLoader)
4544

@@ -57,9 +56,9 @@ final class BaseLinker(config: CommonPhaseConfig, checkIRFor: Option[CheckingPha
5756
assemble(moduleInitializers, analysis)
5857
}
5958
} yield {
60-
for (nextPhase <- checkIRFor) {
59+
if (checkIR) {
6160
logger.time("Linker: Check IR") {
62-
val errorCount = IRChecker.check(linkResult, logger, nextPhase)
61+
val errorCount = IRChecker.check(linkResult, logger, CheckingPhase.BaseLinker)
6362
if (errorCount != 0) {
6463
throw new LinkingException(
6564
s"There were $errorCount IR checking errors.")

linker/shared/src/main/scala/org/scalajs/linker/frontend/LinkerFrontendImpl.scala

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import scala.concurrent._
1616

1717
import org.scalajs.logging.Logger
1818

19-
import org.scalajs.linker.checker.CheckingPhase
2019
import org.scalajs.linker.interface._
2120
import org.scalajs.linker.standard._
2221
import org.scalajs.linker.frontend.optimizer.IncOptimizer
@@ -38,22 +37,14 @@ final class LinkerFrontendImpl private (config: LinkerFrontendImpl.Config)
3837
/** Core specification that this linker frontend implements. */
3938
val coreSpec = config.commonConfig.coreSpec
4039

41-
private def ifCheckIR(phase: CheckingPhase): Option[CheckingPhase] =
42-
if (config.checkIR) Some(phase)
43-
else None
44-
45-
private[this] val linker: BaseLinker = {
46-
val nextPhase =
47-
if (config.optimizer) CheckingPhase.Optimizer
48-
else CheckingPhase.Emitter
49-
new BaseLinker(config.commonConfig, ifCheckIR(nextPhase))
50-
}
40+
private[this] val linker: BaseLinker =
41+
new BaseLinker(config.commonConfig, config.checkIR)
5142

5243
private[this] val optOptimizer: Option[IncOptimizer] =
5344
LinkerFrontendImplPlatform.createOptimizer(config)
5445

5546
private[this] val refiner: Refiner =
56-
new Refiner(config.commonConfig, ifCheckIR(CheckingPhase.Emitter))
47+
new Refiner(config.commonConfig, config.checkIR)
5748

5849
private[this] val splitter: ModuleSplitter = config.moduleSplitStyle match {
5950
case ModuleSplitStyle.FewestModules => ModuleSplitter.fewestModules()

linker/shared/src/main/scala/org/scalajs/linker/frontend/Refiner.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ import org.scalajs.linker.standard.ModuleSet.ModuleID
2727
import org.scalajs.linker.analyzer._
2828

2929
/** Does a dead code elimination pass on a [[LinkingUnit]]. */
30-
final class Refiner(config: CommonPhaseConfig, checkIRFor: Option[CheckingPhase]) {
30+
final class Refiner(config: CommonPhaseConfig, checkIR: Boolean) {
3131
import Refiner._
3232

3333
private val irLoader = new ClassDefIRLoader
34-
private val analyzer =
35-
new Analyzer(config, initial = false, checkIRFor = checkIRFor, failOnError = true, irLoader)
34+
private val analyzer = {
35+
val checkIRFor = Some(CheckingPhase.Optimizer).filter(_ => checkIR)
36+
new Analyzer(config, initial = false, checkIRFor, failOnError = true, irLoader)
37+
}
3638

37-
/* TODO: Remove this and replace with `checkIRFor` once the optimizer generates
39+
/* TODO: Remove this and replace with `checkIR` once the optimizer generates
3840
* well-typed IR with runtime longs.
3941
*/
40-
private val checkIRForAmended = {
42+
private val shouldRunIRChecker = {
4143
val optimizerUsesRuntimeLong =
4244
!config.coreSpec.esFeatures.allowBigIntsForLongs &&
4345
!config.coreSpec.targetIsWebAssembly
44-
checkIRFor.filter(_ => !optimizerUsesRuntimeLong)
46+
checkIR && !optimizerUsesRuntimeLong
4547
}
4648

4749
def refine(classDefs: Seq[(ClassDef, Version)],
@@ -77,9 +79,9 @@ final class Refiner(config: CommonPhaseConfig, checkIRFor: Option[CheckingPhase]
7779
linkedTopLevelExports.flatten.toList, moduleInitializers, globalInfo)
7880
}
7981

80-
for (nextPhase <- checkIRForAmended) {
82+
if (shouldRunIRChecker) {
8183
logger.time("Refiner: Check IR") {
82-
10000 val errorCount = IRChecker.check(result, logger, nextPhase)
84+
val errorCount = IRChecker.check(result, logger, CheckingPhase.Optimizer)
8385
if (errorCount != 0) {
8486
throw new AssertionError(
8587
s"There were $errorCount IR checking errors after optimization (this is a Scala.js bug)")

linker/shared/src/test/scala/org/scalajs/linker/BaseLinkerTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class BaseLinkerTest {
8686

8787
for (moduleSet <- linkToModuleSet(classDefs, MainTestModuleInitializers, config = config)) yield {
8888
val clazz = findClass(moduleSet, BoxedIntegerClass).get
89-
val nextPhase = CheckingPhase.Emitter
90-
val errorCount = ClassDefChecker.check(clazz, nextPhase,
89+
val previousPhase = CheckingPhase.BaseLinker
90+
val errorCount = ClassDefChecker.check(clazz, previousPhase,
9191
new ScalaConsoleLogger(Level.Error))
9292
assertEquals(0, errorCount)
9393
}

linker/shared/src/test/scala/org/scalajs/linker/IRCheckerTest.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.scalajs.logging._
2727

2828
import org.scalajs.junit.async._
2929

30-
import org.scalajs.linker.checker.CheckingPhase
3130
import org.scalajs.linker.interface._
3231
import org.scalajs.linker.interface.unstable.IRFileImpl
3332
import org.scalajs.linker.standard._
@@ -470,8 +469,7 @@ object IRCheckerTest {
470469

471470
TestIRRepo.minilib.flatMap { stdLibFiles =>
472471
if (postOptimizer) {
473-
val checkIRFor = Some(CheckingPhase.Emitter)
474-
val refiner = new Refiner(CommonPhaseConfig.fromStandardConfig(config), checkIRFor)
472+
val refiner = new Refiner(CommonPhaseConfig.fromStandardConfig(config), checkIR = true)
475473

476474
Future.traverse(stdLibFiles)(f => IRFileImpl.fromIRFile(f).tree).flatMap { stdLibClassDefs =>
477475
val allClassDefs = (

0 commit comments

Comments
 (0)
0