Skip to content

Commit

Permalink
Call super for debuginfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jul 10, 2023
1 parent b4c342e commit a5031d5
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 290 deletions.
19 changes: 16 additions & 3 deletions compiler/rustc_mir_transform/src/ref_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
87 changes: 40 additions & 47 deletions tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,95 @@ fn int_range(_1: usize, _2: usize) -> () {
debug start => _1;
debug end => _2;
let mut _0: ();
let mut _3: std::ops::Range<usize>;
let mut _4: std::ops::Range<usize>;
let mut _8: std::option::Option<usize>;
let mut _11: isize;
let _13: ();
let mut _14: &mut std::ops::Range<usize>;
let mut _3: usize;
let mut _6: std::option::Option<usize>;
let mut _9: isize;
let _11: ();
scope 1 {
debug iter => _4;
let _12: usize;
debug iter => std::ops::Range<usize>{ .0 => _3, .1 => _2, };
let _10: usize;
scope 2 {
debug i => _12;
debug i => _10;
}
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
debug self => &_4;
debug self => &std::ops::Range<usize>{ .0 => _3, .1 => _2, };
scope 5 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
debug self => &_4;
let mut _7: bool;
let _9: usize;
let mut _10: usize;
debug self => &std::ops::Range<usize>{ .0 => _3, .1 => _2, };
let mut _5: bool;
let _7: usize;
let mut _8: usize;
scope 6 {
debug old => _9;
debug old => _7;
scope 7 {
}
}
scope 8 (inlined cmp::impls::<impl PartialOrd for usize>::lt) {
debug self => &((*_14).0: usize);
debug other => &((*_14).1: usize);
let mut _5: usize;
let mut _6: usize;
debug self => &_3;
debug other => &_2;
let mut _4: usize;
}
}
}
}
scope 3 (inlined <std::ops::Range<usize> as IntoIterator>::into_iter) {
debug self => _3;
debug self => std::ops::Range<usize>{ .0 => _1, .1 => _2, };
}

bb0: {
_3 = std::ops::Range::<usize> { start: _1, end: _2 };
StorageLive(_4);
_4 = move _3;
StorageLive(_3);
_3 = _1;
goto -> bb1;
}

bb1: {
StorageLive(_8);
StorageLive(_9);
StorageLive(_6);
StorageLive(_7);
StorageLive(_5);
_5 = (_4.0: usize);
StorageLive(_6);
_6 = (_4.1: usize);
_7 = Lt(move _5, move _6);
StorageDead(_6);
StorageDead(_5);
switchInt(move _7) -> [0: bb2, otherwise: bb3];
StorageLive(_4);
_4 = _3;
_5 = Lt(move _4, _2);
StorageDead(_4);
switchInt(move _5) -> [0: bb2, otherwise: bb3];
}

bb2: {
_8 = Option::<usize>::None;
_6 = Option::<usize>::None;
goto -> bb5;
}

bb3: {
_9 = (_4.0: usize);
StorageLive(_10);
_10 = <usize as Step>::forward_unchecked(_9, const 1_usize) -> [return: bb4, unwind continue];
_7 = _3;
StorageLive(_8);
_8 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb4, unwind continue];
}

bb4: {
(_4.0: usize) = move _10;
StorageDead(_10);
_8 = Option::<usize>::Some(_9);
_3 = move _8;
StorageDead(_8);
_6 = Option::<usize>::Some(_7);
goto -> bb5;
}

bb5: {
StorageDead(_5);
StorageDead(_7);
StorageDead(_9);
_11 = discriminant(_8);
switchInt(move _11) -> [0: bb6, 1: bb7, otherwise: bb9];
_9 = discriminant(_6);
switchInt(move _9) -> [0: bb6, 1: bb7, otherwise: bb9];
}

bb6: {
StorageDead(_8);
StorageDead(_4);
StorageDead(_6);
StorageDead(_3);
return;
}

bb7: {
_12 = ((_8 as Some).0: usize);
_13 = opaque::<usize>(_12) -> [return: bb8, unwind continue];
_10 = ((_6 as Some).0: usize);
_11 = opaque::<usize>(_10) -> [return: bb8, unwind continue];
}

bb8: {
StorageDead(_8);
StorageDead(_6);
goto -> bb1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,87 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
debug end => _2;
debug f => _3;
let mut _0: ();
let mut _4: std::ops::Range<u32>;
let mut _5: std::ops::Range<u32>;
let mut _9: std::option::Option<u32>;
let mut _12: isize;
let mut _14: &impl Fn(u32);
let mut _15: (u32,);
let _16: ();
let mut _17: &mut std::ops::Range<u32>;
let mut _4: u32;
let mut _7: std::option::Option<u32>;
let mut _10: isize;
let mut _12: &impl Fn(u32);
let mut _13: (u32,);
let _14: ();
scope 1 {
debug iter => _5;
let _13: u32;
debug iter => std::ops::Range<u32>{ .0 => _4, .1 => _2, };
let _11: u32;
scope 2 {
debug x => _13;
debug x => _11;
}
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
debug self => &_5;
debug self => &std::ops::Range<u32>{ .0 => _4, .1 => _2, };
scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
debug self => &_5;
let mut _8: bool;
let _10: u32;
let mut _11: u32;
debug self => &std::ops::Range<u32>{ .0 => _4, .1 => _2, };
let mut _6: bool;
let _8: u32;
let mut _9: u32;
scope 6 {
debug old => _10;
debug old => _8;
scope 7 {
}
}
scope 8 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
debug self => &((*_17).0: u32);
debug other => &((*_17).1: u32);
let mut _6: u32;
let mut _7: u32;
debug self => &_4;
debug other => &_2;
let mut _5: u32;
}
}
}
}
scope 3 (inlined <std::ops::Range<u32> as IntoIterator>::into_iter) {
debug self => _4;
debug self => std::ops::Range<u32>{ .0 => _1, .1 => _2, };
}

bb0: {
_4 = std::ops::Range::<u32> { start: _1, end: _2 };
StorageLive(_5);
_5 = move _4;
StorageLive(_4);
_4 = _1;
goto -> bb1;
}

bb1: {
StorageLive(_9);
StorageLive(_10);
StorageLive(_7);
StorageLive(_8);
StorageLive(_6);
_6 = (_5.0: u32);
StorageLive(_7);
_7 = (_5.1: u32);
_8 = Lt(move _6, move _7);
StorageDead(_7);
StorageDead(_6);
switchInt(move _8) -> [0: bb2, otherwise: bb3];
StorageLive(_5);
_5 = _4;
_6 = Lt(move _5, _2);
StorageDead(_5);
switchInt(move _6) -> [0: bb2, otherwise: bb3];
}

bb2: {
_9 = Option::<u32>::None;
_7 = Option::<u32>::None;
goto -> bb5;
}

bb3: {
_10 = (_5.0: u32);
StorageLive(_11);
_11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable];
_8 = _4;
StorageLive(_9);
_9 = <u32 as Step>::forward_unchecked(_8, const 1_usize) -> [return: bb4, unwind unreachable];
}

bb4: {
(_5.0: u32) = move _11;
StorageDead(_11);
_9 = Option::<u32>::Some(_10);
_4 = move _9;
StorageDead(_9);
_7 = Option::<u32>::Some(_8);
goto -> bb5;
}

bb5: {
StorageDead(_6);
StorageDead(_8);
StorageDead(_10);
_12 = discriminant(_9);
switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb10];
_10 = discriminant(_7);
switchInt(move _10) -> [0: bb6, 1: bb8, otherwise: bb10];
}

bb6: {
StorageDead(_9);
StorageDead(_5);
StorageDead(_7);
StorageDead(_4);
drop(_3) -> [return: bb7, unwind unreachable];
}

Expand All @@ -101,18 +94,18 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
}

bb8: {
_13 = ((_9 as Some).0: u32);
StorageLive(_14);
_14 = &_3;
StorageLive(_15);
_15 = (_13,);
_16 = <impl Fn(u32) as Fn<(u32,)>>::call(move _14, move _15) -> [return: bb9, unwind unreachable];
_11 = ((_7 as Some).0: u32);
StorageLive(_12);
_12 = &_3;
StorageLive(_13);
_13 = (_11,);
_14 = <impl Fn(u32) as Fn<(u32,)>>::call(move _12, move _13) -> [return: bb9, unwind unreachable];
}

bb9: {
StorageDead(_15);
StorageDead(_14);
StorageDead(_9);
StorageDead(_13);
StorageDead(_12);
StorageDead(_7);
goto -> bb1;
}

Expand Down
Loading

0 comments on commit a5031d5

Please sign in to comment.