Skip to content

Commit eb8f45b

Browse files
committed
Make from collection thread-safe
1 parent 9450a37 commit eb8f45b

File tree

1 file changed

+17
-11
lines changed
  • linker/shared/src/main/scala/org/scalajs/linker/analyzer

1 file changed

+17
-11
lines changed

linker/shared/src/main/scala/org/scalajs/linker/analyzer/Analyzer.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
474474
val nonExistent: Boolean)
475475
extends Analysis.ClassInfo with ClassLoadingState with LoadingResult with ModuleUnit {
476476

477-
var linkedFrom: List[From] = Nil
477+
private[this] val _linkedFrom = new GrowingList[From]
478+
def linkedFrom: List[From] = _linkedFrom.get()
478479

479480
val className = data.className
480481
val kind = data.kind
@@ -511,7 +512,7 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
511512
if (nonExistent)
512513
_errors ::= MissingClass(this, from)
513514

514-
linkedFrom ::= from
515+
_linkedFrom ::= from
515516
}
516517

517518
private[this] def validateSuperClass(superClass: Option[ClassInfo]): Option[ClassInfo] = {
@@ -639,7 +640,8 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
639640
if (className != ObjectClass)
640641
addStaticDependency(ObjectClass)
641642

642-
var instantiatedFrom: List[From] = Nil
643+
private[this] val _instantiatedFrom = new GrowingList[From]
644+
def instantiatedFrom: List[From] = _instantiatedFrom.get()
643645

644646
val dispatchCalledFrom: mutable.Map[MethodName, List[From]] = mutable.Map.empty
645647

@@ -1038,7 +1040,7 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
10381040
}
10391041

10401042
def instantiated()(implicit from: From): Unit = {
1041-
instantiatedFrom ::= from
1043+
_instantiatedFrom ::= from
10421044

10431045
/* TODO? When the second line is false, shouldn't this be a linking error
10441046
* instead?
@@ -1097,7 +1099,8 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
10971099
}
10981100

10991101
private def subclassInstantiated()(implicit from: From): Unit = {
1100-
instantiatedFrom ::= from
1102+
_instantiatedFrom ::= from
1103+
11011104
if (!isAnySubclassInstantiated && (isScalaClass || isJSType)) {
11021105
isAnySubclassInstantiated = true
11031106

@@ -1264,8 +1267,11 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
12641267
var isAbstractReachable: Boolean = false
12651268
var isReachable: Boolean = false
12661269

1267-
var calledFrom: List[From] = Nil
1268-
var instantiatedSubclasses: List[ClassInfo] = Nil
1270+
private[this] val _calledFrom = new GrowingList[From]
1271+
def calledFrom: List[From] = _calledFrom.get()
1272+
1273+
private[this] val _instantiatedSubclasses = new GrowingList[ClassInfo]
1274+
def instantiatedSubclasses: List[ClassInfo] = _instantiatedSubclasses.get()
12691275

12701276
def isReflectiveProxy: Boolean =
12711277
methodName.isReflectiveProxy
@@ -1284,7 +1290,7 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
12841290
def reachStatic()(implicit from: From): Unit = {
12851291
checkConcrete()
12861292

1287-
calledFrom ::= from
1293+
_calledFrom ::= from
12881294
if (!isReachable) {
12891295
isAbstractReachable = true
12901296
isReachable = true
@@ -1297,7 +1303,7 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
12971303

12981304
if (!isAbstractReachable) {
12991305
checkExistent()
1300-
calledFrom ::= from
1306+
_calledFrom ::= from
13011307
isAbstractReachable = true
13021308
}
13031309
}
@@ -1312,8 +1318,8 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
13121318

13131319
checkConcrete()
13141320

1315-
calledFrom ::= from
1316-
instantiatedSubclasses ::= inClass
1321+
_calledFrom ::= from
1322+
_instantiatedSubclasses ::= inClass
13171323

13181324
if (!isReachable) {
13191325
isAbstractReachable = true

0 commit comments

Comments
 (0)