@@ -7,12 +7,12 @@ package scala
7
7
package tools
8
8
package nsc
9
9
10
- import java .io .{ File , FileOutputStream , PrintWriter , IOException , FileNotFoundException }
10
+ import java .io .{ File , IOException , FileNotFoundException }
11
11
import java .net .URL
12
12
import java .nio .charset .{ Charset , CharsetDecoder , IllegalCharsetNameException , UnsupportedCharsetException }
13
13
import scala .collection .{ mutable , immutable }
14
14
import io .{ SourceReader , AbstractFile , Path }
15
- import reporters .{ Reporter , ConsoleReporter }
15
+ import reporters .{ Reporter }
16
16
import util .{ ClassFileLookup , ClassPath , MergedClassPath , StatisticsInfo , returning }
17
17
import scala .reflect .ClassTag
18
18
import scala .reflect .internal .util .{ ScalaClassLoader , SourceFile , NoSourceFile , BatchSourceFile , ScriptSourceFile }
@@ -25,11 +25,9 @@ import ast.parser._
25
25
import typechecker ._
26
26
import transform .patmat .PatternMatching
27
27
import transform ._
28
- import backend .icode .{ ICodes , GenICode , ICodeCheckers }
28
+ import backend .icode .ICodes
29
29
import backend .{ ScalaPrimitives , JavaPlatform }
30
30
import backend .jvm .GenBCode
31
- import backend .opt .{ Inliners , InlineExceptionHandlers , ConstantOptimization , ClosureElimination , DeadCodeElimination }
32
- import backend .icode .analysis ._
33
31
import scala .language .postfixOps
34
32
import scala .tools .nsc .ast .{TreeGen => AstTreeGen }
35
33
import scala .tools .nsc .classpath .FlatClassPath
@@ -156,18 +154,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
156
154
157
155
type SymbolPair = overridingPairs.SymbolPair
158
156
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
-
171
157
// Components for collecting and generating output
172
158
173
159
/** Some statistics (normally disabled) set with -Ystatistics */
@@ -590,52 +576,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
590
576
val runsRightAfter = None
591
577
} with Delambdafy
592
578
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
-
635
579
// phaseName = "bcode"
636
580
object genBCode extends {
637
581
val global : Global .this .type = Global .this
638
- val runsAfter = List (" dce " )
582
+ val runsAfter = List (" cleanup " )
639
583
val runsRightAfter = None
640
584
} with GenBCode
641
585
@@ -666,13 +610,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
666
610
val global : Global .this .type = Global .this
667
611
} with TreeCheckers
668
612
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
-
676
613
object typer extends analyzer.Typer (
677
614
analyzer.NoContext .make(EmptyTree , RootClass , newScope)
678
615
)
@@ -705,12 +642,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
705
642
mixer -> " mixin composition" ,
706
643
delambdafy -> " remove lambdas" ,
707
644
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" ,
714
645
terminal -> " the last phase during a compilation run"
715
646
)
716
647
@@ -1049,9 +980,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1049
980
@ inline final def enteringErasure [T ](op : => T ): T = enteringPhase(currentRun.erasurePhase)(op)
1050
981
@ inline final def enteringExplicitOuter [T ](op : => T ): T = enteringPhase(currentRun.explicitouterPhase)(op)
1051
982
@ 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)
1053
983
@ inline final def enteringMixin [T ](op : => T ): T = enteringPhase(currentRun.mixinPhase)(op)
1054
984
@ 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)
1055
986
@ inline final def enteringPickler [T ](op : => T ): T = enteringPhase(currentRun.picklerPhase)(op)
1056
987
@ inline final def enteringSpecialize [T ](op : => T ): T = enteringPhase(currentRun.specializePhase)(op)
1057
988
@ inline final def enteringTyper [T ](op : => T ): T = enteringPhase(currentRun.typerPhase)(op)
@@ -1325,8 +1256,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1325
1256
// val superaccessorsPhase = phaseNamed("superaccessors")
1326
1257
val picklerPhase = phaseNamed(" pickler" )
1327
1258
val refchecksPhase = phaseNamed(" refchecks" )
1328
- // val selectiveanfPhase = phaseNamed("selectiveanf")
1329
- // val selectivecpsPhase = phaseNamed("selectivecps")
1330
1259
val uncurryPhase = phaseNamed(" uncurry" )
1331
1260
// val tailcallsPhase = phaseNamed("tailcalls")
1332
1261
val specializePhase = phaseNamed(" specialize" )
@@ -1340,20 +1269,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1340
1269
val mixinPhase = phaseNamed(" mixin" )
1341
1270
val delambdafyPhase = phaseNamed(" delambdafy" )
1342
1271
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" )
1349
1273
1350
1274
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)
1357
1276
1358
1277
isDefined = true
1359
1278
@@ -1416,8 +1335,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1416
1335
1417
1336
if (canCheck) {
1418
1337
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()
1421
1341
}
1422
1342
}
1423
1343
@@ -1498,14 +1418,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1498
1418
1499
1419
// progress update
1500
1420
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)) {
1509
1422
// print trees
1510
1423
if (settings.Xshowtrees || settings.XshowtreesCompact || settings.XshowtreesStringified ) nodePrinters.printAll()
1511
1424
else printAllUnits()
@@ -1670,30 +1583,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
1670
1583
/** Returns the file with the given suffix for the given class. Used for icode writing. */
1671
1584
def getFile (clazz : Symbol , suffix : String ): File = getFile(clazz.sourceFile, clazz.fullName split '.' , suffix)
1672
1585
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
- }
1697
1586
def createJavadoc = false
1698
1587
}
1699
1588
0 commit comments