diff options
author | Paul Phillips <paulp@improving.org> | 2011-02-08 21:26:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-02-08 21:26:46 +0000 |
commit | 5b9b417ae019d3d79c63837895b8295be7a44ce1 (patch) | |
tree | fda7f7584964df59a648e2df9396969fb93783b8 /src/compiler/scala/tools/nsc/Global.scala | |
parent | ac17c71b2357cf37386dec9644b5bdbab1e2fa4f (diff) | |
download | scala-5b9b417ae019d3d79c63837895b8295be7a44ce1.tar.gz scala-5b9b417ae019d3d79c63837895b8295be7a44ce1.tar.bz2 scala-5b9b417ae019d3d79c63837895b8295be7a44ce1.zip |
Added compiler crash recovery to the repl.
up it will issue some apologies and then replay the session up
to the crash line with a new compiler. If you combine this with
-Yrich-exceptions then you can induce a crash, see the exact path
through the code which led there, and then continue on your merry way as
if nothing happened.
// say ticket #4188 for example
% scala -Yrich-exceptions
scala> class A {
| object Ding
| class B {
| (null: Any) match { case _: Ding.type => () }
| }
| }
assertion failed: Trying to access the this of another class: tree.symbol = class $read$$iw$$iw$A, ctx.clazz.symbol = class $read$$iw$$iw$A$B compilation unit:<console>
[searching for exception contexts...]
[GenICode.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad]
958:
959: case This(qual) =>
960: assert(tree.symbol == ctx.clazz.symbol || tree.symbol.isModuleClass,
*961: "Trying to access the this of another class: " +
962: "tree.symbol = " + tree.symbol + ", ctx.clazz.symbol = " + ctx.clazz.symbol + " compilation unit:"+unit)
963: if (tree.symbol.isModuleClass && tree.symbol != ctx.clazz.symbol) {
964: if (settings.debug.value)
[GenICode.genLoadQualifier]
1166: tree match {
1167: case Select(qualifier, _) =>
1168: genLoad(qualifier, ctx, toTypeKind(qualifier.tpe))
*1169: case _ =>
1170: abort("Unknown qualifier " + tree)
1171: }
1172:
[...]
Attempting session recovery...
scala>
No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/Global.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 77 |
1 files changed, 29 insertions, 48 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index b1490e411a..6e15906b97 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -15,6 +15,7 @@ import io.{ SourceReader, AbstractFile, Path } import reporters.{ Reporter, ConsoleReporter } import util.{ Exceptional, ClassPath, SourceFile, Statistics, BatchSourceFile, ScriptSourceFile, ShowPickled, returning } import reflect.generic.{ PickleBuffer, PickleFormat } +import settings.{ AestheticSettings } import symtab.{ Flags, SymbolTable, SymbolLoaders, SymbolTrackers } import symtab.classfile.Pickler @@ -206,16 +207,13 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable informComplete("[search path for class files: " + classPath.asClasspathString + "]") } - /** Taking flag checking to a somewhat higher level. */ - object opt { + object opt extends AestheticSettings { + def settings = Global.this.settings + // protected implicit lazy val globalPhaseOrdering: Ordering[Phase] = Ordering[Int] on (_.id) def isActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase def wasActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase.prev - // Some(value) if setting has been set by user, None otherwise. - def optSetting[T](s: Settings#Setting): Option[T] = - if (s.isDefault) None else Some(s.value.asInstanceOf[T]) - // Allows for syntax like scalac -Xshow-class Random@erasure,typer private def splitClassAndPhase(str: String, term: Boolean): Name = { def mkName(s: String) = if (term) newTermName(s) else newTypeName(s) @@ -228,52 +226,35 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable } } - val showClass = optSetting[String](settings.Xshowcls) map (x => splitClassAndPhase(x, false)) - val showObject = optSetting[String](settings.Xshowobj) map (x => splitClassAndPhase(x, true)) - def script = optSetting[String](settings.script) - def encoding = optSetting[String](settings.encoding) - def sourceReader = optSetting[String](settings.sourceReader) + // debugging + def checkPhase = wasActive(settings.check) + def logPhase = isActive(settings.log) + def typerDebug = settings.Ytyperdebug.value + def writeICode = settings.writeICode.value - // XXX: short term, but I can't bear to add another option. - // scalac -Dscala.timings will make this true. - def timings = sys.props contains "scala.timings" + // showing/printing things + def browsePhase = isActive(settings.browse) + def echoFilenames = opt.debug && (opt.verbose || currentRun.size < 5) + def noShow = settings.Yshow.isDefault + def printLate = settings.printLate.value + def printPhase = isActive(settings.Xprint) + def showNames = List(showClass, showObject).flatten + def showPhase = isActive(settings.Yshow) + def showSymbols = settings.Yshowsyms.value + def showTrees = settings.Xshowtrees.value + val showClass = optSetting[String](settings.Xshowcls) map (x => splitClassAndPhase(x, false)) + val showObject = optSetting[String](settings.Xshowobj) map (x => splitClassAndPhase(x, true)) - def debug = settings.debug.value - def deprecation = settings.deprecation.value - def experimental = settings.Xexperimental.value - def fatalWarnings = settings.Xwarnfatal.value - def logClasspath = settings.Ylogcp.value - def printLate = settings.printLate.value - def printStats = settings.Ystatistics.value - def profileClass = settings.YprofileClass.value - def profileMem = settings.YprofileMem.value - def richExes = settings.YrichExes.value - def showTrees = settings.Xshowtrees.value - def showSymbols = settings.Yshowsyms.value - def target = settings.target.value - def typerDebug = settings.Ytyperdebug.value - def unchecked = settings.unchecked.value - def verbose = settings.verbose.value - def writeICode = settings.writeICode.value - def declsOnly = false - - /** Flags as applied to the current or previous phase */ - def browsePhase = isActive(settings.browse) - def checkPhase = wasActive(settings.check) - def logPhase = isActive(settings.log) - def printPhase = isActive(settings.Xprint) - def showPhase = isActive(settings.Yshow) + // profiling def profCPUPhase = isActive(settings.Yprofile) && !profileAll + def profileAll = settings.Yprofile.doAllPhases + def profileAny = !settings.Yprofile.isDefault || !settings.YprofileMem.isDefault + def profileClass = settings.YprofileClass.value + def profileMem = settings.YprofileMem.value - /** Derived values */ - def noShow = settings.Yshow.isDefault - def showNames = List(showClass, showObject).flatten - def profileAll = settings.Yprofile.doAllPhases - def profileAny = !settings.Yprofile.isDefault || !settings.YprofileMem.isDefault - def jvm = target startsWith "jvm" - def msil = target == "msil" - def verboseDebug = debug && verbose - def echoFilenames = opt.debug && (opt.verbose || currentRun.size < 5) + // XXX: short term, but I can't bear to add another option. + // scalac -Dscala.timings will make this true. + def timings = sys.props contains "scala.timings" } // True if -Xscript has been set, indicating a script run. |