10000 Merge pull request #69 from pkukielka/2.13.x-refchecks · romanowski/scala@aec8442 · GitHub
[go: up one dir, main page]

Skip to content

Commit aec8442

Browse files
authored
Merge pull request scala#69 from pkukielka/2.13.x-refchecks
Minor fixes
2 parents 0e53b60 + f4de323 commit aec8442

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,15 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
420420
try {
421421
_synchronizeNames = isParallel
422422

423+
// Funny hack which allows us to create futures lazily or eagerly,
424+
// which in turn causes them to be run sequentially or in parallel
425+
val units = if (settings.YparallelSequential.value) currentRun.units else currentRun.units.toList.iterator()
426+
423427
/* Every unit is now run in separate `Future`. If given phase is not ran as parallel one
424428
* (which is indicated by `isParallel`) it's swill run on the main thread. This is accomplished by
425429
* properly modified `ExecutionContext` returned by `createExecutionContext`.
426430
*/
427-
val futures = currentRun.units.toList.collect {
431+
val futures = units.collect {
428432
case unit if !cancelled(unit) =>
429433
Future {
430434
asWorkerThread {
@@ -1043,7 +1047,6 @@ class Global(var currentSettings 10000 : Settings, reporter0: Reporter)
10431047
protected def lastSeenContext: analyzer.Context = _lastSeenContext.get
10441048
protected def lastSeenContext_=(v: analyzer.Context): Unit = _lastSeenContext.set(v)
10451049

1046-
10471050
/** The currently active run
10481051
*/
10491052
def currentRun: Run = curRun
@@ -1168,7 +1171,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
11681171
*/
11691172
var isDefined = false
11701173
/** The currently compiled unit; set from GlobalPhase */
1171-
private[this] final val _currentUnit: WorkerOrMainThreadLocal[CompilationUnit] = WorkerThreadLocal(NoCompilationUnit)
1174+
private[this] final val _currentUnit: WorkerThreadLocal[CompilationUnit] = WorkerThreadLocal(NoCompilationUnit)
11721175
def currentUnit: CompilationUnit = _currentUnit.get
11731176
def currentUnit_=(unit: CompilationUnit): Unit = _currentUnit.set(unit)
11741177

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ trait ScalaSettings extends AbsScalaSettings
147147

148148
val YparallelPhases = PhasesSetting ("-Yparallel-phases", "Which phases to run in parallel")
149149
val YparallelThreads = IntSetting ("-Yparallel-threads", "Worker threads for parallel compilation", 4, Some((0,64)), _ => None )
150+
val YparallelSequential= BooleanSetting ("-Yparallel-sequential", "Keeps processing units in different threads but do it sequentially")
150151

151152
val XmixinForceForwarders = ChoiceSetting(
152153
name = "-Xmixin-force-forwarders",

src/reflect/scala/reflect/internal/Names.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ trait Names extends api.Names {
3232

3333
/** Memory to store all names sequentially. */
3434
var chrs: Array[Char] = new Array[Char](NAME_SIZE)
35-
private var nc_counter = new util.Parallel.Counter
36-
private def nc: Int = nc_counter.get
37-
private def nc_=(v: Int): Unit = nc_counter.set(v)
35+
private var _nc = new util.Parallel.Counter
36+
private def nc: Int = _nc.get
37+
private def nc_=(v: Int): Unit = _nc.set(v)
3838

3939
/** Hashtable for finding term names quickly. */
4040
private val termHashtable = new Array[TermName](HASH_SIZE)

src/reflect/scala/reflect/internal/Scopes.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
1919
private[scala] def scopeCount: Int = _scopeCount.get
2020
private[scala] def scopeCount_=(v: Int) = _scopeCount.set(v)
2121

22-
2322
perRunCaches.recordCache {
2423
val clearCount: Clearable = () => {scopeCount = 0}
2524
clearCount

src/reflect/scala/reflect/internal/SymbolTable.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,10 @@ abstract class SymbolTable extends macros.Universe
405405
// Weak references so the garbage collector will take care of
406406
// letting us know when a cache is really out of commission.
407407
import java.lang.ref.WeakReference
408-
private val _caches = new Parallel.AnyThreadLocal(List[WeakReference[Clearable]]())
409-
private def caches = _caches.get
410-
private def caches_=(v: List[WeakReference[Clearable]]): Unit = _caches.set(v)
411-
408+
private var caches = List[WeakReference[Clearable]]()
412409
private var javaCaches = List[JavaClearable[_]]()
413410

414-
def recordCache[T <: Clearable](cache: T): T = {
411+
def recordCache[T <: Clearable](cache: T): T = Parallel.synchronizeAccess(perRunCaches) {
415412
cache match {
416413
case jc: JavaClearable[_] =>
417414
javaCaches ::= jc
@@ -425,7 +422,7 @@ abstract class SymbolTable extends macros.Universe
425422
* Removes a cache from the per-run caches. This is useful for testing: it allows running the
426423
* compiler and then inspect the state of a cache.
427424
*/
428-
def unrecordCache[T <: Clearable](cache: T): Unit = {
425+
def unrecordCache[T <: Clearable](cache: T): Unit = Parallel.synchronizeAccess(perRunCaches) {
429426
cache match {
430427
case jc: JavaClearable[_] =>
431428
javaCaches = javaCaches.filterNot(cache == _)
@@ -434,7 +431,8 @@ abstract class SymbolTable extends macros.Universe
434431
}
435432
}
436433

437-
def clearAll() = {
434+
def clearAll() = Parallel.synchronizeAccess(perRunCaches) {
435+
// Non needed anymore since caches are now local to thread and cleaned up after every phase
438436
debuglog("Clearing " + (caches.size + javaCaches.size) + " caches.")
439437
caches foreach (ref => Option(ref.get).foreach(_.clear))
440438
caches = caches.filterNot(_.get == null)
@@ -476,8 +474,6 @@ abstract class SymbolTable extends macros.Universe
476474
}
477475
}
478476

479-
480-
481477
private var _infoTransformers = new InfoTransformer {
482478
val pid = NoPhase.id
483479
val changesBaseClasses = true

src/reflect/scala/reflect/internal/util/Parallel.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ object Parallel {
3232

3333
def WorkerThreadLocal[T <: AnyRef](valueOnWorker: => T) = new WorkerThreadLocal[T](valueOnWorker)
3434

35-
// `WorkerOrMainThreadLocal` allows us to have different type of values on main and worker threads.
36-
// It's useful in cases like reporter, when on workers we want to just store messages and on main we want to print them,
37-
class WorkerOrMainThreadLocal[T](valueOnWorker: => T, valueOnMain: => T) {
38-
35+
abstract class AbstractThreadLocal[T](valueOnWorker: => T, valueOnMain: => T) {
3936
private var main: T = null.asInstanceOf[T]
4037

4138
private val worker: ThreadLocal[T] = new ThreadLocal[T] {
@@ -60,11 +57,11 @@ object Parallel {
6057

6158
// `WorkerThreadLocal` detects reads/writes of given value on the main thread and
6259
// and report such violations by throwing exception.
63-
class WorkerThreadLocal[T](valueOnWorker: => T)
64-
extends WorkerOrMainThreadLocal(valueOnWorker, throw new IllegalStateException("not allowed on main thread"))
60+
class WorkerThreadLocal[T](valueOnWorker: => T) extends AbstractThreadLocal(valueOnWorker, throw new IllegalStateException("not allowed on main thread"))
6561

66-
class AnyThreadLocal[T](value: => T)
67-
extends WorkerOrMainThreadLocal(value, value)
62+
// `WorkerOrMainThreadLocal` allows us to have different type of values on main and worker threads.
63+
// It's useful in cases like reporter, when on workers we want to just store messages and on main we want to print them,
64+
class WorkerOrMainThreadLocal[T](valueOnWorker: => T, valueOnMain: => T) extends AbstractThreadLocal(valueOnWorker, valueOnMain)
6865

6966
// Asserts that current execution happens on the main thread
7067
@inline final def assertOnMain(): Unit = {

0 commit comments

Comments
 (0)
0