Skip to content

Commit 7752f84

Browse files
author
Antonio Cunei
committed
Backport of r25661 and r25664.
1 parent 0379f09 commit 7752f84

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

src/compiler/scala/tools/nsc/interactive/CompilerControl.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ trait CompilerControl { self: Global =>
167167
def askScopeCompletion(pos: Position, response: Response[List[Member]]) =
168168
postWorkItem(new AskScopeCompletionItem(pos, response))
169169

170-
/** Asks to do unit corresponding to given source file on present and subsequent type checking passes */
170+
/** Asks to do unit corresponding to given source file on present and subsequent type checking passes.
171+
* If the file is in the 'crashedFiles' ignore list it is removed and typechecked normally.
172+
*/
171173
def askToDoFirst(source: SourceFile) =
172174
postWorkItem(new AskToDoFirstItem(source))
173175

@@ -315,7 +317,10 @@ trait CompilerControl { self: Global =>
315317
}
316318

317319
class AskToDoFirstItem(val source: SourceFile) extends WorkItem {
318-
def apply() = moveToFront(List(source))
320+
def apply() = {
321+
moveToFront(List(source))
322+
enableIgnoredFile(source.file)
323+
}
319324
override def toString = "dofirst "+source
320325

321326
def raiseMissing() = ()

src/compiler/scala/tools/nsc/interactive/Global.scala

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
4848
else NullLogger
4949

5050
import log.logreplay
51-
debugLog("interactive compiler from 20 Feb")
5251
debugLog("logger: " + log.getClass + " writing to " + (new java.io.File(logName)).getAbsolutePath)
5352
debugLog("classpath: "+classPath)
5453

@@ -161,6 +160,25 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
161160
*/
162161
protected var allSources: List[SourceFile] = List()
163162

163+
private var lastException: Option[Throwable] = None
164+
165+
/** A list of files that crashed the compiler. They will be ignored during background
166+
* compilation until they are removed from this list.
167+
*/
168+
private var ignoredFiles: Set[AbstractFile] = Set()
169+
170+
/** Flush the buffer of sources that are ignored during background compilation. */
171+
def clearIgnoredFiles() {
172+
ignoredFiles = Set()
173+
}
174+
175+
/** Remove a crashed file from the ignore buffer. Background compilation will take it into account
176+
* and errors will be reported against it. */
177+
def enableIgnoredFile(file: AbstractFile) {
178+
ignoredFiles -= file
179+
debugLog("Removed crashed file %s. Still in the ignored buffer: %s".format(file, ignoredFiles))
180+
}
181+
164182
/** The currently active typer run */
165183
private var currentTyperRun: TyperRun = _
166184
newTyperRun()
@@ -440,12 +458,33 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
440458
}
441459

442460
// ensure all loaded units are typechecked
443-
for (s <- allSources; unit <- getUnit(s)) {
444-
if (!unit.isUpToDate) typeCheck(unit)
445-
else debugLog("already up to date: "+unit)
446-
for (r <- waitLoadedTypeResponses(unit.source))
447-
r set unit.body
448-
serviceParsedEntered()
461+
for (s <- allSources; if !ignoredFiles(s.file); unit <- getUnit(s)) {
462+
try {
463+
if (!unit.isUpToDate)
464+
if (unit.problems.isEmpty || !settings.YpresentationStrict.value)
465+
typeCheck(unit)
466+
else debugLog("%s has syntax errors. Skipped typechecking".format(unit))
467+
else debugLog("already up to date: "+unit)
468+
for (r <- waitLoadedTypeResponses(unit.source))
469+
r set unit.body
470+
serviceParsedEntered()
471+
} catch {
472+
case ex: FreshRunReq => throw ex // propagate a new run request
473+
474+
case ex =>
475+
println("[%s]: exception during background compile: ".format(unit.source) + ex)
476+
ex.printStackTrace()
477+
for (r <- waitLoadedTypeResponses(unit.source)) {
478+
r.raise(ex)
479+
}
480+
serviceParsedEntered()
481+
482+
lastException = Some(ex)
483+
ignoredFiles += unit.source.file
484+
println("[%s] marking unit as crashed (crashedFiles: %s)".format(unit, ignoredFiles))
485+
486+
reporter.error(unit.body.pos, "Presentation compiler crashed while type checking this file: %s".format(ex.toString()))
487+
}
449488
}
450489

451490
// clean out stale waiting responses
@@ -888,6 +927,8 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
888927
if (unit.isUpToDate) {
889928
debugLog("already typed");
890929
response set unit.body
930+
} else if (ignoredFiles(source.file)) {
931+
response.raise(lastException.getOrElse(CancelException))
891932
} else if (onSameThread) {
892933
getTypedTree(source, forceReload = false, response)
893934
} else {

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings {
155155
*/
156156
val YpresentationVerbose = BooleanSetting("-Ypresentation-verbose", "Print information about presentation compiler tasks.")
157157
val YpresentationDebug = BooleanSetting("-Ypresentation-debug", "Enable debugging output for the presentation compiler.")
158+
val YpresentationStrict = BooleanSetting("-Ypresentation-strict", "Do not report type errors in sources with syntax errors.")
158159

159160
val YpresentationLog = StringSetting("-Ypresentation-log", "file", "Log presentation compiler events into file", "")
160161
val YpresentationReplay = StringSetting("-Ypresentation-replay", "file", "Replay presentation compiler events from file", "")

0 commit comments

Comments
 (0)