Skip to content

Commit 0302cfd

Browse files
committed
MERGEME Switched refactoring to use trait methods (on tcx/mir/param_env) rather than closures.
1 parent ff3a7f0 commit 0302cfd

File tree

3 files changed

+129
-120
lines changed

3 files changed

+129
-120
lines changed

src/librustc_mir/dataflow/drop_flag_effects.rs

+89-62
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,44 @@
99
// except according to those terms.
1010

1111
use rustc::mir::{self, Mir, Location, Place};
12-
use rustc::ty::{self, TyCtxt};
12+
use rustc::ty::{self, TyCtxt, ParamEnv};
1313
use util::elaborate_drops::DropFlagState;
1414

1515
use super::indexes::MovePathIndex;
1616
use super::move_paths::{MoveData, LookupResult, InitKind};
1717

18+
pub(crate) trait PlaceOneDropFlag<'tcx> {
19+
fn place_contents_drop_state_cannot_differ(&self, &Place<'tcx>) -> bool;
20+
}
21+
22+
pub(crate) trait PlaceNeedsDrop<'tcx> {
23+
fn needs_drop(&self, &Place<'tcx>) -> bool;
24+
}
25+
26+
impl<'a, 'gcx, 'tcx> PlaceOneDropFlag<'tcx> for (TyCtxt<'a, 'gcx, 'tcx>, &'a Mir<'tcx>) {
27+
fn place_contents_drop_state_cannot_differ(&self, place: &Place<'tcx>) -> bool {
28+
place_contents_drop_state_cannot_differ(self.0, self.1, place)
29+
}
30+
}
31+
32+
impl<'a, 'gcx, 'tcx> PlaceOneDropFlag<'tcx> for (TyCtxt<'a, 'gcx, 'tcx>,
33+
&'a Mir<'tcx>,
34+
ParamEnv<'gcx>)
35+
{
36+
fn place_contents_drop_state_cannot_differ(&self, place: &Place<'tcx>) -> bool {
37+
place_contents_drop_state_cannot_differ(self.0, self.1, place)
38+
}
39+
}
40+
41+
impl<'a, 'gcx, 'tcx> PlaceNeedsDrop<'tcx> for (TyCtxt<'a, 'gcx, 'tcx>,
42+
&'a Mir<'tcx>,
43+
ParamEnv<'gcx>)
44+
{
45+
fn needs_drop(&self, place: &Place<'tcx>) -> bool {
46+
place_needs_drop(self.0, self.1, self.2, place)
47+
}
48+
}
49+
1850
pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
1951
path: MovePathIndex,
2052
mut cond: F)
@@ -55,7 +87,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
5587
/// is no need to maintain separate drop flags to track such state.
5688
///
5789
/// FIXME: we have to do something for moving slice patterns.
58-
pub(crate) fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(
90+
fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(
5991
tcx: TyCtxt<'a, 'gcx, 'tcx>,
6092
mir: &Mir<'tcx>,
6193
place: &Place<'tcx>) -> bool
@@ -83,119 +115,114 @@ pub(crate) fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(
83115
}
84116
}
85117

86-
pub(crate) fn place_needs_drop<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
87-
mir: &Mir<'tcx>,
88-
param_env: ty::ParamEnv<'gcx>,
89-
place: &Place<'tcx>)
90-
-> bool
118+
fn place_needs_drop<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
119+
mir: &Mir<'tcx>,
120+
param_env: ty::ParamEnv<'gcx>,
121+
place: &Place<'tcx>)
122+
-> bool
91123
{
92124
let ty = place.ty(mir, tcx).to_ty(tcx);
93-
// debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
94-
95125
let gcx = tcx.global_tcx();
96126
let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap();
97127
erased_ty.needs_drop(gcx, param_env)
98128
}
99129

100-
pub(crate) fn on_lookup_result_bits<'tcx, F, U>(move_data: &MoveData<'tcx>,
101-
lookup_result: LookupResult,
102-
has_uniform_drop_state: U,
103-
each_child: F)
104-
where F: FnMut(MovePathIndex), U: Fn(&Place<'tcx>) -> bool
130+
pub(crate) fn on_lookup_result_bits<'tcx, F, PO>(tcx_mir: &PO,
131+
move_data: &MoveData<'tcx>,
132+
lookup_result: LookupResult,
133+
each_child: F)
134+
where F: FnMut(MovePathIndex), PO: PlaceOneDropFlag<'tcx>,
105135
{
106136
match lookup_result {
107137
LookupResult::Parent(..) => {
108138
// access to untracked value - do not touch children
109139
}
110140
LookupResult::Exact(e) => {
111-
on_all_children_bits(move_data, e, has_uniform_drop_state, each_child)
141+
on_all_children_bits(tcx_mir, move_data, e, each_child)
112142
}
113143
}
114144
}
115145

116-
pub(crate) fn on_all_children_bits<'tcx, F, U>(move_data: &MoveData<'tcx>,
117-
move_path_index: MovePathIndex,
118-
has_uniform_drop_state: U,
119-
mut each_child: F)
120-
where F: FnMut(MovePathIndex), U: Fn(&Place<'tcx>) -> bool
146+
pub(crate) fn on_all_children_bits<'tcx, F, PO>(tcx_mir: &PO,
147+
move_data: &MoveData<'tcx>,
148+
move_path_index: MovePathIndex,
149+
mut each_child: F)
150+
where F: FnMut(MovePathIndex), PO: PlaceOneDropFlag<'tcx>
121151
{
122-
fn is_terminal_path<'tcx, U>(move_data: &MoveData<'tcx>,
123-
path: MovePathIndex,
124-
has_uniform_drop_state: U) -> bool
125-
where U: Fn(&Place<'tcx>) -> bool
152+
fn is_terminal_path<'tcx, PO>(tcx_mir: &PO,
153+
move_data: &MoveData<'tcx>,
154+
path: MovePathIndex) -> bool
155+
where PO: PlaceOneDropFlag<'tcx>
126156
{
127-
// lvalue_contents_drop_state_cannot_differ
128-
has_uniform_drop_state(&move_data.move_paths[path].place)
157+
let place = &move_data.move_paths[path].place;
158+
tcx_mir.place_contents_drop_state_cannot_differ(place)
129159
}
130160

131-
fn on_all_children_bits<'tcx, F, U>(move_data: &MoveData<'tcx>,
132-
move_path_index: MovePathIndex,
133-
has_uniform_drop_state: &U,
134-
each_child: &mut F)
135-
where F: FnMut(MovePathIndex), U: Fn(&Place<'tcx>) -> bool
161+
fn on_all_children_bits<'tcx, F, PO>(tcx_mir: &PO,
162+
move_data: &MoveData<'tcx>,
163+
move_path_index: MovePathIndex,
164+
each_child: &mut F)
165+
where F: FnMut(MovePathIndex), PO: PlaceOneDropFlag<'tcx>
136166
{
137167
each_child(move_path_index);
138168

139-
if is_terminal_path(move_data, move_path_index, has_uniform_drop_state) {
169+
if is_terminal_path(tcx_mir, move_data, move_path_index) {
140170
return
141171
}
142172

143173
let mut next_child_index = move_data.move_paths[move_path_index].first_child;
144174
while let Some(child_index) = next_child_index {
145-
on_all_children_bits(move_data, child_index, has_uniform_drop_state, each_child);
175+
on_all_children_bits(tcx_mir, move_data, child_index, each_child);
146176
next_child_index = move_data.move_paths[child_index].next_sibling;
147177
}
148178
}
149-
on_all_children_bits(move_data, move_path_index, &has_uniform_drop_state, &mut each_child);
179+
on_all_children_bits(tcx_mir, move_data, move_path_index, &mut each_child);
150180
}
151181

152-
pub(crate) fn on_all_drop_children_bits<'tcx, F, U, N>(move_data: &MoveData<'tcx>,
153-
path: MovePathIndex,
154-
has_uniform_drop_state: U,
155-
needs_drop: N,
156-
mut each_child: F)
157-
where F: FnMut(MovePathIndex),
158-
U: Fn(&Place<'tcx>) -> bool,
159-
N: Fn(&Place<'tcx>) -> bool,
182+
pub(crate) fn on_all_drop_children_bits<'tcx, F, PO>(tcx_mir_param_env: &PO,
183+
move_data: &MoveData<'tcx>,
184+
path: MovePathIndex,
185+
mut each_child: F)
186+
where F: FnMut(MovePathIndex), PO: PlaceOneDropFlag<'tcx> + PlaceNeedsDrop<'tcx>
160187
{
161-
on_all_children_bits(move_data, path, has_uniform_drop_state, |child| {
188+
on_all_children_bits(tcx_mir_param_env, move_data, path, |child| {
162189
let place = &move_data.move_paths[path].place;
163190
// let ty = place.ty(mir, tcx).to_ty(tcx);
164191
// debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
165192

166193
// let gcx = tcx.global_tcx();
167194
// let erased_ty = gcx.lift(&tcx.erase_regions(&ty)).unwrap();
168195
// if erased_ty.needs_drop(gcx, ctxt.param_env) {
169-
if needs_drop(place) {
196+
if tcx_mir_param_env.needs_drop(place) {
170197
each_child(child);
171198
} else {
172199
debug!("on_all_drop_children_bits - skipping")
173200
}
174201
})
175202
}
176203

177-
pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F, U>(
204+
pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F, PO>(
205+
tcx_mir: &PO,
178206
mir: &Mir<'tcx>,
179207
move_data: &MoveData<'tcx>,
180-
has_uniform_drop_state: U,
181208
mut callback: F)
182-
where F: FnMut(MovePathIndex, DropFlagState), U: Fn(&Place<'tcx>) -> bool
209+
where F: FnMut(MovePathIndex, DropFlagState), PO: PlaceOneDropFlag<'tcx>
183210
{
184211
for arg in mir.args_iter() {
185212
let place = Place::Local(arg);
186213
let lookup_result = move_data.rev_lookup.find(&place);
187-
on_lookup_result_bits(move_data,
214+
on_lookup_result_bits(tcx_mir,
215+
move_data,
188216
lookup_result,
189-
&has_uniform_drop_state,
190217
|mpi| callback(mpi, DropFlagState::Present));
191218
}
192219
}
193220

194-
pub(crate) fn drop_flag_effects_for_location<'tcx, F, U>(move_data: &MoveData<'tcx>,
195-
loc: Location,
196-
has_uniform_drop_state: U,
197-
mut callback: F)
198-
where F: FnMut(MovePathIndex, DropFlagState), U: Fn(&Place<'tcx>) -> bool
221+
pub(crate) fn drop_flag_effects_for_location<'tcx, F, PO>(tcx_mir: &PO,
222+
move_data: &MoveData<'tcx>,
223+
loc: Location,
224+
mut callback: F)
225+
where F: FnMut(MovePathIndex, DropFlagState), PO: PlaceOneDropFlag<'tcx>
199226
{
200227
debug!("drop_flag_effects_for_location({:?})", loc);
201228

@@ -204,38 +231,38 @@ pub(crate) fn drop_flag_effects_for_location<'tcx, F, U>(move_data: &MoveData<'t
204231
let path = mi.move_path_index(move_data);
205232
debug!("moving out of path {:?}", move_data.move_paths[path]);
206233

207-
on_all_children_bits(move_data,
234+
on_all_children_bits(tcx_mir,
235+
move_data,
208236
path,
209-
&has_uniform_drop_state,
210237
|mpi| callback(mpi, DropFlagState::Absent))
211238
}
212239

213240
debug!("drop_flag_effects: assignment for location({:?})", loc);
214241

215242
for_location_inits(
243+
tcx_mir,
216244
move_data,
217245
loc,
218-
has_uniform_drop_state,
219246
|mpi| callback(mpi, DropFlagState::Present)
220247
);
221248
}
222249

223-
pub(crate) fn for_location_inits<'tcx, F, U>(
250+
pub(crate) fn for_location_inits<'tcx, F, PO>(
251+
tcx_mir: &PO,
224252
move_data: &MoveData<'tcx>,
225253
loc: Location,
226-
has_uniform_drop_state: U,
227254
mut callback: F)
228-
where F: FnMut(MovePathIndex), U: Fn(&Place<'tcx>) -> bool
255+
where F: FnMut(MovePathIndex), PO: PlaceOneDropFlag<'tcx>
229256
{
230257
for ii in &move_data.init_loc_map[loc] {
231258
let init = move_data.inits[*ii];
232259
match init.kind {
233260
InitKind::Deep => {
234261
let path = init.path;
235262

236-
on_all_children_bits(move_data,
263+
on_all_children_bits(tcx_mir,
264+
move_data,
237265
path,
238-
&has_uniform_drop_state,
239266
&mut callback)
240267
},
241268
InitKind::Shallow => {

0 commit comments

Comments
 (0)