Skip to content

Commit ba7d127

Browse files
committed
More tracing and tests
1 parent 4574152 commit ba7d127

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ impl DropRangeVisitor<'tcx> {
773773
debug!("reinitializing {:?} at {}", hir_id, location);
774774
self.drop_range(hir_id).reinit(location)
775775
} else {
776-
warn!("reinitializing {:?} is not supported", expr);
776+
debug!("reinitializing {:?} is not supported", expr);
777777
}
778778
}
779779
}
@@ -899,6 +899,7 @@ impl<'tcx> Visitor<'tcx> for DropRangeVisitor<'tcx> {
899899
reinit = Some(lhs);
900900
}
901901
ExprKind::Loop(body, ..) => {
902+
// FIXME: we probably need to iterate this to a fixpoint.
902903
let body_drop_ranges = self.fork_drop_ranges();
903904
let old_drop_ranges = self.swap_drop_ranges(body_drop_ranges);
904905

@@ -1026,8 +1027,8 @@ impl DropRange {
10261027
}
10271028

10281029
fn is_dropped_at(&self, id: usize) -> bool {
1029-
match self.events.iter().try_fold(false, |is_dropped, event| {
1030-
if event.location() < id {
1030+
let dropped = match self.events.iter().try_fold(false, |is_dropped, event| {
1031+
if event.location() <= id {
10311032
Ok(match event {
10321033
Event::Drop(_) => true,
10331034
Event::Reinit(_) => false,
@@ -1037,7 +1038,9 @@ impl DropRange {
10371038
}
10381039
}) {
10391040
Ok(is_dropped) | Err(is_dropped) => is_dropped,
1040-
}
1041+
};
1042+
trace!("is_dropped_at({}): events = {:?}, dropped = {}", id, self.events, dropped);
1043+
dropped
10411044
}
10421045

10431046
fn drop(&mut self, location: usize) {
@@ -1052,13 +1055,14 @@ impl DropRange {
10521055
///
10531056
/// After merging, the value will be dead at the end of the range only if it was dead
10541057
/// at the end of both self and other.
1058+
#[tracing::instrument]
10551059
fn merge_with(&mut self, other: &DropRange, join_point: usize) {
10561060
let join_event = if self.is_dropped_at(join_point) && other.is_dropped_at(join_point) {
10571061
Event::Drop(join_point)
10581062
} else {
10591063
Event::Reinit(join_point)
10601064
};
1061-
let mut events: Vec<_> = self
1065+
let events: Vec<_> = self
10621066
.events
10631067
.iter()
10641068
.merge([join_event].iter())
@@ -1067,11 +1071,7 @@ impl DropRange {
10671071
.cloned()
10681072
.collect();
10691073

1070-
events.push(if self.is_dropped_at(join_point) && other.is_dropped_at(join_point) {
1071-
Event::Drop(join_point)
1072-
} else {
1073-
Event::Reinit(join_point)
1074-
});
1074+
trace!("events after merging: {:?}", events);
10751075

10761076
self.events = events;
10771077
}
@@ -1080,13 +1080,15 @@ impl DropRange {
10801080
///
10811081
/// Used to model branching control flow.
10821082
fn fork_at(&self, split_point: usize) -> Self {
1083-
Self {
1083+
let result = Self {
10841084
events: vec![if self.is_dropped_at(split_point) {
10851085
Event::Drop(split_point)
10861086
} else {
10871087
Event::Reinit(split_point)
10881088
}],
1089-
}
1089+
};
1090+
trace!("forking at {}: {:?}; result = {:?}", split_point, self.events, result);
1091+
result
10901092
}
10911093

10921094
fn trimmed(&self, trim_from: usize) -> Self {
@@ -1096,12 +1098,14 @@ impl DropRange {
10961098
Event::Reinit(trim_from)
10971099
};
10981100

1099-
Self {
1101+
let result = Self {
11001102
events: [start]
11011103
.iter()
11021104
.chain(self.events.iter().skip_while(|event| event.location() <= trim_from))
11031105
.cloned()
11041106
.collect(),
1105-
}
1107+
};
1108+
trace!("trimmed {:?} at {}, got {:?}", self, trim_from, result);
1109+
result
11061110
}
11071111
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::DropRange;
2+
3+
#[test]
4+
fn drop_range_uses_last_event() {
5+
let mut range = DropRange::empty();
6+
range.drop(10);
7+
range.reinit(10);
8+
assert!(!range.is_dropped_at(10));
9+
10+
let mut range = DropRange::empty();
11+
range.reinit(10);
12+
range.drop(10);
13+
assert!(range.is_dropped_at(10));
14+
}

0 commit comments

Comments
 (0)