Permalink
Browse files

Transitively handle nested binds

Adding ability to process additional maps at the end of the original flatmap clause.
  • Loading branch information...
deusaquilus committed Dec 28, 2016
1 parent 3f5c675 commit 14e0ce5cbde3d975e54db7a496ea3409db552a01
Showing with 35 additions and 21 deletions.
  1. +35 −21 slick/src/main/scala/slick/compiler/UnrollTailBinds.scala
@@ -16,32 +16,46 @@ class UnrollTailBinds extends Phase {
def tr(n: Node): Node = {
n match {
case bb@Bind(br,
Bind(bo, Filter(fa, ff1, where1), Filter(fb, ff2, where2)),
downstream:Bind,
Bind(bi, bf, select)) => {
// make a new symbol
val bm = new AnonSymbol
def rep(node: Node) = {
def repInternal(node: Node): Node = {
val out = node.replace({
case p@Path(brs :: tail) if brs == br => {
Path(List(bm) ++ tail)
}
}, bottomUp = true, keepType = true)
out.mapChildren(repInternal)
// make a new symbol
val bm = new AnonSymbol
def rep(node: Node) = {
def repInternal(node: Node): Node = {
val out = node.replace({
case p@Path(brs :: tail) if brs == br => {
Path(List(bm) ++ tail)
}
}, bottomUp = true, keepType = true)
out.mapChildren(repInternal)
}
repInternal(node)
}
def replaceDownstream(node:Bind):Option[Node] = {
node match {
case Bind(bo, Filter(fa, ff1, where1), Filter(fb, ff2, where2)) => {
val out = Bind(bo,
Filter(fa, rep(ff1), rep(where1)),
Bind(bm,
Filter(fb, rep(ff2), rep(where2)),
Bind(bi, rep(bf), rep(select))))
Some(out)
}
repInternal(node)
case Bind(bo1, bi1:Bind, sel1) => replaceDownstream(bi1).map(
replacement => Bind(bo1, replacement, sel1))
case n => None
}
// bind all needed elements to the new symbol
val bindCombo = Bind(bo,
Filter(fa, rep(ff1), rep(where1)), //replace s4 here with s5
Bind(bm,
Filter(fb, rep(ff2), rep(where2)), // replace s4 here with s5
Bind(bi, rep(bf), rep(select)))) // replace s4 here with s5
bindCombo.mapChildren(tr)
}
case n => n.mapChildren(tr)
// bind all needed elements to the new symbol
val bindCombo = replaceDownstream(downstream).getOrElse(bb)
bindCombo.mapChildren(tr)
}
case n => n.mapChildren(tr)
}
}

0 comments on commit 14e0ce5

Please sign in to comment.