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 writing a temporary closure kind #34986

Merged
merged 2 commits into from
Jul 31, 2016
Merged

Conversation

nikomatsakis
Copy link
Contributor

We used to write a temporary closure kind into the inference table, but
this could lead to obligations being incorrectled resolved before
inference had completed. This result could then be cached, leading to
further trouble. This patch avoids writing any closure kind until the
computation is complete.

Fixes #34349.

r? @arielb1 -- what do you think?

We used to write a temporary closure kind into the inference table, but
this could lead to obligations being incorrectled resolved before
inference had completed. This result could then be cached, leading to
further trouble. This patch avoids writing any closure kind until the
computation is complete.

Fixes rust-lang#34349.
@arielb1
Copy link
Contributor

arielb1 commented Jul 23, 2016

I would prefer passing the "during_closure_kind_inference" flag to MC (through EUV) rather than a on-infcx flag.

Are you sure the value of the closure kind is not needed for upvar inference to work correctly? Using EUV/MC in this context feels super-dubious, but it is what we have now.

@nikomatsakis
Copy link
Contributor Author

I would prefer passing the "during_closure_kind_inference" flag to MC (through EUV) rather than a on-infcx flag.

I started this way, but mainly stopped because it seemed like it was affecting a lot of code. The flag has to be passed through both the MC and EUV. But I can do it that way if you prefer; I agree it's mildly cleaner (and hence the reason I started that way).

Are you sure the value of the closure kind is not needed for upvar inference to work correctly? Using EUV/MC in this context feels super-dubious, but it is what we have now.

I didn't go back digging through the code, so I don't have citations, but indeed it's how it was designed to work. IIRC we translate a reference to an upvar x to something like *self.x -- and the upvar inference code intercepts a borrow/write/whatever of this whole chain, so it never really looks at the details.

We used to put the flag on the `InferCtxt`.
@nikomatsakis
Copy link
Contributor Author

@arielb1 moved flag.

@@ -259,7 +263,7 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
})
}

fn adjust_upvar_borrow_kind_for_consume(&self,
fn adjust_upvar_borrow_kind_for_consume(&mut self,
cmt: mc::cmt<'tcx>,
mode: euv::ConsumeMode)
{
Copy link
Contributor

@arielb1 arielb1 Jul 31, 2016

Choose a reason for hiding this comment

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

The code below is, like, super-dubious. Why is the guarantor supposed to be a deref of anything when we are moving out of a closure?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc #30046

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code below is, like, super-dubious. Why is the guarantor supposed to be a deref of anything when we are moving out of a closure?

I'll have to re-read it, but I imagine because we are hard-coding the closure upvar kind to Fn.

@arielb1
Copy link
Contributor

arielb1 commented Jul 31, 2016

The code at upvar is a bit too dubious and is seriously in need of cleanup.

OTOH, beta probably wants this fix, so

@bors r+

and leave the cleanup to another commit.

@bors
Copy link
Contributor

bors commented Jul 31, 2016

📌 Commit 63eb4d9 has been approved by arielb1

@bors
Copy link
Contributor

bors commented Jul 31, 2016

⌛ Testing commit 63eb4d9 with merge 2b87f03...

bors added a commit that referenced this pull request Jul 31, 2016
Avoid writing a temporary closure kind

We used to write a temporary closure kind into the inference table, but
this could lead to obligations being incorrectled resolved before
inference had completed. This result could then be cached, leading to
further trouble. This patch avoids writing any closure kind until the
computation is complete.

Fixes #34349.

r? @arielb1 -- what do you think?
@bors bors merged commit 63eb4d9 into rust-lang:master Jul 31, 2016
@arielb1 arielb1 added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 31, 2016
@nikomatsakis nikomatsakis added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Aug 4, 2016
brson added a commit that referenced this pull request Aug 8, 2016
@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 8, 2016
pmatos pushed a commit to LinkiTools/rust that referenced this pull request Sep 27, 2016
@nikomatsakis nikomatsakis deleted the issue-34349 branch October 3, 2016 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encountered error Unimplemented selecting Binder(<[closure ...] as Fn()>) during trans
4 participants