Skip to content

Commit 1699a5b

Browse files
committed
Clarify the need for a counter
1 parent fd06af4 commit 1699a5b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/cargo/core/resolver/types.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -317,33 +317,44 @@ impl Ord for DepsFrame {
317317
/// graph quickly and hopefully lock down what later larger dependencies can
318318
/// use (those with more candidates).
319319
#[derive(Clone)]
320-
pub struct RemainingDeps(usize, im_rc::OrdSet<(DepsFrame, usize)>);
320+
pub struct RemainingDeps {
321+
/// a monotonic counter, increased for each new insertion.
322+
time: u32,
323+
/// the data is augmented by the insertion time.
324+
/// This insures that no two items will cmp eq.
325+
/// Forcing the OrdSet into a multi set.
326+
data: im_rc::OrdSet<(DepsFrame, u32)>,
327+
}
321328

322329
impl RemainingDeps {
323330
pub fn new() -> RemainingDeps {
324-
RemainingDeps(0, im_rc::OrdSet::new())
331+
RemainingDeps {
332+
time: 0,
333+
data: im_rc::OrdSet::new(),
334+
}
325335
}
326336
pub fn push(&mut self, x: DepsFrame) {
327-
self.1.insert((x, self.0));
328-
self.0 += 1;
337+
let insertion_time = self.time;
338+
self.data.insert((x, insertion_time));
339+
self.time += 1;
329340
}
330341
pub fn pop_most_constrained(&mut self) -> Option<(bool, (Summary, (usize, DepInfo)))> {
331-
while let Some((mut deps_frame, i)) = self.1.remove_min() {
342+
while let Some((mut deps_frame, insertion_time)) = self.data.remove_min() {
332343
let just_here_for_the_error_messages = deps_frame.just_for_error_messages;
333344

334345
// Figure out what our next dependency to activate is, and if nothing is
335346
// listed then we're entirely done with this frame (yay!) and we can
336347
// move on to the next frame.
337348
if let Some(sibling) = deps_frame.remaining_siblings.next() {
338349
let parent = Summary::clone(&deps_frame.parent);
339-
self.1.insert((deps_frame, i));
350+
self.data.insert((deps_frame, insertion_time));
340351
return Some((just_here_for_the_error_messages, (parent, sibling)));
341352
}
342353
}
343354
None
344355
}
345356
pub fn iter(&mut self) -> impl Iterator<Item = (&PackageId, Dependency)> {
346-
self.1.iter().flat_map(|(other, _)| other.flatten())
357+
self.data.iter().flat_map(|(other, _)| other.flatten())
347358
}
348359
}
349360

0 commit comments

Comments
 (0)