Skip to content

Commit

Permalink
Do not add nodes that already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
pierwill committed Dec 15, 2021
1 parent 20da7b0 commit e090b18
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions chalk-solve/src/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ where

// Build the forest of specialization relationships.
fn build_specialization_forest(&self) -> Result<Graph<ImplId<I>, ()>, CoherenceError<I>> {
// The forest is returned as a graph but built as a GraphMap; this is
// so that we never add multiple nodes with the same ItemId.
let mut forest = DiGraph::new();

// Find all specializations (implemented in coherence/solve)
// Record them in the forest by adding an edge from the less special
// to the more special.
self.visit_specializations_of_trait(|less_special, more_special| {
let l = forest.add_node(less_special);
let m = forest.add_node(more_special);
let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();

forest.add_edge(l, m, ());
// Check so that we never add multiple nodes with the same ImplId.
if !node_impls.contains(&less_special) && !node_impls.contains(&more_special) {
let l = forest.add_node(less_special);
let m = forest.add_node(more_special);

forest.add_edge(l, m, ());
}
})?;

Ok(forest)
Expand Down

0 comments on commit e090b18

Please sign in to comment.