Skip to content

Commit

Permalink
Added ControlException marker trait and update ...
Browse files Browse the repository at this point in the history
Added ControlException marker trait and update various exceptions to
mix it in; the typer now correctly propagates ControlExceptions rather
than reporting them; the IDE reports attempts to log ControlExceptions;
Global.signalDone no longer leaks ValidateErrors back into the typer;
the set of compiler options offered by the IDE has been updated.
  • Loading branch information
milessabin committed Jul 15, 2009
1 parent 370817a commit 69e1ddb
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/actors/scala/actors/Actor.scala
Expand Up @@ -11,6 +11,7 @@
package scala.actors

import scala.compat.Platform
import scala.util.control.ControlException
import java.util.{Timer, TimerTask}
import java.util.concurrent.ExecutionException

Expand Down Expand Up @@ -881,7 +882,7 @@ case class Exit(from: AbstractActor, reason: AnyRef)
* @version 0.9.8
* @author Philipp Haller
*/
private[actors] class SuspendActorException extends Throwable {
private[actors] class SuspendActorException extends Throwable with ControlException {
/*
* For efficiency reasons we do not fill in
* the execution stack trace.
Expand Down
3 changes: 2 additions & 1 deletion src/actors/scala/actors/Reaction.scala
Expand Up @@ -11,9 +11,10 @@

package scala.actors

import scala.util.control.ControlException
import java.lang.{InterruptedException, Runnable}

private[actors] class KillActorException extends Throwable {
private[actors] class KillActorException extends Throwable with ControlException {
/*
* For efficiency reasons we do not fill in
* the execution stack trace.
Expand Down
3 changes: 2 additions & 1 deletion src/actors/scala/actors/SchedulerService.scala
Expand Up @@ -10,6 +10,7 @@

package scala.actors

import scala.util.control.ControlException
import java.lang.{Runnable, Thread, InterruptedException}

/**
Expand Down Expand Up @@ -95,7 +96,7 @@ abstract class SchedulerService(daemon: Boolean) extends Thread with ActorGC {
* @version 0.9.8
* @author Philipp Haller
*/
private[actors] class QuitException extends Throwable {
private[actors] class QuitException extends Throwable with ControlException {
/*
For efficiency reasons we do not fill in
the execution stack trace.
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
Expand Up @@ -7,6 +7,7 @@
package scala.tools.nsc.ast.parser

import scala.collection.mutable
import scala.util.control.ControlException
import scala.tools.nsc.util.{Position,NoPosition,SourceFile,CharArrayReader}
import scala.xml.{Text, TextBuffer}
import SourceFile.{SU,LF}
Expand All @@ -18,15 +19,15 @@ import scala.annotation.switch
* @version 1.0
*/
trait MarkupParsers {self: Parsers =>
case object MissingEndTagException extends RuntimeException {
case object MissingEndTagException extends RuntimeException with ControlException {
override def getMessage = "start tag was here: "
}

case object ConfusedAboutBracesException extends RuntimeException {
case object ConfusedAboutBracesException extends RuntimeException with ControlException {
override def getMessage = " I encountered a '}' where I didn't expect one, maybe this tag isn't closed <"
}

case object TruncatedXML extends RuntimeException {
case object TruncatedXML extends RuntimeException with ControlException {
override def getMessage = "input ended while parsing XML"
}

Expand Down
@@ -1,6 +1,7 @@
package scala.tools.nsc.interactive

import scala.concurrent.SyncVar
import scala.util.control.ControlException
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.util.{SourceFile, Position, WorkScheduler}
import scala.tools.nsc.symtab._
Expand Down Expand Up @@ -104,8 +105,8 @@ trait CompilerControl { self: Global =>

// ---------------- Interpreted exeptions -------------------

class CancelActionReq extends Exception
class FreshRunReq extends Exception
class ShutdownReq extends Exception
class CancelActionReq extends Exception with ControlException
class FreshRunReq extends Exception with ControlException
class ShutdownReq extends Exception with ControlException

}
22 changes: 15 additions & 7 deletions src/compiler/scala/tools/nsc/interactive/Global.scala
Expand Up @@ -4,6 +4,7 @@ import java.io.{ PrintWriter, StringWriter }

import scala.collection.mutable.{LinkedHashMap, SynchronizedMap}
import scala.concurrent.SyncVar
import scala.util.control.ControlException
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.util.{SourceFile, Position, RangePosition, OffsetPosition, NoPosition, WorkScheduler}
import scala.tools.nsc.reporters._
Expand Down Expand Up @@ -77,11 +78,19 @@ self =>
throw new TyperResult(located)
}
val typerRun = currentTyperRun
pollForWork()
if (typerRun != currentTyperRun) {
integrateNew()
throw new FreshRunReq
}

while(true)
try {
pollForWork()
if (typerRun == currentTyperRun)
return

integrateNew()
throw new FreshRunReq
} catch {
case ex : ValidateError => // Ignore, this will have been reported elsewhere
case t : Throwable => throw t
}
}
}

Expand Down Expand Up @@ -421,9 +430,8 @@ self =>
}
}

class TyperResult(val tree: Tree) extends Exception
class TyperResult(val tree: Tree) extends Exception with ControlException

assert(globalPhase.id == 0)

}

3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Infer.scala
Expand Up @@ -7,6 +7,7 @@
package scala.tools.nsc.typechecker
import scala.tools.nsc.util.{Position, NoPosition}
import scala.collection.mutable.ListBuffer
import scala.util.control.ControlException
import symtab.Flags._

/** This trait ...
Expand Down Expand Up @@ -77,7 +78,7 @@ trait Infer {
//todo: remove comments around following privates; right now they cause an IllegalAccess
// error when built with scalac

/*private*/ class NoInstance(msg: String) extends RuntimeException(msg)
/*private*/ class NoInstance(msg: String) extends RuntimeException(msg) with ControlException

/*private*/ class DeferredNoInstance(getmsg: () => String) extends NoInstance("") {
override def getMessage(): String = getmsg()
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -11,7 +11,9 @@
package scala.tools.nsc.typechecker

import scala.collection.mutable.{HashMap, ListBuffer}
import scala.util.control.ControlException
import scala.compat.Platform.currentTime
import scala.tools.nsc.interactive.RangePositions
import scala.tools.nsc.util.{HashSet, Position, Set, NoPosition, SourceFile}
import symtab.Flags._
import util.HashSet
Expand Down Expand Up @@ -3735,7 +3737,6 @@ trait Typers { self: Analyzer =>
* @return ...
*/
def typed(tree: Tree, mode: Int, pt: Type): Tree = {
import scala.tools.nsc.interactive.CompilerControl

def dropExistential(tp: Type): Type = tp match {
case ExistentialType(tparams, tpe) =>
Expand Down Expand Up @@ -3767,7 +3768,7 @@ trait Typers { self: Analyzer =>
if (phase.id <= currentRun.typerPhase.id) signalDone(context.asInstanceOf[analyzer.Context], tree, result)
result
} catch {
case ex: CompilerControl#FreshRunReq => throw ex
case ex: ControlException => throw ex
case ex: TypeError =>
tree.tpe = null
//Console.println("caught "+ex+" in typed");//DEBUG
Expand Down
3 changes: 2 additions & 1 deletion src/library/scala/runtime/NonLocalReturnException.scala
Expand Up @@ -13,8 +13,9 @@ package scala.runtime


import Predef.RuntimeException
import scala.util.control.ControlException

class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException {
class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException with ControlException {
/*
* For efficiency reasons we do not fill in
* the execution stack trace.
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/util/control/Breaks.scala
Expand Up @@ -44,5 +44,5 @@ class Breaks {
/** A singleton object providing the Break functionality */
object Breaks extends Breaks

private class BreakException extends RuntimeException
private class BreakException extends RuntimeException with ControlException

39 changes: 39 additions & 0 deletions src/library/scala/util/control/ControlException.scala
@@ -0,0 +1,39 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */

// $Id$

package scala.util.control

/**
* A marker trait indicating that the <code>Throwable</code> it is mixed
* into is intended for flow control.
*
* <p>Note that <code>Throwable</code> subclasses which extend this trait
* may extend any other <code>Throwable</code> subclass (eg.
* <code>RuntimeException</code>) and are not required to extend
* <code>Throwable</code> directly.</p>
*
* <p>Instances of <code>Throwable</code> subclasses marked in
* this way should not normally be caught. Where catch-all behaviour is
* required <code>ControlException</code>s should be propagated, for
* example,</p>
*
* <pre>
* import scala.util.control.ControlException
*
* try {
* // Body might throw arbitrarily
* } catch {
* case ce : ControlException => throw ce // propagate
* case t : Exception => log(t) // log and suppress
* </pre>
*
* @author Miles Sabin
*/
trait ControlException extends Throwable

0 comments on commit 69e1ddb

Please sign in to comment.