Skip to content

Commit 9a0143c

Browse files
committed
Honor the parallel flag in the Analyzer
1 parent a28fa78 commit 9a0143c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

linker/js/src/main/scala/org/scalajs/linker/analyzer/Platform.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
package org.scalajs.linker.analyzer
1414

1515
import scala.collection.mutable
16+
import scala.concurrent.ExecutionContext
1617

1718
private[analyzer] object Platform {
1819
def emptyThreadSafeMap[K, V]: mutable.Map[K, V] = mutable.Map.empty
20+
21+
def adjustExecutionContextForParallelism(ec: ExecutionContext,
22+
parallel: Boolean): ExecutionContext = {
23+
ec // we're never parallel on JS
24+
}
1925
}

linker/jvm/src/main/scala/org/scalajs/linker/analyzer/Platform.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ package org.scalajs.linker.analyzer
1414

1515
import scala.collection.mutable
1616
import scala.collection.concurrent.TrieMap
17+
import scala.concurrent.ExecutionContext
18+
19+
import java.util.concurrent.Executors
1720

1821
private[analyzer] object Platform {
1922
def emptyThreadSafeMap[K, V]: mutable.Map[K, V] = TrieMap.empty
23+
24+
def adjustExecutionContextForParallelism(ec: ExecutionContext,
25+
parallel: Boolean): ExecutionContext = {
26+
/* Parallel is the default. Parallelism is disabled (likely for debugging),
27+
* we create our own single thread executor. This is for sure not the most
28+
* efficient, but it is simpler than, say, attempting to build single thread
29+
* execution on top of an arbitrary execution context.
30+
* Further, if parallel is false, we do not expect that speed is the primary
31+
* aim of the execution.
32+
*/
33+
if (parallel) ec
34+
else ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor())
35+
}
2036
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import org.scalajs.linker.standard.ModuleSet.ModuleID
3737

3838
import org.scalajs.logging._
3939

40-
import Platform.emptyThreadSafeMap
40+
import Platform._
4141

4242
import Analysis._
4343
import Infos.{NamespacedMethodName, ReachabilityInfo, ReachabilityInfoInClass}
@@ -74,6 +74,14 @@ final class Analyzer(config: CommonPhaseConfig, initial: Boolean,
7474
def computeReachability(moduleInitializers: Seq[ModuleInitializer],
7575
symbolRequirements: SymbolRequirement, logger: Logger)(implicit ec: ExecutionContext): Future[Analysis] = {
7676

77+
computeInternal(moduleInitializers, symbolRequirements, logger)(
78+
adjustExecutionContextForParallelism(ec, config.parallel))
79+
}
80+
81+
/** Internal helper to isolate the execution context. */
82+
private def computeInternal(moduleInitializers: Seq[ModuleInitializer],
83+
symbolRequirements: SymbolRequirement, logger: Logger)(implicit ec: ExecutionContext): Future[Analysis] = {
84+
7785
resetState()
7886

7987
infoLoader.update(logger)

0 commit comments

Comments
 (0)