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

Is an InlineAsm output a potential use that needs to activate a borrow? #46891

Closed
scottmcm opened this issue Dec 20, 2017 · 5 comments
Closed
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-sound Working towards the "invalid code does not compile" goal P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

I added the following FIXME recently: https://github.com/rust-lang/rust/blob/fb245e0/src/librustc_mir/dataflow/impls/borrows.rs#L543-L546

I'll gladly make a PR to change this or remove the fixme, but I don't know enough to decide what should happen.

cc @nikomatsakis maybe?

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Dec 20, 2017 via email

@pnkfelix pnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll labels Dec 21, 2017
@nikomatsakis nikomatsakis added the NLL-sound Working towards the "invalid code does not compile" goal label Mar 14, 2018
@XAMPPRocky XAMPPRocky added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Mar 26, 2018
@nikomatsakis
Copy link
Contributor

Given the more limited definition of two-phase borrows, I think it's impossible for such a use to activate a borrow?

@nikomatsakis nikomatsakis added NLL-deferred and removed NLL-sound Working towards the "invalid code does not compile" goal labels Apr 3, 2018
@pnkfelix
Copy link
Member

Re-triaging for #56754. NLL-sound. But since inline ASM is unstable, I'm tentatively tagging as P-medium; there's bigger fish for NLL to fry, IMO.

@pnkfelix pnkfelix added P-medium Medium priority NLL-sound Working towards the "invalid code does not compile" goal and removed NLL-deferred labels Dec 19, 2018
@matthewjasper
Copy link
Contributor

It also applies only to a version of two-phase borrows that no-longer exists. The current two-phase borrow implementation activates on any use other than a SharedBorrow:

fn visit_local(
&mut self,
temp: &Local,
context: PlaceContext<'tcx>,
location: Location,
) {
if !context.is_use() {
return;
}
// We found a use of some temporary TMP
// check whether we (earlier) saw a 2-phase borrow like
//
// TMP = &mut place
if let Some(&borrow_index) = self.pending_activations.get(temp) {
let borrow_data = &mut self.idx_vec[borrow_index];
// Watch out: the use of TMP in the borrow itself
// doesn't count as an activation. =)
if borrow_data.reserve_location == location &&
context == PlaceContext::MutatingUse(MutatingUseContext::Store)
{
return;
}
if let TwoPhaseActivation::ActivatedAt(other_location) =
borrow_data.activation_location {
span_bug!(
self.mir.source_info(location).span,
"found two uses for 2-phase borrow temporary {:?}: \
{:?} and {:?}",
temp,
location,
other_location,
);
}
// Otherwise, this is the unique later use
// that we expect.
borrow_data.activation_location = match context {
// The use of TMP in a shared borrow does not
// count as an actual activation.
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) =>
TwoPhaseActivation::NotActivated,
_ => {
// Double check: This borrow is indeed a two-phase borrow (that is,
// we are 'transitioning' from `NotActivated` to `ActivatedAt`) and
// we've not found any other activations (checked above).
assert_eq!(
borrow_data.activation_location,
TwoPhaseActivation::NotActivated,
"never found an activation for this borrow!",
);
self.activation_map
.entry(location)
.or_default()
.push(borrow_index);
TwoPhaseActivation::ActivatedAt(location)
}
};
}
}

@nikomatsakis
Copy link
Contributor

Discussing in NLL meeting. Closing as out of date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-enhancement Category: An issue proposing an enhancement or a PR with one. NLL-sound Working towards the "invalid code does not compile" goal P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants