LinkedGraph: support adding nodes and edges in arbitrary order#152621
LinkedGraph: support adding nodes and edges in arbitrary order#152621petrochenkov wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If an edge uses some not-yet-known node, we just leave the node's data empty, that data can be added later. Use this support to avoid skipping edges in DepGraphQuery
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
||
| pub fn nodes(&self) -> Vec<&DepNode> { | ||
| self.inner.all_nodes().iter().map(|n| &n.data).collect() | ||
| self.inner.all_nodes().iter().map(|n| n.data.as_ref().unwrap()).collect() |
There was a problem hiding this comment.
This looks a bit suspicious.
The more obvious implementation would be to skip data-less nodes. Is there a reason to think that nodes will always be densely initialized whenever this is called?
There was a problem hiding this comment.
The assumption is that the graph is used only when it's fully built (e.g. in assert_dep_graph/save_dep_graph).
The holes in data are supposed to occur only during the (parallel) graph building process.
If this ever changes, then it's better to fail with some noise than to silently lose nodes (like we are losing edges now).
|
Beyond the scope of this particular PR, but if |
|
r? me |
|
|
If LinkedGraph is used in multiple places that don't all want this change, then it's a big layering violation, and I feel pretty uneasy about it. |
|
|
|
I don't think it's a layering violation, setting node data by index requires supporting In this sense |
|
I looked into |
If an edge uses some not-yet-known node, we just leave the node's data empty, that data can be added later.
Use this support to avoid skipping edges in RetainedDepGraph.
This is continuation of #152590, that PR just fixes the ICE, this PR also preserves all the edges in debug dumps.
This is also a minimized version of #151821 with a smaller amount of data structure hacks.