Skip to content

Commit a73b830

Browse files
committed
Mark some more lazy vals as @ThreadUnsafe
1 parent 324683d commit a73b830

File tree

9 files changed

+30
-23
lines changed

9 files changed

+30
-23
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package backend
33
package jvm
44

55
import scala.tools.asm
6+
import scala.annotation.threadUnsafe
67

78
/**
89
* This class mainly contains the method classBTypeFromSymbol, which extracts the necessary
@@ -30,14 +31,14 @@ class BTypesFromSymbols[I <: BackendInterface](val int: I) extends BTypes {
3031
coreBTypes.setBTypes(new CoreBTypes[this.type](this))
3132
}
3233

33-
protected lazy val classBTypeFromInternalNameMap = {
34+
@threadUnsafe protected lazy val classBTypeFromInternalNameMap = {
3435
perRunCaches.recordCache(collection.concurrent.TrieMap.empty[String, ClassBType])
3536
}
3637

3738
/**
3839
* Cache for the method classBTypeFromSymbol.
3940
*/
40-
private lazy val convertedClasses = perRunCaches.newMap[Symbol, ClassBType]()
41+
@threadUnsafe private lazy val convertedClasses = perRunCaches.newMap[Symbol, ClassBType]()
4142

4243
/**
4344
* The ClassBType for a class symbol `sym`.

compiler/src/dotty/tools/backend/jvm/BackendInterface.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dotty.tools.io.AbstractFile
88
import scala.language.implicitConversions
99
import scala.tools.asm
1010

11-
1211
/* Interface to abstract over frontend inside backend.
1312
* Intended to be implemented by both scalac and dotc
1413
*/

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.dotc.transform.{Erasure, GenericSignatures}
88
import dotty.tools.dotc.transform.SymUtils._
99
import java.io.{File => _}
1010

11+
import scala.annotation.threadUnsafe
1112
import scala.collection.generic.Clearable
1213
import scala.collection.mutable
1314
import scala.reflect.ClassTag
@@ -104,8 +105,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
104105
val nme_EQEQ_LOCAL_VAR: Name = StdNames.nme.EQEQ_LOCAL_VAR
105106

106107
// require LambdaMetafactory: scalac uses getClassIfDefined, but we need those always.
107-
override lazy val LambdaMetaFactory: ClassSymbol = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
108-
override lazy val MethodHandle: ClassSymbol = ctx.requiredClass("java.lang.invoke.MethodHandle")
108+
@threadUnsafe override lazy val LambdaMetaFactory: ClassSymbol = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
109+
@threadUnsafe override lazy val MethodHandle: ClassSymbol = ctx.requiredClass("java.lang.invoke.MethodHandle")
109110

110111
val nme_valueOf: Name = StdNames.nme.valueOf
111112
val nme_apply: TermName = StdNames.nme.apply
@@ -145,13 +146,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
145146
val PartialFunctionClass: Symbol = defn.PartialFunctionClass
146147
val AbstractPartialFunctionClass: Symbol = defn.AbstractPartialFunctionClass
147148
val String_valueOf: Symbol = defn.String_valueOf_Object
148-
lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf)
149+
@threadUnsafe lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf)
149150

150-
lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
151-
lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
152-
lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
153-
lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
154-
lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
151+
@threadUnsafe lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
152+
@threadUnsafe lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
153+
@threadUnsafe lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
154+
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
155+
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
155156

156157
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def?
157158
(x, Erasure.Boxing.boxMethod(x.asClass))

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Names.TermName, StdNames._
1414
import Types.{JavaArrayType, UnspecifiedErrorType, Type}
1515
import Symbols.{Symbol, NoSymbol}
1616

17+
import scala.annotation.threadUnsafe
1718
import scala.collection.immutable
1819

1920

@@ -37,7 +38,7 @@ import scala.collection.immutable
3738
class DottyPrimitives(ctx: Context) {
3839
import dotty.tools.backend.ScalaPrimitivesOps._
3940

40-
private lazy val primitives: immutable.Map[Symbol, Int] = init
41+
@threadUnsafe private lazy val primitives: immutable.Map[Symbol, Int] = init
4142

4243
/** Return the code for the given symbol. */
4344
def getPrimitive(sym: Symbol): Int = {

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import reporting.trace
3535
import java.lang.ref.WeakReference
3636

3737
import scala.annotation.internal.sharable
38+
import scala.annotation.threadUnsafe
3839

3940
object Types {
4041

@@ -3325,7 +3326,7 @@ object Types {
33253326

33263327
def newParamRef(n: Int): TypeParamRef = new TypeParamRefImpl(this, n)
33273328

3328-
lazy val typeParams: List[LambdaParam] =
3329+
@threadUnsafe lazy val typeParams: List[LambdaParam] =
33293330
paramNames.indices.toList.map(new LambdaParam(this, _))
33303331

33313332
def derivedLambdaAbstraction(paramNames: List[TypeName], paramInfos: List[TypeBounds], resType: Type)(implicit ctx: Context): Type =

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import reporting.trace
3232
import Constants.{Constant, IntTag, LongTag}
3333
import dotty.tools.dotc.reporting.diagnostic.messages.{UnapplyInvalidReturnType, NotAnExtractor, UnapplyInvalidNumberOfArguments}
3434
import Denotations.SingleDenotation
35-
import annotation.constructorOnly
35+
import annotation.{constructorOnly, threadUnsafe}
3636

3737
object Applications {
3838
import tpd._
@@ -311,13 +311,13 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
311311
/** The function's type after widening and instantiating polytypes
312312
* with TypeParamRefs in constraint set
313313
*/
314-
lazy val methType: Type = liftedFunType.widen match {
314+
@threadUnsafe lazy val methType: Type = liftedFunType.widen match {
315315
case funType: MethodType => funType
316316
case funType: PolyType => constrained(funType).resultType
317317
case tp => tp //was: funType
318318
}
319319

320-
lazy val liftedFunType: Type =
320+
@threadUnsafe lazy val liftedFunType: Type =
321321
if (needLiftFun) {
322322
liftFun()
323323
normalizedFun.tpe
@@ -327,7 +327,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
327327
/** The arguments re-ordered so that each named argument matches the
328328
* same-named formal parameter.
329329
*/
330-
lazy val orderedArgs: List[Arg] =
330+
@threadUnsafe lazy val orderedArgs: List[Arg] =
331331
if (hasNamedArg(args))
332332
reorder(args.asInstanceOf[List[untpd.Tree]]).asInstanceOf[List[Arg]]
333333
else
@@ -618,7 +618,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
618618
def fail(msg: => Message): Unit =
619619
ok = false
620620
def appPos: SourcePosition = NoSourcePosition
621-
lazy val normalizedFun: Tree = ref(methRef)
621+
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef)
622622
init()
623623
}
624624

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import reporting.trace
3939
import annotation.tailrec
4040

4141
import scala.annotation.internal.sharable
42+
import scala.annotation.threadUnsafe
4243

4344
/** Implicit resolution */
4445
object Implicits {
@@ -231,14 +232,14 @@ object Implicits {
231232
*/
232233
class OfTypeImplicits(tp: Type, val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) {
233234
assert(initctx.typer != null)
234-
lazy val refs: List[ImplicitRef] = {
235+
@threadUnsafe lazy val refs: List[ImplicitRef] = {
235236
val buf = new mutable.ListBuffer[TermRef]
236237
for (companion <- companionRefs) buf ++= companion.implicitMembers(ImplicitOrImpliedOrGiven)
237238
buf.toList
238239
}
239240

240241
/** The candidates that are eligible for expected type `tp` */
241-
lazy val eligible: List[Candidate] =
242+
@threadUnsafe lazy val eligible: List[Candidate] =
242243
/*>|>*/ track("eligible in tpe") /*<|<*/ {
243244
/*>|>*/ trace(i"eligible($tp), companions = ${companionRefs.toList}%, %", implicitsDetailed, show = true) /*<|<*/ {
244245
if (refs.nonEmpty && monitored) record(s"check eligible refs in tpe", refs.length)
@@ -1302,7 +1303,7 @@ trait Implicits { self: Typer =>
13021303
private def isCoherent = pt.isRef(defn.EqlClass)
13031304

13041305
/** The expected type for the searched implicit */
1305-
lazy val fullProto: Type = implicitProto(pt, identity)
1306+
@threadUnsafe lazy val fullProto: Type = implicitProto(pt, identity)
13061307

13071308
/** The expected type where parameters and uninstantiated typevars are replaced by wildcard types */
13081309
val wildProto: Type = implicitProto(pt, wildApprox(_))

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import reporting._
1717
import collection.mutable
1818

1919
import scala.annotation.internal.sharable
20+
import scala.annotation.threadUnsafe
2021

2122
object Inferencing {
2223

@@ -53,7 +54,7 @@ object Inferencing {
5354
*/
5455
def instantiateDependent(tp: Type, tparams: List[Symbol], vparamss: List[List[Symbol]])(implicit ctx: Context): Unit = {
5556
val dependentVars = new TypeAccumulator[Set[TypeVar]] {
56-
lazy val params = (tparams :: vparamss).flatten
57+
@threadUnsafe lazy val params = (tparams :: vparamss).flatten
5758
def apply(tvars: Set[TypeVar], tp: Type) = tp match {
5859
case tp: TypeVar
5960
if !tp.isInstantiated &&

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import collection.mutable
1515
import reporting.diagnostic.messages._
1616
import Checking.{checkNoPrivateLeaks, checkNoWildcard}
1717

18+
import scala.annotation.threadUnsafe
19+
1820
trait TypeAssigner {
1921
import tpd._
2022

@@ -91,7 +93,7 @@ trait TypeAssigner {
9193
*/
9294
def avoid(tp: Type, symsToAvoid: => List[Symbol])(implicit ctx: Context): Type = {
9395
val widenMap = new ApproximatingTypeMap {
94-
lazy val forbidden = symsToAvoid.toSet
96+
@threadUnsafe lazy val forbidden = symsToAvoid.toSet
9597
def toAvoid(sym: Symbol) = !sym.isStatic && forbidden.contains(sym)
9698
def partsToAvoid = new NamedPartsAccumulator(tp => toAvoid(tp.symbol))
9799
def apply(tp: Type): Type = tp match {

0 commit comments

Comments
 (0)