<commit_before>package dotty.tools.backend.jvm

import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.Names.TypeName

import scala.collection.mutable
import scala.collection.JavaConverters._
import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm._
import dotty.tools.dotc
import dotty.tools.dotc.backend.jvm.DottyPrimitives
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.interfaces
import java.util.Optional

import scala.reflect.ClassTag
import dotty.tools.dotc.core._
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Phases._
import java.lang.AssertionError
import java.io.{DataOutputStream, File => JFile}
import java.nio.file.{Files, FileSystem, FileSystems, Path => JPath}

import dotty.tools.io.{Directory, File, Jar}

import scala.tools.asm
import scala.tools.asm.tree._
import dotty.tools.dotc.util.{DotClass, Positions}
import tpd._
import StdNames._
import dotty.tools.io._

class GenBCode extends Phase {
  def phaseName: String = "genBCode"
  private val entryPoints = new mutable.HashSet[Symbol]()
  def registerEntryPoint(sym: Symbol) = entryPoints += sym

  private val superCallsMap = new mutable.HashMap[Symbol, Set[ClassSymbol]]()
  def registerSuperCall(sym: Symbol, calls: ClassSymbol) = {
    val old = superCallsMap.getOrElse(sym, Set.empty)
    superCallsMap.put(sym, old + calls)
  }

  private[this] var jarFS: JarFS = _

  def outputDir(implicit ctx: Context): AbstractFile = {
    val path = Directory(ctx.settings.outputDir.value)
    if (path.extension == "jar") {
      if (jarFS == null) {
        path.delete()
        jarFS = JarFS.create(path)
      }
      jarFS.getRoot()
    }
    else new PlainDirectory(path)
  }

  def run(implicit ctx: Context): Unit = {
    new GenBCodePipeline(entryPoints.toList,
        new DottyBackendInterface(outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
    entryPoints.clear()
  }

  override def runOn(units: List[CompilationUnit])(implicit ctx: Context) = {
    try super.runOn(units)
    finally if (jarFS ne null) {
      try { jarFS.close() } catch { case _: Throwable => }
      jarFS = null
    }
  }
}

class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

  var tree: Tree = _

  val sourceFile = ctx.compilationUnit.source<commit_msg>Don't catch exceptions when closing jar<commit_after>package dotty.tools.backend.jvm

import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.Names.TypeName

import scala.collection.mutable
import scala.collection.JavaConverters._
import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm._
import dotty.tools.dotc
import dotty.tools.dotc.backend.jvm.DottyPrimitives
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.interfaces
import java.util.Optional

import scala.reflect.ClassTag
import dotty.tools.dotc.core._
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Phases._
import java.lang.AssertionError
import java.io.{DataOutputStream, File => JFile}
import java.nio.file.{Files, FileSystem, FileSystems, Path => JPath}

import dotty.tools.io.{Directory, File, Jar}

import scala.tools.asm
import scala.tools.asm.tree._
import dotty.tools.dotc.util.{DotClass, Positions}
import tpd._
import StdNames._
import dotty.tools.io._

class GenBCode extends Phase {
  def phaseName: String = "genBCode"
  private val entryPoints = new mutable.HashSet[Symbol]()
  def registerEntryPoint(sym: Symbol) = entryPoints += sym

  private val superCallsMap = new mutable.HashMap[Symbol, Set[ClassSymbol]]()
  def registerSuperCall(sym: Symbol, calls: ClassSymbol) = {
    val old = superCallsMap.getOrElse(sym, Set.empty)
    superCallsMap.put(sym, old + calls)
  }

  private[this] var jarFS: JarFS = _

  def outputDir(implicit ctx: Context): AbstractFile = {
    val path = Directory(ctx.settings.outputDir.value)
    if (path.extension == "jar") {
      if (jarFS == null) {
        path.delete()
        jarFS = JarFS.create(path)
      }
      jarFS.getRoot()
    }
    else new PlainDirectory(path)
  }

  def run(implicit ctx: Context): Unit = {
    new GenBCodePipeline(entryPoints.toList,
        new DottyBackendInterface(outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
    entryPoints.clear()
  }

  override def runOn(units: List[CompilationUnit])(implicit ctx: Context) = {
    try super.runOn(units)
    finally if (jarFS ne null) {
      jarFS.close()
      jarFS = null
    }
  }
}

class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

  var tree: Tree = _

  val sourceFile = ctx.compilationUnit.source
{'fraction_non_alphanumeric': 0.10751865314712072, 'fraction_numerical': 0.0, 'mean_word_length': 4.33469387755102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6265937', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1722, 'n_words': 382}