diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-10 15:59:23 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-04 15:26:52 +0200 |
commit | ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4 (patch) | |
tree | 94bdbf3809b8029ced7adb53e9731c79d344c9f9 /src/compiler/scala/tools/nsc/Global.scala | |
parent | b38fc5eaac3eb938902fe56a69e44830d41c1f87 (diff) | |
download | scala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.tar.gz scala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.tar.bz2 scala-ffb0e25fc8ec9d6ecb0cd806bc534e9430e37bd4.zip |
Unclutter Reporter. Move truncation to ReplReporter.
Refactor to reduce the Reporter interface. Working towards
minimal interfaces in scala.reflect.internal that can be consumed by sbt/IDE/....
The scala.tools.nsc package is entirely private to the compiler (in principle).
A `Reporter` should only be used to inform (info/warning/error). No state.
Ideally, we'd move to having only one reporter, whose lifetime is adjusted
appropriately (from per-run in general to per-context for type checking,
so errors can be buffered -- "silenced" -- during nested type checking calls).
Start the clean up by moving truncation to the REPL,
since it's not relevant for regular reporting. Perversely, we were checking
truncation all the time, even though it's only on during a repl run.
(Truncation is now always turned off in the repl under -verbose.)
Untangle error resetting on symbols from error reporting (reportAdditionalErrors).
This fixes a nice&subtle bug that caused feature warnings to be suppressed under
`-Xfatal-warnings`:
```
def reportCompileErrors() {
if (!reporter.hasErrors && reporter.hasWarnings && settings.fatalWarnings)
globalError("No warnings can be incurred under -Xfatal-warnings.")
if (reporter.hasErrors) { ... }
else {
// will erroneously not get here if
// `reporter.hasWarnings && settings.fatalWarnings`
// since the `globalError` call above means `reporter.hasErrors`...
allConditionalWarnings foreach (_.summarize())
...
}
}
```
The second `if`'s condition depends on the `globalError` call in the first `if`...
Diffstat (limited to 'src/compiler/scala/tools/nsc/Global.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index cb785de4b3..836203e80d 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -291,8 +291,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) log(s"!!!$pos_s $msg") // such warnings always at least logged } - def informComplete(msg: String): Unit = reporter.withoutTruncating(inform(msg)) - def logError(msg: String, t: Throwable): Unit = () override def shouldLogAtThisPhase = settings.log.isSetByUser && ( @@ -351,9 +349,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter) } if (settings.verbose || settings.Ylogcp) { - // Uses the "do not truncate" inform - informComplete("[search path for source files: " + classPath.sourcepaths.mkString(",") + "]") - informComplete("[search path for class files: " + classPath.asClasspathString + "]") + reporter.echo( + s"[search path for source files: ${classPath.sourcepaths.mkString(",")}]\n"+ + s"[search path for class files: ${classPath.asClasspathString}") } // The current division between scala.reflect.* and scala.tools.nsc.* is pretty @@ -1212,6 +1210,20 @@ class Global(var currentSettings: Settings, var reporter: Reporter) def uncheckedWarnings: List[(Position, String)] = uncheckedWarnings0.warnings.toList // used in sbt def deprecationWarnings: List[(Position, String)] = deprecationWarnings0.warnings.toList // used in sbt + def reportAdditionalErrors(): Unit = { + if (!reporter.hasErrors) { + if (reporter.hasWarnings && settings.fatalWarnings) + globalError("No warnings can be incurred under -Xfatal-warnings.") + + allConditionalWarnings foreach (_.summarize()) + + if (seenMacroExpansionsFallingBack) + warning("some macros could not be expanded and code fell back to overridden methods;"+ + "\nrecompiling with generated classfiles on the classpath might help.") + // todo: migrationWarnings + } + } + var reportedFeature = Set[Symbol]() /** Has any macro expansion used a fallback during this run? */ @@ -1416,6 +1428,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) refreshProgress() } + // for sbt def cancel() { reporter.cancelled = true } private def currentProgress = (phasec * size) + unitc @@ -1565,26 +1578,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) } } - def reportCompileErrors() { - if (!reporter.hasErrors && reporter.hasWarnings && settings.fatalWarnings) - globalError("No warnings can be incurred under -Xfatal-warnings.") - - if (reporter.hasErrors) { - for ((sym, file) <- symSource.iterator) { - sym.reset(new loaders.SourcefileLoader(file)) - if (sym.isTerm) - sym.moduleClass reset loaders.moduleClassLoader - } - } - else { - allConditionalWarnings foreach (_.summarize()) - - if (seenMacroExpansionsFallingBack) - warning("some macros could not be expanded and code fell back to overridden methods;"+ - "\nrecompiling with generated classfiles on the classpath might help.") - // todo: migrationWarnings - } - } /** Caching member symbols that are def-s in Defintions because they might change from Run to Run. */ val runDefinitions: definitions.RunDefinitions = new definitions.RunDefinitions @@ -1597,7 +1590,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) def checkDeprecations() = { checkDeprecatedSettings(newCompilationUnit("")) - reportCompileErrors() + reportAdditionalErrors() } val units = sources map scripted map (new CompilationUnit(_)) @@ -1621,7 +1614,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) checkDeprecatedSettings(unitbuf.head) globalPhase = fromPhase - while (globalPhase.hasNext && !reporter.hasErrors) { + while (globalPhase.hasNext && !reporter.hasErrors) { val startTime = currentTime phase = globalPhase globalPhase.run() @@ -1667,6 +1660,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter) advancePhase() } + reportAdditionalErrors() + if (traceSymbolActivity) units map (_.body) foreach (traceSymbols recordSymbolsInTree _) @@ -1674,8 +1669,15 @@ class Global(var currentSettings: Settings, var reporter: Reporter) if (settings.Yshow.isDefault) showMembers() - reportCompileErrors() + if (reporter.hasErrors) { + for ((sym, file) <- symSource.iterator) { + sym.reset(new loaders.SourcefileLoader(file)) + if (sym.isTerm) + sym.moduleClass reset loaders.moduleClassLoader + } + } symSource.keys foreach (x => resetPackageClass(x.owner)) + informTime("total", startTime) // Clear any sets or maps created via perRunCaches. |