summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-03-07 17:58:40 +0000
committerMartin Odersky <odersky@gmail.com>2011-03-07 17:58:40 +0000
commit7e2259fc9412c429ba80fed07d5a3839c8f1e2c1 (patch)
tree7aba3c79f627af66f305c7bdac7991d8a95f0471 /src
parentfe94d625630e36a97f9e7845b94b9619e3707382 (diff)
downloadscala-7e2259fc9412c429ba80fed07d5a3839c8f1e2c1.tar.gz
scala-7e2259fc9412c429ba80fed07d5a3839c8f1e2c1.tar.bz2
scala-7e2259fc9412c429ba80fed07d5a3839c8f1e2c1.zip
Better workflow + debug logs in presentation co...
Better workflow + debug logs in presentation compiler. Ask is non-interruptable. Responses can't be dropped anymore.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/interactive/CompilerControl.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala43
-rw-r--r--src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala6
3 files changed, 34 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
index aefdece905..8c1f1c7db2 100644
--- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
+++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
@@ -51,7 +51,7 @@ trait CompilerControl { self: Global =>
*/
def getUnitOf(s: SourceFile): Option[RichCompilationUnit] = getUnit(s)
- /** Run operation `op` on a compilation unit assocuated with given `source`.
+ /** Run operation `op` on a compilation unit associated with given `source`.
* If source has a loaded compilation unit, this one is passed to `op`.
* Otherwise a new compilation unit is created, but not added to the set of loaded units.
*/
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 90d6a498b0..6026663ddb 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -68,7 +68,18 @@ class Global(settings: Settings, reporter: Reporter)
/** A map of all loaded files to the rich compilation units that correspond to them.
*/
val unitOfFile = new LinkedHashMap[AbstractFile, RichCompilationUnit] with
- SynchronizedMap[AbstractFile, RichCompilationUnit]
+ SynchronizedMap[AbstractFile, RichCompilationUnit] {
+ override def put(key: AbstractFile, value: RichCompilationUnit) = {
+ val r = super.put(key, value)
+ if (r.isEmpty) debugLog("added uhnit for "+key)
+ r
+ }
+ override def remove(key: AbstractFile) = {
+ val r = super.remove(key)
+ if (r.nonEmpty) debugLog("removed unit for "+key)
+ r
+ }
+ }
/** A list containing all those files that need to be removed
* Units are removed by getUnit, typically once a unit is finished compiled.
@@ -117,9 +128,18 @@ class Global(settings: Settings, reporter: Reporter)
/** Is a background compiler run needed?
* Note: outOfDate is true as long as there is a background compile scheduled or going on.
*/
- protected[interactive] var outOfDate = false
+ private var outOfDate = false
+
+ protected[interactive] def isOutOfDate =
+ outOfDate || waitLoadedTypeResponses.nonEmpty || getParsedEnteredResponses.nonEmpty
+
+ protected[interactive] def setUpToDate() = outOfDate = false
+
+ def demandNewCompilerRun() = {
+ if (isOutOfDate) throw FreshRunReq // cancel background compile
+ else outOfDate = true // proceed normally and enable new background compile
+ }
- /** Units compiled by a run with id >= minRunId are considered up-to-date */
protected[interactive] var minRunId = 1
private var interruptsEnabled = true
@@ -221,6 +241,7 @@ class Global(settings: Settings, reporter: Reporter)
*
*/
protected[interactive] def pollForWork(pos: Position) {
+ if (!interruptsEnabled) return
if (pos == NoPosition || nodesSeen % yieldPeriod == 0)
Thread.`yield`()
@@ -339,11 +360,6 @@ class Global(settings: Settings, reporter: Reporter)
compileRunner
}
- def demandNewCompilerRun() = {
- if (outOfDate) throw FreshRunReq // cancel background compile
- else outOfDate = true // proceed normally and enable new background compile
- }
-
/** Compile all loaded source files in the order given by `allSources`.
*/
protected[interactive] def backgroundCompile() {
@@ -450,7 +466,7 @@ class Global(settings: Settings, reporter: Reporter)
allSources = fs ::: (allSources diff fs)
}
- // ----------------- Implementations of client commands -----------------------+lknwqdklnwlknqwkldnlkwdn
+ // ----------------- Implementations of client commands -----------------------
def respond[T](result: Response[T])(op: => T): Unit =
respondGradually(result)(Stream(op))
@@ -530,7 +546,7 @@ class Global(settings: Settings, reporter: Reporter)
case _ =>
}
if (stabilizedType(tree) ne null) {
- debugLog("already attributed")
+ debugLog("already attributed: "+tree.symbol+" "+tree.tpe)
tree
} else {
unit.targetPos = pos
@@ -786,9 +802,10 @@ class Global(settings: Settings, reporter: Reporter)
protected def waitLoadedTyped(source: SourceFile, response: Response[Tree]) {
getUnit(source) match {
case Some(unit) =>
- if (unit.isUpToDate) response set unit.body
- else waitLoadedTypeResponses(source) += response
+ if (unit.isUpToDate) { debugLog("already typed"); response set unit.body }
+ else { debugLog("wait for later"); waitLoadedTypeResponses(source) += response }
case None =>
+ debugLog("load unit and type")
reloadSources(List(source))
waitLoadedTyped(source, response)
}
@@ -803,7 +820,7 @@ class Global(settings: Settings, reporter: Reporter)
if (keepLoaded) {
reloadSources(List(source))
getParsedEnteredNow(source, response)
- } else if (outOfDate) {
+ } else if (isOutOfDate) {
getParsedEnteredResponses(source) += response
} else {
getParsedEnteredNow(source, response)
diff --git a/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala b/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
index f504427076..1751fad5c6 100644
--- a/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
+++ b/src/compiler/scala/tools/nsc/interactive/PresentationCompilerThread.scala
@@ -17,10 +17,10 @@ class PresentationCompilerThread(var compiler: Global, threadId: Int) extends Th
while (true) {
compiler.log.logreplay("wait for more work", { compiler.scheduler.waitForMoreWork(); true })
compiler.pollForWork(compiler.NoPosition)
- while (compiler.outOfDate) {
+ while (compiler.isOutOfDate) {
try {
compiler.backgroundCompile()
- compiler.outOfDate = false
+ compiler.setUpToDate()
} catch {
case FreshRunReq =>
compiler.debugLog("fresh run req caught, starting new pass")
@@ -37,7 +37,7 @@ class PresentationCompilerThread(var compiler: Global, threadId: Int) extends Th
compiler = null
case ex =>
compiler.log.flush()
- compiler.outOfDate = false
+ compiler.setUpToDate()
compiler.newRunnerThread()
ex match {