rust/compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

613 lines
23 KiB
Rust
Raw Normal View History

use rustc_index::IndexVec;
2023-09-30 20:55:15 +00:00
use rustc_middle::mir::tcx::{PlaceTy, RvalueInitializationState};
2020-03-29 16:41:09 +02:00
use rustc_middle::mir::*;
2023-09-30 20:55:15 +00:00
use rustc_middle::ty::{self, Ty, TyCtxt};
2019-08-19 15:56:16 +02:00
use smallvec::{smallvec, SmallVec};
use std::mem;
use super::abs_domain::Lift;
use super::{Init, InitIndex, InitKind, InitLocation, LookupResult};
2019-08-19 15:56:16 +02:00
use super::{
LocationMap, MoveData, MoveOut, MoveOutIndex, MovePath, MovePathIndex, MovePathLookup,
};
2023-09-30 20:55:15 +00:00
struct MoveDataBuilder<'a, 'tcx, F> {
body: &'a Body<'tcx>,
2019-06-14 00:48:52 +03:00
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
data: MoveData<'tcx>,
2023-09-30 20:55:15 +00:00
filter: F,
}
2023-10-21 12:09:02 +00:00
impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
2023-09-30 20:55:15 +00:00
fn new(
body: &'a Body<'tcx>,
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
filter: F,
) -> Self {
let mut move_paths = IndexVec::new();
let mut path_map = IndexVec::new();
let mut init_path_map = IndexVec::new();
2023-09-30 20:55:15 +00:00
let locals = body
.local_decls
.iter_enumerated()
.map(|(i, l)| {
if l.is_deref_temp() {
return None;
}
if filter(l.ty) {
Some(new_move_path(
&mut move_paths,
&mut path_map,
&mut init_path_map,
None,
Place::from(i),
))
} else {
None
}
})
.collect();
MoveDataBuilder {
body,
tcx,
param_env,
data: MoveData {
moves: IndexVec::new(),
loc_map: LocationMap::new(body),
rev_lookup: MovePathLookup {
2023-09-30 20:55:15 +00:00
locals,
projections: Default::default(),
un_derefer: Default::default(),
},
move_paths,
path_map,
inits: IndexVec::new(),
init_loc_map: LocationMap::new(body),
init_path_map,
2019-08-19 15:56:16 +02:00
},
2023-09-30 20:55:15 +00:00
filter,
}
}
2023-09-30 20:55:15 +00:00
}
2023-09-30 20:55:15 +00:00
fn new_move_path<'tcx>(
move_paths: &mut IndexVec<MovePathIndex, MovePath<'tcx>>,
path_map: &mut IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
init_path_map: &mut IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
parent: Option<MovePathIndex>,
place: Place<'tcx>,
) -> MovePathIndex {
let move_path =
move_paths.push(MovePath { next_sibling: None, first_child: None, parent, place });
if let Some(parent) = parent {
let next_sibling = mem::replace(&mut move_paths[parent].first_child, Some(move_path));
move_paths[move_path].next_sibling = next_sibling;
}
2023-09-30 20:55:15 +00:00
let path_map_ent = path_map.push(smallvec![]);
assert_eq!(path_map_ent, move_path);
2023-09-30 20:55:15 +00:00
let init_path_map_ent = init_path_map.push(smallvec![]);
assert_eq!(init_path_map_ent, move_path);
2023-09-30 20:55:15 +00:00
move_path
}
enum MovePathResult {
Path(MovePathIndex),
Union(MovePathIndex),
Error,
}
2023-10-21 12:09:02 +00:00
impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
/// This creates a MovePath for a given place, returning an `MovePathError`
/// if that place can't be moved from.
///
/// NOTE: places behind references *do not* get a move path, which is
/// problematic for borrowck.
///
/// Maybe we should have separate "borrowck" and "moveck" modes.
fn move_path_for(&mut self, place: Place<'tcx>) -> MovePathResult {
let data = &mut self.builder.data;
2022-06-13 16:37:41 +03:00
debug!("lookup({:?})", place);
let Some(mut base) = data.rev_lookup.find_local(place.local) else {
return MovePathResult::Error;
};
// The move path index of the first union that we find. Once this is
// some we stop creating child move paths, since moves from unions
// move the whole thing.
// We continue looking for other move errors though so that moving
// from `*(u.f: &_)` isn't allowed.
let mut union_path = None;
for (place_ref, elem) in data.rev_lookup.un_derefer.iter_projections(place.as_ref()) {
let body = self.builder.body;
let tcx = self.builder.tcx;
let place_ty = place_ref.ty(body, tcx).ty;
2023-09-12 10:28:37 +03:00
match elem {
ProjectionElem::Deref => match place_ty.kind() {
ty::Ref(..) | ty::RawPtr(..) => {
return MovePathResult::Error;
2019-08-19 15:56:16 +02:00
}
2023-09-12 21:09:29 +03:00
ty::Adt(adt, _) => {
if !adt.is_box() {
2023-09-22 11:31:14 +03:00
bug!("Adt should be a box type when Place is deref");
2023-09-12 21:09:29 +03:00
}
}
ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Foreign(_)
| ty::Str
| ty::Array(_, _)
| ty::Slice(_)
| ty::FnDef(_, _)
| ty::FnPtr(_)
| ty::Dynamic(_, _, _)
| ty::Closure(..)
| ty::CoroutineClosure(..)
| ty::Coroutine(_, _)
2023-10-19 16:06:43 +00:00
| ty::CoroutineWitness(..)
2023-09-12 21:09:29 +03:00
| ty::Never
| ty::Tuple(_)
| ty::Alias(_, _)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
| ty::Error(_)
2023-09-22 11:31:14 +03:00
| ty::Placeholder(_) => {
bug!("When Place is Deref it's type shouldn't be {place_ty:#?}")
}
2023-09-12 10:28:37 +03:00
},
2023-09-12 21:09:29 +03:00
ProjectionElem::Field(_, _) => match place_ty.kind() {
ty::Adt(adt, _) => {
if adt.has_dtor(tcx) {
return MovePathResult::Error;
}
2023-09-12 21:09:29 +03:00
if adt.is_union() {
union_path.get_or_insert(base);
}
2023-09-12 10:28:37 +03:00
}
ty::Closure(..)
| ty::CoroutineClosure(..)
| ty::Coroutine(_, _)
| ty::Tuple(_) => (),
2023-09-12 21:09:29 +03:00
ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Foreign(_)
| ty::Str
| ty::Array(_, _)
| ty::Slice(_)
| ty::RawPtr(_)
| ty::Ref(_, _, _)
| ty::FnDef(_, _)
| ty::FnPtr(_)
| ty::Dynamic(_, _, _)
2023-10-19 16:06:43 +00:00
| ty::CoroutineWitness(..)
2023-09-12 21:09:29 +03:00
| ty::Never
| ty::Alias(_, _)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
| ty::Error(_)
2023-09-22 11:31:14 +03:00
| ty::Placeholder(_) => bug!(
"When Place contains ProjectionElem::Field it's type shouldn't be {place_ty:#?}"
),
2023-09-12 10:28:37 +03:00
},
2023-09-12 21:09:29 +03:00
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
match place_ty.kind() {
ty::Slice(_) => {
return MovePathResult::Error;
2023-09-12 21:09:29 +03:00
}
ty::Array(_, _) => (),
_ => bug!("Unexpected type {:#?}", place_ty.is_array()),
2023-09-12 10:28:37 +03:00
}
2023-09-12 21:09:29 +03:00
}
ProjectionElem::Index(_) => match place_ty.kind() {
ty::Array(..) | ty::Slice(_) => {
return MovePathResult::Error;
2023-09-12 21:09:29 +03:00
}
_ => bug!("Unexpected type {place_ty:#?}"),
2023-09-12 10:28:37 +03:00
},
// `OpaqueCast`:Only transmutes the type, so no moves there.
// `Downcast` :Only changes information about a `Place` without moving.
// `Subtype` :Only transmutes the type, so moves.
2023-09-12 21:09:29 +03:00
// So it's safe to skip these.
ProjectionElem::OpaqueCast(_)
| ProjectionElem::Subtype(_)
| ProjectionElem::Downcast(_, _) => (),
2023-09-12 10:28:37 +03:00
}
2023-09-30 20:55:15 +00:00
let elem_ty = PlaceTy::from_ty(place_ty).projection_ty(tcx, elem).ty;
if !(self.builder.filter)(elem_ty) {
return MovePathResult::Error;
}
if union_path.is_none() {
// inlined from add_move_path because of a borrowck conflict with the iterator
base =
*data.rev_lookup.projections.entry((base, elem.lift())).or_insert_with(|| {
2023-09-30 20:55:15 +00:00
new_move_path(
&mut data.move_paths,
&mut data.path_map,
&mut data.init_path_map,
Some(base),
place_ref.project_deeper(&[elem], tcx),
)
})
}
}
if let Some(base) = union_path {
// Move out of union - always move the entire union.
MovePathResult::Union(base)
} else {
MovePathResult::Path(base)
}
}
fn add_move_path(
&mut self,
base: MovePathIndex,
2020-05-23 12:02:54 +02:00
elem: PlaceElem<'tcx>,
mk_place: impl FnOnce(TyCtxt<'tcx>) -> Place<'tcx>,
) -> MovePathIndex {
let MoveDataBuilder {
data: MoveData { rev_lookup, move_paths, path_map, init_path_map, .. },
tcx,
..
} = self.builder;
*rev_lookup.projections.entry((base, elem.lift())).or_insert_with(move || {
2023-09-30 20:55:15 +00:00
new_move_path(move_paths, path_map, init_path_map, Some(base), mk_place(*tcx))
})
}
fn create_move_path(&mut self, place: Place<'tcx>) {
// This is an non-moving access (such as an overwrite or
// drop), so this not being a valid move path is OK.
let _ = self.move_path_for(place);
}
}
2023-09-30 20:55:15 +00:00
impl<'a, 'tcx, F> MoveDataBuilder<'a, 'tcx, F> {
fn finalize(self) -> MoveData<'tcx> {
debug!("{}", {
debug!("moves for {:?}:", self.body.span);
for (j, mo) in self.data.moves.iter_enumerated() {
debug!(" {:?} = {:?}", j, mo);
}
debug!("move paths for {:?}:", self.body.span);
for (j, path) in self.data.move_paths.iter_enumerated() {
debug!(" {:?} = {:?}", j, path);
}
"done dumping moves"
});
self.data
}
}
2019-06-14 00:48:52 +03:00
pub(super) fn gather_moves<'tcx>(
body: &Body<'tcx>,
2019-06-14 00:48:52 +03:00
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
2023-09-30 20:55:15 +00:00
filter: impl Fn(Ty<'tcx>) -> bool,
) -> MoveData<'tcx> {
2023-09-30 20:55:15 +00:00
let mut builder = MoveDataBuilder::new(body, tcx, param_env, filter);
builder.gather_args();
for (bb, block) in body.basic_blocks.iter_enumerated() {
for (i, stmt) in block.statements.iter().enumerate() {
let source = Location { block: bb, statement_index: i };
builder.gather_statement(source, stmt);
}
2019-08-19 15:56:16 +02:00
let terminator_loc = Location { block: bb, statement_index: block.statements.len() };
builder.gather_terminator(terminator_loc, block.terminator());
}
builder.finalize()
}
2023-10-21 12:09:02 +00:00
impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
fn gather_args(&mut self) {
for arg in self.body.args_iter() {
if let Some(path) = self.data.rev_lookup.find_local(arg) {
let init = self.data.inits.push(Init {
path,
kind: InitKind::Deep,
location: InitLocation::Argument(arg),
});
debug!("gather_args: adding init {:?} of {:?} for argument {:?}", init, path, arg);
self.data.init_path_map[path].push(init);
}
}
}
fn gather_statement(&mut self, loc: Location, stmt: &Statement<'tcx>) {
debug!("gather_statement({:?}, {:?})", loc, stmt);
(Gatherer { builder: self, loc }).gather_statement(stmt);
}
fn gather_terminator(&mut self, loc: Location, term: &Terminator<'tcx>) {
debug!("gather_terminator({:?}, {:?})", loc, term);
(Gatherer { builder: self, loc }).gather_terminator(term);
}
}
2023-09-30 20:55:15 +00:00
struct Gatherer<'b, 'a, 'tcx, F> {
builder: &'b mut MoveDataBuilder<'a, 'tcx, F>,
loc: Location,
}
2023-10-21 12:09:02 +00:00
impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
match &stmt.kind {
2022-06-13 16:37:41 +03:00
StatementKind::Assign(box (place, Rvalue::CopyForDeref(reffed))) => {
let local = place.as_local().unwrap();
assert!(self.builder.body.local_decls[local].is_deref_temp());
let rev_lookup = &mut self.builder.data.rev_lookup;
rev_lookup.un_derefer.insert(local, reffed.as_ref());
let base_local = rev_lookup.un_derefer.deref_chain(local).first().unwrap().local;
rev_lookup.locals[local] = rev_lookup.locals[base_local];
2022-06-13 16:37:41 +03:00
}
StatementKind::Assign(box (place, rval)) => {
self.create_move_path(*place);
if let RvalueInitializationState::Shallow = rval.initialization_state() {
// Box starts out uninitialized - need to create a separate
// move-path for the interior so it will be separate from
// the exterior.
self.create_move_path(self.builder.tcx.mk_place_deref(*place));
self.gather_init(place.as_ref(), InitKind::Shallow);
} else {
self.gather_init(place.as_ref(), InitKind::Deep);
}
self.gather_rvalue(rval);
}
2021-03-29 22:48:44 -04:00
StatementKind::FakeRead(box (_, place)) => {
self.create_move_path(*place);
}
2017-11-10 14:11:25 +03:00
StatementKind::StorageLive(_) => {}
StatementKind::StorageDead(local) => {
2022-06-13 16:37:41 +03:00
// DerefTemp locals (results of CopyForDeref) don't actually move anything.
if !self.builder.body.local_decls[*local].is_deref_temp() {
2022-06-13 16:37:41 +03:00
self.gather_move(Place::from(*local));
}
2017-11-10 14:11:25 +03:00
}
2022-04-05 17:14:59 -04:00
StatementKind::SetDiscriminant { .. } | StatementKind::Deinit(..) => {
2019-08-19 15:56:16 +02:00
span_bug!(
stmt.source_info.span,
2022-04-05 17:14:59 -04:00
"SetDiscriminant/Deinit should not exist during borrowck"
2019-08-19 15:56:16 +02:00
);
}
2019-08-19 15:56:16 +02:00
StatementKind::Retag { .. }
| StatementKind::AscribeUserType(..)
| StatementKind::PlaceMention(..)
| StatementKind::Coverage(..)
| StatementKind::Intrinsic(..)
| StatementKind::ConstEvalCounter
2019-08-19 15:56:16 +02:00
| StatementKind::Nop => {}
}
}
fn gather_rvalue(&mut self, rvalue: &Rvalue<'tcx>) {
match *rvalue {
2020-05-02 21:44:25 +02:00
Rvalue::ThreadLocalRef(_) => {} // not-a-move
2019-08-19 15:56:16 +02:00
Rvalue::Use(ref operand)
| Rvalue::Repeat(ref operand, _)
| Rvalue::Cast(_, ref operand, _)
2021-09-06 18:33:23 +01:00
| Rvalue::ShallowInitBox(ref operand, _)
2019-08-19 15:56:16 +02:00
| Rvalue::UnaryOp(_, ref operand) => self.gather_operand(operand),
2021-03-05 09:32:47 +00:00
Rvalue::BinaryOp(ref _binop, box (ref lhs, ref rhs))
| Rvalue::CheckedBinaryOp(ref _binop, box (ref lhs, ref rhs)) => {
self.gather_operand(lhs);
self.gather_operand(rhs);
}
Rvalue::Aggregate(ref _kind, ref operands) => {
for operand in operands {
self.gather_operand(operand);
}
}
2022-06-13 16:37:41 +03:00
Rvalue::CopyForDeref(..) => unreachable!(),
2019-08-19 15:56:16 +02:00
Rvalue::Ref(..)
| Rvalue::AddressOf(..)
2019-08-19 15:56:16 +02:00
| Rvalue::Discriminant(..)
| Rvalue::Len(..)
2022-09-11 00:37:49 -07:00
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => {}
}
}
fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
match term.kind {
2019-08-19 15:56:16 +02:00
TerminatorKind::Goto { target: _ }
2020-10-02 15:40:24 -04:00
| TerminatorKind::FalseEdge { .. }
2020-05-08 20:00:32 +01:00
| TerminatorKind::FalseUnwind { .. }
// In some sense returning moves the return place into the current
// call's destination, however, since there are no statements after
// this that could possibly access the return place, this doesn't
// need recording.
| TerminatorKind::Return
| TerminatorKind::UnwindResume
| TerminatorKind::UnwindTerminate(_)
2023-10-19 16:06:43 +00:00
| TerminatorKind::CoroutineDrop
| TerminatorKind::Unreachable
| TerminatorKind::Drop { .. } => {}
TerminatorKind::Assert { ref cond, .. } => {
self.gather_operand(cond);
}
TerminatorKind::SwitchInt { ref discr, .. } => {
self.gather_operand(discr);
}
TerminatorKind::Yield { ref value, resume_arg: place, .. } => {
self.gather_operand(value);
self.create_move_path(place);
self.gather_init(place.as_ref(), InitKind::Deep);
}
TerminatorKind::Call {
ref func,
ref args,
destination,
target,
unwind: _,
call_source: _,
fn_span: _,
} => {
self.gather_operand(func);
for arg in args {
self.gather_operand(&arg.node);
}
if let Some(_bb) = target {
self.create_move_path(destination);
self.gather_init(destination.as_ref(), InitKind::NonPanicPathOnly);
}
}
2020-05-26 20:07:59 +01:00
TerminatorKind::InlineAsm {
template: _,
ref operands,
options: _,
line_spans: _,
2020-06-04 12:25:18 -04:00
destination: _,
unwind: _,
2020-05-26 20:07:59 +01:00
} => {
2020-02-14 18:17:50 +00:00
for op in operands {
match *op {
InlineAsmOperand::In { reg: _, ref value }
2021-04-06 05:50:55 +01:00
=> {
2020-02-14 18:17:50 +00:00
self.gather_operand(value);
}
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
if let Some(place) = place {
self.create_move_path(place);
self.gather_init(place.as_ref(), InitKind::Deep);
}
}
InlineAsmOperand::InOut { reg: _, late: _, ref in_value, out_place } => {
self.gather_operand(in_value);
if let Some(out_place) = out_place {
self.create_move_path(out_place);
self.gather_init(out_place.as_ref(), InitKind::Deep);
}
}
2021-04-06 05:50:55 +01:00
InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {}
2020-02-14 18:17:50 +00:00
}
}
}
}
}
fn gather_operand(&mut self, operand: &Operand<'tcx>) {
match *operand {
2019-08-19 15:56:16 +02:00
Operand::Constant(..) | Operand::Copy(..) => {} // not-a-move
Operand::Move(place) => {
2019-08-19 15:56:16 +02:00
// a move
self.gather_move(place);
}
}
}
fn gather_move(&mut self, place: Place<'tcx>) {
debug!("gather_move({:?}, {:?})", self.loc, place);
if let [ref base @ .., ProjectionElem::Subslice { from, to, from_end: false }] =
**place.projection
{
// Split `Subslice` patterns into the corresponding list of
// `ConstIndex` patterns. This is done to ensure that all move paths
// are disjoint, which is expected by drop elaboration.
let base_place =
Rename many interner functions. (This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-02-17 14:33:08 +11:00
Place { local: place.local, projection: self.builder.tcx.mk_place_elems(base) };
let base_path = match self.move_path_for(base_place) {
MovePathResult::Path(path) => path,
MovePathResult::Union(path) => {
self.record_move(place, path);
return;
}
MovePathResult::Error => {
return;
}
};
let base_ty = base_place.ty(self.builder.body, self.builder.tcx).ty;
2020-08-03 00:49:11 +02:00
let len: u64 = match base_ty.kind() {
ty::Array(_, size) => {
size.eval_target_usize(self.builder.tcx, self.builder.param_env)
}
_ => bug!("from_end: false slice pattern of non-array type"),
};
for offset in from..to {
let elem =
ProjectionElem::ConstantIndex { offset, min_length: len, from_end: false };
let path =
2020-05-23 12:02:54 +02:00
self.add_move_path(base_path, elem, |tcx| tcx.mk_place_elem(base_place, elem));
self.record_move(place, path);
}
} else {
match self.move_path_for(place) {
MovePathResult::Path(path) | MovePathResult::Union(path) => {
self.record_move(place, path)
}
MovePathResult::Error => {}
};
}
}
fn record_move(&mut self, place: Place<'tcx>, path: MovePathIndex) {
let move_out = self.builder.data.moves.push(MoveOut { path, source: self.loc });
2019-08-19 15:56:16 +02:00
debug!(
"gather_move({:?}, {:?}): adding move {:?} of {:?}",
self.loc, place, move_out, path
);
self.builder.data.path_map[path].push(move_out);
self.builder.data.loc_map[self.loc].push(move_out);
}
2020-03-04 18:25:03 -03:00
fn gather_init(&mut self, place: PlaceRef<'tcx>, kind: InitKind) {
debug!("gather_init({:?}, {:?})", self.loc, place);
2019-07-19 21:58:03 +02:00
let mut place = place;
// Check if we are assigning into a field of a union, if so, lookup the place
// of the union so it is marked as initialized again.
if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
if place_base.ty(self.builder.body, self.builder.tcx).ty.is_union() {
place = place_base;
}
2019-07-19 21:58:03 +02:00
}
2019-07-19 21:49:34 +02:00
if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place) {
let init = self.builder.data.inits.push(Init {
location: InitLocation::Statement(self.loc),
path,
kind,
});
2019-08-19 15:56:16 +02:00
debug!(
"gather_init({:?}, {:?}): adding init {:?} of {:?}",
self.loc, place, init, path
);
self.builder.data.init_path_map[path].push(init);
self.builder.data.init_loc_map[self.loc].push(init);
}
}
}