1
Fork 0

Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk

[mir-opt] Allow debuginfo to be generated for a constant or a Place

Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
This commit is contained in:
bors 2020-12-15 08:46:00 +00:00
commit e99a89c7c0
16 changed files with 398 additions and 79 deletions

View file

@ -1925,7 +1925,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
place: for_arm_body.into(),
value: VarDebugInfoContents::Place(for_arm_body.into()),
});
let locals = if has_guard.0 {
let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
@ -1944,7 +1944,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
place: ref_for_guard.into(),
value: VarDebugInfoContents::Place(ref_for_guard.into()),
});
LocalsForNode::ForGuard { ref_for_guard, for_arm_body }
} else {

View file

@ -809,7 +809,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.var_debug_info.push(VarDebugInfo {
name: ident.name,
source_info,
place: arg_local.into(),
value: VarDebugInfoContents::Place(arg_local.into()),
});
}
}
@ -882,10 +882,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.var_debug_info.push(VarDebugInfo {
name,
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
place: Place {
value: VarDebugInfoContents::Place(Place {
local: closure_env_arg,
projection: tcx.intern_place_elems(&projs),
},
}),
});
mutability