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

Avoid adding drops for types w/ no dtor in MIR construction #30492

Merged
merged 1 commit into from
Jan 6, 2016

Conversation

wesleywiser
Copy link
Member

Fixes #28159

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

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

@wesleywiser
Copy link
Member Author

I'm not really sure how to write an automated test for this. If someone can point me in the right direction, I'd be happy to add one.

/// (Note that this implies that if `ty` has a destructor attached,
/// then `type_needs_drop` will definitely return `true` for `ty`.)
pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
self.type_needs_drop_given_env(ty, &self.empty_parameter_environment())
Copy link
Member

Choose a reason for hiding this comment

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

Is it really fine to use empty param environment here? I assume this is supposed to hold some sort of substs for generics. It was fine to do pass empty environment in trans, because all types are monomorphized there, but in middle::ty or mir::hair::cx you cannot assume that types will be monomorphized (they usually won’t be).

@wesleywiser
Copy link
Member Author

@nagisa @pnkfelix I've updated the code to pass along self.infcx.parameter_environment. From your feedback, I don't think it makes sense to have type_needs_drop in middle since any code at that point should be passing in a ParameterEnvironment so I've moved type_needs_drop back into trans.

@@ -105,11 +105,7 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {

pub fn needs_drop(&mut self, ty: Ty<'tcx>, span: Span) -> bool {
if self.infcx.type_moves_by_default(ty, span) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this first if redundant now? Maybe the whole method body can be simplified to a single function call?

@pnkfelix
Copy link
Member

Seems fine apart from the potential redundancy noted above. r=me once that is either removed or explained (in the latter case, a comment on this PR would suffice)

@wesleywiser
Copy link
Member Author

type_moves_by_default simply checks if the type implements Copy. type_needs_drop_given_env already checks that so I think you are correct and the function can be simplified.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 5, 2016

@bors r+ 8c897ee

bors added a commit that referenced this pull request Jan 6, 2016
@bors
Copy link
Contributor

bors commented Jan 6, 2016

⌛ Testing commit 8c897ee with merge dc1f442...

@bors
Copy link
Contributor

bors commented Jan 6, 2016

💔 Test failed - auto-linux-64-opt

@pnkfelix
Copy link
Member

pnkfelix commented Jan 6, 2016

@bors retry

@bors bors merged commit 8c897ee into rust-lang:master Jan 6, 2016
@wesleywiser
Copy link
Member Author

Thanks everybody!

On Wed, Jan 6, 2016, 2:29 AM bors [email protected] wrote:

Merged #30492 #30492.


Reply to this email directly or view it on GitHub
#30492 (comment).

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.

5 participants