Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Simplify patchIRFiles.
Browse files Browse the repository at this point in the history
Now that we only *add* classes instead of *replacing* some
existing classes, we can use a simpler algorithm in `patchIRFiles`.
  • Loading branch information
sjrd committed Mar 16, 2024
1 parent 1d28680 commit 5a803ac
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions wasm/src/main/scala/ir2wasm/LibraryPatches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@ import wasm.utils.MemClassDefIRFile
/** Patches that we apply to the standard library classes to make them wasm-friendly. */
object LibraryPatches {
def patchIRFiles(irFiles: Seq[IRFile])(implicit ec: ExecutionContext): Future[Seq[IRFile]] = {
val derivedCharBox = new java.util.concurrent.atomic.AtomicReference[IRFile](null)
val derivedLongBox = new java.util.concurrent.atomic.AtomicReference[IRFile](null)

val patched1: Future[Seq[IRFile]] = Future.traverse(irFiles) { irFile =>
val derivedIRFiles: Future[Seq[Option[IRFile]]] = Future.traverse(irFiles) { irFile =>
val irFileImpl = IRFileImpl.fromIRFile(irFile)
irFileImpl.entryPointsInfo.flatMap { entryPointsInfo =>
entryPointsInfo.className match {
case BoxedCharacterClass | BoxedLongClass =>
irFileImpl.tree.map { classDef =>
val derivedBox = MemClassDefIRFile(deriveBoxClass(classDef))
if (classDef.className == BoxedCharacterClass)
derivedCharBox.set(derivedBox)
else
derivedLongBox.set(derivedBox)
irFile
Some(MemClassDefIRFile(deriveBoxClass(classDef)))
}
case _ =>
Future.successful(irFile)
Future.successful(None)
}
}
}

patched1.map { irFiles1 =>
val extra = List(derivedCharBox.get(), derivedLongBox.get())
extra ++ irFiles1
derivedIRFiles.map { derived =>
derived.flatten ++ irFiles
}
}

Expand Down

0 comments on commit 5a803ac

Please sign in to comment.