diff options
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Denotations.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Names.scala | 91 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Symbols.scala | 30 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeOps.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 16 |
8 files changed, 87 insertions, 77 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index c9deaab10..206ef9d8b 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -28,6 +28,7 @@ import printing._ import config.{Settings, ScalaSettings, Platform, JavaPlatform} import language.implicitConversions import DenotTransformers.DenotTransformer + object Contexts { /** A context is passed basically everywhere in dotc. @@ -473,7 +474,7 @@ object Contexts { gadt = new GADTMap(SimpleMap.Empty) } - object NoContext extends Context { + @sharable object NoContext extends Context { lazy val base = unsupported("base") override val implicits: ContextualImplicits = new ContextualImplicits(Nil, null)(this) } @@ -620,7 +621,7 @@ object Contexts { /** implicit conversion that injects all ContextBase members into a context */ implicit def toBase(ctx: Context): ContextBase = ctx.base - val theBase = new ContextBase // !!! DEBUG, so that we can use a minimal context for reporting even in code that normally cannot access a context + // @sharable val theBase = new ContextBase // !!! DEBUG, so that we can use a minimal context for reporting even in code that normally cannot access a context } /** Info that changes on each compiler run */ diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 70ca88702..fc97fb32b 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -556,7 +556,7 @@ object Denotations { */ private def bringForward()(implicit ctx: Context): SingleDenotation = this match { case denot: SymDenotation if ctx.stillValid(denot) => - if (denot.exists) assert(ctx.runId > validFor.runId, s"denotation $denot invalid in run ${ctx.runId}. ValidFor: $validFor") + assert(ctx.runId > validFor.runId, s"denotation $denot invalid in run ${ctx.runId}. ValidFor: $validFor") var d: SingleDenotation = denot do { d.validFor = Period(ctx.period.runId, d.validFor.firstPhaseId, d.validFor.lastPhaseId) @@ -592,7 +592,9 @@ object Denotations { assert(false) } - if (valid.runId != currentPeriod.runId) initial.bringForward.current + if (valid.runId != currentPeriod.runId) + if (exists) initial.bringForward.current + else this else { var cur = this if (currentPeriod.code > valid.code) { diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index f39f2bac6..161c8fde3 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -136,7 +136,7 @@ object Flags { private final val FirstNotPickledFlag = 48 private final val MaxFlag = 63 - private var flagName = Array.fill(64, 2)("") + private val flagName = Array.fill(64, 2)("") private def isDefinedAsFlag(idx: Int) = flagName(idx) exists (_.nonEmpty) diff --git a/src/dotty/tools/dotc/core/Names.scala b/src/dotty/tools/dotc/core/Names.scala index ea30b1c3b..1ee56fe1c 100644 --- a/src/dotty/tools/dotc/core/Names.scala +++ b/src/dotty/tools/dotc/core/Names.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package core import scala.io.Codec @@ -151,11 +152,13 @@ object Names { override def seq = toCollection(this) } - class TermName(val start: Int, val length: Int, private[Names] var next: TermName) extends Name { + class TermName(val start: Int, val length: Int, @sharable private[Names] var next: TermName) extends Name { + // `next` is @sharable because it is only modified in the synchronized block of termName. type ThisName = TermName def isTypeName = false def isTermName = true + @sharable // because it is only modified in the synchronized block of toTypeName. @volatile private[this] var _typeName: TypeName = null def toTypeName: TypeName = { @@ -200,44 +203,21 @@ object Names { private final val fillFactor = 0.7 /** Memory to store all names sequentially. */ + @sharable // because it's only mutated in synchronized block of termName private[dotty] var chrs: Array[Char] = new Array[Char](InitialNameSize) /** The number of characters filled. */ + @sharable // because it's only mutated in synchronized block of termName private var nc = 0 /** Hashtable for finding term names quickly. */ + @sharable // because it's only mutated in synchronized block of termName private var table = new Array[TermName](InitialHashSize) /** The number of defined names. */ + @sharable // because it's only mutated in synchronized block of termName private var size = 1 - /** Make sure the capacity of the character array is at least `n` */ - private def ensureCapacity(n: Int) = - if (n > chrs.length) { - val newchrs = new Array[Char](chrs.length * 2) - chrs.copyToArray(newchrs) - chrs = newchrs - } - - /** Make sure the hash table is large enough for the given load factor */ - private def incTableSize() = { - size += 1 - if (size.toDouble / table.size > fillFactor) { - val oldTable = table - table = new Array[TermName](table.size * 2) - for (i <- 0 until oldTable.size) rehash(oldTable(i)) - } - } - - /** Rehash chain of names */ - private def rehash(name: TermName): Unit = - if (name != null) { - rehash(name.next) - val h = hashValue(chrs, name.start, name.length) & (table.size - 1) - name.next = table(h) - table(h) = name - } - /** The hash of a name made of from characters cs[offset..offset+len-1]. */ private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = if (len > 0) @@ -257,24 +237,53 @@ object Names { i == len } - /** Enter characters into chrs array. */ - private def enterChars(cs: Array[Char], offset: Int, len: Int): Unit = { - ensureCapacity(nc + len) - var i = 0 - while (i < len) { - chrs(nc + i) = cs(offset + i) - i += 1 - } - nc += len - } - /** Create a term name from the characters in cs[offset..offset+len-1]. * Assume they are already encoded. */ def termName(cs: Array[Char], offset: Int, len: Int): TermName = { util.Stats.record("termName") val h = hashValue(cs, offset, len) & (table.size - 1) + synchronized { + + /** Make sure the capacity of the character array is at least `n` */ + def ensureCapacity(n: Int) = + if (n > chrs.length) { + val newchrs = new Array[Char](chrs.length * 2) + chrs.copyToArray(newchrs) + chrs = newchrs + } + + /** Enter characters into chrs array. */ + def enterChars(): Unit = { + ensureCapacity(nc + len) + var i = 0 + while (i < len) { + chrs(nc + i) = cs(offset + i) + i += 1 + } + nc += len + } + + /** Rehash chain of names */ + def rehash(name: TermName): Unit = + if (name != null) { + rehash(name.next) + val h = hashValue(chrs, name.start, name.length) & (table.size - 1) + name.next = table(h) + table(h) = name + } + + /** Make sure the hash table is large enough for the given load factor */ + def incTableSize() = { + size += 1 + if (size.toDouble / table.size > fillFactor) { + val oldTable = table + table = new Array[TermName](table.size * 2) + for (i <- 0 until oldTable.size) rehash(oldTable(i)) + } + } + val next = table(h) var name = next while (name ne null) { @@ -283,7 +292,7 @@ object Names { name = name.next } name = new TermName(nc, len, next) - enterChars(cs, offset, len) + enterChars() table(h) = name incTableSize() name diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 164b0b8f3..53973b587 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package core import Periods._, Contexts._, Symbols._, Denotations._, Names._, NameOps._, Annotations._ @@ -1713,8 +1714,8 @@ object SymDenotations { validFor = Period.allInRun(NoRunId) // will be brought forward automatically } - val NoDenotation = new NoDenotation - val NotDefinedHereDenotation = new NoDenotation + @sharable val NoDenotation = new NoDenotation + @sharable val NotDefinedHereDenotation = new NoDenotation // ---- Completion -------------------------------------------------------- @@ -1757,7 +1758,7 @@ object SymDenotations { val NoSymbolFn = (ctx: Context) => NoSymbol /** A missing completer */ - class NoCompleter extends LazyType { + @sharable class NoCompleter extends LazyType { def complete(denot: SymDenotation)(implicit ctx: Context): Unit = unsupported("complete") } 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 } diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 2b2ef83a2..b61d39749 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package core import Contexts._, Types._, Symbols._, Names._, Flags._, Scopes._ @@ -572,5 +573,5 @@ trait TypeOps { this: Context => // TODO: Make standalone object. object TypeOps { val emptyDNF = (Nil, Set[Name]()) :: Nil - var track = false // !!!DEBUG + @sharable var track = false // !!!DEBUG } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index f4dbfb0e3..61ab1133b 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package core import util.common._ @@ -35,7 +36,7 @@ import language.implicitConversions object Types { - private var nextId = 0 + @sharable private var nextId = 0 /** The class of types. * The principal subclasses and sub-objects are as follows: @@ -73,6 +74,7 @@ object Types { // ----- Tests ----------------------------------------------------- + // debug only: a unique identifier for a type val uniqId = { nextId = nextId + 1 // if (nextId == 19555) @@ -2753,13 +2755,13 @@ object Types { case class ImportType(expr: Tree) extends UncachedGroundType /** Sentinel for "missing type" */ - case object NoType extends CachedGroundType { + @sharable case object NoType extends CachedGroundType { override def exists = false override def computeHash = hashSeed } /** Missing prefix */ - case object NoPrefix extends CachedGroundType { + @sharable case object NoPrefix extends CachedGroundType { override def computeHash = hashSeed } @@ -2776,7 +2778,7 @@ object Types { final class CachedWildcardType(optBounds: Type) extends WildcardType(optBounds) - object WildcardType extends WildcardType(NoType) { + @sharable object WildcardType extends WildcardType(NoType) { def apply(bounds: TypeBounds)(implicit ctx: Context) = unique(new CachedWildcardType(bounds)) } @@ -2984,7 +2986,7 @@ object Types { } } - object IdentityTypeMap extends TypeMap()(NoContext) { + @sharable object IdentityTypeMap extends TypeMap()(NoContext) { override def stopAtStatic = true def apply(tp: Type) = tp } @@ -3218,7 +3220,7 @@ object Types { // ----- Debug --------------------------------------------------------- - var debugTrace = false + @sharable var debugTrace = false val watchList = List[String]( ) map (_.toTypeName) |