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

Ensure we do not zero when "moving" types that are Copy #22818

Merged
merged 4 commits into from
Feb 28, 2015

Conversation

pnkfelix
Copy link
Member

Ensure we do not zero when "moving" types that are Copy.

Uses more precise type_needs_drop for deciding about emitting cleanup code. Added notes about the weaknesses regarding ty::type_contents here.

Fix #22536

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@pnkfelix
Copy link
Member Author

(caveat: i have not yet run this through even a make check-stage1 locally yet. But I thought I should get it up for review ASAP.)

cc @nikomatsakis ; I'll happily take a review from anyone who wants to give it, but @eddyb is certainly appropriate too.

@pnkfelix
Copy link
Member Author

see also #22815 -- I had meant to audit (and write comments attached to) all the calls to ty::type_contents in trans, but I only looked at the ones related to type_needs_drop for this task.

@pnkfelix
Copy link
Member Author

(also, I definitely want to play around and write some more tests related to the corner cases here. For example, there are notes in the commits regarding the behavior of the needs_drop intrinsic and what guarantees one can rely on there. but I do not think we need to block this PR on those side tasks.)

@pnkfelix
Copy link
Member Author

(caveat: i have not yet run this through even a make check-stage1 locally yet. But I thought I should get it up for review ASAP.)

It passes make check on my machine. Lets land this puppy!

@pnkfelix
Copy link
Member Author

(one might reasonably point out that I should have alpha-renamed the old common::type_needs_drop to something that makes its less precise nature clear. I can do that if given a good name; common::type_vaguely_needs_drop ? :) )

((one might also reasonably point out that better fixes to #22815 would actually make this particular PR unnecessary.))

@eddyb
Copy link
Member

eddyb commented Feb 26, 2015

@pnkfelix what about type_may_need_drop?


/// Issue #22815: call the `FunctionContext::type_needs_drop` method
/// instead, if possible; it is strictly more precise than this
/// function.
pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to remove this fn, or make it scoped to FunctionContext::type_needs_drop -- is there a reason we can't do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was only implicit in the PR: the two cases where I left calls to common::type_needs_drop were because there is not a FunctionContext readily available. I spent a while tracing back through the call chain to see if I could refactor the code to pass down a Block (with its attached FunctionContext) instead of passing down a CrateContext in each of the two cases, but in both of them as I worked my way backwards it seemed not feasible. (In particular, in one case the call chain goes back to translating const expressions, where I assume it is by design that there is no FunctionContext available.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(okay, fixed so that one can call either one; they have the same semantics now.)

@pnkfelix
Copy link
Member Author

@nikomatsakis has pointed out that even an empty ParameterEnvironment will probably be fine for what I am using it for here, and thus I could probably just change the behavior of common::type_needs_contents rather than adding a new method.

@nikomatsakis
Copy link
Contributor

@bors r+ 9a6e3b9

@bors
Copy link
Contributor

bors commented Feb 26, 2015

⌛ Testing commit 9a6e3b9 with merge e4498c1...

@bors
Copy link
Contributor

bors commented Feb 26, 2015

💔 Test failed - auto-win-32-nopt-t

@pnkfelix
Copy link
Member Author

@alexcrichton this looks safe to retry, yes? (I will be heading off to bed now, so if you could hit "retry" in my stead I would greatly appreciate it!)

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Contributor

bors commented Feb 27, 2015

⌛ Testing commit 9a6e3b9 with merge 431430c...

@bors
Copy link
Contributor

bors commented Feb 27, 2015

💔 Test failed - auto-mac-64-nopt-t

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 27, 2015
…sakis

 Ensure we do not zero when \"moving\" types that are Copy.

Uses more precise `type_needs_drop` for deciding about emitting cleanup code.  Added notes about the weaknesses regarding `ty::type_contents` here.

Fix rust-lang#22536
@alexcrichton
Copy link
Member

@bors: retry

@bors bors merged commit 9a6e3b9 into rust-lang:master Feb 28, 2015
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

Successfully merging this pull request may close these issues.

Some objects get zeroed when copied from, affecting original object
6 participants