in scalding-base/src/main/scala/com/twitter/scalding/ExecutionOptimizationRules.scala [17:66]
def widen[T](l: LiteralExecution[_ <: T]): LiteralExecution[T] =
// to prove this is safe, see that if you have
// LiteralExecution[_ <: T] we can call .evaluate to get
// Execution[_ <: T] which due to covariance is
// Execution[T], and then using toLiteral we can get
// LiteralExecution[T]
//
// that would be wasteful to apply since the final
// result is identity.
l.asInstanceOf[LiteralExecution[T]]
def toLiteral: FunctionK[Execution, LiteralExecution] =
Memoize.functionK[Execution, LiteralExecution](
new Memoize.RecursiveK[Execution, LiteralExecution] {
override def toFunction[A] = {
case (e @ Execution.ReaderExecution, _) =>
Literal.Const(e)
case (e: Execution.FutureConst[a], _) =>
Literal.Const(e)
case (e: Execution.UniqueIdExecution[a], _) =>
Literal.Const(e)
case (e: Execution.BackendExecution[a], _) =>
Literal.Const(e)
case (e: Execution.WriteExecution[a], _) =>
Literal.Const(e)
case (e: Execution.GetCounters[a], f) =>
widen(
Literal.Unary[Execution, a, (a, ExecutionCounters)](
f(e.prev),
Execution.GetCounters(_: Execution[a])
)
)
case (e: Execution.ResetCounters[a], f) =>
Literal.Unary(f(e.prev), Execution.ResetCounters(_: Execution[a]))
case (e: Execution.WithNewCache[a], f) =>
Literal.Unary(f(e.prev), Execution.WithNewCache(_: Execution[a]))
case (e: Execution.TransformedConfig[a], f) =>
Literal.Unary(f(e.prev), Execution.TransformedConfig(_: Execution[a], e.fn))
case (e: Execution.OnComplete[a], f) =>
Literal.Unary(f(e.prev), Execution.OnComplete(_: Execution[a], e.fn))
case (e: Execution.RecoverWith[a], f) =>
Literal.Unary(f(e.prev), Execution.RecoverWith(_: Execution[a], e.fn))
case (e: Execution.Mapped[a, b], f) =>
Literal.Unary(f(e.prev), Execution.Mapped(_: Execution[a], e.fn))
case (e: Execution.FlatMapped[a, b], f) =>
Literal.Unary(f(e.prev), Execution.FlatMapped(_: Execution[a], e.fn))
case (e: Execution.Zipped[a, b], f) =>
Literal.Binary(f(e.one), f(e.two), Execution.Zipped(_: Execution[a], _: Execution[b]))
}
}