@@ -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 {
0 commit comments