From bec4f9d2cbf7fe000efb849abd5d86a34a0a084a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 11 Apr 2017 08:55:17 +0200 Subject: Better documentation of sharable structures in Names, NameKinds --- compiler/src/dotty/tools/dotc/core/NameKinds.scala | 3 +++ compiler/src/dotty/tools/dotc/core/Names.scala | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala index bee39adaa..0f08e4701 100644 --- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala +++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala @@ -13,6 +13,9 @@ import collection.mutable object NameKinds { + // These are sharable since all NameKinds are created eagerly at the start of the program + // before any concurrent threads are forked. for this to work, NameKinds should never + // be created lazily or in modules that start running after compilers are forked. @sharable private val simpleNameKinds = new mutable.HashMap[Int, ClassifiedNameKind] @sharable private val qualifiedNameKinds = new mutable.HashMap[Int, QualifiedNameKind] @sharable private val uniqueNameKinds = new mutable.HashMap[String, UniqueNameKind] diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index cef55a482..a72a02844 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -134,7 +134,8 @@ object Names { def info: NameInfo = SimpleTermNameKind.info def underlying: TermName = unsupported("underlying") - @sharable private var derivedNames: AnyRef /* SimpleMap | j.u.HashMap */ = + @sharable // because of synchronized block in `and` + private var derivedNames: AnyRef /* SimpleMap | j.u.HashMap */ = SimpleMap.Empty[NameInfo] private def getDerived(info: NameInfo): DerivedTermName /* | Null */= derivedNames match { -- cgit v1.2.3