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

Use place directly its copy #70627

Merged
merged 18 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d45dca3
Use Place directly, it's Copy
spastorino Mar 30, 2020
f026441
Use Place directly on propagate_closure_used_mut_place, it's Copy
spastorino Mar 30, 2020
a67b28a
Use Place directly on borrow_of_local_data, it's Copy
spastorino Mar 30, 2020
32a7618
Use Place directly on remove_never_initialized_mut_locals, it's Copy
spastorino Mar 30, 2020
760bca4
Use Place directly on check_mut_borrowing_layout_constrained_field, i…
spastorino Mar 30, 2020
25528c1
Use Place directly, it's Copy more use cases
spastorino Mar 30, 2020
890b393
Use Place directly, it's Copy even more use cases
spastorino Mar 31, 2020
6a95bf8
Use Place directly on Operand::place and friends, it's Copy
spastorino Mar 31, 2020
f37d2b8
Use Place directly in librustc_mir_build, it's Copy
spastorino Mar 31, 2020
5987b0f
Use Place directly in place_as_reborrow, it's Copy
spastorino Mar 31, 2020
947c1dc
Use Place directly on place_contents_drop_state_cannot_differ, it's Copy
spastorino Mar 31, 2020
017620f
Use Place directly in peek_at, it's Copy
spastorino Mar 31, 2020
afcd7fc
Use Place directly on codegen_drop_terminator, it's Copy
spastorino Mar 31, 2020
5f8a6ed
Use Place directly on make_return_dest, it's Copy
spastorino Mar 31, 2020
1f5338c
Use Place directly in codegen_transmute, it's Copy
spastorino Mar 31, 2020
a865e77
Use Place directly in evaluate_array_len, it's Copy
spastorino Mar 31, 2020
017608f
Use Place directly in codegen_place_to_pointer, it's Copy
spastorino Mar 31, 2020
b46754e
Use Place directly in apply_call_return_effect on framework/tests, it…
spastorino Mar 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self,
helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx,
location: &mir::Place<'tcx>,
location: mir::Place<'tcx>,
target: mir::BasicBlock,
unwind: Option<mir::BasicBlock>,
) {
Expand Down Expand Up @@ -580,7 +580,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

if intrinsic == Some("transmute") {
if let Some(destination_ref) = destination.as_ref() {
let &(ref dest, target) = destination_ref;
let &(dest, target) = destination_ref;
self.codegen_transmute(&mut bx, &args[0], dest);
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
helper.funclet_br(self, &mut bx, target);
Expand Down Expand Up @@ -619,7 +619,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let mut llargs = Vec::with_capacity(arg_count);

// Prepare the return value destination
let ret_dest = if let Some((ref dest, _)) = *destination {
let ret_dest = if let Some((dest, _)) = *destination {
let is_intrinsic = intrinsic.is_some();
self.make_return_dest(&mut bx, dest, &fn_abi.ret, &mut llargs, is_intrinsic)
} else {
Expand Down Expand Up @@ -873,7 +873,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.unreachable();
}

mir::TerminatorKind::Drop { ref location, target, unwind } => {
mir::TerminatorKind::Drop { location, target, unwind } => {
self.codegen_drop_terminator(helper, bx, location, target, unwind);
}

Expand Down Expand Up @@ -1123,7 +1123,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn make_return_dest(
&mut self,
bx: &mut Bx,
dest: &mir::Place<'tcx>,
dest: mir::Place<'tcx>,
fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
llargs: &mut Vec<Bx::Value>,
is_intrinsic: bool,
Expand Down Expand Up @@ -1184,7 +1184,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}

fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir::Place<'tcx>) {
fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: mir::Place<'tcx>) {
if let Some(index) = dst.as_local() {
match self.locals[index] {
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, OperandRef { val, layout: cast })
}

mir::Rvalue::Ref(_, bk, ref place) => {
mir::Rvalue::Ref(_, bk, place) => {
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ref(
tcx.lifetimes.re_erased,
Expand All @@ -393,14 +393,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.codegen_place_to_pointer(bx, place, mk_ref)
}

mir::Rvalue::AddressOf(mutability, ref place) => {
mir::Rvalue::AddressOf(mutability, place) => {
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
};
self.codegen_place_to_pointer(bx, place, mk_ptr)
}

mir::Rvalue::Len(ref place) => {
mir::Rvalue::Len(place) => {
let size = self.evaluate_array_len(&mut bx, place);
let operand = OperandRef {
val: OperandValue::Immediate(size),
Expand Down Expand Up @@ -537,7 +537,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}

fn evaluate_array_len(&mut self, bx: &mut Bx, place: &mir::Place<'tcx>) -> Bx::Value {
fn evaluate_array_len(&mut self, bx: &mut Bx, place: mir::Place<'tcx>) -> Bx::Value {
// ZST are passed as operands and require special handling
// because codegen_place() panics if Local is operand.
if let Some(index) = place.as_local() {
Expand All @@ -557,7 +557,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn codegen_place_to_pointer(
&mut self,
mut bx: Bx,
place: &mir::Place<'tcx>,
place: mir::Place<'tcx>,
mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>,
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
let cg_place = self.codegen_place(&mut bx, place.as_ref());
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2030,9 +2030,9 @@ impl<'tcx> Operand<'tcx> {

/// Returns the `Place` that is the target of this `Operand`, or `None` if this `Operand` is a
/// constant.
pub fn place(&self) -> Option<&Place<'tcx>> {
pub fn place(&self) -> Option<Place<'tcx>> {
match self {
Operand::Copy(place) | Operand::Move(place) => Some(place),
Operand::Copy(place) | Operand::Move(place) => Some(*place),
Operand::Constant(_) => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
let idx = self.idx_vec.push(borrow);
self.location_map.insert(location, idx);

self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
self.insert_as_pending_if_two_phase(location, assigned_place, kind, idx);

self.local_map.entry(borrowed_place.local).or_default().insert(idx);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/constraint_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
// When we see `X = ...`, then kill borrows of
// `(*X).foo` and so forth.
self.record_killed_borrows_for_place(place, location);
self.record_killed_borrows_for_place(*place, location);

self.super_assign(place, rvalue, location);
}
Expand All @@ -139,7 +139,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {

// A `Call` terminator's return value can be a local which has borrows,
// so we need to record those as `killed` as well.
if let TerminatorKind::Call { ref destination, .. } = terminator.kind {
if let TerminatorKind::Call { destination, .. } = terminator.kind {
if let Some((place, _)) = destination {
self.record_killed_borrows_for_place(place, location);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {

/// When recording facts for Polonius, records the borrows on the specified place
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
fn record_killed_borrows_for_place(&mut self, place: &Place<'tcx>, location: Location) {
fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) {
if let Some(all_facts) = self.all_facts {
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");

Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
let places_conflict = places_conflict::places_conflict(
self.infcx.tcx,
self.body,
&self.borrow_set.borrows[borrow_index].borrowed_place,
self.borrow_set.borrows[borrow_index].borrowed_place,
place,
places_conflict::PlaceConflictBias::NoOverlap,
);
Expand Down
57 changes: 26 additions & 31 deletions src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
pub(in crate::borrow_check) fn report_move_out_while_borrowed(
&mut self,
location: Location,
(place, span): (&Place<'tcx>, Span),
(place, span): (Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
) {
debug!(
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
pub(in crate::borrow_check) fn report_use_while_mutably_borrowed(
&mut self,
location: Location,
(place, _span): (&Place<'tcx>, Span),
(place, _span): (Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
) -> DiagnosticBuilder<'cx> {
let borrow_spans = self.retrieve_borrow_spans(borrow);
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
pub(in crate::borrow_check) fn report_conflicting_borrow(
&mut self,
location: Location,
(place, span): (&Place<'tcx>, Span),
(place, span): (Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
issued_borrow: &BorrowData<'tcx>,
) -> DiagnosticBuilder<'cx> {
Expand All @@ -347,7 +347,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
};

let (desc_place, msg_place, msg_borrow, union_type_name) =
self.describe_place_for_conflicting_borrow(place, &issued_borrow.borrowed_place);
self.describe_place_for_conflicting_borrow(place, issued_borrow.borrowed_place);

let explanation = self.explain_why_borrow_contains_point(location, issued_borrow, None);
let second_borrow_desc = if explanation.is_explained() { "second " } else { "" };
Expand Down Expand Up @@ -396,8 +396,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
self.suggest_split_at_mut_if_applicable(
&mut err,
&place,
&issued_borrow.borrowed_place,
place,
issued_borrow.borrowed_place,
);
err
}
Expand All @@ -410,7 +410,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(BorrowKind::Mut { .. }, BorrowKind::Shallow)
| (BorrowKind::Unique, BorrowKind::Shallow) => {
if let Some(immutable_section_description) =
self.classify_immutable_section(&issued_borrow.assigned_place)
self.classify_immutable_section(issued_borrow.assigned_place)
{
let mut err = self.cannot_mutate_in_immutable_section(
span,
Expand Down Expand Up @@ -546,8 +546,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
fn suggest_split_at_mut_if_applicable(
&self,
err: &mut DiagnosticBuilder<'_>,
place: &Place<'tcx>,
borrowed_place: &Place<'tcx>,
place: Place<'tcx>,
borrowed_place: Place<'tcx>,
) {
if let ([ProjectionElem::Index(_)], [ProjectionElem::Index(_)]) =
(&place.projection[..], &borrowed_place.projection[..])
Expand Down Expand Up @@ -584,8 +584,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// > mutable (via `a.u.s.b`) [E0502]
pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow(
&self,
first_borrowed_place: &Place<'tcx>,
second_borrowed_place: &Place<'tcx>,
first_borrowed_place: Place<'tcx>,
second_borrowed_place: Place<'tcx>,
) -> (String, String, String, String) {
// Define a small closure that we can use to check if the type of a place
// is a union.
Expand Down Expand Up @@ -615,13 +615,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
cursor = proj_base;

match elem {
ProjectionElem::Field(field, _)
if union_ty(*local, proj_base).is_some() =>
{
return Some((
PlaceRef { local: *local, projection: proj_base },
field,
));
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
return Some((PlaceRef { local, projection: proj_base }, field));
}
_ => {}
}
Expand All @@ -631,7 +626,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.and_then(|(target_base, target_field)| {
// With the place of a union and a field access into it, we traverse the second
// borrowed place and look for a access to a different field of the same union.
let Place { local, ref projection } = *second_borrowed_place;
let Place { local, ref projection } = second_borrowed_place;

let mut cursor = &projection[..];
while let [proj_base @ .., elem] = cursor {
Expand Down Expand Up @@ -682,7 +677,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
location: Location,
borrow: &BorrowData<'tcx>,
place_span: (&Place<'tcx>, Span),
place_span: (Place<'tcx>, Span),
kind: Option<WriteKind>,
) {
debug!(
Expand Down Expand Up @@ -967,7 +962,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
location: Location,
borrow: &BorrowData<'tcx>,
(place, drop_span): (&Place<'tcx>, Span),
(place, drop_span): (Place<'tcx>, Span),
kind: Option<WriteKind>,
dropped_ty: Ty<'tcx>,
) {
Expand Down Expand Up @@ -1379,15 +1374,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed(
&mut self,
location: Location,
(place, span): (&Place<'tcx>, Span),
(place, span): (Place<'tcx>, Span),
loan: &BorrowData<'tcx>,
) {
let loan_spans = self.retrieve_borrow_spans(loan);
let loan_span = loan_spans.args_or_use();

let descr_place = self.describe_any_place(place.as_ref());
if loan.kind == BorrowKind::Shallow {
if let Some(section) = self.classify_immutable_section(&loan.assigned_place) {
if let Some(section) = self.classify_immutable_section(loan.assigned_place) {
let mut err = self.cannot_mutate_in_immutable_section(
span,
loan_span,
Expand Down Expand Up @@ -1432,9 +1427,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
pub(in crate::borrow_check) fn report_illegal_reassignment(
&mut self,
_location: Location,
(place, span): (&Place<'tcx>, Span),
(place, span): (Place<'tcx>, Span),
assigned_span: Span,
err_place: &Place<'tcx>,
err_place: Place<'tcx>,
) {
let (from_arg, local_decl, local_name) = match err_place.as_local() {
Some(local) => (
Expand Down Expand Up @@ -1539,17 +1534,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}

/// Describe the reason for the fake borrow that was assigned to `place`.
fn classify_immutable_section(&self, place: &Place<'tcx>) -> Option<&'static str> {
fn classify_immutable_section(&self, place: Place<'tcx>) -> Option<&'static str> {
use rustc_middle::mir::visit::Visitor;
struct FakeReadCauseFinder<'a, 'tcx> {
place: &'a Place<'tcx>,
struct FakeReadCauseFinder<'tcx> {
place: Place<'tcx>,
cause: Option<FakeReadCause>,
}
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'_, 'tcx> {
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'tcx> {
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
match statement {
Statement { kind: StatementKind::FakeRead(cause, box ref place), .. }
if *place == *self.place =>
Statement { kind: StatementKind::FakeRead(cause, box place), .. }
if *place == self.place =>
{
self.cause = Some(*cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self,
location: Location,
borrow: &BorrowData<'tcx>,
kind_place: Option<(WriteKind, &Place<'tcx>)>,
kind_place: Option<(WriteKind, Place<'tcx>)>,
) -> BorrowExplanation {
debug!(
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
Expand Down
Loading