Skip to content

Commit

Permalink
Fix graph logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pierwill committed Dec 23, 2021
1 parent c9d3afd commit 34d8011
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions chalk-solve/src/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,47 @@ where

let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();

// Find all specializations (implemented in coherence/solve)
// Record them in the forest by adding an edge from the less special
// to the more special.
// Find all specializations. 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| {
// 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, ());
match (
node_impls.contains(&less_special),
node_impls.contains(&more_special),
) {
(true, true) => {
// but how do we get indices for l and m?
let l = forest
.node_indices()
.find(|i| forest[*i] == less_special)
.unwrap();
let m = forest
.node_indices()
.find(|i| forest[*i] == more_special)
.unwrap();
forest.add_edge(l, m, ());
}
(true, false) => {
let m = forest.add_node(more_special);
let l = forest
.node_indices()
.find(|i| forest[*i] == less_special)
.unwrap();
forest.add_edge(l, m, ());
}
(false, true) => {
let l = forest.add_node(less_special);
let m = forest
.node_indices()
.find(|i| forest[*i] == more_special)
.unwrap();
forest.add_edge(l, m, ());
}
(false, false) => {
// add L and M
let l = forest.add_node(less_special);
let m = forest.add_node(more_special);
forest.add_edge(l, m, ());
}
}
})?;

Expand Down

0 comments on commit 34d8011

Please sign in to comment.