Skip to content

Commit 16f7c5a

Browse files
committed
Change GraphMap to Graph
1 parent 92bc820 commit 16f7c5a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chalk-integration/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ chalk-solve = { version = "0.76.0-dev.0", path = "../chalk-solve" }
2020
chalk-recursive = { version = "0.76.0-dev.0", path = "../chalk-recursive" }
2121
chalk-engine = { version = "0.76.0-dev.0", path = "../chalk-engine" }
2222
chalk-parse = { version = "0.76.0-dev.0", path = "../chalk-parse" }
23+
indexmap = "1.6.2"

chalk-solve/src/coherence.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,21 @@ where
105105

106106
// Build the forest of specialization relationships.
107107
fn build_specialization_forest(&self) -> Result<Graph<ImplId<I>, ()>, CoherenceError<I>> {
108-
// The forest is returned as a graph but built as a GraphMap; this is
109-
// so that we never add multiple nodes with the same ItemId.
110-
let mut forest = DiGraphMap::new();
108+
let mut forest = DiGraph::new();
109+
110+
let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();
111111

112-
// Find all specializations (implemented in coherence/solve)
113-
// Record them in the forest by adding an edge from the less special
114-
// to the more special.
115112
self.visit_specializations_of_trait(|less_special, more_special| {
116-
forest.add_edge(less_special, more_special, ());
113+
// Check so that we never add multiple nodes with the same ImplId.
114+
if !node_impls.contains(&less_special) && !node_impls.contains(&more_special) {
115+
let l = forest.add_node(less_special);
116+
let m = forest.add_node(more_special);
117+
118+
forest.add_edge(l, m, ());
119+
}
117120
})?;
118121

119-
Ok(forest.into_graph())
122+
Ok(forest)
120123
}
121124

122125
// Recursively set priorities for those node and all of its children.

0 commit comments

Comments
 (0)