<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -93,9 +93,10 @@ trait Matrix extends MatrixAdditions {
       roots: List[PatternVar],
       cases: List[CaseDef],
       default: Tree
-    ) {    
+    ) {
       def tvars = roots map (_.lhs)
       def valDefs = roots map (_.valDef)
+      override def toString() = &quot;MatrixInit(roots = %s, %d cases)&quot;.format(pp(roots), cases.size)
     }
     
     implicit def pvlist2pvgroup(xs: List[PatternVar]): PatternVarGroup =
@@ -104,6 +105,20 @@ trait Matrix extends MatrixAdditions {
     object PatternVarGroup {
       def apply(xs: PatternVar*) = new PatternVarGroup(xs.toList)
       def apply(xs: List[PatternVar]) = new PatternVarGroup(xs)
+      
+      // XXX - transitional
+      def fromBindings(vlist: List[Binding], freeVars: List[Symbol] = Nil) = {
+        def vmap(v: Symbol): Option[Binding] = vlist find (_.pvar eq v)
+        val info = 
+          if (freeVars.isEmpty) vlist
+          else (freeVars map vmap).flatten
+        
+        val xs =
+          for (Binding(lhs, rhs) &lt;- info) yield
+            new PatternVar(lhs, Ident(rhs) setType lhs.tpe, !(rhs hasFlag TRANS_FLAG))
+        
+        new PatternVarGroup(xs)
+      }
     }
       
     val emptyPatternVarGroup = PatternVarGroup()
@@ -135,8 +150,8 @@ trait Matrix extends MatrixAdditions {
     class PatternVar(val lhs: Symbol, val rhs: Tree, val checked: Boolean) {
       def sym = lhs
       def valsym = valDef.symbol
-
-      def tpe = valsym.tpe // XXX how will sym.tpe differ from sym.tpe ?
+      // XXX how will valsym.tpe differ from sym.tpe ?
+      def tpe = valsym.tpe
 
       lazy val ident  = ID(lhs)
       lazy val valDef = tracing(&quot;typedVal&quot;, typer typedValDef (VAL(lhs) === rhs))</diff>
      <filename>src/compiler/scala/tools/nsc/matching/Matrix.scala</filename>
    </modified>
    <modified>
      <diff>@@ -57,20 +57,15 @@ trait ParallelMatching extends ast.TreeDSL
      *  the function takes care of binding
      */
     final def requestBody(bx: Int, subst: Bindings): Tree = {
-      implicit val ctx = context
       val target @ FinalState(tbx, body, freeVars) = targets(bx)
-      val substInfo = subst infoFor freeVars
-      import substInfo._
-      
-      // XXX when is this not true?
-      // assert(tbx == bx)
+      val pvgroup = PatternVarGroup.fromBindings(subst.get(), freeVars)
       
       // shortcut
-      if (bx &lt; 0) Apply(ID(shortCuts(-bx-1)), Nil)
+      if (bx &lt; 0) Apply(ID(shortCuts(-bx-1)), Nil)      
       // first time this bx is requested - might be bound elsewhere
-      else if (target.isNotReached) target.createLabelBody(bx, patternVars, patternValDefs)
+      else if (target.isNotReached) target.createLabelBody(bx, pvgroup)
       // call label &quot;method&quot; if possible
-      else target.getLabelBody(idents, patternValDefs)
+      else target.getLabelBody(pvgroup)
     }
 
     /** the injection here handles alternatives and unapply type tests */
@@ -179,7 +174,10 @@ trait ParallelMatching extends ast.TreeDSL
 
       def apply(i: Int): Pattern = ps(i)
       def pzip() = ps.zipWithIndex
-      def pzip[T](others: List[T]) = ps zip others
+      def pzip[T](others: List[T]) = {
+        assert(ps.size == others.size, &quot;Internal error: ps = %s, others = %s&quot;.format(ps, others))
+        ps zip others
+      }
 
       // Any unapply - returns Some(true) if a type test is needed before the unapply can
       // be called (e.g. def unapply(x: Foo) = { ... } but our scrutinee is type Any.)
@@ -223,6 +221,10 @@ trait ParallelMatching extends ast.TreeDSL
     /***** Rule Applications *****/
 
     sealed abstract class RuleApplication {
+      // def isFinal = false
+      // def body = tree
+      // def freeVars = (scrut.pv :: rest.tvars).syms
+      
       def pmatch: PatternMatch
       def rest: Rep
       def cond: Tree
@@ -242,14 +244,14 @@ trait ParallelMatching extends ast.TreeDSL
         pvgroup: PatternVarGroup = emptyPatternVarGroup,
         includeScrut: Boolean = true): Rep =
       {
-        val scrutpvs = if (includeScrut) List(pmatch.scrut.pv) else Nil
+        val scrutpvs = if (includeScrut) List(scrut.pv) else Nil
         make(pvgroup.pvs ::: scrutpvs ::: rest.tvars, rows)  
       }
 
       /** translate outcome of the rule application into code (possible involving recursive application of rewriting) */
       def tree(): Tree
       
-      override def toString = 
+      override def toString =       
         &quot;Rule/%s (%s =^= %s)&quot;.format(getClass.getSimpleName, scrut, head)
     }
 
@@ -262,11 +264,10 @@ trait ParallelMatching extends ast.TreeDSL
       lazy val cond     = if (guard.isEmpty) TRUE else guard.duplicate.tree
       lazy val success  = requestBody(bx, subst)
       lazy val failure  = guardedRest.toTree
-
-      final def tree(): Tree = {
-        implicit val ctx = context
-        squeezedBlock(subst.infoForAll.patternValDefs, codegen)
-      }
+      
+      lazy val pvgroup  = PatternVarGroup.fromBindings(subst.get())
+      
+      final def tree(): Tree = squeezedBlock(pvgroup.valDefs, codegen)
     }
 
     /** Mixture rule for all literal ints (and chars) i.e. hopefully a switch
@@ -721,7 +722,10 @@ trait ParallelMatching extends ast.TreeDSL
         abort(msg.format(name, pp(labelParamTypes), pp(idents), pp(vdefs)))
       }
       
-      def createLabelBody(index: Int, args: List[Symbol], vdefs: List[Tree]) = {
+      def createLabelBody(index: Int, pvgroup: PatternVarGroup) = {
+        def args = pvgroup.syms
+        def vdefs = pvgroup.valDefs
+        
         val name = &quot;body%&quot; + index
         require(_labelSym == null)
         referenceCount += 1
@@ -744,7 +748,9 @@ trait ParallelMatching extends ast.TreeDSL
         ifLabellable(vdefs, squeezedBlock(vdefs, label))
       }
       
-      def getLabelBody(idents: List[Tree], vdefs: List[Tree]): Tree = {        
+      def getLabelBody(pvgroup: PatternVarGroup): Tree = {
+        def idents = pvgroup map (_.rhs)
+        def vdefs = pvgroup.valDefs
         referenceCount += 1
         // if (idents.size != labelParamTypes.size)
         //   consistencyFailure(idents, vdefs)</diff>
      <filename>src/compiler/scala/tools/nsc/matching/ParallelMatching.scala</filename>
    </modified>
    <modified>
      <diff>@@ -114,40 +114,20 @@ trait PatternBindings extends ast.TreeDSL
     // in the compiler, but it suffices for now.
     if (tvar.info containsTp WildcardType)
       tvar setInfo pvar.info
-    
-    def toIdent       = Ident(tvar) setType pvar.tpe
-    def castIfNeeded  = 
-      if (tvar.tpe &lt;:&lt; pvar.tpe) ID(tvar)
-      else ID(tvar) AS_ANY pvar.tpe
-    
+
     override def toString() = pp(pvar -&gt; tvar)
   }
 
-  case class BindingsInfo(xs: List[Binding]) {
-    def patternVars = xs map (_.pvar)
-    def temporaryVars = xs map (_.tvar)
-    def idents = xs map (_.toIdent)
-    
-    def patternValDefs(implicit context: MatrixContext) =
-      for (b @ Binding(pvar, tvar) &lt;- xs) yield
-        context.typedValDef(pvar, b.toIdent)
-  }
-  
-  class Bindings(private val vlist: List[Binding]) extends Function1[Symbol, Option[Ident]] {
+  class Bindings(private val vlist: List[Binding]) {
     if (!vlist.isEmpty)
       traceCategory(&quot;Bindings&quot;, this.toString)
-      
-    def vmap(v: Symbol): Option[Binding] = vlist find (_.pvar eq v)
-    
-    // filters the given list down to those defined in these bindings
-    def infoFor(vs: List[Symbol]) = BindingsInfo(vs map vmap flatten)
-    def infoForAll                = BindingsInfo(vlist)
+
+    def get() = vlist
     
     def add(vs: Iterable[Symbol], tvar: Symbol): Bindings = {
       val newBindings = vs.toList map (v =&gt; Binding(v, tvar))
       new Bindings(newBindings ++ vlist)
     }
-    def apply(v: Symbol): Option[Ident] = vmap(v) map (_.toIdent)
 
     override def toString() = pp(vlist)
   }</diff>
      <filename>src/compiler/scala/tools/nsc/matching/PatternBindings.scala</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c204310f0a304e4179713691aa9f79c1ff913675</id>
    </parent>
  </parents>
  <author>
    <name>extempore</name>
    <email>extempore@5e8d7ff9-d8ef-0310-90f0-a4852d11357a</email>
  </author>
  <url>http://github.com/paulp/scala/commit/69fcfedcf02154b1ea630dd77b0557daeac7b38f</url>
  <id>69fcfedcf02154b1ea630dd77b0557daeac7b38f</id>
  <committed-date>2009-10-11T11:40:08-07:00</committed-date>
  <authored-date>2009-10-11T11:40:08-07:00</authored-date>
  <message>More transitioning bindings to pattern vars.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@19047 5e8d7ff9-d8ef-0310-90f0-a4852d11357a</message>
  <tree>32f0ca5e8e0ddae9908fb9101d3877c939233854</tree>
  <committer>
    <name>extempore</name>
    <email>extempore@5e8d7ff9-d8ef-0310-90f0-a4852d11357a</email>
  </committer>
</commit>
