From 8d9b4a5e1cc8e8e694b74a6ab3e0ec8cca09a2c8 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 29 Jun 2024 13:31:54 -0400 Subject: [PATCH] Sort indexes during graph edge removal (#4649) ## Summary `remove_edge` will invalidate the last index in the graph, so we need to ensure that each index we look at is "earlier" than the last. Co-authored-by: bluss --- crates/uv-resolver/src/resolution/display.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/uv-resolver/src/resolution/display.rs b/crates/uv-resolver/src/resolution/display.rs index 04532ba84..f5f0acf66 100644 --- a/crates/uv-resolver/src/resolution/display.rs +++ b/crates/uv-resolver/src/resolution/display.rs @@ -360,11 +360,12 @@ fn propagate_markers(mut graph: IntermediatePetGraph) -> IntermediatePetGraph { // TODO(charlie): The above reasoning could be incorrect. Consider using a graph algorithm that // can handle weight propagation with cycles. let edges = { - let fas = greedy_feedback_arc_set(&graph) + let mut fas = greedy_feedback_arc_set(&graph) .map(|edge| edge.id()) .collect::>(); + fas.sort_unstable(); let mut edges = Vec::with_capacity(fas.len()); - for edge_id in fas { + for edge_id in fas.into_iter().rev() { edges.push(graph.edge_endpoints(edge_id).unwrap()); graph.remove_edge(edge_id); }