Skip to content

Commit d38d31b

Browse files
committed
Remove ICode
1 parent 72538aa commit d38d31b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+104
-11249
lines changed

src/compiler/scala/tools/ant/Scalac.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
9191
val values = List("namer", "typer", "pickler", "refchecks",
9292
"uncurry", "tailcalls", "specialize", "explicitouter",
9393
"erasure", "lazyvals", "lambdalift", "constructors",
94-
"flatten", "mixin", "delambdafy", "cleanup", "icode", "inliner",
95-
"closelim", "dce", "jvm", "terminal")
94+
"flatten", "mixin", "delambdafy", "cleanup", "icode",
95+
"jvm", "terminal")
9696
}
9797

9898
/** Defines valid values for the `target` property. */

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 11 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package scala
77
package tools
88
package nsc
99

10-
import java.io.{ File, FileOutputStream, PrintWriter, IOException, FileNotFoundException }
10+
import java.io.{ File, IOException, FileNotFoundException }
1111
import java.net.URL
1212
import java.nio.charset.{ Charset, CharsetDecoder, IllegalCharsetNameException, UnsupportedCharsetException }
1313
import scala.collection.{ mutable, immutable }
1414
import io.{ SourceReader, AbstractFile, Path }
15-
import reporters.{ Reporter, ConsoleReporter }
15+
import reporters.{ Reporter }
1616
import util.{ ClassFileLookup, ClassPath, MergedClassPath, StatisticsInfo, returning }
1717
import scala.reflect.ClassTag
1818
import scala.reflect.internal.util.{ ScalaClassLoader, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
@@ -25,11 +25,9 @@ import ast.parser._
2525
import typechecker._
2626
import transform.patmat.PatternMatching
2727
import transform._
28-
import backend.icode.{ ICodes, GenICode, ICodeCheckers }
28+
import backend.icode.ICodes
2929
import backend.{ ScalaPrimitives, JavaPlatform }
3030
import backend.jvm.GenBCode
31-
import backend.opt.{ Inliners, InlineExceptionHandlers, ConstantOptimization, ClosureElimination, DeadCodeElimination }
32-
import backend.icode.analysis._
3331
import scala.language.postfixOps
3432
import scala.tools.nsc.ast.{TreeGen => AstTreeGen}
3533
import scala.tools.nsc.classpath.FlatClassPath
@@ -156,18 +154,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
156154

157155
type SymbolPair = overridingPairs.SymbolPair
158156

159-
// Optimizer components
160-
161-
/** ICode analysis for optimization */
162-
object analysis extends {
163-
val global: Global.this.type = Global.this
164-
} with TypeFlowAnalysis
165-
166-
/** Copy propagation for optimization */
167-
object copyPropagation extends {
168-
val global: Global.this.type = Global.this
169-
} with CopyPropagation
170-
171157
// Components for collecting and generating output
172158

173159
/** Some statistics (normally disabled) set with -Ystatistics */
@@ -590,52 +576,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
590576
val runsRightAfter = None
591577
} with Delambdafy
592578

593-
// phaseName = "icode"
594-
object genicode extends {
595-
val global: Global.this.type = Global.this
596-
val runsAfter = List("cleanup")
597-
val runsRightAfter = None
598-
} with GenICode
599-
600-
// phaseName = "inliner"
601-
object inliner extends {
602-
val global: Global.this.type = Global.this
603-
val runsAfter = List("icode")
604-
val runsRightAfter = None
605-
} with Inliners
606-
607-
// phaseName = "inlinehandlers"
608-
object inlineExceptionHandlers extends {
609-
val global: Global.this.type = Global.this
610-
val runsAfter = List("inliner")
611-
val runsRightAfter = None
612-
} with InlineExceptionHandlers
613-
614-
// phaseName = "closelim"
615-
object closureElimination extends {
616-
val global: Global.this.type = Global.this
617-
val runsAfter = List("inlinehandlers")
618-
val runsRightAfter = None
619-
} with ClosureElimination
620-
621-
// phaseName = "constopt"
622-
object constantOptimization extends {
623-
val global: Global.this.type = Global.this
624-
val runsAfter = List("closelim")
625-
val runsRightAfter = None
626-
} with ConstantOptimization
627-
628-
// phaseName = "dce"
629-
object deadCode extends {
630-
val global: Global.this.type = Global.this
631-
val runsAfter = List("closelim")
632-
val runsRightAfter = None
633-
} with DeadCodeElimination
634-
635579
// phaseName = "bcode"
636580
object genBCode extends {
637581
val global: Global.this.type = Global.this
638-
val runsAfter = List("dce")
582+
val runsAfter = List("cleanup")
639583
val runsRightAfter = None
640584
} with GenBCode
641585

@@ -666,13 +610,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
666610
val global: Global.this.type = Global.this
667611
} with TreeCheckers
668612

669-
/** Icode verification */
670-
object icodeCheckers extends {
671-
val global: Global.this.type = Global.this
672-
} with ICodeCheckers
673-
674-
object icodeChecker extends icodeCheckers.ICodeChecker()
675-
676613
object typer extends analyzer.Typer(
677614
analyzer.NoContext.make(EmptyTree, RootClass, newScope)
678615
)
@@ -705,12 +642,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
705642
mixer -> "mixin composition",
706643
delambdafy -> "remove lambdas",
707644
cleanup -> "platform-specific cleanups, generate reflective calls",
708-
genicode -> "generate portable intermediate code",
709-
inliner -> "optimization: do inlining",
710-
inlineExceptionHandlers -> "optimization: inline exception handlers",
711-
closureElimination -> "optimization: eliminate uncalled closures",
712-
constantOptimization -> "optimization: optimize null and other constants",
713-
deadCode -> "optimization: eliminate dead code",
714645
terminal -> "the last phase during a compilation run"
715646
)
716647

@@ -1049,9 +980,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1049980
@inline final def enteringErasure[T](op: => T): T = enteringPhase(currentRun.erasurePhase)(op)
1050981
@inline final def enteringExplicitOuter[T](op: => T): T = enteringPhase(currentRun.explicitouterPhase)(op)
1051982
@inline final def enteringFlatten[T](op: => T): T = enteringPhase(currentRun.flattenPhase)(op)
1052-
@inline final def enteringIcode[T](op: => T): T = enteringPhase(currentRun.icodePhase)(op)
1053983
@inline final def enteringMixin[T](op: => T): T = enteringPhase(currentRun.mixinPhase)(op)
1054984
@inline final def enteringDelambdafy[T](op: => T): T = enteringPhase(currentRun.delambdafyPhase)(op)
985+
@inline final def enteringJVM[T](op: => T): T = enteringPhase(currentRun.jvmPhase)(op)
1055986
@inline final def enteringPickler[T](op: => T): T = enteringPhase(currentRun.picklerPhase)(op)
1056987
@inline final def enteringSpecialize[T](op: => T): T = enteringPhase(currentRun.specializePhase)(op)
1057988
@inline final def enteringTyper[T](op: => T): T = enteringPhase(currentRun.typerPhase)(op)
@@ -1325,8 +1256,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
13251256
// val superaccessorsPhase = phaseNamed("superaccessors")
13261257
val picklerPhase = phaseNamed("pickler")
13271258
val refchecksPhase = phaseNamed("refchecks")
1328-
// val selectiveanfPhase = phaseNamed("selectiveanf")
1329-
// val selectivecpsPhase = phaseNamed("selectivecps")
13301259
val uncurryPhase = phaseNamed("uncurry")
13311260
// val tailcallsPhase = phaseNamed("tailcalls")
13321261
val specializePhase = phaseNamed("specialize")
@@ -1340,20 +1269,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
13401269
val mixinPhase = phaseNamed("mixin")
13411270
val delambdafyPhase = phaseNamed("delambdafy")
13421271
val cleanupPhase = phaseNamed("cleanup")
1343-
val icodePhase = phaseNamed("icode")
1344-
val inlinerPhase = phaseNamed("inliner")
1345-
val inlineExceptionHandlersPhase = phaseNamed("inlinehandlers")
1346-
val closelimPhase = phaseNamed("closelim")
1347-
val dcePhase = phaseNamed("dce")
1348-
// val jvmPhase = phaseNamed("jvm")
1272+
val jvmPhase = phaseNamed("jvm")
13491273

13501274
def runIsAt(ph: Phase) = globalPhase.id == ph.id
1351-
def runIsAtOptimiz = {
1352-
runIsAt(inlinerPhase) || // listing phases in full for robustness when -Ystop-after has been given.
1353-
runIsAt(inlineExceptionHandlersPhase) ||
1354-
runIsAt(closelimPhase) ||
1355-
runIsAt(dcePhase)
1356-
}
1275+
def runIsAtOptimiz = runIsAt(jvmPhase)
13571276

13581277
isDefined = true
13591278

@@ -1416,8 +1335,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
14161335

14171336
if (canCheck) {
14181337
phase = globalPhase
1419-
if (globalPhase.id >= icodePhase.id) icodeChecker.checkICodes()
1420-
else treeChecker.checkTrees()
1338+
/// !!! This is probably not what we want ...
1339+
if (globalPhase.id <= delambdafyPhase.id)
1340+
treeChecker.checkTrees()
14211341
}
14221342
}
14231343

@@ -1498,14 +1418,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
14981418

14991419
// progress update
15001420
informTime(globalPhase.description, startTime)
1501-
val shouldWriteIcode = (
1502-
(settings.writeICode.isSetByUser && (settings.writeICode containsPhase globalPhase))
1503-
|| (!settings.Xprint.doAllPhases && (settings.Xprint containsPhase globalPhase) && runIsAtOptimiz)
1504-
)
1505-
if (shouldWriteIcode) {
1506-
// Write *.icode files when -Xprint-icode or -Xprint:<some-optimiz-phase> was given.
1507-
writeICode()
1508-
} else if ((settings.Xprint containsPhase globalPhase) || settings.printLate && runIsAt(cleanupPhase)) {
1421+
if ((settings.Xprint containsPhase globalPhase) || settings.printLate && runIsAt(cleanupPhase)) {
15091422
// print trees
15101423
if (settings.Xshowtrees || settings.XshowtreesCompact || settings.XshowtreesStringified) nodePrinters.printAll()
15111424
else printAllUnits()
@@ -1670,30 +1583,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
16701583
/** Returns the file with the given suffix for the given class. Used for icode writing. */
16711584
def getFile(clazz: Symbol, suffix: String): File = getFile(clazz.sourceFile, clazz.fullName split '.', suffix)
16721585

1673-
private def writeICode() {
1674-
val printer = new icodes.TextPrinter(writer = null, icodes.linearizer)
1675-
icodes.classes.values foreach { cls =>
1676-
val file = {
1677-
val module = if (cls.symbol.hasModuleFlag) "$" else ""
1678-
val faze = if (settings.debug) phase.name else f"${phase.id}%02d" // avoid breaking windows build with long filename
1679-
getFile(cls.symbol, s"$module-$faze.icode")
1680-
}
1681-
1682-
try {
1683-
val stream = new FileOutputStream(file)
1684-
printer.setWriter(new PrintWriter(stream, true))
1685-
try
1686-
printer.printClass(cls)
1687-
finally
1688-
stream.close()
1689-
informProgress(s"wrote $file")
1690-
} catch {
1691-
case e: IOException =>
1692-
if (settings.debug) e.printStackTrace()
1693-
globalError(s"could not write file $file")
1694-
}
1695-
}
1696-
}
16971586
def createJavadoc = false
16981587
}
16991588

src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ abstract class ScalaPrimitives {
3131

3232
import global._
3333
import definitions._
34-
import global.icodes._
34+
import global.icodes.{TypeKind, toTypeKind}
35+
import global.icodes.{BOOL, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT, REFERENCE, ARRAY}
3536

3637
// Arithmetic unary operations
3738
final val POS = 1 // +x
@@ -549,10 +550,8 @@ abstract class ScalaPrimitives {
549550
def isPrimitive(sym: Symbol): Boolean = primitives contains sym
550551

551552
/** Return the code for the given symbol. */
552-
def getPrimitive(sym: Symbol): Int = {
553-
assert(isPrimitive(sym), "Unknown primitive " + sym)
554-
primitives(sym)
555-
}
553+
def getPrimitive(sym: Symbol): Int =
554+
primitives.getOrElse(sym, throw new AssertionError(s"Unknown primitive $sym"))
556555

557556
/**
558557
* Return the primitive code of the given operation. If the

src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import scala.collection.mutable
1919
*
2020
* @author Martin Odersky
2121
* @version 1.0
22-
* @see [[scala.tools.nsc.backend.icode.Linearizers]]
2322
*/
2423
trait WorklistAlgorithm {
2524
type Elem

0 commit comments

Comments
 (0)