Skip to content

Commit d8e72a0

Browse files
committed
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.
1 parent 3c5390b commit d8e72a0

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ trait Symbols { this: Context =>
3838
* Note this uses a cast instead of a direct type refinement because
3939
* it's debug-friendlier not to create an anonymous class here.
4040
*/
41-
def newNakedSymbol[N <: Name](coord: Coord = NoCoord): Symbol { type ThisName = N } =
42-
new Symbol(coord).asInstanceOf[Symbol { type ThisName = N }]
41+
def newNakedSymbol[N <: Name](coord: Coord = NoCoord)(implicit ctx: Context): Symbol { type ThisName = N } =
42+
new Symbol(coord, ctx.nextId).asInstanceOf[Symbol { type ThisName = N }]
4343

4444
/** Create a class symbol without a denotation. */
45-
def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null) =
46-
new ClassSymbol(coord, assocFile)
45+
def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null)(implicit ctx: Context) =
46+
new ClassSymbol(coord, assocFile, ctx.nextId)
4747

4848
// ---- Symbol creation methods ----------------------------------
4949

@@ -364,22 +364,16 @@ trait Symbols { this: Context =>
364364

365365
object Symbols {
366366

367-
var _nextId = 0 // !!! DEBUG, use global counter instead
368-
def nextId = { _nextId += 1; _nextId }
369-
370-
371367
/** A Symbol represents a Scala definition/declaration or a package.
368+
* @param coord The coordinates of the symbol (a position or an index)
369+
* @param id A unique identifier of the symbol (unique per ContextBase)
372370
*/
373-
class Symbol private[Symbols] (val coord: Coord) extends DotClass with printing.Showable {
371+
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with printing.Showable {
374372

375373
type ThisName <: Name
376374

377-
private[this] var _id: Int = nextId
378375
//assert(_id != 30214)
379376

380-
/** The unique id of this symbol */
381-
def id = _id
382-
383377
/** The last denotation of this symbol */
384378
private[this] var lastDenot: SymDenotation = _
385379

@@ -514,8 +508,8 @@ object Symbols {
514508
type TermSymbol = Symbol { type ThisName = TermName }
515509
type TypeSymbol = Symbol { type ThisName = TypeName }
516510

517-
class ClassSymbol private[Symbols] (coord: Coord, val assocFile: AbstractFile)
518-
extends Symbol(coord) {
511+
class ClassSymbol private[Symbols] (coord: Coord, val assocFile: AbstractFile, id: Int)
512+
extends Symbol(coord, id) {
519513

520514
type ThisName = TypeName
521515

@@ -551,12 +545,12 @@ object Symbols {
551545
override protected def prefixString = "ClassSymbol"
552546
}
553547

554-
class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord) {
548+
class ErrorSymbol(val underlying: Symbol, msg: => String)(implicit ctx: Context) extends Symbol(NoCoord, ctx.nextId) {
555549
type ThisName = underlying.ThisName
556550
denot = underlying.denot
557551
}
558552

559-
object NoSymbol extends Symbol(NoCoord) {
553+
@sharable object NoSymbol extends Symbol(NoCoord, 0) {
560554
denot = NoDenotation
561555

562556
override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file
@@ -590,5 +584,5 @@ object Symbols {
590584
/** The current class */
591585
def currentClass(implicit ctx: Context): ClassSymbol = ctx.owner.enclosingClass.asClass
592586

593-
var stubs: List[Symbol] = Nil // diagnostic
587+
@sharable var stubs: List[Symbol] = Nil // diagnostic only
594588
}

0 commit comments

Comments
 (0)