<commit_before>package scalan.staged

import scalan.ScalanExp
import scalan.common.GraphUtil

trait ProgramGraphs extends AstGraphs { self: ScalanExp =>

  type PGraph = ProgramGraph[MapTransformer]

  // immutable program graph
  case class ProgramGraph[Ctx <: Transformer : TransformerOps](roots: List[Exp[_]], mapping: Ctx)
  	  extends AstGraph {
    def this(roots: List[Exp[_]]) { this(roots, implicitly[TransformerOps[Ctx]].empty) }
    def this(root: Exp[_]) { this(List(root)) }

    override def boundVars = Nil
    override def freeVars = Set()
    override lazy val schedule = super.schedule

    def transform(m: Mirror[Ctx], rw: Rewriter, t: Ctx): ProgramGraph[Ctx] = {
      val t0 = t merge mapping
      val (t1, _) = m.mirrorSymbols(t0, rw, this, scheduleSyms)
      val newRoots = roots map { t1(_) }
      new ProgramGraph(newRoots, t1)
    }

    def transformOne(oldExp:Exp[_], newExp:Exp[_]): ProgramGraph[Ctx] = {
      val newRoots = roots map (x => x match {case v: Exp[_] if v == oldExp => newExp; case t => t }  )
      new ProgramGraph(newRoots, mapping)
    }


    def withoutContext = ProgramGraph(roots, implicitly[TransformerOps[Ctx]].empty)
  }
}<commit_msg>[Transform] simplify graph transformation from REPL or debug session<commit_after>package scalan.staged

import scalan.ScalanExp
import scalan.common.GraphUtil

trait ProgramGraphs extends AstGraphs { self: ScalanExp =>

  type PGraph = ProgramGraph[MapTransformer]

  // immutable program graph
  case class ProgramGraph[Ctx <: Transformer : TransformerOps](roots: List[Exp[_]], mapping: Ctx)
  	  extends AstGraph {
    def this(roots: List[Exp[_]]) { this(roots, implicitly[TransformerOps[Ctx]].empty) }
    def this(root: Exp[_]) { this(List(root)) }

    override def boundVars = Nil
    override def freeVars = Set()
    override lazy val schedule = super.schedule

    def transform(m: Mirror[Ctx], rw: Rewriter, t: Ctx): ProgramGraph[Ctx] = {
      val t0 = t merge mapping
      val (t1, _) = m.mirrorSymbols(t0, rw, this, scheduleSyms)
      val newRoots = roots map { t1(_) }
      new ProgramGraph(newRoots, t1)
    }

    def transformOne(oldExp:Exp[_], newExp:Exp[_]): ProgramGraph[Ctx] = {
      val newRoots = roots map (x => x match {case v: Exp[_] if v == oldExp => newExp; case t => t }  )
      new ProgramGraph(newRoots, mapping)
    }


    def withoutContext = ProgramGraph(roots, implicitly[TransformerOps[Ctx]].empty)
  }

  object ProgramGraph {
    def transform[A](s: Rep[A], rw: Rewriter = NoRewriting, t: MapTransformer = MapTransformer.Empty): Rep[A] = {
      val g = ProgramGraph(List(s), t)
      val g1 = g.transform(DefaultMirror, rw, t)
      g1.roots(0).asRep[A]
    }
  }
}
{'fraction_non_alphanumeric': 0.12273567467652495, 'fraction_numerical': 0.004805914972273568, 'mean_word_length': 3.722513089005236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '131616', 'n_tokens_mistral': 916, 'n_tokens_neox': 895, 'n_words': 240}