Skip to content

Commit 117418f

Browse files
committed
Payoff: much simpler event selection
Error messages unchanged
1 parent 6b0fb3c commit 117418f

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

Diff for: src/borrow_tracker/tree_borrows/diagnostics.rs

+15-42
Original file line numberDiff line numberDiff line change
@@ -196,44 +196,19 @@ impl History {
196196
History { events: Vec::new(), created: self.created, tag: self.tag }
197197
}
198198

199-
/// Reconstruct the history relevant to `error_offset` knowing that
200-
/// its permission followed `complete_transition`.
201-
///
202-
/// Here's how we do this:
203-
/// - we know `full := complete_transition` the transition of the permission from
204-
/// its initialization to the state just before the error was caused,
205-
/// we want to find a chain of events that produces `full`
206-
/// - we decompose `full` into `pre o post` where
207-
/// `pre` is the best applicable transition from recorded events
208-
/// - we select the event that caused `pre` and iterate
209-
/// to find the chain of events that produces `full := post`
210-
///
211-
/// To find the "best applicable transition" for full:
212-
/// - eliminate events that cannot be applied because their offset is too big
213-
/// - eliminate events that cannot be applied because their starting point is wrong
214-
/// - select the one that happened closest to the range of interest
215-
fn extract_relevant(&self, complete_transition: PermTransition, error_offset: Size) -> Self {
216-
let mut selected_events: Vec<Event> = Vec::new();
217-
let mut full = complete_transition;
218-
while !full.is_noop() {
219-
let (pre, post) = self
199+
/// Reconstruct the history relevant to `error_offset` by filtering
200+
/// only events whose range contains the offset we are interested in.
201+
fn extract_relevant(&self, error_offset: u64) -> Self {
202+
History {
203+
events: self
220204
.events
221205
.iter()
222-
.filter(|e| e.offset <= error_offset)
223-
.filter_map(|pre_canditate| {
224-
full.apply_start(pre_canditate.transition)
225-
.map(|post_canditate| (pre_canditate, post_canditate))
226-
})
227-
.max_by_key(|(pre_canditate, _post_candidate)| pre_canditate.offset)
228-
.unwrap();
229-
// If this occurs we will loop infinitely !
230-
// Make sure to only put non-noop transitions in `History`.
231-
assert!(!pre.transition.is_noop());
232-
full = post;
233-
selected_events.push(pre.clone());
206+
.filter(|e| e.offset.start <= error_offset && error_offset < e.offset.end)
207+
.cloned()
208+
.collect::<Vec<_>>(),
209+
created: self.created,
210+
tag: self.tag,
234211
}
235-
236-
History { events: selected_events, created: self.created, tag: self.tag }
237212
}
238213
}
239214

@@ -260,12 +235,11 @@ impl TbError<'_> {
260235
/// Produce a UB error.
261236
pub fn build<'tcx>(self) -> InterpError<'tcx> {
262237
use TransitionError::*;
263-
let started_as = self.conflicting_info.history.created.1;
264238
let kind = self.access_kind;
265239
let accessed = self.accessed_info;
266240
let conflicting = self.conflicting_info;
267241
let accessed_is_conflicting = accessed.tag == conflicting.tag;
268-
let (pre_error, title, details, conflicting_tag_name) = match self.error_kind {
242+
let (title, details, conflicting_tag_name) = match self.error_kind {
269243
ChildAccessForbidden(perm) => {
270244
let conflicting_tag_name =
271245
if accessed_is_conflicting { "accessed" } else { "conflicting" };
@@ -279,7 +253,7 @@ impl TbError<'_> {
279253
details.push(format!(
280254
"the {conflicting_tag_name} tag {conflicting} has state {perm} which forbids child {kind}es"
281255
));
282-
(perm, title, details, conflicting_tag_name)
256+
(title, details, conflicting_tag_name)
283257
}
284258
ProtectedTransition(transition) => {
285259
let conflicting_tag_name = "protected";
@@ -296,7 +270,7 @@ impl TbError<'_> {
296270
loss = transition.summary(),
297271
),
298272
];
299-
(transition.started(), title, details, conflicting_tag_name)
273+
(title, details, conflicting_tag_name)
300274
}
301275
ProtectedDealloc => {
302276
let conflicting_tag_name = "strongly protected";
@@ -307,16 +281,15 @@ impl TbError<'_> {
307281
),
308282
format!("the {conflicting_tag_name} tag {conflicting} disallows deallocations"),
309283
];
310-
(started_as, title, details, conflicting_tag_name)
284+
(title, details, conflicting_tag_name)
311285
}
312286
};
313-
let pre_transition = PermTransition::from(started_as, pre_error).unwrap();
314287
let mut history = HistoryData::default();
315288
if !accessed_is_conflicting {
316289
history.extend(self.accessed_info.history.forget(), "accessed", false);
317290
}
318291
history.extend(
319-
self.conflicting_info.history.extract_relevant(pre_transition, self.error_offset),
292+
self.conflicting_info.history.extract_relevant(self.error_offset),
320293
conflicting_tag_name,
321294
true,
322295
);

0 commit comments

Comments
 (0)