Closed
Description
The liveness pass should be extended to treat stack closures just like a loop body. This is relatively straightforward. It would allow for a couple of nice things:
-
it'd be more efficient in some cases (I believe the last_use code I replaced actually did this right) because we could move values in if there were a loop like
let mut v = [];
uint::range(...) { |i|
use(v);
v = [some new vec];
} -
it allows us to right fold for arbitrary iteration with only moves:
let mut b = b0;
for as.each { |a|
b <- op(a, b);
}
ret b;In this case, the value in
op(e, b)
is actually moved out temporarily but always restored by the end of the loop. This would work today with a while loop but not with a closure-based loop.