-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Use of unimplemented!() causing ICE with NLL #52058
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,25 +53,22 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> { | |
} | ||
} | ||
|
||
/// Every two-phase borrow has *exactly one* use (or else it is not a | ||
/// proper two-phase borrow under our current definition). However, not | ||
/// all uses are actually ones that activate the reservation.. In | ||
/// particular, a shared borrow of a `&mut` does not activate the | ||
/// reservation. | ||
/// Location where a two phase borrow is activated, if a borrow | ||
/// is in fact a two phase borrow. | ||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
crate enum TwoPhaseUse { | ||
MutActivate, | ||
SharedUse, | ||
crate enum TwoPhaseActivation { | ||
NotTwoPhase, | ||
NotActivated, | ||
ActivatedAt(Location), | ||
} | ||
|
||
#[derive(Debug)] | ||
crate struct BorrowData<'tcx> { | ||
/// Location where the borrow reservation starts. | ||
/// In many cases, this will be equal to the activation location but not always. | ||
crate reserve_location: Location, | ||
/// Location where the borrow is activated. None if this is not a | ||
/// 2-phase borrow. | ||
crate activation_location: Option<(TwoPhaseUse, Location)>, | ||
/// Location where the borrow is activated. | ||
crate activation_location: TwoPhaseActivation, | ||
/// What kind of borrow this is | ||
crate kind: mir::BorrowKind, | ||
/// The region for which this borrow is live | ||
|
@@ -116,19 +113,6 @@ impl<'tcx> BorrowSet<'tcx> { | |
visitor.visit_basic_block_data(block, block_data); | ||
} | ||
|
||
// Double check: We should have found an activation for every pending | ||
// activation. | ||
assert_eq!( | ||
visitor | ||
.pending_activations | ||
.iter() | ||
.find(|&(_local, &borrow_index)| visitor.idx_vec[borrow_index] | ||
.activation_location | ||
.is_none()), | ||
None, | ||
"never found an activation for this borrow!", | ||
); | ||
|
||
BorrowSet { | ||
borrows: visitor.idx_vec, | ||
location_map: visitor.location_map, | ||
|
@@ -183,7 +167,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> { | |
kind, | ||
region, | ||
reserve_location: location, | ||
activation_location: None, | ||
activation_location: TwoPhaseActivation::NotTwoPhase, | ||
borrowed_place: borrowed_place.clone(), | ||
assigned_place: assigned_place.clone(), | ||
}; | ||
|
@@ -232,38 +216,42 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> { | |
return; | ||
} | ||
|
||
if let Some(other_activation) = borrow_data.activation_location { | ||
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_activation, | ||
other_location, | ||
); | ||
} | ||
|
||
// Otherwise, this is the unique later use | ||
// that we expect. | ||
|
||
let two_phase_use; | ||
|
||
match context { | ||
borrow_data.activation_location = match context { | ||
// The use of TMP in a shared borrow does not | ||
// count as an actual activation. | ||
PlaceContext::Borrow { kind: mir::BorrowKind::Shared, .. } => { | ||
two_phase_use = TwoPhaseUse::SharedUse; | ||
TwoPhaseActivation::NotActivated | ||
} | ||
_ => { | ||
two_phase_use = TwoPhaseUse::MutActivate; | ||
// Double check: We should have found an activation for every pending | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this commit is not quite correct -- that is, what we are checking here is that (a) this is indeed a 2-phase borrow and (b) we've not found some other activation (though we also check that above), right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed improved comments. |
||
// activation. | ||
assert_eq!( | ||
borrow_data.activation_location, | ||
TwoPhaseActivation::NotActivated, | ||
"never found an activation for this borrow!", | ||
); | ||
|
||
self.activation_map | ||
.entry(location) | ||
.or_insert(Vec::new()) | ||
.push(borrow_index); | ||
TwoPhaseActivation::ActivatedAt(location) | ||
} | ||
} | ||
|
||
borrow_data.activation_location = Some((two_phase_use, location)); | ||
}; | ||
} | ||
|
||
None => {} | ||
|
@@ -342,6 +330,10 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> { | |
); | ||
}; | ||
|
||
// Consider the borrow not activated. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say "Consider the borrow not activated to start. When we find an activation, we'll update this field." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed improved comments. |
||
let borrow_data = &mut self.idx_vec[borrow_index]; | ||
borrow_data.activation_location = TwoPhaseActivation::NotActivated; | ||
|
||
// Insert `temp` into the list of pending activations. From | ||
// now on, we'll be on the lookout for a use of it. Note that | ||
// we are guaranteed that this use will come after the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// error-pattern: thread 'main' panicked at 'explicit panic' | ||
|
||
#![feature(nll)] | ||
|
||
fn main() { | ||
let mut vec = vec![]; | ||
vec.push((vec.len(), panic!())); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(nll)] | ||
|
||
fn main() { | ||
let mut v = Vec::new(); | ||
|
||
loop { v.push(break) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned here because I don't know where two-phase borrows that wind up unactivated will be set to
TwoPhaseActivation::NotActivated
. I think they will erroneously be recorded as not two phase. This means we will get an error with e.g. this code:I expect this to error because the borrow of
vec
for callingpush
will incorrectly be considered "not two phase".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix this, I think we can modify
insert_as_pending_if_two_phase
to set theactivation_location
field toNotActivated
instead ofNotTwoPhase
. Then when we do find an activation we can assert that the field is "not activated".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am correct about all this btw please add that above test. =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit that addresses this.