Skip to content

Commit

Permalink
Use ClearableLinker to recover from exceptions in Scala.js (#1891)
Browse files Browse the repository at this point in the history
Pull request: #1891
  • Loading branch information
lolgab authored Jun 3, 2022
1 parent 1a2fbde commit eb6204d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions scalajslib/worker/0.6/src/ScalaJSWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.scalajs.core.tools.io.IRFileCache.IRContainer
import org.scalajs.core.tools.io._
import org.scalajs.core.tools.jsdep.ResolvedJSDependency
import org.scalajs.core.tools.linker.{
ClearableLinker,
ESFeatures => ScalaJSESFeatures,
Linker,
ModuleInitializer,
Expand All @@ -31,15 +32,15 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
esFeatures: ESFeatures
)
private object ScalaJSLinker {
private val cache = mutable.Map.empty[LinkerInput, WeakReference[Linker]]
def reuseOrCreate(input: LinkerInput): Linker = cache.get(input) match {
private val cache = mutable.Map.empty[LinkerInput, WeakReference[ClearableLinker]]
def reuseOrCreate(input: LinkerInput): ClearableLinker = cache.get(input) match {
case Some(WeakReference(linker)) => linker
case _ =>
val newLinker = createLinker(input)
cache.update(input, WeakReference(newLinker))
newLinker
}
private def createLinker(input: LinkerInput): Linker = {
private def createLinker(input: LinkerInput): ClearableLinker = {
val semantics = input.isFullLinkJS match {
case true => Semantics.Defaults.optimized
case false => Semantics.Defaults
Expand All @@ -65,7 +66,8 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
.withSemantics(semantics)
.withModuleKind(scalaJSModuleKind)
.withESFeatures(scalaJSESFeatures)
StandardLinker(config)

new ClearableLinker(() => StandardLinker(config), config.batchMode)
}
}

Expand Down
2 changes: 1 addition & 1 deletion scalajslib/worker/1/src/ScalaJSWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ScalaJSWorkerImpl extends ScalaJSWorkerApi {
if (minorIsGreaterThanOrEqual(3)) withModuleSplitStyle_1_3_plus(partialConfig)
else withModuleSplitStyle_1_2_minus(partialConfig)

StandardImpl.linker(config)
StandardImpl.clearableLinker(config)
}
}
def link(
Expand Down

0 comments on commit eb6204d

Please sign in to comment.