Remove Ord from chalk_ir::interner::DefId#740
Remove Ord from chalk_ir::interner::DefId#740bors merged 1 commit intorust-lang:masterfrom pierwill:rm2
Ord from chalk_ir::interner::DefId#740Conversation
Ord from chalk_ir::interner::DefId (second attempt)Ord from chalk_ir::interner::DefId
|
@rustbot assign @jackh726 cc @nikomatsakis |
|
Interesting...I forgot that auto traits are sorted in |
This comment has been minimized.
This comment has been minimized.
|
Error: The feature Please let |
chalk-solve/src/coherence.rs
Outdated
| self.visit_specializations_of_trait(|less_special, more_special| { | ||
| forest.add_edge(less_special, more_special, ()); | ||
| // Check so that we never add multiple nodes with the same ImplId. | ||
| let l = forest.add_node(less_special); |
There was a problem hiding this comment.
If we didn't add the nodes before, why do we need to add them now? update_edge doesn't do anything different versus add_edge with respect to nodes.
There was a problem hiding this comment.
The nodes must be added because petgraph::graphmap::GraphMap::add_edge can take a generic type N (that must implement Ord), where petgraph::graph::Graph::update_edge takes a NodeIndex.
We need to use Graph since this PR removes Ord from ImplId.
There was a problem hiding this comment.
Ah, I was looking at Graph::add_edge.
Can this create duplicate nodes?
There was a problem hiding this comment.
petgraph::graph::Graph::add_node does create multiple nodes when given the same value. (Playground example.)
There was a problem hiding this comment.
I'm going to see if I can handle this logic with a match statement:
let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();
self.visit_specializations_of_trait(|less_special, more_special| {
match (
node_impls.contains(&less_special),
node_impls.contains(&more_special),
) {
(true, true) => todo!(),
(true, false) => todo!(),
(false, true) => todo!(),
(false, false) => todo!(),
}
}
There was a problem hiding this comment.
I see "Add or update an edge from a to b." - So it's basically add_edge without allowing duplicates.
There was a problem hiding this comment.
Seems like it might make sense to keep around a Map<ImplId, NodeIndex>
There was a problem hiding this comment.
Before visit_specialization_of_trait, forest will be empty...
There was a problem hiding this comment.
I'm trying to reason this out. The logic below seems right, but I'm not sure how to get the indices for existing nodes...
// Find all specializations. (This is 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| {
match (
node_impls.contains(&less_special),
node_impls.contains(&more_special),
) {
(true, true) => {
// but how do we get indices for l and m?
forest.add_edge(l, m, ());
}
(true, false) => {
let m = forest.add_node(more_special);
// but how do we get index for l?
forest.add_edge(l, m, ());
}
(false, true) => {
let l = forest.add_node(less_special);
// but how do we get index for m?
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, ());
}
}
})?;
Can this even be done correctly without GraphMap? 😬
Update: Ah. node_indices might work...
There was a problem hiding this comment.
I'm thinking something like
let mut forest = DiGraph::new();
let mut node_map = FxHashMap::new();
self.visit_specializations_of_trait(|less_special, more_special| {
let less_special_node = *node_map.entry(less_special).or_insert_with(|| forest.add_node(less_special));
let more_special_node = *node_map.entry(more_special).or_insert_with(|| forest.add_node(more_special));
forest.update_edge(less_special_noe, more_special_node, ());
}Use `indexmap` to obviate need for ordering `DefId`s. In specialization forest, use a map of ImplIds to node indices to avoid duplicate nodes.
|
@bors r+ |
|
📌 Commit 29c1d17 has been approved by |
|
☀️ Test successful - checks-actions |
⬆ chalk to 0.76.0 This update contains rust-lang/chalk#740, which is needed for work on rust-lang#90317.
This change is required for rust-lang/rust#90749.
For background on the initiative of removing ordering traits from items like
DefIdinrustc, see rust-lang/rust#90317.