summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/internal/SymbolTable.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/reflect/internal/SymbolTable.scala')
-rw-r--r--src/compiler/scala/reflect/internal/SymbolTable.scala45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/compiler/scala/reflect/internal/SymbolTable.scala b/src/compiler/scala/reflect/internal/SymbolTable.scala
index bd46a6f55d..b58a0ef7d5 100644
--- a/src/compiler/scala/reflect/internal/SymbolTable.scala
+++ b/src/compiler/scala/reflect/internal/SymbolTable.scala
@@ -8,6 +8,7 @@ package internal
import scala.collection.{ mutable, immutable }
import util._
+import scala.tools.nsc.util.WeakHashSet
abstract class SymbolTable extends api.Universe
with Collections
@@ -15,6 +16,7 @@ abstract class SymbolTable extends api.Universe
with Symbols
with Types
with Kinds
+ with ExistentialsAndSkolems
with Scopes
with Definitions
with Constants
@@ -35,7 +37,7 @@ abstract class SymbolTable extends api.Universe
def log(msg: => AnyRef): Unit
def abort(msg: String): Nothing = throw new FatalError(supplementErrorMessage(msg))
- @deprecated("2.10.0", "Give us a reason")
+ @deprecated("Give us a reason", "2.10.0")
def abort(): Nothing = abort("unknown error")
/** Override with final implementation for inlining. */
@@ -77,16 +79,29 @@ abstract class SymbolTable extends api.Universe
type RunId = Int
final val NoRunId = 0
+ // sigh, this has to be public or atPhase doesn't inline.
+ var phStack: List[Phase] = Nil
private var ph: Phase = NoPhase
private var per = NoPeriod
+ final def atPhaseStack: List[Phase] = phStack
final def phase: Phase = ph
final def phase_=(p: Phase) {
//System.out.println("setting phase to " + p)
- assert((p ne null) && p != NoPhase)
+ assert((p ne null) && p != NoPhase, p)
ph = p
- per = (currentRunId << 8) + p.id
+ per = period(currentRunId, p.id)
+ }
+ final def pushPhase(ph: Phase): Phase = {
+ val current = phase
+ phase = ph
+ phStack ::= ph
+ current
+ }
+ final def popPhase(ph: Phase) {
+ phStack = phStack.tail
+ phase = ph
}
/** The current compiler run identifier. */
@@ -111,7 +126,7 @@ abstract class SymbolTable extends api.Universe
final def phaseOf(period: Period): Phase = phaseWithId(phaseId(period))
final def period(rid: RunId, pid: Phase#Id): Period =
- (currentRunId << 8) + pid
+ (rid << 8) + pid
/** Are we later than given phase in compilation? */
final def isAtPhaseAfter(p: Phase) =
@@ -119,14 +134,19 @@ abstract class SymbolTable extends api.Universe
/** Perform given operation at given phase. */
@inline final def atPhase[T](ph: Phase)(op: => T): T = {
- val current = phase
- phase = ph
+ val saved = pushPhase(ph)
try op
- finally phase = current
+ finally popPhase(saved)
}
+
- @inline final def afterPhase[T](ph: Phase)(op: => T): T =
- atPhase(ph.next)(op)
+ /** Since when it is to be "at" a phase is inherently ambiguous,
+ * a couple unambiguously named methods.
+ */
+ @inline final def beforePhase[T](ph: Phase)(op: => T): T = atPhase(ph)(op)
+ @inline final def afterPhase[T](ph: Phase)(op: => T): T = atPhase(ph.next)(op)
+ @inline final def afterCurrentPhase[T](op: => T): T = atPhase(phase.next)(op)
+ @inline final def beforePrevPhase[T](op: => T): T = atPhase(phase.prev)(op)
@inline final def atPhaseNotLaterThan[T](target: Phase)(op: => T): T =
if (isAtPhaseAfter(target)) atPhase(target)(op) else op
@@ -261,9 +281,10 @@ abstract class SymbolTable extends api.Universe
}
}
- def newWeakMap[K, V]() = recordCache(mutable.WeakHashMap[K, V]())
- def newMap[K, V]() = recordCache(mutable.HashMap[K, V]())
- def newSet[K]() = recordCache(mutable.HashSet[K]())
+ def newWeakMap[K, V]() = recordCache(mutable.WeakHashMap[K, V]())
+ def newMap[K, V]() = recordCache(mutable.HashMap[K, V]())
+ def newSet[K]() = recordCache(mutable.HashSet[K]())
+ def newWeakSet[K <: AnyRef]() = recordCache(new WeakHashSet[K]())
}
/** Break into repl debugger if assertion is true. */