diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-12-06 05:24:14 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-12-06 05:24:14 -0800 |
commit | 6926e8d4a0f9bbb6deb29586ef7134b4efa0ca2b (patch) | |
tree | b2078f6dd38128c5d0a295635ddfab2289d789f7 /src | |
parent | 49f7414a1ed42f00f0b5e703d01d0327eb103943 (diff) | |
parent | 2ea8aad5bc63582b563bb999c96e980597a84084 (diff) | |
download | scala-6926e8d4a0f9bbb6deb29586ef7134b4efa0ca2b.tar.gz scala-6926e8d4a0f9bbb6deb29586ef7134b4efa0ca2b.tar.bz2 scala-6926e8d4a0f9bbb6deb29586ef7134b4efa0ca2b.zip |
Merge pull request #3228 from retronym/merge/2.10.x-and-pr-3209-to-master
Merge #3209 and 2.10.x to master
Diffstat (limited to 'src')
6 files changed, 43 insertions, 25 deletions
diff --git a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala index 69cae24808..2e4f6b08e9 100644 --- a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala +++ b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala @@ -186,15 +186,20 @@ trait CompilerControl { self: Global => postWorkItem(new AskToDoFirstItem(source)) /** If source is not yet loaded, loads it, and starts a new run, otherwise - * continues with current pass. - * Waits until source is fully type checked and returns body in response. - * @param source The source file that needs to be fully typed. - * @param response The response, which is set to the fully attributed tree of `source`. + * continues with current pass. + * Waits until source is fully type checked and returns body in response. + * @param source The source file that needs to be fully typed. + * @param keepLoaded Whether to keep that file in the PC if it was not loaded before. If + the file is already loaded, this flag is ignored. + * @param response The response, which is set to the fully attributed tree of `source`. * If the unit corresponding to `source` has been removed in the meantime * the a NoSuchUnitError is raised in the response. */ - def askLoadedTyped(source: SourceFile, response: Response[Tree]) = - postWorkItem(new AskLoadedTypedItem(source, response)) + def askLoadedTyped(source:SourceFile, keepLoaded: Boolean, response: Response[Tree]): Unit = + postWorkItem(new AskLoadedTypedItem(source, keepLoaded, response)) + + final def askLoadedTyped(source: SourceFile, response: Response[Tree]): Unit = + askLoadedTyped(source, false, response) /** If source if not yet loaded, get an outline view with askParseEntered. * If source is loaded, wait for it to be typechecked. @@ -203,7 +208,7 @@ trait CompilerControl { self: Global => */ def askStructure(keepSrcLoaded: Boolean)(source: SourceFile, response: Response[Tree]) = { getUnit(source) match { - case Some(_) => askLoadedTyped(source, response) + case Some(_) => askLoadedTyped(source, keepSrcLoaded, response) case None => askParsedEntered(source, keepSrcLoaded, response) } } @@ -375,8 +380,8 @@ trait CompilerControl { self: Global => response raise new MissingResponse } - case class AskLoadedTypedItem(source: SourceFile, response: Response[Tree]) extends WorkItem { - def apply() = self.waitLoadedTyped(source, response, this.onCompilerThread) + case class AskLoadedTypedItem(source: SourceFile, keepLoaded: Boolean, response: Response[Tree]) extends WorkItem { + def apply() = self.waitLoadedTyped(source, response, keepLoaded, this.onCompilerThread) override def toString = "wait loaded & typed "+source def raiseMissing() = diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala index 441398e443..467a210cab 100644 --- a/src/interactive/scala/tools/nsc/interactive/Global.scala +++ b/src/interactive/scala/tools/nsc/interactive/Global.scala @@ -327,7 +327,12 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") * @param result The transformed node */ override def signalDone(context: Context, old: Tree, result: Tree) { - if (interruptsEnabled && analyzer.lockedCount == 0) { + val canObserveTree = ( + interruptsEnabled + && analyzer.lockedCount == 0 + && !context.bufferErrors // SI-7558 look away during exploratory typing in "silent mode" + ) + if (canObserveTree) { if (context.unit.exists && result.pos.isOpaqueRange && (result.pos includes context.unit.targetPos)) { @@ -338,14 +343,16 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } throw new TyperResult(located) } - try { - checkForMoreWork(old.pos) - } catch { - case ex: ValidateException => // Ignore, this will have been reported elsewhere - debugLog("validate exception caught: "+ex) - case ex: Throwable => - log.flush() - throw ex + else { + try { + checkForMoreWork(old.pos) + } catch { + case ex: ValidateException => // Ignore, this will have been reported elsewhere + debugLog("validate exception caught: "+ex) + case ex: Throwable => + log.flush() + throw ex + } } } } @@ -1127,7 +1134,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } /** Implements CompilerControl.askLoadedTyped */ - private[interactive] def waitLoadedTyped(source: SourceFile, response: Response[Tree], onSameThread: Boolean = true) { + private[interactive] def waitLoadedTyped(source: SourceFile, response: Response[Tree], keepLoaded: Boolean = false, onSameThread: Boolean = true) { getUnit(source) match { case Some(unit) => if (unit.isUpToDate) { @@ -1145,7 +1152,10 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") case None => debugLog("load unit and type") try reloadSources(List(source)) - finally waitLoadedTyped(source, response, onSameThread) + finally { + waitLoadedTyped(source, response, onSameThread) + if (!keepLoaded) removeUnitOf(source) + } } } diff --git a/src/interactive/scala/tools/nsc/interactive/Picklers.scala b/src/interactive/scala/tools/nsc/interactive/Picklers.scala index 30d3048aa0..1f89e6d3aa 100644 --- a/src/interactive/scala/tools/nsc/interactive/Picklers.scala +++ b/src/interactive/scala/tools/nsc/interactive/Picklers.scala @@ -170,7 +170,7 @@ trait Picklers { self: Global => implicit def askLoadedTypedItem: CondPickler[AskLoadedTypedItem] = pkl[SourceFile] - .wrapped { source => new AskLoadedTypedItem(source, new Response) } { _.source } + .wrapped { source => new AskLoadedTypedItem(source, false, new Response) } { _.source } .asClass (classOf[AskLoadedTypedItem]) implicit def askParsedEnteredItem: CondPickler[AskParsedEnteredItem] = diff --git a/src/interactive/scala/tools/nsc/interactive/REPL.scala b/src/interactive/scala/tools/nsc/interactive/REPL.scala index 8e9b0ceee0..ffa61b0524 100644 --- a/src/interactive/scala/tools/nsc/interactive/REPL.scala +++ b/src/interactive/scala/tools/nsc/interactive/REPL.scala @@ -118,7 +118,7 @@ object REPL { comp.askReload(List(toSourceFile(file)), reloadResult) Thread.sleep(millis.toLong) println("ask type now") - comp.askLoadedTyped(toSourceFile(file), typedResult) + comp.askLoadedTyped(toSourceFile(file), keepLoaded = true, typedResult) typedResult.get case List("typeat", file, off1, off2) => doTypeAt(makePos(file, off1, off2)) diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala index 4f9df6808f..d5da52bc13 100644 --- a/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala +++ b/src/interactive/scala/tools/nsc/interactive/tests/core/AskCommand.scala @@ -113,9 +113,9 @@ trait AskTypeAt extends AskCommand { trait AskLoadedTyped extends AskCommand { import compiler.Tree - protected def askLoadedTyped(source: SourceFile)(implicit reporter: Reporter): Response[Tree] = { + protected def askLoadedTyped(source: SourceFile, keepLoaded: Boolean = false)(implicit reporter: Reporter): Response[Tree] = { ask { - compiler.askLoadedTyped(source, _) + compiler.askLoadedTyped(source, keepLoaded, _) } } diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index f905785bd6..d271c4cdeb 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -384,7 +384,10 @@ trait Future[+T] extends Awaitable[T] { val p = Promise[U]() onComplete { case s @ Success(_) => p complete s - case _ => p completeWith that + case f @ Failure(_) => that onComplete { + case s2 @ Success(_) => p complete s2 + case _ => p complete f // Use the first failure as the failure + } } p.future } |