diff options
-rw-r--r-- | src/compiler/scala/tools/ant/ScalaBazaar.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/ant/ScalaTool.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileServer.scala | 154 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileSocket.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/GenericRunnerCommand.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 18 |
7 files changed, 107 insertions, 96 deletions
diff --git a/src/compiler/scala/tools/ant/ScalaBazaar.scala b/src/compiler/scala/tools/ant/ScalaBazaar.scala index 24836e8aec..91656482c9 100644 --- a/src/compiler/scala/tools/ant/ScalaBazaar.scala +++ b/src/compiler/scala/tools/ant/ScalaBazaar.scala @@ -104,10 +104,10 @@ package scala.tools.ant { /** Sets the depends attribute. Used by Ant. * @param input The value for <code>depends</code>. */ def setDepends(input: String) = { - depends = List.fromArray(input.split(",")).flatMap(s: String => { + depends = List.fromArray(input.split(",")).flatMap { s: String => val st = s.trim() (if (st != "") List(st) else Nil) - }) + } } /** Sets the description attribute of this package. Used by Ant. diff --git a/src/compiler/scala/tools/ant/ScalaTool.scala b/src/compiler/scala/tools/ant/ScalaTool.scala index 64277636ce..f0898a1f04 100644 --- a/src/compiler/scala/tools/ant/ScalaTool.scala +++ b/src/compiler/scala/tools/ant/ScalaTool.scala @@ -115,7 +115,7 @@ package scala.tools.ant { /** Sets the platforms attribute. Used by Ant. * @param input The value for <code>platforms</code>. */ def setPlatforms(input: String) = { - platforms = List.fromArray(input.split(",")).flatMap(s: String => { + platforms = List.fromArray(input.split(",")).flatMap { s: String => val st = s.trim() if (Platforms.isPermissible(st)) (if (input != "") List(st) else Nil) @@ -123,7 +123,7 @@ package scala.tools.ant { error("Platform " + st + " does not exist.") Nil } - }) + } } /** Sets the version attribute. Used by Ant. @@ -149,12 +149,12 @@ package scala.tools.ant { /** Sets the properties attribute. Used by Ant. * @param input The value for <code>properties</code>. */ def setProperties(input: String) = { - properties = List.fromArray(input.split(",")).flatMap(s: String => { + properties = List.fromArray(input.split(",")).flatMap { s: String => val st = s.trim(); val stArray = st.split("=", 2) if (stArray.length == 2) { if (input != "") List(Pair(stArray(0), stArray(1))) else Nil } else error("Property " + st + " does not conform to specification.") - }) + } } /** Sets the version attribute. Used by Ant. diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index ec45fa15f6..53ca8dff56 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -27,9 +27,12 @@ object CompileServer extends SocketServer { val MaxCharge = 0.8 - var compiler: Global = null var shutDown: boolean = false + private var compiler: Global = null + private var inSession: boolean = false + private var progress: boolean = false + private def settingsAreCompatible(s1: Settings, s2: Settings) = s1.encoding.value == s2.encoding.value && s1.classpath.value == s2.classpath.value && @@ -45,19 +48,18 @@ object CompileServer extends SocketServer { } private def spawnWatchDog(): unit = spawn { - try { - while (true) { - Thread.sleep(10000) - if (!CompileSocket.portFile(port).exists()) { - System.err.println("port file no longer exists; exiting") - exit(1) + while (true) { + Thread.sleep(10000) + if (!CompileSocket.portFile(port).exists() && !inSession) { + progress = false + spawn { + Thread.sleep(10000) + if (!progress) { + System.err.println("port file no longer exists; exiting") + exit(1) + } } } - } catch { - case ex: Throwable => - ex.printStackTrace() - System.err.println("exiting") - exit(1) } } @@ -69,71 +71,77 @@ object CompileServer extends SocketServer { ", free memory = "+runtime.freeMemory) val input = in.readLine() if (input != null) { - val args = StringOps.words(input) - if (args contains "-shutdown") { - out.println("[Scala compile server exited]") - shutDown = true - return - } - if (args contains "-reset") { - out.println("[Scala compile server was reset]") - compiler = null - } - val reporter = new ConsoleReporter(in, out) { - // disable prompts, so that compile server cannot block - override def displayPrompt = {} - } - def error(msg: String): unit = - reporter.error(new Position(PRODUCT), - msg + "\n " + PRODUCT + " -help gives more information") - val command = new CompilerCommand(args, error, false) { - override val cmdName = "fsc" - settings.disable(settings.prompt) - settings.disable(settings.resident) - new settings.BooleanSetting("-reset", "Reset compile server caches") - new settings.BooleanSetting("-shutdown", "Shutdown compile server") - new settings.StringSetting("-server", "hostname:portnumber", - "Specify compile server socket", "") - new settings.BooleanSetting("-J<flag>", "Pass <flag> directly to runtime system") - } + try { + inSession = true + progress = true + val args = StringOps.words(input) + if (args contains "-shutdown") { + out.println("[Scala compile server exited]") + shutDown = true + return + } + if (args contains "-reset") { + out.println("[Scala compile server was reset]") + compiler = null + } + val reporter = new ConsoleReporter(in, out) { + // disable prompts, so that compile server cannot block + override def displayPrompt = {} + } + def error(msg: String): unit = + reporter.error(new Position(PRODUCT), + msg + "\n " + PRODUCT + " -help gives more information") + val command = new CompilerCommand(args, error, false) { + override val cmdName = "fsc" + settings.disable(settings.prompt) + settings.disable(settings.resident) + new settings.BooleanSetting("-reset", "Reset compile server caches") + new settings.BooleanSetting("-shutdown", "Shutdown compile server") + new settings.StringSetting("-server", "hostname:portnumber", + "Specify compile server socket", "") + new settings.BooleanSetting("-J<flag>", "Pass <flag> directly to runtime system") + } - reporter.prompt = command.settings.prompt.value; - if (command.settings.version.value) - reporter.info(null, versionMsg, true) - else if (command.settings.help.value) - reporter.info(null, command.usageMsg, true) - else if (command.files.isEmpty) - reporter.info(null, command.usageMsg, true) - else { - try {scala.tools.nsc.CompileServer - if (compiler != null && settingsAreCompatible(command.settings, compiler.settings)) { - compiler.settings = command.settings - compiler.reporter = reporter - } else { - if (args exists ("-verbose" ==)) - out.println("[Starting new Scala compile server instance]") - compiler = new Global(command.settings, reporter) { - override def inform(msg: String) = out.println(msg) + reporter.prompt = command.settings.prompt.value; + if (command.settings.version.value) + reporter.info(null, versionMsg, true) + else if (command.settings.help.value) + reporter.info(null, command.usageMsg, true) + else if (command.files.isEmpty) + reporter.info(null, command.usageMsg, true) + else { + try {scala.tools.nsc.CompileServer + if (compiler != null && settingsAreCompatible(command.settings, compiler.settings)) { + compiler.settings = command.settings + compiler.reporter = reporter + } else { + if (args exists ("-verbose" ==)) + out.println("[Starting new Scala compile server instance]") + compiler = new Global(command.settings, reporter) { + override def inform(msg: String) = out.println(msg) + } } - } - val c = compiler - val run = new c.Run - run compile command.files - } catch { - case ex @ FatalError(msg) => - if (command.settings.debug.value) + val c = compiler + val run = new c.Run + run compile command.files + } catch { + case ex @ FatalError(msg) => + if (command.settings.debug.value) + ex.printStackTrace(out); + reporter.error(null, "fatal error: " + msg) + compiler = null + case ex: Throwable => ex.printStackTrace(out); - reporter.error(null, "fatal error: " + msg) - compiler = null - case ex: Throwable => - ex.printStackTrace(out); - reporter.error(null, "fatal error (server aborted): " + ex.getMessage()) - shutDown = true + reporter.error(null, "fatal error (server aborted): " + ex.getMessage()) + shutDown = true + } + reporter.printSummary() + runtime.gc() + if ((runtime.totalMemory() - runtime.freeMemory()).toDouble / + runtime.maxMemory().toDouble > MaxCharge) compiler = null } - reporter.printSummary() - runtime.gc() - if ((runtime.totalMemory() - runtime.freeMemory()).toDouble / - runtime.maxMemory().toDouble > MaxCharge) compiler = null + } finally { + inSession = false } } } diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index ea3e8e64d1..207df561bf 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -14,7 +14,7 @@ object CompileSocket { private val dirName = "scalac-compile-server-port" /** The vm-part of the command to start a new scala compile server */ - private val vmCommand = "java" + private val vmCommand = "scala" /** The class name of the scala compile server */ private val serverClass = "scala.tools.nsc.CompileServer" @@ -112,10 +112,12 @@ object CompileSocket { case e: IOException => System.err.println(e) System.err.println("...connection attempt to server at port "+port+" failed; re-trying...") + if (attempts % 2 == 0) portFile(port).delete() + Thread.sleep(100) getsock(attempts - 1) } } - getsock(3) + getsock(9) } def getSocket(serverAdr: String): Socket = { diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala index 9d071e1b0a..b082e0c7a7 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala @@ -9,9 +9,8 @@ package scala.tools.nsc /** A command for ScriptRunner */ class GenericRunnerCommand(allargs: List[String], error: String => Unit) { - def this(allargs: List[String]) = this(allargs, str:String => { - Console.println("Error: " + str) - }) + def this(allargs: List[String]) = + this(allargs, str => Console.println("Error: " + str)) /** Settings specified by this command */ val settings = new GenericRunnerSettings(error) diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 07026d5fdb..e6a94f4aca 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -886,7 +886,9 @@ trait Types requires SymbolTable { } val str = (pre.prefixString + sym.nameString + (if (args.isEmpty) "" else args.mkString("[", ",", "]"))) - if (sym.isModuleClass) "<object "+str+">" else str + if (sym.isPackageClass) "package "+str + else if (sym.isModuleClass) "object "+str + else str } override def prefixString = @@ -1818,7 +1820,7 @@ trait Types requires SymbolTable { * @See glbList for more explanations. */ private def glbArray(tss: List[Array[Type]]): Array[Type] = { - val tss1 = tss map (ts: Array[Type] => List.fromArray(ts)); + val tss1 = tss map { ts: Array[Type] => List.fromArray(ts) } val glbs = glbList(tss1); val result = new Array[Type](glbs.length); var i = 0; @@ -1846,7 +1848,7 @@ trait Types requires SymbolTable { * of closures. * @See lubList for more explanations. */ private def lubArray(tss: List[Array[Type]]): Array[Type] = { - var lubs = lubList(tss map (ts: Array[Type] => List.fromArray(ts))); + var lubs = lubList(tss map { ts: Array[Type] => List.fromArray(ts) }); var arr = new Array[Type](lubs.length); var i = 0; while (i < arr.length) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index aae0db6d5e..4f5eab5756 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -352,7 +352,6 @@ trait Typers requires Analyzer { * (13) When in mode EXPRmode, apply a view * If all this fails, error */ -// def adapt(tree: Tree, mode: int, pt: Type): Tree = { protected def adapt(tree: Tree, mode: int, pt: Type): Tree = tree.tpe match { case ct @ ConstantType(value) if ((mode & TYPEmode) == 0 && (ct <:< pt)) => // (0) copy.Literal(tree, value) @@ -455,10 +454,7 @@ trait Typers requires Analyzer { .filter(m => m.tpe.paramSectionCount > 0) != NoSymbol) { // (8) typed(atPos(tree.pos)(Select(adaptToName(tree, nme.apply), nme.apply)), mode, pt) } else if (!context.undetparams.isEmpty && (mode & POLYmode) == 0) { // (9) - val tparams = context.undetparams - context.undetparams = List() - inferExprInstance(tree, tparams, pt) - adapt(tree, mode, pt) + instantiate(tree, mode, pt) } else if (tree.tpe <:< pt) { tree } else { @@ -475,10 +471,7 @@ trait Typers requires Analyzer { case _ => } if (!context.undetparams.isEmpty) { - val tparams = context.undetparams - context.undetparams = List() - inferExprInstance(tree, tparams, pt) - return adapt(tree, mode, pt) + return instantiate(tree, mode, pt) } if (context.implicitsEnabled && !tree.tpe.isError && !pt.isError) { // (13); the condition prevents chains of views @@ -499,6 +492,13 @@ trait Typers requires Analyzer { // adapt(tree, mode, pt) // } + def instantiate(tree: Tree, mode: int, pt: Type): Tree = { + val tparams = context.undetparams + context.undetparams = List() + inferExprInstance(tree, tparams, pt) + adapt(tree, mode, pt) + } + def adaptToMember(qual: Tree, name: Name, tp: Type): Tree = { val qtpe = qual.tpe.widen; if (qual.isTerm && (qual.symbol == null || !qual.symbol.isTerm || qual.symbol.isValue) && |