Skip to content

Commit 989c95d

Browse files
committed
Mark some more lazy vals as @ThreadUnsafe
1 parent 322487b commit 989c95d

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
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/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

@@ -3324,7 +3325,7 @@ object Types {
33243325

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

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

33303331
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
@@ -31,7 +31,7 @@ import reporting.trace
3131
import Constants.{Constant, IntTag, LongTag}
3232
import dotty.tools.dotc.reporting.diagnostic.messages.{UnapplyInvalidReturnType, NotAnExtractor, UnapplyInvalidNumberOfArguments}
3333
import Denotations.SingleDenotation
34-
import annotation.constructorOnly
34+
import annotation.{constructorOnly, threadUnsafe}
3535

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

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

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

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

3838
import scala.annotation.internal.sharable
39+
import scala.annotation.threadUnsafe
3940

4041
/** Implicit resolution */
4142
object Implicits {
@@ -228,14 +229,14 @@ object Implicits {
228229
*/
229230
class OfTypeImplicits(tp: Type, val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) {
230231
assert(initctx.typer != null)
231-
lazy val refs: List[ImplicitRef] = {
232+
@threadUnsafe lazy val refs: List[ImplicitRef] = {
232233
val buf = new mutable.ListBuffer[TermRef]
233234
for (companion <- companionRefs) buf ++= companion.implicitMembers(ImplicitOrImpliedOrGiven)
234235
buf.toList
235236
}
236237

237238
/** The candidates that are eligible for expected type `tp` */
238-
lazy val eligible: List[Candidate] =
239+
@threadUnsafe lazy val eligible: List[Candidate] =
239240
/*>|>*/ track("eligible in tpe") /*<|<*/ {
240241
/*>|>*/ trace(i"eligible($tp), companions = ${companionRefs.toList}%, %", implicitsDetailed, show = true) /*<|<*/ {
241242
if (refs.nonEmpty && monitored) record(s"check eligible refs in tpe", refs.length)
@@ -1113,7 +1114,7 @@ trait Implicits { self: Typer =>
11131114
private def isCoherent = pt.isRef(defn.EqlClass)
11141115

11151116
/** The expected type for the searched implicit */
1116-
lazy val fullProto: Type = implicitProto(pt, identity)
1117+
@threadUnsafe lazy val fullProto: Type = implicitProto(pt, identity)
11171118

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

0 commit comments

Comments
 (0)