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 14, 2021
1 parent e1d9f37 commit 14dffd5
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions chalk-solve/src/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,19 @@ where

// Build the forest of specialization relationships.
fn build_specialization_forest(&self) -> Result<Graph<ImplId<I>, ()>, CoherenceError<I>> {
// FIXME(pierwill): Previously, the forest was built as a GraphMap
// so that we never add multiple nodes with the same ItemId.
// Will need to add a check for this.
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 nodes = forest.raw_nodes();
let mut goodnodes: Vec<ImplId<_>> = vec![];
let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();

for node in nodes {
goodnodes.push(node.weight);
}

if !goodnodes.contains(&less_special) && !goodnodes.contains(&more_special) {
// 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);

#[rustfmt::skip]
println!( "adding an edge from {:?} to {:?}", less_special, more_special );
forest.add_edge(l, m, ());
}
})?;
Expand Down

0 comments on commit 14dffd5

Please sign in to comment.