1
Fork 0

Give collect_drop_flags and elaborate_drops closer structure.

This commit is contained in:
Camille GILLOT 2023-10-12 17:42:49 +00:00
parent 252c64722f
commit f038882fc0

View file

@ -287,38 +287,14 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
fn collect_drop_flags(&mut self) { fn collect_drop_flags(&mut self) {
for (bb, data) in self.body.basic_blocks.iter_enumerated() { for (bb, data) in self.body.basic_blocks.iter_enumerated() {
let terminator = data.terminator(); let terminator = data.terminator();
let place = match terminator.kind { let TerminatorKind::Drop { ref place, .. } = terminator.kind else { continue };
TerminatorKind::Drop { ref place, .. } => place,
_ => continue,
};
self.init_data.seek_before(self.body.terminator_loc(bb));
let path = self.move_data().rev_lookup.find(place.as_ref()); let path = self.move_data().rev_lookup.find(place.as_ref());
debug!("collect_drop_flags: {:?}, place {:?} ({:?})", bb, place, path); debug!("collect_drop_flags: {:?}, place {:?} ({:?})", bb, place, path);
let path = match path { match path {
LookupResult::Exact(e) => e, LookupResult::Exact(path) => {
LookupResult::Parent(None) => continue, self.init_data.seek_before(self.body.terminator_loc(bb));
LookupResult::Parent(Some(parent)) => {
let (_maybe_live, maybe_dead) = self.init_data.maybe_live_dead(parent);
if self.body.local_decls[place.local].is_deref_temp() {
continue;
}
if maybe_dead {
self.tcx.sess.delay_span_bug(
terminator.source_info.span,
format!(
"drop of untracked, uninitialized value {bb:?}, place {place:?} ({path:?})"
),
);
}
continue;
}
};
on_all_drop_children_bits(self.tcx, self.body, self.env, path, |child| { on_all_drop_children_bits(self.tcx, self.body, self.env, path, |child| {
let (maybe_live, maybe_dead) = self.init_data.maybe_live_dead(child); let (maybe_live, maybe_dead) = self.init_data.maybe_live_dead(child);
debug!( debug!(
@ -333,22 +309,40 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
} }
}); });
} }
LookupResult::Parent(None) => {}
LookupResult::Parent(Some(parent)) => {
if self.body.local_decls[place.local].is_deref_temp() {
continue;
}
self.init_data.seek_before(self.body.terminator_loc(bb));
let (_maybe_live, maybe_dead) = self.init_data.maybe_live_dead(parent);
if maybe_dead {
self.tcx.sess.delay_span_bug(
terminator.source_info.span,
format!(
"drop of untracked, uninitialized value {bb:?}, place {place:?} ({path:?})"
),
);
}
}
};
}
} }
fn elaborate_drops(&mut self) { fn elaborate_drops(&mut self) {
// This function should mirror what `collect_drop_flags` does.
for (bb, data) in self.body.basic_blocks.iter_enumerated() { for (bb, data) in self.body.basic_blocks.iter_enumerated() {
let loc = Location { block: bb, statement_index: data.statements.len() };
let terminator = data.terminator(); let terminator = data.terminator();
let TerminatorKind::Drop { place, target, unwind, replace } = terminator.kind else {
continue;
};
match terminator.kind { let path = self.move_data().rev_lookup.find(place.as_ref());
TerminatorKind::Drop { place, target, unwind, replace } => { match path {
self.init_data.seek_before(loc);
match self.move_data().rev_lookup.find(place.as_ref()) {
LookupResult::Exact(path) => { LookupResult::Exact(path) => {
let unwind = if data.is_cleanup { let unwind = match unwind {
Unwind::InCleanup _ if data.is_cleanup => Unwind::InCleanup,
} else {
match unwind {
UnwindAction::Cleanup(cleanup) => Unwind::To(cleanup), UnwindAction::Cleanup(cleanup) => Unwind::To(cleanup),
UnwindAction::Continue => Unwind::To(self.patch.resume_block()), UnwindAction::Continue => Unwind::To(self.patch.resume_block()),
UnwindAction::Unreachable => { UnwindAction::Unreachable => {
@ -362,8 +356,8 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
); );
Unwind::To(self.patch.terminate_block(reason)) Unwind::To(self.patch.terminate_block(reason))
} }
}
}; };
self.init_data.seek_before(self.body.terminator_loc(bb));
elaborate_drop( elaborate_drop(
&mut Elaborator { ctxt: self }, &mut Elaborator { ctxt: self },
terminator.source_info, terminator.source_info,
@ -374,7 +368,8 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
bb, bb,
) )
} }
LookupResult::Parent(..) => { LookupResult::Parent(None) => {}
LookupResult::Parent(Some(_)) => {
if !replace { if !replace {
self.tcx.sess.delay_span_bug( self.tcx.sess.delay_span_bug(
terminator.source_info.span, terminator.source_info.span,
@ -388,9 +383,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
} }
} }
} }
_ => continue,
}
}
} }
fn constant_bool(&self, span: Span, val: bool) -> Rvalue<'tcx> { fn constant_bool(&self, span: Span, val: bool) -> Rvalue<'tcx> {