diff options
Diffstat (limited to 'src/compiler')
9 files changed, 63 insertions, 85 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index 0df9bbed57..a51bd8e9b3 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -6,7 +6,6 @@ package scala.tools.nsc package ast -import compat.Platform.{EOL => LINE_SEPARATOR} import java.io.{ OutputStream, PrintWriter, StringWriter, Writer } import symtab.Flags._ import symtab.SymbolTable @@ -435,13 +434,12 @@ trait TreePrinters { trees: SymbolTable => } def print(unit: CompilationUnit) { - print("// Scala source: " + unit.source + LINE_SEPARATOR) - if (unit.body ne null) { - print(unit.body); println() - } else { - print("<null>") - } - println(); flush + print("// Scala source: " + unit.source + "\n") + if (unit.body == null) print("<null>") + else { print(unit.body); println() } + + println() + flush() } } @@ -695,8 +693,7 @@ trait TreePrinters { trees: SymbolTable => override def write(str: String) { Console.print(str) } def write(cbuf: Array[Char], off: Int, len: Int) { - val str = new String(cbuf, off, len) - write(str) + write(new String(cbuf, off, len)) } def close = { /* do nothing */ } diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala index c7cdad7c20..dbc8c106f3 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala @@ -303,7 +303,7 @@ trait BasicBlocks { /** Close the block */ def close { assert(!closed || ignore) - assert(instructionList.length > 0, "Empty block.") + assert(instructionList.nonEmpty, "Empty block.") closed = true setFlag(DIRTYSUCCS) instructionList = instructionList.reverse diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 0e2c39aeee..50bb26d491 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -9,7 +9,7 @@ package backend package icode import scala.collection.{ mutable, immutable } -import scala.collection.mutable.{ HashMap, ListBuffer, Buffer, HashSet } +import scala.collection.mutable.{ ListBuffer, Buffer } import scala.tools.nsc.symtab._ import scala.annotation.switch import PartialFunction._ @@ -1757,7 +1757,7 @@ abstract class GenICode extends SubComponent { * to delay it any more: they will be used at some point. */ class DuplicateLabels(boundLabels: Set[Symbol]) extends Transformer { - val labels: mutable.Map[Symbol, Symbol] = new HashMap + val labels: mutable.Map[Symbol, Symbol] = new mutable.HashMap var method: Symbol = _ var ctx: Context = _ @@ -1835,7 +1835,7 @@ abstract class GenICode extends SubComponent { var bb: BasicBlock = _ /** Map from label symbols to label objects. */ - var labels: HashMap[Symbol, Label] = new HashMap() + var labels = mutable.HashMap[Symbol, Label]() /** Current method definition. */ var defdef: DefDef = _ @@ -1939,7 +1939,7 @@ abstract class GenICode extends SubComponent { */ def enterMethod(m: IMethod, d: DefDef): Context = { val ctx1 = new Context(this) setMethod(m) - ctx1.labels = new HashMap() + ctx1.labels = new mutable.HashMap() ctx1.method.code = new Code(m.symbol.simpleName.toString(), m) ctx1.bb = ctx1.method.code.startBlock ctx1.defdef = d @@ -1953,7 +1953,7 @@ abstract class GenICode extends SubComponent { val block = method.code.newBlock handlers foreach (_ addCoveredBlock block) currentExceptionHandlers foreach (_ addBlock block) - block.varsInScope = new HashSet() ++= scope.varsInScope + block.varsInScope = new mutable.HashSet() ++= scope.varsInScope new Context(this) setBasicBlock block } diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala index dc31edc569..227ba36426 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala @@ -13,8 +13,7 @@ package backend package icode import java.io.PrintWriter - -import scala.collection.{ mutable, immutable, generic } +import scala.collection.mutable import scala.tools.nsc.symtab._ import analysis.{ Liveness, ReachingDefinitions } import scala.tools.nsc.symtab.classfile.ICodeReader diff --git a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala index 05259772f4..aaf8037768 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala @@ -6,10 +6,11 @@ package scala.tools.nsc package backend -package icode; +package icode import scala.tools.nsc.ast._ -import scala.collection.mutable.{Stack, HashSet, BitSet, ListBuffer} +import scala.collection.{ mutable, immutable } +import mutable.ListBuffer trait Linearizers { self: ICodes => import opcodes._; @@ -29,7 +30,7 @@ trait Linearizers { self: ICodes => class NormalLinearizer extends Linearizer with WorklistAlgorithm { type Elem = BasicBlock; - val worklist: WList = new Stack(); + val worklist: WList = new mutable.Stack(); var blocks: List[BasicBlock] = Nil; @@ -126,9 +127,7 @@ trait Linearizers { self: ICodes => * @return Returns true if the block was added. */ def add(b: BasicBlock): Boolean = - if (blocks.contains(b)) - false - else { + !(blocks contains b) && { blocks = b :: blocks; true } @@ -140,13 +139,13 @@ trait Linearizers { self: ICodes => * This way, it is constructed already in reverse post order. */ class ReversePostOrderLinearizer extends Linearizer { - var blocks: List[BasicBlock] = Nil; - var visited: HashSet[BasicBlock] = new HashSet; - val added: BitSet = new BitSet + var blocks: List[BasicBlock] = Nil + val visited = new mutable.HashSet[BasicBlock] + val added = new mutable.BitSet def linearize(m: IMethod): List[BasicBlock] = { blocks = Nil; - visited.clear; + visited.clear() added.clear; m.exh foreach (b => rpo(b.startBlock)); @@ -162,18 +161,18 @@ trait Linearizers { self: ICodes => def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = { blocks = Nil - visited.clear - added.clear + visited.clear() + added.clear() rpo(start) blocks } def rpo(b: BasicBlock): Unit = - if (b.size > 0 && !(visited contains b)) { + if (b.nonEmpty && !visited(b)) { visited += b; - b.successors foreach rpo; - add(b); + b.successors foreach rpo + add(b) } /** @@ -192,12 +191,8 @@ trait Linearizers { self: ICodes => * the last instruction being a jump). */ class DumpLinearizer extends Linearizer { - def linearize(m: IMethod): List[BasicBlock] = - m.code.blocks.toList; - - def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = { - system.error("not implemented") - } + def linearize(m: IMethod): List[BasicBlock] = m.code.blocks.toList + def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = system.error("not implemented") } /** The MSIL linearizer is used only for methods with at least one exception handler. @@ -238,10 +233,9 @@ trait Linearizers { self: ICodes => } val tryBlocks = handlersByCovered.keys.toList sortBy size + var result = normalLinearizer.linearize(m) + val frozen = mutable.HashSet[BasicBlock](result.head) - var result = normalLinearizer.linearize(m) - - val frozen = HashSet[BasicBlock](result.head) for (tryBlock <- tryBlocks) { result = groupBlocks(m, result, handlersByCovered(tryBlock), frozen) } @@ -251,7 +245,7 @@ trait Linearizers { self: ICodes => /** @param handlers a list of handlers covering the same blocks (same try, multiple catches) * @param frozen blocks can't be moved (fist block of a method, blocks directly following a try-catch) */ - def groupBlocks(method: IMethod, blocks: List[BasicBlock], handlers: List[ExceptionHandler], frozen: HashSet[BasicBlock]) = { + def groupBlocks(method: IMethod, blocks: List[BasicBlock], handlers: List[ExceptionHandler], frozen: mutable.HashSet[BasicBlock]) = { assert(blocks.head == method.code.startBlock, method) // blocks before the try, and blocks for the try @@ -281,7 +275,7 @@ trait Linearizers { self: ICodes => } // reorder the blocks in "catches" so that the "firstBlock" is actually first - for ((lb, handler) <- catches.zip(handlers)) { + (catches, handlers).zipped foreach { (lb, handler) => lb -= handler.startBlock handler.startBlock +=: lb } @@ -305,7 +299,7 @@ trait Linearizers { self: ICodes => } if (firstAfter.isDefined) { val b = firstAfter.get - if (frozen contains b) { + if (frozen(b)) { assert(after contains b, b +", "+ method) } else { frozen += b @@ -328,7 +322,7 @@ trait Linearizers { self: ICodes => * that list, i.e. successors outside the `blocks` list. */ private def leavingBlocks(blocks: List[BasicBlock]) = { - val res = new HashSet[BasicBlock]() + val res = new mutable.HashSet[BasicBlock]() for (b <- blocks; s <- b.directSuccessors; if (!blocks.contains(s))) res += s res diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala index d7e5e84a80..c18408ddbd 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala @@ -10,7 +10,6 @@ package analysis import scala.collection.{ mutable, immutable } import immutable.ListSet -import mutable.HashMap /** Compute reaching definitions. We are only interested in reaching * definitions for local variables, since values on the stack @@ -69,10 +68,10 @@ abstract class ReachingDefinitions { var method: IMethod = _ - val gen: mutable.Map[BasicBlock, Set[Definition]] = new HashMap() - val kill: mutable.Map[BasicBlock, Set[Local]] = new HashMap() - val drops: mutable.Map[BasicBlock, Int] = new HashMap() - val outStack: mutable.Map[BasicBlock, Stack] = new HashMap() + val gen: mutable.Map[BasicBlock, Set[Definition]] = new mutable.HashMap() + val kill: mutable.Map[BasicBlock, Set[Local]] = new mutable.HashMap() + val drops: mutable.Map[BasicBlock, Int] = new mutable.HashMap() + val outStack: mutable.Map[BasicBlock, Stack] = new mutable.HashMap() def init(m: IMethod) { this.method = m diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 41df23427b..8a09009ad2 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -1008,7 +1008,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid { linearization = linearizer.linearize(m) val labels = makeLabels(linearization) /** local variables whose scope appears in this block. */ - var varsInBlock: mutable.Set[Local] = new mutable.HashSet + val varsInBlock: mutable.Set[Local] = new mutable.HashSet var nextBlock: BasicBlock = linearization.head @@ -1085,7 +1085,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid { var lastMappedPC = 0 var lastLineNr = 0 var crtPC = 0 - varsInBlock.clear + varsInBlock.clear() for (instr <- b) { class CompilationException(msg: String) extends Exception(msg) { diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index 9b7bb3444a..acb4274cb2 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -7,9 +7,7 @@ package scala.tools.nsc package backend.opt -import scala.util.control.Breaks._ -import scala.collection.{ mutable, immutable } -import mutable.{ HashMap, HashSet } +import scala.collection.mutable import scala.tools.nsc.symtab._ /** @@ -80,17 +78,15 @@ abstract class Inliners extends SubComponent { val Public, Protected, Private = Value /** Cache whether a method calls private members. */ - val usesNonPublics: mutable.Map[IMethod, Value] = new HashMap + val usesNonPublics: mutable.Map[IMethod, Value] = new mutable.HashMap } import NonPublicRefs._ /* fresh name counter */ - val fresh = new HashMap[String, Int] - var count = 0 + val fresh = new mutable.HashMap[String, Int] withDefaultValue 0 def freshName(s: String) = { - val count = fresh.getOrElseUpdate(s, 0) fresh(s) += 1 - s + count + s + fresh(s) } private def hasInline(sym: Symbol) = sym hasAnnotation ScalaInlineClass @@ -110,10 +106,10 @@ abstract class Inliners extends SubComponent { } val tfa = new analysis.MethodTFA() - tfa.stat = settings.Ystatistics.value + tfa.stat = global.opt.printStats // how many times have we already inlined this method here? - private val inlinedMethodCount: mutable.Map[Symbol, Int] = new HashMap[Symbol, Int] { + private val inlinedMethodCount: mutable.Map[Symbol, Int] = new mutable.HashMap[Symbol, Int] { override def default(k: Symbol) = 0 } @@ -122,8 +118,8 @@ abstract class Inliners extends SubComponent { var instrBeforeInlining = if (m.code ne null) m.code.blocks.foldLeft(0)(_ + _.length) else 0 var retry = false var count = 0 - fresh.clear - inlinedMethodCount.clear + fresh.clear() + inlinedMethodCount.clear() val caller = new IMethodInfo(m) var info: tfa.lattice.Elem = null @@ -218,7 +214,6 @@ abstract class Inliners extends SubComponent { i match { case CALL_METHOD(msym, Dynamic) => if (analyzeInc(msym, i, bb)) break - case _ => () } info = tfa.interpret(info, i) @@ -342,9 +337,9 @@ abstract class Inliners extends SubComponent { val activeHandlers = caller.handlers filter (_ covered block) /* Map 'original' blocks to the ones inlined in the caller. */ - val inlinedBlock: mutable.Map[BasicBlock, BasicBlock] = new HashMap + val inlinedBlock: mutable.Map[BasicBlock, BasicBlock] = new mutable.HashMap - val varsInScope: mutable.Set[Local] = HashSet() ++= block.varsInScope + val varsInScope: mutable.Set[Local] = mutable.HashSet() ++= block.varsInScope /** Side effects varsInScope when it sees SCOPE_ENTERs. */ def instrBeforeFilter(i: Instruction): Boolean = { @@ -365,7 +360,7 @@ abstract class Inliners extends SubComponent { case x => newLocal("$retVal", x) } - val inlinedLocals: mutable.Map[Local, Local] = new HashMap + val inlinedLocals: mutable.Map[Local, Local] = new mutable.HashMap /** Add a new block in the current context. */ def newBlock() = { @@ -386,7 +381,7 @@ abstract class Inliners extends SubComponent { /** alfa-rename `l' in caller's context. */ def dupLocal(l: Local): Local = { - val sym = caller.sym.newVariable(l.sym.pos, freshName(l.sym.name.toString())) + val sym = caller.sym.newVariable(l.sym.pos, freshName(l.sym.name.toString)) // sym.setInfo(l.sym.tpe) val dupped = new Local(sym, l.kind, false) inlinedLocals(l) = dupped @@ -396,7 +391,7 @@ abstract class Inliners extends SubComponent { val afterBlock = newBlock() /** Map from nw.init instructions to their matching NEW call */ - val pending: mutable.Map[Instruction, NEW] = new HashMap + val pending: mutable.Map[Instruction, NEW] = new mutable.HashMap /** Map an instruction from the callee to one suitable for the caller. */ def map(i: Instruction): Instruction = { @@ -488,7 +483,6 @@ abstract class Inliners extends SubComponent { afterBlock emit instrAfter afterBlock.close - count += 1 // add exception handlers of the callee caller addHandlers (inc.handlers map translateExh) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 95d278a7a5..1d8df4fa02 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -7,13 +7,11 @@ package scala.tools.nsc package symtab package classfile -import java.io.IOException - -import scala.collection.mutable._ +import scala.collection.{ mutable, immutable } +import mutable.ListBuffer import scala.tools.nsc._ import scala.tools.nsc.backend.icode._ import scala.tools.nsc.io._ - import ClassfileConstants._ import Flags._ @@ -665,8 +663,8 @@ abstract class ICodeReader extends ClassfileParser { class LinearCode { var instrs: ListBuffer[(Int, Instruction)] = new ListBuffer - var jmpTargets: Set[Int] = new HashSet[Int] - var locals: Map[Int, List[(Local, TypeKind)]] = new HashMap() + var jmpTargets: mutable.Set[Int] = new mutable.HashSet[Int] + var locals: mutable.Map[Int, List[(Local, TypeKind)]] = new mutable.HashMap() var containsDUPX = false var containsNEW = false @@ -689,11 +687,8 @@ abstract class ICodeReader extends ClassfileParser { method.setCode(code) var bb = code.startBlock - def makeBasicBlocks: Map[Int, BasicBlock] = { - val block: Map[Int, BasicBlock] = new HashMap - for (pc <- jmpTargets) block += (pc -> code.newBlock) - block - } + def makeBasicBlocks: mutable.Map[Int, BasicBlock] = + mutable.Map(jmpTargets.toSeq map (_ -> code.newBlock): _*) val blocks = makeBasicBlocks var otherBlock: BasicBlock = null @@ -701,7 +696,7 @@ abstract class ICodeReader extends ClassfileParser { for ((pc, instr) <- instrs.iterator) { // Console.println("> " + pc + ": " + instr); - if (jmpTargets contains pc) { + if (jmpTargets(pc)) { otherBlock = blocks(pc) if (!bb.closed && otherBlock != bb) { bb.emit(JUMP(otherBlock)) @@ -1054,7 +1049,7 @@ abstract class ICodeReader extends ClassfileParser { case class LSWITCH(tags: List[List[Int]], targets: List[Int]) extends LazyJump(targets.head) { override def toString(): String ="LSWITCH (tags: " + tags + ") targets: " + targets; - targets.tail.foreach(t => jmpTargets += t) + jmpTargets ++= targets.tail } /** Duplicate and exchange pseudo-instruction. Should be later |