Call super for debuginfo.

This commit is contained in:
Camille GILLOT 2023-07-01 09:01:33 +00:00
parent b4c342edea
commit a5031d569e
6 changed files with 266 additions and 290 deletions

View file

@ -355,7 +355,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
}
fn visit_var_debug_info(&mut self, debuginfo: &mut VarDebugInfo<'tcx>) {
if let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
// If the debuginfo is a pointer to another place:
// - if it's a reborrow, see through it;
// - if it's a direct borrow, increase `debuginfo.references`.
while let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
&& place.projection.is_empty()
&& let Value::Pointer(target, _) = self.targets[place.local]
&& target.projection.iter().all(|p| p.can_use_in_debuginfo())
@ -369,8 +372,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
debuginfo.references = references;
*place = target;
self.any_replacement = true;
} else {
break
}
}
// Simplify eventual projections left inside `debuginfo`.
self.super_var_debug_info(debuginfo);
}
fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
@ -381,8 +389,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
let Value::Pointer(target, _) = self.targets[place.local] else { return };
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
|| self.allowed_replacements.contains(&(target.local, loc));
let perform_opt = match ctxt {
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {
target.projection.iter().all(|p| p.can_use_in_debuginfo())
}
PlaceContext::NonUse(_) => true,
_ => self.allowed_replacements.contains(&(target.local, loc)),
};
if !perform_opt {
return;