aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-07-01 16:30:13 +0200
committerMartin Odersky <odersky@gmail.com>2015-07-06 17:46:47 +0200
commitbcbd6a213b23e8576ee9badacd86d7694433a0c4 (patch)
tree20b7111e47ecd2ef053d2ecd6e6c03ce831d0512 /src
parent6c09236f6ee4b9194f12bcb553c803d337c54052 (diff)
downloaddotty-bcbd6a213b23e8576ee9badacd86d7694433a0c4.tar.gz
dotty-bcbd6a213b23e8576ee9badacd86d7694433a0c4.tar.bz2
dotty-bcbd6a213b23e8576ee9badacd86d7694433a0c4.zip
Eliminate global _nextId field in Symbols
_nextId is used to set Symbol's id fields. That field is actually used for more than priunting. In LambdaLift, it determines Symbol ordering when constructing (tree-) sets of symbols. Instead of a thread-unsafe global counter, we not use existing infrastructure in ConetxtState.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 602bdba80..ce308459a 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -38,12 +38,12 @@ trait Symbols { this: Context =>
* Note this uses a cast instead of a direct type refinement because
* it's debug-friendlier not to create an anonymous class here.
*/
- def newNakedSymbol[N <: Name](coord: Coord = NoCoord): Symbol { type ThisName = N } =
- new Symbol(coord).asInstanceOf[Symbol { type ThisName = N }]
+ def newNakedSymbol[N <: Name](coord: Coord = NoCoord)(implicit ctx: Context): Symbol { type ThisName = N } =
+ new Symbol(coord, ctx.nextId).asInstanceOf[Symbol { type ThisName = N }]
/** Create a class symbol without a denotation. */
- def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null) =
- new ClassSymbol(coord, assocFile)
+ def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null)(implicit ctx: Context) =
+ new ClassSymbol(coord, assocFile, ctx.nextId)
// ---- Symbol creation methods ----------------------------------
@@ -364,22 +364,16 @@ trait Symbols { this: Context =>
object Symbols {
- var _nextId = 0 // !!! DEBUG, use global counter instead
- def nextId = { _nextId += 1; _nextId }
-
-
/** A Symbol represents a Scala definition/declaration or a package.
+ * @param coord The coordinates of the symbol (a position or an index)
+ * @param id A unique identifier of the symbol (unique per ContextBase)
*/
- class Symbol private[Symbols] (val coord: Coord) extends DotClass with printing.Showable {
+ class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with printing.Showable {
type ThisName <: Name
- private[this] var _id: Int = nextId
//assert(_id != 30214)
- /** The unique id of this symbol */
- def id = _id
-
/** The last denotation of this symbol */
private[this] var lastDenot: SymDenotation = _
@@ -514,8 +508,8 @@ object Symbols {
type TermSymbol = Symbol { type ThisName = TermName }
type TypeSymbol = Symbol { type ThisName = TypeName }
- class ClassSymbol private[Symbols] (coord: Coord, val assocFile: AbstractFile)
- extends Symbol(coord) {
+ class ClassSymbol private[Symbols] (coord: Coord, val assocFile: AbstractFile, id: Int)
+ extends Symbol(coord, id) {
type ThisName = TypeName
@@ -551,12 +545,12 @@ object Symbols {
override protected def prefixString = "ClassSymbol"
}
- class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord) {
+ class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord, ctx.nextId) {
type ThisName = underlying.ThisName
denot = underlying.denot
}
- object NoSymbol extends Symbol(NoCoord) {
+ @sharable object NoSymbol extends Symbol(NoCoord, 0) {
denot = NoDenotation
override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file
@@ -590,5 +584,5 @@ object Symbols {
/** The current class */
def currentClass(implicit ctx: Context): ClassSymbol = ctx.owner.enclosingClass.asClass
- var stubs: List[Symbol] = Nil // diagnostic
+ @sharable var stubs: List[Symbol] = Nil // diagnostic only
}