diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-08-31 10:09:26 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-08-31 10:09:26 +0000 |
commit | aade88f8a7b95980ba25d03322be275cc21856ae (patch) | |
tree | 1b12ac4622f53a9dda0c56960dd4539bf9fc8839 /src | |
parent | d8add367dd9e432b53d98a33880bdf56a4505be1 (diff) | |
download | scala-aade88f8a7b95980ba25d03322be275cc21856ae.tar.gz scala-aade88f8a7b95980ba25d03322be275cc21856ae.tar.bz2 scala-aade88f8a7b95980ba25d03322be275cc21856ae.zip |
Better handling of presentation compiler shutdown.
of deadlocks: when the PC was asked to shutdown, all work items in the
work queue would be left pending, and no response would be set.
This commit attempts to clean up a bit better: a shutdown request clears
the work queue and all pending loaded&typed or parsed-entered requests
by setting their responses to 'MissingResponse'. review by odersky.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/CompilerControl.scala | 52 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/Global.scala | 16 |
2 files changed, 60 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala index 25a80bc4a6..63793fa21a 100644 --- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala +++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala @@ -276,62 +276,98 @@ trait CompilerControl { self: Global => abstract class WorkItem extends (() => Unit) { val onCompilerThread = self.onCompilerThread + + /** Raise a MissingReponse, if the work item carries a response. */ + def raiseMissing(): Unit } case class ReloadItem(sources: List[SourceFile], response: Response[Unit]) extends WorkItem { def apply() = reload(sources, response) override def toString = "reload "+sources + + def raiseMissing() = + response raise new MissingResponse } case class FilesDeletedItem(sources: List[SourceFile], response: Response[Unit]) extends WorkItem { def apply() = filesDeleted(sources, response) override def toString = "files deleted "+sources + + def raiseMissing() = + response raise new MissingResponse } - class AskTypeAtItem(val pos: Position, response: Response[Tree]) extends WorkItem { + case class AskTypeAtItem(val pos: Position, response: Response[Tree]) extends WorkItem { def apply() = self.getTypedTreeAt(pos, response) override def toString = "typeat "+pos.source+" "+pos.show + + def raiseMissing() = + response raise new MissingResponse } - class AskTypeItem(val source: SourceFile, val forceReload: Boolean, response: Response[Tree]) extends WorkItem { + case class AskTypeItem(val source: SourceFile, val forceReload: Boolean, response: Response[Tree]) extends WorkItem { def apply() = self.getTypedTree(source, forceReload, response) override def toString = "typecheck" + + def raiseMissing() = + response raise new MissingResponse } - class AskTypeCompletionItem(val pos: Position, response: Response[List[Member]]) extends WorkItem { + case class AskTypeCompletionItem(val pos: Position, response: Response[List[Member]]) extends WorkItem { def apply() = self.getTypeCompletion(pos, response) override def toString = "type completion "+pos.source+" "+pos.show + + def raiseMissing() = + response raise new MissingResponse } - class AskScopeCompletionItem(val pos: Position, response: Response[List[Member]]) extends WorkItem { + case class AskScopeCompletionItem(val pos: Position, response: Response[List[Member]]) extends WorkItem { def apply() = self.getScopeCompletion(pos, response) override def toString = "scope completion "+pos.source+" "+pos.show + + def raiseMissing() = + response raise new MissingResponse } class AskToDoFirstItem(val source: SourceFile) extends WorkItem { def apply() = moveToFront(List(source)) override def toString = "dofirst "+source + + def raiseMissing() = () } - class AskLinkPosItem(val sym: Symbol, val source: SourceFile, response: Response[Position]) extends WorkItem { + case class AskLinkPosItem(val sym: Symbol, val source: SourceFile, response: Response[Position]) extends WorkItem { def apply() = self.getLinkPos(sym, source, response) override def toString = "linkpos "+sym+" in "+source + + def raiseMissing() = + response raise new MissingResponse } - class AskLoadedTypedItem(val source: SourceFile, response: Response[Tree]) extends WorkItem { + case class AskLoadedTypedItem(val source: SourceFile, response: Response[Tree]) extends WorkItem { def apply() = self.waitLoadedTyped(source, response, this.onCompilerThread) override def toString = "wait loaded & typed "+source + + def raiseMissing() = + response raise new MissingResponse } - class AskParsedEnteredItem(val source: SourceFile, val keepLoaded: Boolean, response: Response[Tree]) extends WorkItem { + case class AskParsedEnteredItem(val source: SourceFile, val keepLoaded: Boolean, response: Response[Tree]) extends WorkItem { def apply() = self.getParsedEntered(source, keepLoaded, response, this.onCompilerThread) override def toString = "getParsedEntered "+source+", keepLoaded = "+keepLoaded + + def raiseMissing() = + response raise new MissingResponse } - class AskInstrumentedItem(val source: SourceFile, line: Int, response: Response[(String, Array[Char])]) extends WorkItem { + case class AskInstrumentedItem(val source: SourceFile, line: Int, response: Response[(String, Array[Char])]) extends WorkItem { def apply() = self.getInstrumented(source, line, response) override def toString = "getInstrumented "+source + + def raiseMissing() = + response raise new MissingResponse } + } // ---------------- Interpreted exceptions ------------------- diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 3d7d14627c..362ec1bae0 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -320,6 +320,22 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "") newTyperRun() minRunId = currentRunId demandNewCompilerRun() + + case Some(ShutdownReq) => + scheduler.synchronized { // lock the work queue so no more items are posted while we clean it up + val units = scheduler.dequeueAll { + case item: WorkItem => Some(item.raiseMissing()) + case _ => Some(()) + } + debugLog("ShutdownReq: cleaning work queue (%d items)".format(units.size)) + debugLog("Cleanup up responses (%d loadedType pending, %d parsedEntered pending)" + .format(waitLoadedTypeResponses.size, getParsedEnteredResponses.size)) + checkNoResponsesOutstanding() + + log.flush(); + throw ShutdownReq + } + case Some(ex: Throwable) => log.flush(); throw ex case _ => } |