You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program prints "0\n0\n", when it should print "0\n":
resource echo(x: {mut a: int}) {
io::println(#fmt("%d", x.a));
x.a += 1;
}
fn main() {
let x = [echo({mut a: 0})];
let y = x;
}
The same effect occurs if you rename y to _y to eliminate the unused variable warning. The same effect does not occur if you use y, eg the following program has correct behavior:
resource echo(x: {mut a: int}) {
io::println(#fmt("%d", x.a));
x.a += 1;
}
fn main() {
let x = [echo({mut a: 0})];
let y = x;
y;
}
The use of a record with a mutable field is also not essential to the bug; I used it to demonstrate that the bug is actually due to copying, and not running the destructor twice on the same value.
It looks like the bug is in the code for initializing locals when it has been determined that they can be kept off of the stack. As it turns out, basically the only way to keep liveness from saying something needs to be kept on the stack is for it to be unused.
I'm just going to fix this by getting rid of the stuff where we avoid spilling variables. It never seems to get used and llvm can do it anyways.
Activity
pcwalton commentedon May 18, 2012
I suspect the no-implicit-copies proposal fixes this.
nikomatsakis commentedon May 18, 2012
in theory, resources ought not to be copyable in the first place.
msullivan commentedon May 29, 2012
y is a last-use of x, though, so it isn't a copy, it's a move, right?
nikomatsakis commentedon May 30, 2012
indeed. I presume then that this is a bug in trans, where the last_use information is not being used and so a copy is induced.
nikomatsakis commentedon May 30, 2012
hmm, my theory may not hold water. it's not clear to me why using y would prevent the error, then.
msullivan commentedon Jun 5, 2012
It looks like the bug is in the code for initializing locals when it has been determined that they can be kept off of the stack. As it turns out, basically the only way to keep liveness from saying something needs to be kept on the stack is for it to be unused.
I'm just going to fix this by getting rid of the stuff where we avoid spilling variables. It never seems to get used and llvm can do it anyways.
nikomatsakis commentedon Jun 6, 2012
@msullivan is this bug specifically in the code that you will be deleting? or is it some more general thing in the treatment of immediates?
msullivan commentedon Jun 6, 2012
I believe the bug is specifically in the code for immediate local variable initialization, but similar bugs might lurk elsewhere.
Auto merge of rust-lang#2408 - RalfJung:deps, r=oli-obk
Explicitly pass out_file to benchcomp visualizers (rust-lang#2408)
Merge pull request rust-lang#2408 from chenyukang/yukang-add-llvm-link
Merge rust-lang#2408