<commit_before>/* NSC -- new Scala compiler
 * Copyright 2005-2010 LAMP/EPFL
 * @author <NAME>
 */

package scala.tools.nsc

/** An nsc sub-component.
 *
 *  @author <NAME>
 */
abstract class SubComponent {

  /** The global environment; overridden by instantiation in Global. */
  val global: Global

  /** The name of the phase */
  val phaseName: String

  /** List of phase names, this phase should run after  */
  val runsAfter: List[String]

  /** List of phase names, this phase should run before  */
  val runsBefore: List[String] = Nil

  /** Phase name this phase will attach itself to, not allowing any phase to come between it
   * and the phase name declared  */
  val runsRightAfter: Option[String]

  /** Internal flag to tell external from internal phases */
  val internal: Boolean = true

  /** SubComponent are added to a HashSet and two phases are the same if they have the same name  */
  override def hashCode() = phaseName.hashCode()

  /** New flags defined by the phase which are not valid before */
  def phaseNewFlags: Long = 0

  /** New flags defined by the phase which are not valid until immediately after it */
  def phaseNextFlags: Long = 0

  /** The phase factory */
  def newPhase(prev: Phase): Phase

  private var ownPhaseCache: Phase = _
  private var ownPhaseRunId = global.NoRunId

  /** The phase corresponding to this subcomponent in the current compiler run */
  def ownPhase: Phase = {
    if (ownPhaseRunId != global.currentRunId) {
      ownPhaseCache = global.currentRun.phaseNamed(phaseName)
      ownPhaseRunId = global.currentRunId
    }
    ownPhaseCache
  }

  /** The phase defined by this subcomponent. Can be called only after phase is installed by newPhase. */
  //  lazy val ownPhase: Phase = global.currentRun.phaseNamed(phaseName)

  /** A standard phase template */
  abstract class StdPhase(prev: Phase) extends global.GlobalPhase(prev) {
    def name = phaseName
    override def newFlags = phaseNewFlags
    override def nextFlags = phaseNextFlags
  }
}<commit_msg>Make the ownPhaseCache field a weak reference.<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2010 LAMP/EPFL
 * @author <NAME>
 */

package scala.tools.nsc

import scala.ref.WeakReference

/** An nsc sub-component.
 *
 *  @author <NAME>
 */
abstract class SubComponent {

  /** The global environment; overridden by instantiation in Global. */
  val global: Global

  /** The name of the phase */
  val phaseName: String

  /** List of phase names, this phase should run after  */
  val runsAfter: List[String]

  /** List of phase names, this phase should run before  */
  val runsBefore: List[String] = Nil

  /** Phase name this phase will attach itself to, not allowing any phase to come between it
   * and the phase name declared  */
  val runsRightAfter: Option[String]

  /** Internal flag to tell external from internal phases */
  val internal: Boolean = true

  /** SubComponent are added to a HashSet and two phases are the same if they have the same name  */
  override def hashCode() = phaseName.hashCode()

  /** New flags defined by the phase which are not valid before */
  def phaseNewFlags: Long = 0

  /** New flags defined by the phase which are not valid until immediately after it */
  def phaseNextFlags: Long = 0

  /** The phase factory */
  def newPhase(prev: Phase): Phase

  private var ownPhaseCache: WeakReference[Phase] = new WeakReference(null)
  private var ownPhaseRunId = global.NoRunId

  /** The phase corresponding to this subcomponent in the current compiler run */
  def ownPhase: Phase = {
    ownPhaseCache.get match {
      case Some(phase) if ownPhaseRunId == global.currentRunId =>
        phase
      case _ =>
        val phase = global.currentRun.phaseNamed(phaseName)
        ownPhaseCache = new WeakReference(phase)
        ownPhaseRunId = global.currentRunId
        phase
    }
  }

  /** The phase defined by this subcomponent. Can be called only after phase is installed by newPhase. */
  //  lazy val ownPhase: Phase = global.currentRun.phaseNamed(phaseName)

  /** A standard phase template */
  abstract class StdPhase(prev: Phase) extends global.GlobalPhase(prev) {
    def name = phaseName
    override def newFlags = phaseNewFlags
    override def nextFlags = phaseNextFlags
  }
}
{'fraction_non_alphanumeric': 0.08475367732897501, 'fraction_numerical': 0.0046696240952603316, 'mean_word_length': 3.2457879088206143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5004408', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1153, 'n_words': 488}