2017-07-04 15:57:55 +02:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
|
|
use rustc::ty::{self, TyCtxt};
|
|
|
|
use rustc::mir::*;
|
|
|
|
use rustc::mir::tcx::RvalueInitializationState;
|
|
|
|
use rustc::util::nodemap::FxHashMap;
|
|
|
|
use rustc_data_structures::indexed_vec::{IndexVec};
|
|
|
|
|
|
|
|
use std::collections::hash_map::Entry;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
use super::abs_domain::Lift;
|
|
|
|
|
|
|
|
use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex};
|
2017-11-27 08:06:36 +00:00
|
|
|
use super::{MoveError, InitIndex, Init, LookupResult, InitKind};
|
2017-10-04 11:02:26 +02:00
|
|
|
use super::IllegalMoveOriginKind::*;
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
struct MoveDataBuilder<'a, 'gcx: 'tcx, 'tcx: 'a> {
|
2017-07-04 15:57:55 +02:00
|
|
|
mir: &'a Mir<'tcx>,
|
2017-10-30 05:50:39 -04:00
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2017-07-04 15:57:55 +02:00
|
|
|
data: MoveData<'tcx>,
|
2018-08-07 17:06:21 +02:00
|
|
|
errors: Vec<(Place<'tcx>, MoveError<'tcx>)>,
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
|
2017-11-17 17:19:57 +02:00
|
|
|
fn new(mir: &'a Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self {
|
2017-07-04 15:57:55 +02:00
|
|
|
let mut move_paths = IndexVec::new();
|
|
|
|
let mut path_map = IndexVec::new();
|
2017-11-27 08:06:36 +00:00
|
|
|
let mut init_path_map = IndexVec::new();
|
2017-07-04 15:57:55 +02:00
|
|
|
|
|
|
|
MoveDataBuilder {
|
|
|
|
mir,
|
|
|
|
tcx,
|
2017-10-04 11:02:26 +02:00
|
|
|
errors: Vec::new(),
|
2017-07-04 15:57:55 +02:00
|
|
|
data: MoveData {
|
|
|
|
moves: IndexVec::new(),
|
|
|
|
loc_map: LocationMap::new(mir),
|
|
|
|
rev_lookup: MovePathLookup {
|
2017-12-01 14:31:47 +02:00
|
|
|
locals: mir.local_decls.indices().map(Place::Local).map(|v| {
|
2017-11-27 08:06:36 +00:00
|
|
|
Self::new_move_path(
|
|
|
|
&mut move_paths,
|
|
|
|
&mut path_map,
|
|
|
|
&mut init_path_map,
|
|
|
|
None,
|
|
|
|
v,
|
|
|
|
)
|
2017-07-04 15:57:55 +02:00
|
|
|
}).collect(),
|
|
|
|
projections: FxHashMap(),
|
|
|
|
},
|
|
|
|
move_paths,
|
|
|
|
path_map,
|
2017-11-27 08:06:36 +00:00
|
|
|
inits: IndexVec::new(),
|
|
|
|
init_loc_map: LocationMap::new(mir),
|
|
|
|
init_path_map,
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_move_path(move_paths: &mut IndexVec<MovePathIndex, MovePath<'tcx>>,
|
|
|
|
path_map: &mut IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
|
2017-11-27 08:06:36 +00:00
|
|
|
init_path_map: &mut IndexVec<MovePathIndex, Vec<InitIndex>>,
|
2017-07-04 15:57:55 +02:00
|
|
|
parent: Option<MovePathIndex>,
|
2017-12-01 14:39:51 +02:00
|
|
|
place: Place<'tcx>)
|
2017-07-04 15:57:55 +02:00
|
|
|
-> MovePathIndex
|
|
|
|
{
|
|
|
|
let move_path = move_paths.push(MovePath {
|
|
|
|
next_sibling: None,
|
|
|
|
first_child: None,
|
|
|
|
parent,
|
2017-12-01 14:39:51 +02:00
|
|
|
place,
|
2017-07-04 15:57:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
let path_map_ent = path_map.push(vec![]);
|
|
|
|
assert_eq!(path_map_ent, move_path);
|
2017-11-27 08:06:36 +00:00
|
|
|
|
|
|
|
let init_path_map_ent = init_path_map.push(vec![]);
|
|
|
|
assert_eq!(init_path_map_ent, move_path);
|
|
|
|
|
2017-07-04 15:57:55 +02:00
|
|
|
move_path
|
|
|
|
}
|
2017-10-04 12:34:35 +02:00
|
|
|
}
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
|
2017-12-01 14:39:51 +02:00
|
|
|
/// This creates a MovePath for a given place, returning an `MovePathError`
|
|
|
|
/// if that place can't be moved from.
|
2017-07-04 15:57:55 +02:00
|
|
|
///
|
2017-12-01 14:39:51 +02:00
|
|
|
/// NOTE: places behind references *do not* get a move path, which is
|
2017-07-04 15:57:55 +02:00
|
|
|
/// problematic for borrowck.
|
|
|
|
///
|
|
|
|
/// Maybe we should have separate "borrowck" and "moveck" modes.
|
2017-12-01 14:39:51 +02:00
|
|
|
fn move_path_for(&mut self, place: &Place<'tcx>)
|
2017-10-04 11:02:26 +02:00
|
|
|
-> Result<MovePathIndex, MoveError<'tcx>>
|
2017-07-04 15:57:55 +02:00
|
|
|
{
|
2017-12-01 14:39:51 +02:00
|
|
|
debug!("lookup({:?})", place);
|
|
|
|
match *place {
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Local(local) => Ok(self.builder.data.rev_lookup.locals[local]),
|
2018-07-22 01:01:07 +02:00
|
|
|
Place::Promoted(..) |
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Static(..) => {
|
2018-06-27 22:06:54 +01:00
|
|
|
Err(MoveError::cannot_move_out_of(self.loc, Static))
|
2017-10-04 12:34:35 +02:00
|
|
|
}
|
2017-12-01 14:31:47 +02:00
|
|
|
Place::Projection(ref proj) => {
|
2017-12-01 14:39:51 +02:00
|
|
|
self.move_path_for_projection(place, proj)
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
fn create_move_path(&mut self, place: &Place<'tcx>) {
|
2018-05-31 12:46:43 +02:00
|
|
|
// This is an non-moving access (such as an overwrite or
|
|
|
|
// drop), so this not being a valid move path is OK.
|
2017-12-01 14:39:51 +02:00
|
|
|
let _ = self.move_path_for(place);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn move_path_for_projection(&mut self,
|
2017-12-01 14:39:51 +02:00
|
|
|
place: &Place<'tcx>,
|
2017-12-01 14:31:47 +02:00
|
|
|
proj: &PlaceProjection<'tcx>)
|
2017-10-04 11:02:26 +02:00
|
|
|
-> Result<MovePathIndex, MoveError<'tcx>>
|
2017-07-04 15:57:55 +02:00
|
|
|
{
|
|
|
|
let base = try!(self.move_path_for(&proj.base));
|
2017-10-04 12:34:35 +02:00
|
|
|
let mir = self.builder.mir;
|
|
|
|
let tcx = self.builder.tcx;
|
2017-12-01 14:39:51 +02:00
|
|
|
let place_ty = proj.base.ty(mir, tcx).to_ty(tcx);
|
2018-07-13 23:39:10 +01:00
|
|
|
match place_ty.sty {
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Ref(..) | ty::RawPtr(..) =>
|
2018-05-31 12:46:43 +02:00
|
|
|
return Err(MoveError::cannot_move_out_of(
|
2018-06-27 22:06:54 +01:00
|
|
|
self.loc,
|
2018-07-13 23:39:10 +01:00
|
|
|
BorrowedContent { target_place: place.clone() })),
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Adt(adt, _) if adt.has_dtor(tcx) && !adt.is_box() =>
|
2018-06-27 22:06:54 +01:00
|
|
|
return Err(MoveError::cannot_move_out_of(self.loc,
|
2017-10-04 12:34:35 +02:00
|
|
|
InteriorOfTypeWithDestructor {
|
2017-12-01 14:39:51 +02:00
|
|
|
container_ty: place_ty
|
2017-10-04 11:02:26 +02:00
|
|
|
})),
|
2017-07-04 15:57:55 +02:00
|
|
|
// move out of union - always move the entire union
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Adt(adt, _) if adt.is_union() =>
|
2017-10-04 11:02:26 +02:00
|
|
|
return Err(MoveError::UnionMove { path: base }),
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Slice(_) =>
|
2017-10-04 12:34:35 +02:00
|
|
|
return Err(MoveError::cannot_move_out_of(
|
2018-06-27 22:06:54 +01:00
|
|
|
self.loc,
|
2017-11-13 22:40:22 +00:00
|
|
|
InteriorOfSliceOrArray {
|
2017-12-01 14:39:51 +02:00
|
|
|
ty: place_ty, is_index: match proj.elem {
|
2017-10-04 12:34:35 +02:00
|
|
|
ProjectionElem::Index(..) => true,
|
|
|
|
_ => false
|
|
|
|
},
|
|
|
|
})),
|
2018-08-22 01:35:02 +01:00
|
|
|
ty::Array(..) => match proj.elem {
|
2017-10-04 11:02:26 +02:00
|
|
|
ProjectionElem::Index(..) =>
|
2017-10-04 12:34:35 +02:00
|
|
|
return Err(MoveError::cannot_move_out_of(
|
2018-06-27 22:06:54 +01:00
|
|
|
self.loc,
|
2017-11-13 22:40:22 +00:00
|
|
|
InteriorOfSliceOrArray {
|
2017-12-01 14:39:51 +02:00
|
|
|
ty: place_ty, is_index: true
|
2017-10-04 12:34:35 +02:00
|
|
|
})),
|
2017-07-04 15:57:55 +02:00
|
|
|
_ => {
|
|
|
|
// FIXME: still badly broken
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {}
|
|
|
|
};
|
2017-10-04 12:34:35 +02:00
|
|
|
match self.builder.data.rev_lookup.projections.entry((base, proj.elem.lift())) {
|
2017-07-04 15:57:55 +02:00
|
|
|
Entry::Occupied(ent) => Ok(*ent.get()),
|
|
|
|
Entry::Vacant(ent) => {
|
2017-10-04 12:34:35 +02:00
|
|
|
let path = MoveDataBuilder::new_move_path(
|
|
|
|
&mut self.builder.data.move_paths,
|
|
|
|
&mut self.builder.data.path_map,
|
2017-11-27 08:06:36 +00:00
|
|
|
&mut self.builder.data.init_path_map,
|
2017-07-04 15:57:55 +02:00
|
|
|
Some(base),
|
2017-12-01 14:39:51 +02:00
|
|
|
place.clone()
|
2017-07-04 15:57:55 +02:00
|
|
|
);
|
|
|
|
ent.insert(path);
|
|
|
|
Ok(path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 12:34:35 +02:00
|
|
|
}
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
|
2018-08-07 17:06:21 +02:00
|
|
|
fn finalize(
|
|
|
|
self
|
|
|
|
) -> Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> {
|
2017-07-04 15:57:55 +02:00
|
|
|
debug!("{}", {
|
|
|
|
debug!("moves for {:?}:", self.mir.span);
|
|
|
|
for (j, mo) in self.data.moves.iter_enumerated() {
|
|
|
|
debug!(" {:?} = {:?}", j, mo);
|
|
|
|
}
|
|
|
|
debug!("move paths for {:?}:", self.mir.span);
|
|
|
|
for (j, path) in self.data.move_paths.iter_enumerated() {
|
|
|
|
debug!(" {:?} = {:?}", j, path);
|
|
|
|
}
|
|
|
|
"done dumping moves"
|
|
|
|
});
|
2017-10-04 11:02:26 +02:00
|
|
|
|
|
|
|
if self.errors.len() > 0 {
|
|
|
|
Err((self.data, self.errors))
|
|
|
|
} else {
|
|
|
|
Ok(self.data)
|
|
|
|
}
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 17:06:21 +02:00
|
|
|
pub(super) fn gather_moves<'a, 'gcx, 'tcx>(
|
|
|
|
mir: &Mir<'tcx>,
|
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>
|
|
|
|
) -> Result<MoveData<'tcx>, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> {
|
2017-11-17 17:19:57 +02:00
|
|
|
let mut builder = MoveDataBuilder::new(mir, tcx);
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-11-27 08:06:36 +00:00
|
|
|
builder.gather_args();
|
|
|
|
|
2017-07-04 15:57:55 +02:00
|
|
|
for (bb, block) in mir.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
let terminator_loc = Location {
|
|
|
|
block: bb,
|
|
|
|
statement_index: block.statements.len()
|
|
|
|
};
|
|
|
|
builder.gather_terminator(terminator_loc, block.terminator());
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.finalize()
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
|
2017-11-27 08:06:36 +00:00
|
|
|
fn gather_args(&mut self) {
|
|
|
|
for arg in self.mir.args_iter() {
|
|
|
|
let path = self.data.rev_lookup.locals[arg];
|
|
|
|
let span = self.mir.local_decls[arg].source_info.span;
|
|
|
|
|
|
|
|
let init = self.data.inits.push(Init {
|
|
|
|
path, span, kind: InitKind::Deep
|
|
|
|
});
|
|
|
|
|
|
|
|
debug!("gather_args: adding init {:?} of {:?} for argument {:?}",
|
|
|
|
init, path, arg);
|
|
|
|
|
|
|
|
self.data.init_path_map[path].push(init);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 15:57:55 +02:00
|
|
|
fn gather_statement(&mut self, loc: Location, stmt: &Statement<'tcx>) {
|
|
|
|
debug!("gather_statement({:?}, {:?})", loc, stmt);
|
2017-10-04 12:34:35 +02:00
|
|
|
(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
struct Gatherer<'b, 'a: 'b, 'gcx: 'tcx, 'tcx: 'a> {
|
|
|
|
builder: &'b mut MoveDataBuilder<'a, 'gcx, 'tcx>,
|
2017-10-04 12:34:35 +02:00
|
|
|
loc: Location,
|
|
|
|
}
|
|
|
|
|
2017-10-30 05:50:39 -04:00
|
|
|
impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
|
2017-10-04 12:34:35 +02:00
|
|
|
fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
|
2017-07-04 15:57:55 +02:00
|
|
|
match stmt.kind {
|
2017-12-01 14:39:51 +02:00
|
|
|
StatementKind::Assign(ref place, ref rval) => {
|
|
|
|
self.create_move_path(place);
|
2017-07-04 15:57:55 +02:00
|
|
|
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.
|
2017-12-01 14:39:51 +02:00
|
|
|
self.create_move_path(&place.clone().deref());
|
|
|
|
self.gather_init(place, InitKind::Shallow);
|
2017-11-27 08:06:36 +00:00
|
|
|
} else {
|
2017-12-01 14:39:51 +02:00
|
|
|
self.gather_init(place, InitKind::Deep);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_rvalue(rval);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
2018-05-04 12:04:33 +02:00
|
|
|
StatementKind::ReadForMatch(ref place) => {
|
|
|
|
self.create_move_path(place);
|
|
|
|
}
|
2017-12-23 23:45:07 +00:00
|
|
|
StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {
|
|
|
|
for (output, kind) in outputs.iter().zip(&asm.outputs) {
|
|
|
|
if !kind.is_indirect {
|
|
|
|
self.gather_init(output, InitKind::Deep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for input in inputs {
|
|
|
|
self.gather_operand(input);
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 14:11:25 +03:00
|
|
|
StatementKind::StorageLive(_) => {}
|
|
|
|
StatementKind::StorageDead(local) => {
|
2017-12-01 14:31:47 +02:00
|
|
|
self.gather_move(&Place::Local(local));
|
2017-11-10 14:11:25 +03:00
|
|
|
}
|
2017-07-04 15:57:55 +02:00
|
|
|
StatementKind::SetDiscriminant{ .. } => {
|
|
|
|
span_bug!(stmt.source_info.span,
|
|
|
|
"SetDiscriminant should not exist during borrowck");
|
|
|
|
}
|
|
|
|
StatementKind::EndRegion(_) |
|
|
|
|
StatementKind::Validate(..) |
|
2018-02-23 20:52:05 +00:00
|
|
|
StatementKind::UserAssertTy(..) |
|
2017-07-04 15:57:55 +02:00
|
|
|
StatementKind::Nop => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:34:35 +02:00
|
|
|
fn gather_rvalue(&mut self, rvalue: &Rvalue<'tcx>) {
|
2017-07-04 15:57:55 +02:00
|
|
|
match *rvalue {
|
|
|
|
Rvalue::Use(ref operand) |
|
|
|
|
Rvalue::Repeat(ref operand, _) |
|
|
|
|
Rvalue::Cast(_, ref operand, _) |
|
|
|
|
Rvalue::UnaryOp(_, ref operand) => {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(operand)
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
Rvalue::BinaryOp(ref _binop, ref lhs, ref rhs) |
|
|
|
|
Rvalue::CheckedBinaryOp(ref _binop, ref lhs, ref rhs) => {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(lhs);
|
|
|
|
self.gather_operand(rhs);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
Rvalue::Aggregate(ref _kind, ref operands) => {
|
|
|
|
for operand in operands {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(operand);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Rvalue::Ref(..) |
|
|
|
|
Rvalue::Discriminant(..) |
|
|
|
|
Rvalue::Len(..) |
|
|
|
|
Rvalue::NullaryOp(NullOp::SizeOf, _) |
|
|
|
|
Rvalue::NullaryOp(NullOp::Box, _) => {
|
|
|
|
// This returns an rvalue with uninitialized contents. We can't
|
|
|
|
// move out of it here because it is an rvalue - assignments always
|
2017-12-01 14:39:51 +02:00
|
|
|
// completely initialize their place.
|
2017-07-04 15:57:55 +02:00
|
|
|
//
|
|
|
|
// However, this does not matter - MIR building is careful to
|
|
|
|
// only emit a shallow free for the partially-initialized
|
|
|
|
// temporary.
|
|
|
|
//
|
|
|
|
// In any case, if we want to fix this, we have to register a
|
|
|
|
// special move and change the `statement_effect` functions.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:34:35 +02:00
|
|
|
fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
|
2017-07-04 15:57:55 +02:00
|
|
|
match term.kind {
|
|
|
|
TerminatorKind::Goto { target: _ } |
|
|
|
|
TerminatorKind::Resume |
|
2017-12-19 01:17:16 +01:00
|
|
|
TerminatorKind::Abort |
|
2017-08-16 11:33:10 -07:00
|
|
|
TerminatorKind::GeneratorDrop |
|
2017-10-13 16:36:15 +03:00
|
|
|
TerminatorKind::FalseEdges { .. } |
|
2018-01-25 01:45:45 -05:00
|
|
|
TerminatorKind::FalseUnwind { .. } |
|
2017-07-04 15:57:55 +02:00
|
|
|
TerminatorKind::Unreachable => { }
|
|
|
|
|
|
|
|
TerminatorKind::Return => {
|
2017-12-01 14:39:51 +02:00
|
|
|
self.gather_move(&Place::Local(RETURN_PLACE));
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
|
2018-02-15 15:04:43 +01:00
|
|
|
TerminatorKind::Assert { ref cond, .. } => {
|
|
|
|
self.gather_operand(cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
TerminatorKind::SwitchInt { ref discr, .. } => {
|
|
|
|
self.gather_operand(discr);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 11:33:10 -07:00
|
|
|
TerminatorKind::Yield { ref value, .. } => {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(value);
|
2017-08-16 11:33:10 -07:00
|
|
|
}
|
|
|
|
|
2017-07-04 15:57:55 +02:00
|
|
|
TerminatorKind::Drop { ref location, target: _, unwind: _ } => {
|
2017-11-17 17:19:57 +02:00
|
|
|
self.gather_move(location);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
TerminatorKind::DropAndReplace { ref location, ref value, .. } => {
|
|
|
|
self.create_move_path(location);
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(value);
|
2017-11-27 08:06:36 +00:00
|
|
|
self.gather_init(location, InitKind::Deep);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
TerminatorKind::Call { ref func, ref args, ref destination, cleanup: _ } => {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(func);
|
2017-07-04 15:57:55 +02:00
|
|
|
for arg in args {
|
2017-10-04 12:34:35 +02:00
|
|
|
self.gather_operand(arg);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
if let Some((ref destination, _bb)) = *destination {
|
|
|
|
self.create_move_path(destination);
|
2017-11-27 08:06:36 +00:00
|
|
|
self.gather_init(destination, InitKind::NonPanicPathOnly);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:34:35 +02:00
|
|
|
fn gather_operand(&mut self, operand: &Operand<'tcx>) {
|
2017-07-04 15:57:55 +02:00
|
|
|
match *operand {
|
2017-11-17 17:19:57 +02:00
|
|
|
Operand::Constant(..) |
|
|
|
|
Operand::Copy(..) => {} // not-a-move
|
2017-12-01 14:39:51 +02:00
|
|
|
Operand::Move(ref place) => { // a move
|
|
|
|
self.gather_move(place);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
fn gather_move(&mut self, place: &Place<'tcx>) {
|
|
|
|
debug!("gather_move({:?}, {:?})", self.loc, place);
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
let path = match self.move_path_for(place) {
|
2017-10-04 11:02:26 +02:00
|
|
|
Ok(path) | Err(MoveError::UnionMove { path }) => path,
|
|
|
|
Err(error @ MoveError::IllegalMove { .. }) => {
|
2018-08-07 17:06:21 +02:00
|
|
|
self.builder.errors.push((place.clone(), error));
|
2017-10-04 11:02:26 +02:00
|
|
|
return;
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
|
|
|
};
|
2017-10-04 12:34:35 +02:00
|
|
|
let move_out = self.builder.data.moves.push(MoveOut { path: path, source: self.loc });
|
2017-07-04 15:57:55 +02:00
|
|
|
|
|
|
|
debug!("gather_move({:?}, {:?}): adding move {:?} of {:?}",
|
2017-12-01 14:39:51 +02:00
|
|
|
self.loc, place, move_out, path);
|
2017-07-04 15:57:55 +02:00
|
|
|
|
2017-10-04 12:34:35 +02:00
|
|
|
self.builder.data.path_map[path].push(move_out);
|
|
|
|
self.builder.data.loc_map[self.loc].push(move_out);
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|
2017-11-27 08:06:36 +00:00
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
fn gather_init(&mut self, place: &Place<'tcx>, kind: InitKind) {
|
|
|
|
debug!("gather_init({:?}, {:?})", self.loc, place);
|
2017-11-27 08:06:36 +00:00
|
|
|
|
2017-12-01 14:39:51 +02:00
|
|
|
if let LookupResult::Exact(path) = self.builder.data.rev_lookup.find(place) {
|
2017-11-27 08:06:36 +00:00
|
|
|
let init = self.builder.data.inits.push(Init {
|
|
|
|
span: self.builder.mir.source_info(self.loc).span,
|
|
|
|
path,
|
|
|
|
kind,
|
|
|
|
});
|
|
|
|
|
|
|
|
debug!("gather_init({:?}, {:?}): adding init {:?} of {:?}",
|
2017-12-01 14:39:51 +02:00
|
|
|
self.loc, place, init, path);
|
2017-11-27 08:06:36 +00:00
|
|
|
|
|
|
|
self.builder.data.init_path_map[path].push(init);
|
|
|
|
self.builder.data.init_loc_map[self.loc].push(init);
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 15:57:55 +02:00
|
|
|
}
|