pub fn fuse_loops_vertical(expr: &mut Expr) {
    expr.transform_and_continue_res(&mut |ref mut expr| {
        let mut sym_gen = SymbolGenerator::from_expression(expr);
        if let For {
            iters: ref all_iters,
            builder: ref bldr1,
            func: ref nested,
        } = expr.kind
        {
            if all_iters.len() == 1 {
                let iter1 = &all_iters[0];
                if let Res {
                    builder: ref res_bldr,
                } = iter1.data.kind
                {
                    if let For {
                        iters: ref iters2,
                        builder: ref bldr2,
                        func: ref lambda,
                    } = res_bldr.kind
                    {
                        if iters2.iter().all(|ref i| consumes_all(&i)) {
                            if let NewBuilder(_) = bldr2.kind {
                                if let Builder(ref kind, _) = bldr2.ty {
                                    if let Appender(_) = *kind {
                                        let mut e = Expr::new_for(
                                            iters2.clone(),
                                            *bldr1.clone(),
                                            replace_builder(lambda, nested, &mut sym_gen)?,
                                        )?;
                                        e.annotations = expr.annotations.clone();
                                        return Ok((Some(e), true));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        Ok((None, true))
    });
}
Fuses loops where one for loop takes another as it's input, which prevents intermediate results
from being materialized.
weld/src/optimizer/transforms/loop_fusion.rs