Skip to content

Commit

Permalink
Parametrize gather_moves by filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 30, 2023
1 parent 2a29b20 commit 62a9d29
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 158 deletions.
40 changes: 36 additions & 4 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::*;
use rustc_middle::query::Providers;
use rustc_middle::traits::DefiningAnchor;
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
use rustc_middle::ty::{self, Ty, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
use rustc_session::lint::builtin::UNUSED_MUT;
use rustc_span::{Span, Symbol};
use rustc_target::abi::FieldIdx;
Expand All @@ -48,7 +48,7 @@ use rustc_mir_dataflow::impls::{
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
};
use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData, PathFilter};
use rustc_mir_dataflow::Analysis;
use rustc_mir_dataflow::MoveDataParamEnv;

Expand Down Expand Up @@ -215,10 +215,42 @@ fn do_mir_borrowck<'tcx>(
let location_table_owned = LocationTable::new(body);
let location_table = &location_table_owned;

let move_data = MoveData::gather_moves(&body, tcx, param_env);
let move_path_filter = |ty: Ty<'tcx>| match ty.kind() {
ty::Ref(..) | ty::RawPtr(..) | ty::Slice(_) => PathFilter::Leaf,
ty::Adt(adt, _) => {
if adt.has_dtor(tcx) && !adt.is_box() {
PathFilter::Leaf
} else {
PathFilter::Create
}
}
ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Foreign(_)
| ty::Str
| ty::Array(_, _)
| ty::FnDef(_, _)
| ty::FnPtr(_)
| ty::Dynamic(_, _, _)
| ty::Closure(_, _)
| ty::Generator(_, _, _)
| ty::GeneratorWitness(..)
| ty::Never
| ty::Tuple(_)
| ty::Alias(_, _)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
| ty::Error(_)
| ty::Placeholder(_) => PathFilter::Create,
};
let move_data = MoveData::gather_moves(&body, tcx, param_env, move_path_filter);
let promoted_move_data = promoted
.iter_enumerated()
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env, move_path_filter)));

let mdpe = MoveDataParamEnv { move_data, param_env };

Expand Down
Loading

0 comments on commit 62a9d29

Please sign in to comment.