1use std::mem;
2
3use rustc_index::IndexVec;
4use rustc_middle::mir::*;
5use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
6use rustc_span::{bug, span_bug};
7use smallvec::{SmallVec, smallvec};
8use tracing::debug;
9
10use super::{
11 Init, InitIndex, InitKind, InitLocation, LocationMap, LookupResult, MoveData, MoveOut,
12 MoveOutIndex, MovePath, MovePathIndex, MovePathLookup, MoveSubPath, MoveSubPathResult,
13};
14
15struct MoveDataBuilder<'a, 'tcx, F> {
16 body: &'a Body<'tcx>,
17 loc: Location,
18 tcx: TyCtxt<'tcx>,
19 data: MoveData<'tcx>,
20 filter: F,
21}
22
23impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
24 fn new(body: &'a Body<'tcx>, tcx: TyCtxt<'tcx>, filter: F) -> Self {
25 let mut move_paths = IndexVec::new();
26 let mut move_out_path_map = IndexVec::new();
27 let mut init_path_map = IndexVec::new();
28
29 let locals = body
30 .local_decls
31 .iter_enumerated()
32 .map(|(i, l)| {
33 if l.is_deref_temp() {
34 return None;
35 }
36 if filter(l.ty) {
37 Some(new_move_path(
38 &mut move_paths,
39 &mut move_out_path_map,
40 &mut init_path_map,
41 None,
42 Place::from(i),
43 ))
44 } else {
45 None
46 }
47 })
48 .collect();
49
50 MoveDataBuilder {
51 body,
52 loc: Location::START,
53 tcx,
54 data: MoveData {
55 move_outs: IndexVec::new(),
56 move_out_loc_map: LocationMap::new(body),
57 rev_lookup: MovePathLookup {
58 locals,
59 projections: Default::default(),
60 un_derefer: Default::default(),
61 },
62 move_paths,
63 move_out_path_map,
64 inits: IndexVec::new(),
65 init_loc_map: LocationMap::new(body),
66 init_path_map,
67 },
68 filter,
69 }
70 }
71}
72
73fn new_move_path<'tcx>(
74 move_paths: &mut IndexVec<MovePathIndex, MovePath<'tcx>>,
75 move_out_path_map: &mut IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
76 init_path_map: &mut IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
77 parent: Option<MovePathIndex>,
78 place: Place<'tcx>,
79) -> MovePathIndex {
80 let move_path =
81 move_paths.push(MovePath { next_sibling: None, first_child: None, parent, place });
82
83 if let Some(parent) = parent {
84 let next_sibling = mem::replace(&mut move_paths[parent].first_child, Some(move_path));
85 move_paths[move_path].next_sibling = next_sibling;
86 }
87
88 let path_map_ent = move_out_path_map.push(::smallvec::SmallVec::new()smallvec![]);
89 {
match (&path_map_ent, &move_path) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(path_map_ent, move_path);
90
91 let init_path_map_ent = init_path_map.push(::smallvec::SmallVec::new()smallvec![]);
92 {
match (&init_path_map_ent, &move_path) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(init_path_map_ent, move_path);
93
94 move_path
95}
96
97impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
98 fn move_path_for<G>(&mut self, place: Place<'tcx>, mut on_move: G)
108 where
109 G: FnMut(&mut Self, MovePathIndex),
110 {
111 let data = &mut self.data;
112
113 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:113",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(113u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("lookup({0:?})",
place) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("lookup({:?})", place);
114 let Some(mut base) = data.rev_lookup.find_local(place.local) else {
115 return;
116 };
117
118 let mut union_path = None;
124
125 let mut iter = data.rev_lookup.un_derefer.iter_projections(place.as_ref());
126 while let Some((place_ref, elem)) = iter.next() {
127 let body = self.body;
128 let tcx = self.tcx;
129 let place_ty = place_ref.ty(body, tcx).ty;
130 if place_ty.references_error() {
131 return;
132 }
133
134 let res = MoveSubPath::of(elem.kind());
135
136 let move_elem = match res {
137 MoveSubPathResult::One(move_elem) => {
138 match move_elem {
139 MoveSubPath::Deref => match place_ty.kind() {
140 ty::Ref(..) | ty::RawPtr(..) => {
141 return;
142 }
143 ty::Adt(adt, _) => {
144 if !adt.is_box() {
145 ::rustc_span::macros::bug_impl(None,
format_args!("Adt should be a box type when Place is deref"),
Location::caller());bug!("Adt should be a box type when Place is deref");
146 }
147 }
148 ty::Bool
149 | ty::Char
150 | ty::Int(_)
151 | ty::Uint(_)
152 | ty::Float(_)
153 | ty::Foreign(_)
154 | ty::Str
155 | ty::Array(_, _)
156 | ty::Pat(_, _)
157 | ty::Slice(_)
158 | ty::FnDef(_, _)
159 | ty::FnPtr(..)
160 | ty::Dynamic(_, _)
161 | ty::Closure(..)
162 | ty::CoroutineClosure(..)
163 | ty::Coroutine(_, _)
164 | ty::CoroutineWitness(..)
165 | ty::Never
166 | ty::Tuple(_)
167 | ty::UnsafeBinder(_)
168 | ty::Alias(_, _)
169 | ty::Param(_)
170 | ty::Bound(_, _)
171 | ty::Infer(_)
172 | ty::Error(_)
173 | ty::Placeholder(_) => {
174 ::rustc_span::macros::bug_impl(None,
format_args!("When Place is Deref it\'s type shouldn\'t be {0:#?}",
place_ty), Location::caller())bug!("When Place is Deref it's type shouldn't be {place_ty:#?}")
175 }
176
177 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
179 },
180 MoveSubPath::Field(_) => match place_ty.kind() {
181 ty::Adt(adt, _) => {
182 if adt.has_dtor(tcx) {
183 return;
184 }
185 if adt.is_union() {
186 union_path.get_or_insert(base);
187 }
188 }
189 ty::Closure(..)
190 | ty::CoroutineClosure(..)
191 | ty::Coroutine(_, _)
192 | ty::Tuple(_) => (),
193 ty::Bool
194 | ty::Char
195 | ty::Int(_)
196 | ty::Uint(_)
197 | ty::Float(_)
198 | ty::Foreign(_)
199 | ty::Str
200 | ty::Array(_, _)
201 | ty::Pat(_, _)
202 | ty::Slice(_)
203 | ty::RawPtr(_, _)
204 | ty::Ref(_, _, _)
205 | ty::FnDef(_, _)
206 | ty::FnPtr(..)
207 | ty::Dynamic(_, _)
208 | ty::CoroutineWitness(..)
209 | ty::Never
210 | ty::UnsafeBinder(_)
211 | ty::Alias(_, _)
212 | ty::Param(_)
213 | ty::Bound(_, _)
214 | ty::Infer(_)
215 | ty::Error(_)
216 | ty::Placeholder(_) => ::rustc_span::macros::bug_impl(None,
format_args!("When Place contains ProjectionElem::Field its type shouldn\'t be {0:#?}",
place_ty), Location::caller())bug!(
217 "When Place contains ProjectionElem::Field its type shouldn't be {place_ty:#?}"
218 ),
219
220 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
222 },
223 MoveSubPath::ConstantIndex(_) => match place_ty.kind() {
224 ty::Slice(_) => {
225 return;
226 }
227 ty::Array(_, _) => (),
228 _ => ::rustc_span::macros::bug_impl(None,
format_args!("Unexpected type {0:#?}", place_ty.is_array()),
Location::caller())bug!("Unexpected type {:#?}", place_ty.is_array()),
229 },
230 MoveSubPath::Downcast(_) => (),
231 MoveSubPath::UnwrapUnsafeBinder => (),
232 };
233
234 move_elem
235 }
236
237 MoveSubPathResult::Subslice { from, to } => {
241 if !iter.all(|(_, elem)|
MoveSubPath::of(elem.kind()) == MoveSubPathResult::Skip) {
::core::panicking::panic("assertion failed: iter.all(|(_, elem)| MoveSubPath::of(elem.kind()) == MoveSubPathResult::Skip)")
};assert!(
242 iter.all(
243 |(_, elem)| MoveSubPath::of(elem.kind()) == MoveSubPathResult::Skip
244 )
245 );
246 drop(iter); let (&elem_ty, len) = match place_ty.kind() {
249 ty::Array(ty, size) => (
250 ty,
251 size.try_to_target_usize(self.tcx)
252 .expect("expected subslice projection on fixed-size array"),
253 ),
254 _ => ::rustc_span::macros::bug_impl(None,
format_args!("from_end: false slice pattern of non-array type"),
Location::caller())bug!("from_end: false slice pattern of non-array type"),
255 };
256
257 if !(self.filter)(elem_ty) {
258 return;
259 }
260
261 for offset in from..to {
262 let place_elem =
263 PlaceElem::ConstantIndex { offset, min_length: len, from_end: false };
264 let subpath_elem = MoveSubPath::ConstantIndex(offset);
265
266 let mpi = self.add_move_path(base, subpath_elem, |tcx| {
267 place_ref.project_deeper(&[place_elem], tcx)
268 });
269 on_move(self, mpi);
270 }
271
272 return;
273 }
274
275 MoveSubPathResult::Skip => continue,
276 MoveSubPathResult::Stop => return,
277 };
278
279 let elem_ty = PlaceTy::from_ty(place_ty).projection_ty(tcx, elem).ty;
280 if !(self.filter)(elem_ty) {
281 return;
282 }
283 if union_path.is_none() {
284 base = *data.rev_lookup.projections.entry((base, move_elem)).or_insert_with(|| {
286 new_move_path(
287 &mut data.move_paths,
288 &mut data.move_out_path_map,
289 &mut data.init_path_map,
290 Some(base),
291 place_ref.project_deeper(&[elem], tcx),
292 )
293 })
294 }
295 }
296
297 drop(iter); if let Some(base) = union_path {
300 on_move(self, base);
302 } else {
303 on_move(self, base);
304 }
305 }
306
307 fn add_move_path(
308 &mut self,
309 base: MovePathIndex,
310 elem: MoveSubPath,
311 mk_place: impl FnOnce(TyCtxt<'tcx>) -> Place<'tcx>,
312 ) -> MovePathIndex {
313 let MoveDataBuilder {
314 data: MoveData { rev_lookup, move_paths, move_out_path_map, init_path_map, .. },
315 tcx,
316 ..
317 } = self;
318 *rev_lookup.projections.entry((base, elem)).or_insert_with(move || {
319 new_move_path(move_paths, move_out_path_map, init_path_map, Some(base), mk_place(*tcx))
320 })
321 }
322
323 fn create_move_path(&mut self, place: Place<'tcx>) {
324 self.move_path_for(place, |_, _| ());
327 }
328
329 fn finalize(self) -> MoveData<'tcx> {
330 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:330",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(330u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("{0}",
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:331",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(331u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("moves for {0:?}:",
self.body.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for (j, mo) in self.data.move_outs.iter_enumerated() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:333",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(333u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" {0:?} = {1:?}",
j, mo) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:335",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(335u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("move paths for {0:?}:",
self.body.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for (j, path) in self.data.move_paths.iter_enumerated() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:337",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(337u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" {0:?} = {1:?}",
j, path) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
"done dumping moves"
}) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("{}", {
331 debug!("moves for {:?}:", self.body.span);
332 for (j, mo) in self.data.move_outs.iter_enumerated() {
333 debug!(" {:?} = {:?}", j, mo);
334 }
335 debug!("move paths for {:?}:", self.body.span);
336 for (j, path) in self.data.move_paths.iter_enumerated() {
337 debug!(" {:?} = {:?}", j, path);
338 }
339 "done dumping moves"
340 });
341
342 self.data
343 }
344}
345
346pub(super) fn gather_moves<'tcx>(
347 body: &Body<'tcx>,
348 tcx: TyCtxt<'tcx>,
349 filter: impl Fn(Ty<'tcx>) -> bool,
350) -> MoveData<'tcx> {
351 let mut builder = MoveDataBuilder::new(body, tcx, filter);
352
353 builder.gather_args();
354
355 for (bb, block) in body.basic_blocks.iter_enumerated() {
356 for (i, stmt) in block.statements.iter().enumerate() {
357 builder.loc = Location { block: bb, statement_index: i };
358 builder.gather_statement(stmt);
359 }
360
361 builder.loc = Location { block: bb, statement_index: block.statements.len() };
362 builder.gather_terminator(block.terminator());
363 }
364
365 builder.finalize()
366}
367
368impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
369 fn gather_args(&mut self) {
370 for arg in self.body.args_iter() {
371 if let Some(path) = self.data.rev_lookup.find_local(arg) {
372 let init = self.data.inits.push(Init {
373 path,
374 kind: InitKind::Unconditional,
375 location: InitLocation::Argument(arg),
376 });
377
378 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:378",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(378u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_args: adding init {0:?} of {1:?} for argument {2:?}",
init, path, arg) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("gather_args: adding init {:?} of {:?} for argument {:?}", init, path, arg);
379
380 self.data.init_path_map[path].push(init);
381 }
382 }
383 }
384
385 fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
386 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:386",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(386u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_statement({0:?}, {1:?})",
self.loc, stmt) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("gather_statement({:?}, {:?})", self.loc, stmt);
387 match &stmt.kind {
388 StatementKind::Assign((place, Rvalue::CopyForDeref(reffed))) => {
389 let local = place.as_local().unwrap();
390 if !self.body.local_decls[local].is_deref_temp() {
::core::panicking::panic("assertion failed: self.body.local_decls[local].is_deref_temp()")
};assert!(self.body.local_decls[local].is_deref_temp());
391
392 let rev_lookup = &mut self.data.rev_lookup;
393
394 rev_lookup.un_derefer.insert(local, reffed.as_ref());
395 let base_local = rev_lookup.un_derefer.deref_chain(local).first().unwrap().local;
396 rev_lookup.locals[local] = rev_lookup.locals[base_local];
397 }
398 StatementKind::Assign((place, rval)) => {
399 self.create_move_path(*place);
400 self.gather_init(place.as_ref(), InitKind::Unconditional);
401 self.gather_rvalue(rval);
402 }
403 StatementKind::FakeRead((_, place)) => {
404 self.create_move_path(*place);
405 }
406 StatementKind::StorageLive(_) => {}
407 StatementKind::StorageDead(local) => {
408 if !self.body.local_decls[*local].is_deref_temp() {
410 self.gather_move(Place::from(*local));
411 }
412 }
413 StatementKind::SetDiscriminant { .. } => {
414 ::rustc_span::macros::bug_impl(Some(stmt.source_info.span),
format_args!("SetDiscriminant/Deinit should not exist during borrowck"),
Location::caller());span_bug!(
415 stmt.source_info.span,
416 "SetDiscriminant/Deinit should not exist during borrowck"
417 );
418 }
419 StatementKind::AscribeUserType(..)
420 | StatementKind::PlaceMention(..)
421 | StatementKind::Coverage(..)
422 | StatementKind::Intrinsic(..)
423 | StatementKind::ConstEvalCounter
424 | StatementKind::BackwardIncompatibleDropHint { .. }
425 | StatementKind::Nop => {}
426 }
427 }
428
429 fn gather_rvalue(&mut self, rvalue: &Rvalue<'tcx>) {
430 match *rvalue {
431 Rvalue::ThreadLocalRef(_) => {} Rvalue::Use(ref operand, _)
433 | Rvalue::Repeat(ref operand, _)
434 | Rvalue::Cast(_, ref operand, _)
435 | Rvalue::UnaryOp(_, ref operand)
436 | Rvalue::WrapUnsafeBinder(ref operand, _) => self.gather_operand(operand),
437 Rvalue::BinaryOp(ref _binop, (ref lhs, ref rhs)) => {
438 self.gather_operand(lhs);
439 self.gather_operand(rhs);
440 }
441 Rvalue::Aggregate(ref _kind, ref operands) => {
442 for operand in operands {
443 self.gather_operand(operand);
444 }
445 }
446 Rvalue::CopyForDeref(..) => ::core::panicking::unreachable_default_msg()unreachable!(),
447 Rvalue::Ref(..)
448 | Rvalue::Reborrow(..)
449 | Rvalue::RawPtr(..)
450 | Rvalue::Discriminant(..) => {}
451 }
452 }
453
454 fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
455 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:455",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(455u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_terminator({0:?}, {1:?})",
self.loc, term) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("gather_terminator({:?}, {:?})", self.loc, term);
456 match term.kind {
457 TerminatorKind::Goto { target: _, .. }
458 | TerminatorKind::FalseEdge { .. }
459 | TerminatorKind::FalseUnwind { .. } => {}
460 TerminatorKind::Return
465 | TerminatorKind::UnwindResume
466 | TerminatorKind::UnwindTerminate(_)
467 | TerminatorKind::CoroutineDrop
468 | TerminatorKind::Unreachable
469 | TerminatorKind::Drop { .. } => {}
470
471 TerminatorKind::Assert { ref cond, .. } => {
472 self.gather_operand(cond);
473 }
474
475 TerminatorKind::SwitchInt { ref discr, .. } => {
476 self.gather_operand(discr);
477 }
478
479 TerminatorKind::Yield { ref value, resume_arg: place, .. } => {
480 self.gather_operand(value);
481 self.create_move_path(place);
482 self.gather_init(place.as_ref(), InitKind::OnReturn);
483 }
484 TerminatorKind::Call {
485 ref func,
486 ref args,
487 destination,
488 target,
489 unwind: _,
490 call_source: _,
491 fn_span: _,
492 } => {
493 self.gather_operand(func);
494 for arg in args {
495 self.gather_operand(&arg.node);
496 }
497 if let Some(_bb) = target {
498 self.create_move_path(destination);
499 self.gather_init(destination.as_ref(), InitKind::OnReturn);
500 }
501 }
502 TerminatorKind::TailCall { ref func, ref args, .. } => {
503 self.gather_operand(func);
504 for arg in args {
505 self.gather_operand(&arg.node);
506 }
507 }
508 TerminatorKind::InlineAsm {
509 asm_macro: _,
510 template: _,
511 ref operands,
512 options: _,
513 line_spans: _,
514 targets: _,
515 unwind: _,
516 } => {
517 for op in operands {
518 match *op {
519 InlineAsmOperand::In { reg: _, ref value } => {
520 self.gather_operand(value);
521 }
522 InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
523 if let Some(place) = place {
524 self.create_move_path(place);
525 self.gather_init(place.as_ref(), InitKind::OnReturn);
526 }
527 }
528 InlineAsmOperand::InOut { reg: _, late: _, ref in_value, out_place } => {
529 self.gather_operand(in_value);
530 if let Some(out_place) = out_place {
531 self.create_move_path(out_place);
532 self.gather_init(out_place.as_ref(), InitKind::OnReturn);
533 }
534 }
535 InlineAsmOperand::Const { value: _ }
536 | InlineAsmOperand::SymFn { value: _ }
537 | InlineAsmOperand::SymStatic { def_id: _ }
538 | InlineAsmOperand::Label { target_index: _ } => {}
539 }
540 }
541 }
542 }
543 }
544
545 fn gather_operand(&mut self, operand: &Operand<'tcx>) {
546 match *operand {
547 Operand::Constant(..) | Operand::Copy(..) | Operand::RuntimeChecks(_) => {}
549 Operand::Move(place) => {
551 self.gather_move(place);
552 }
553 }
554 }
555
556 fn gather_move(&mut self, place: Place<'tcx>) {
557 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:557",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(557u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_move({0:?}, {1:?})",
self.loc, place) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("gather_move({:?}, {:?})", self.loc, place);
558 self.move_path_for(place, |this, mpi| this.record_move(place, mpi));
559 }
560
561 fn record_move(&mut self, place: Place<'tcx>, path: MovePathIndex) {
562 let move_out = self.data.move_outs.push(MoveOut { path, source: self.loc });
563 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:563",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(563u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_move({0:?}, {1:?}): adding move {2:?} of {3:?}",
self.loc, place, move_out, path) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
564 "gather_move({:?}, {:?}): adding move {:?} of {:?}",
565 self.loc, place, move_out, path
566 );
567 self.data.move_out_path_map[path].push(move_out);
568 self.data.move_out_loc_map[self.loc].push(move_out);
569 }
570
571 fn gather_init(&mut self, place: PlaceRef<'tcx>, kind: InitKind) {
572 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:572",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(572u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_init({0:?}, {1:?})",
self.loc, place) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("gather_init({:?}, {:?})", self.loc, place);
573
574 let mut place = place;
575
576 if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
579 if place_base.ty(self.body, self.tcx).ty.is_union() {
580 place = place_base;
581 }
582 }
583
584 if let LookupResult::Exact(path) = self.data.rev_lookup.find(place) {
585 let init = self.data.inits.push(Init {
586 location: InitLocation::Statement(self.loc),
587 path,
588 kind,
589 });
590
591 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs:591",
"rustc_mir_dataflow::move_paths::builder",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/6c709eb428d472a3c3d93681c1ba37d44a1c27cf/compiler/rustc_mir_dataflow/src/move_paths/builder.rs"),
::tracing_core::__macro_support::Option::Some(591u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_dataflow::move_paths::builder"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("gather_init({0:?}, {1:?}): adding init {2:?} of {3:?}",
self.loc, place, init, path) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
592 "gather_init({:?}, {:?}): adding init {:?} of {:?}",
593 self.loc, place, init, path
594 );
595
596 self.data.init_path_map[path].push(init);
597 self.data.init_loc_map[self.loc].push(init);
598 }
599 }
600}