Skip to content

Commit a5031d5

Browse files
committed
Call super for debuginfo.
1 parent b4c342e commit a5031d5

6 files changed

+266
-290
lines changed

compiler/rustc_mir_transform/src/ref_prop.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
355355
}
356356

357357
fn visit_var_debug_info(&mut self, debuginfo: &mut VarDebugInfo<'tcx>) {
358-
if let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
358+
// If the debuginfo is a pointer to another place:
359+
// - if it's a reborrow, see through it;
360+
// - if it's a direct borrow, increase `debuginfo.references`.
361+
while let VarDebugInfoContents::Place(ref mut place) = debuginfo.value
359362
&& place.projection.is_empty()
360363
&& let Value::Pointer(target, _) = self.targets[place.local]
361364
&& target.projection.iter().all(|p| p.can_use_in_debuginfo())
@@ -369,8 +372,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
369372
debuginfo.references = references;
370373
*place = target;
371374
self.any_replacement = true;
375+
} else {
376+
break
372377
}
373378
}
379+
380+
// Simplify eventual projections left inside `debuginfo`.
381+
self.super_var_debug_info(debuginfo);
374382
}
375383

376384
fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
@@ -381,8 +389,13 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
381389

382390
let Value::Pointer(target, _) = self.targets[place.local] else { return };
383391

384-
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
385-
|| self.allowed_replacements.contains(&(target.local, loc));
392+
let perform_opt = match ctxt {
393+
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {
394+
target.projection.iter().all(|p| p.can_use_in_debuginfo())
395+
}
396+
PlaceContext::NonUse(_) => true,
397+
_ => self.allowed_replacements.contains(&(target.local, loc)),
398+
};
386399

387400
if !perform_opt {
388401
return;

tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir

+40-47
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,95 @@ fn int_range(_1: usize, _2: usize) -> () {
44
debug start => _1;
55
debug end => _2;
66
let mut _0: ();
7-
let mut _3: std::ops::Range<usize>;
8-
let mut _4: std::ops::Range<usize>;
9-
let mut _8: std::option::Option<usize>;
10-
let mut _11: isize;
11-
let _13: ();
12-
let mut _14: &mut std::ops::Range<usize>;
7+
let mut _3: usize;
8+
let mut _6: std::option::Option<usize>;
9+
let mut _9: isize;
10+
let _11: ();
1311
scope 1 {
14-
debug iter => _4;
15-
let _12: usize;
12+
debug iter => std::ops::Range<usize>{ .0 => _3, .1 => _2, };
13+
let _10: usize;
1614
scope 2 {
17-
debug i => _12;
15+
debug i => _10;
1816
}
1917
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
20-
debug self => &_4;
18+
debug self => &std::ops::Range<usize>{ .0 => _3, .1 => _2, };
2119
scope 5 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
22-
debug self => &_4;
23-
let mut _7: bool;
24-
let _9: usize;
25-
let mut _10: usize;
20+
debug self => &std::ops::Range<usize>{ .0 => _3, .1 => _2, };
21+
let mut _5: bool;
22+
let _7: usize;
23+
let mut _8: usize;
2624
scope 6 {
27-
debug old => _9;
25+
debug old => _7;
2826
scope 7 {
2927
}
3028
}
3129
scope 8 (inlined cmp::impls::<impl PartialOrd for usize>::lt) {
32-
debug self => &((*_14).0: usize);
33-
debug other => &((*_14).1: usize);
34-
let mut _5: usize;
35-
let mut _6: usize;
30+
debug self => &_3;
31+
debug other => &_2;
32+
let mut _4: usize;
3633
}
3734
}
3835
}
3936
}
4037
scope 3 (inlined <std::ops::Range<usize> as IntoIterator>::into_iter) {
41-
debug self => _3;
38+
debug self => std::ops::Range<usize>{ .0 => _1, .1 => _2, };
4239
}
4340

4441
bb0: {
45-
_3 = std::ops::Range::<usize> { start: _1, end: _2 };
46-
StorageLive(_4);
47-
_4 = move _3;
42+
StorageLive(_3);
43+
_3 = _1;
4844
goto -> bb1;
4945
}
5046

5147
bb1: {
52-
StorageLive(_8);
53-
StorageLive(_9);
48+
StorageLive(_6);
5449
StorageLive(_7);
5550
StorageLive(_5);
56-
_5 = (_4.0: usize);
57-
StorageLive(_6);
58-
_6 = (_4.1: usize);
59-
_7 = Lt(move _5, move _6);
60-
StorageDead(_6);
61-
StorageDead(_5);
62-
switchInt(move _7) -> [0: bb2, otherwise: bb3];
51+
StorageLive(_4);
52+
_4 = _3;
53+
_5 = Lt(move _4, _2);
54+
StorageDead(_4);
55+
switchInt(move _5) -> [0: bb2, otherwise: bb3];
6356
}
6457

6558
bb2: {
66-
_8 = Option::<usize>::None;
59+
_6 = Option::<usize>::None;
6760
goto -> bb5;
6861
}
6962

7063
bb3: {
71-
_9 = (_4.0: usize);
72-
StorageLive(_10);
73-
_10 = <usize as Step>::forward_unchecked(_9, const 1_usize) -> [return: bb4, unwind continue];
64+
_7 = _3;
65+
StorageLive(_8);
66+
_8 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb4, unwind continue];
7467
}
7568

7669
bb4: {
77-
(_4.0: usize) = move _10;
78-
StorageDead(_10);
79-
_8 = Option::<usize>::Some(_9);
70+
_3 = move _8;
71+
StorageDead(_8);
72+
_6 = Option::<usize>::Some(_7);
8073
goto -> bb5;
8174
}
8275

8376
bb5: {
77+
StorageDead(_5);
8478
StorageDead(_7);
85-
StorageDead(_9);
86-
_11 = discriminant(_8);
87-
switchInt(move _11) -> [0: bb6, 1: bb7, otherwise: bb9];
79+
_9 = discriminant(_6);
80+
switchInt(move _9) -> [0: bb6, 1: bb7, otherwise: bb9];
8881
}
8982

9083
bb6: {
91-
StorageDead(_8);
92-
StorageDead(_4);
84+
StorageDead(_6);
85+
StorageDead(_3);
9386
return;
9487
}
9588

9689
bb7: {
97-
_12 = ((_8 as Some).0: usize);
98-
_13 = opaque::<usize>(_12) -> [return: bb8, unwind continue];
90+
_10 = ((_6 as Some).0: usize);
91+
_11 = opaque::<usize>(_10) -> [return: bb8, unwind continue];
9992
}
10093

10194
bb8: {
102-
StorageDead(_8);
95+
StorageDead(_6);
10396
goto -> bb1;
10497
}
10598

tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir

+48-55
Original file line numberDiff line numberDiff line change
@@ -5,94 +5,87 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
55
debug end => _2;
66
debug f => _3;
77
let mut _0: ();
8-
let mut _4: std::ops::Range<u32>;
9-
let mut _5: std::ops::Range<u32>;
10-
let mut _9: std::option::Option<u32>;
11-
let mut _12: isize;
12-
let mut _14: &impl Fn(u32);
13-
let mut _15: (u32,);
14-
let _16: ();
15-
let mut _17: &mut std::ops::Range<u32>;
8+
let mut _4: u32;
9+
let mut _7: std::option::Option<u32>;
10+
let mut _10: isize;
11+
let mut _12: &impl Fn(u32);
12+
let mut _13: (u32,);
13+
let _14: ();
1614
scope 1 {
17-
debug iter => _5;
18-
let _13: u32;
15+
debug iter => std::ops::Range<u32>{ .0 => _4, .1 => _2, };
16+
let _11: u32;
1917
scope 2 {
20-
debug x => _13;
18+
debug x => _11;
2119
}
2220
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
23-
debug self => &_5;
21+
debug self => &std::ops::Range<u32>{ .0 => _4, .1 => _2, };
2422
scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
25-
debug self => &_5;
26-
let mut _8: bool;
27-
let _10: u32;
28-
let mut _11: u32;
23+
debug self => &std::ops::Range<u32>{ .0 => _4, .1 => _2, };
24+
let mut _6: bool;
25+
let _8: u32;
26+
let mut _9: u32;
2927
scope 6 {
30-
debug old => _10;
28+
debug old => _8;
3129
scope 7 {
3230
}
3331
}
3432
scope 8 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
35-
debug self => &((*_17).0: u32);
36-
debug other => &((*_17).1: u32);
37-
let mut _6: u32;
38-
let mut _7: u32;
33+
debug self => &_4;
34+
debug other => &_2;
35+
let mut _5: u32;
3936
}
4037
}
4138
}
4239
}
4340
scope 3 (inlined <std::ops::Range<u32> as IntoIterator>::into_iter) {
44-
debug self => _4;
41+
debug self => std::ops::Range<u32>{ .0 => _1, .1 => _2, };
4542
}
4643

4744
bb0: {
48-
_4 = std::ops::Range::<u32> { start: _1, end: _2 };
49-
StorageLive(_5);
50-
_5 = move _4;
45+
StorageLive(_4);
46+
_4 = _1;
5147
goto -> bb1;
5248
}
5349

5450
bb1: {
55-
StorageLive(_9);
56-
StorageLive(_10);
51+
StorageLive(_7);
5752
StorageLive(_8);
5853
StorageLive(_6);
59-
_6 = (_5.0: u32);
60-
StorageLive(_7);
61-
_7 = (_5.1: u32);
62-
_8 = Lt(move _6, move _7);
63-
StorageDead(_7);
64-
StorageDead(_6);
65-
switchInt(move _8) -> [0: bb2, otherwise: bb3];
54+
StorageLive(_5);
55+
_5 = _4;
56+
_6 = Lt(move _5, _2);
57+
StorageDead(_5);
58+
switchInt(move _6) -> [0: bb2, otherwise: bb3];
6659
}
6760

6861
bb2: {
69-
_9 = Option::<u32>::None;
62+
_7 = Option::<u32>::None;
7063
goto -> bb5;
7164
}
7265

7366
bb3: {
74-
_10 = (_5.0: u32);
75-
StorageLive(_11);
76-
_11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable];
67+
_8 = _4;
68+
StorageLive(_9);
69+
_9 = <u32 as Step>::forward_unchecked(_8, const 1_usize) -> [return: bb4, unwind unreachable];
7770
}
7871

7972
bb4: {
80-
(_5.0: u32) = move _11;
81-
StorageDead(_11);
82-
_9 = Option::<u32>::Some(_10);
73+
_4 = move _9;
74+
StorageDead(_9);
75+
_7 = Option::<u32>::Some(_8);
8376
goto -> bb5;
8477
}
8578

8679
bb5: {
80+
StorageDead(_6);
8781
StorageDead(_8);
88-
StorageDead(_10);
89-
_12 = discriminant(_9);
90-
switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb10];
82+
_10 = discriminant(_7);
83+
switchInt(move _10) -> [0: bb6, 1: bb8, otherwise: bb10];
9184
}
9285

9386
bb6: {
94-
StorageDead(_9);
95-
StorageDead(_5);
87+
StorageDead(_7);
88+
StorageDead(_4);
9689
drop(_3) -> [return: bb7, unwind unreachable];
9790
}
9891

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

10396
bb8: {
104-
_13 = ((_9 as Some).0: u32);
105-
StorageLive(_14);
106-
_14 = &_3;
107-
StorageLive(_15);
108-
_15 = (_13,);
109-
_16 = <impl Fn(u32) as Fn<(u32,)>>::call(move _14, move _15) -> [return: bb9, unwind unreachable];
97+
_11 = ((_7 as Some).0: u32);
98+
StorageLive(_12);
99+
_12 = &_3;
100+
StorageLive(_13);
101+
_13 = (_11,);
102+
_14 = <impl Fn(u32) as Fn<(u32,)>>::call(move _12, move _13) -> [return: bb9, unwind unreachable];
110103
}
111104

112105
bb9: {
113-
StorageDead(_15);
114-
StorageDead(_14);
115-
StorageDead(_9);
106+
StorageDead(_13);
107+
StorageDead(_12);
108+
StorageDead(_7);
116109
goto -> bb1;
117110
}
118111

0 commit comments

Comments
 (0)