Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused var causes copying of resource type #2408

Closed
rntz opened this issue May 18, 2012 · 8 comments
Closed

unused var causes copying of resource type #2408

rntz opened this issue May 18, 2012 · 8 comments

Comments

@rntz
Copy link
Contributor

rntz commented May 18, 2012

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.

@pcwalton
Copy link
Contributor

I suspect the no-implicit-copies proposal fixes this.

@nikomatsakis
Copy link
Contributor

in theory, resources ought not to be copyable in the first place.

@msullivan
Copy link
Contributor

y is a last-use of x, though, so it isn't a copy, it's a move, right?

@nikomatsakis
Copy link
Contributor

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
Copy link
Contributor

hmm, my theory may not hold water. it's not clear to me why using y would prevent the error, then.

@msullivan
Copy link
Contributor

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.

@ghost ghost assigned msullivan Jun 5, 2012
@nikomatsakis
Copy link
Contributor

@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
Copy link
Contributor

I believe the bug is specifically in the code for immediate local variable initialization, but similar bugs might lurk elsewhere.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
make test-cargo-miri only about cargo

Move the things that actually test dependency behavior into the regular test suite, now that we can do that. :)
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
This commit adds an `out_file` to the benchcomp visualizes that emit
output (currently just one visualization, dump_yaml). This is to allow
different visualizations to be written to different output files,
including stdout.

The intention (for a future commit) is that CI will save certain
visualizations as artifacts, which users can then download.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants