Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprewrite the predecessors code to create a reduced graph #39424
Conversation
rust-highfive
assigned
michaelwoerister
Jan 31, 2017
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister I did some measurements of syntex-syntax. The rust master takes 3.6 seconds to encode the dep-graph. This branch takes 2.6 seconds. So this seems like a clear win overall. |
michaelwoerister
reviewed
Feb 2, 2017
|
I did one pass over this and it looks very good! I want to take another, closer look at the implementation and tests for the graph reduction algorithm. |
| let mut len = 0; | ||
| while len != dirty_nodes.len() { | ||
| len = dirty_nodes.len(); | ||
| for edge in edges { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Feb 2, 2017
Author
Contributor
Yeah, I was lazy. :) I can rewrite it to use a work-list or some such thing. One thing is that we don't have the edges indexed by their target, which we would want here. Perhaps I'll change how things are serialized to be a Map<Target, Vec<Source>>. I think we even build one of those in the "reduction" algorithm, so perhaps I should just return that (i.e., don't return a Graph, but some kind of ReducedGraph). I have to look at how the code works there.
| } | ||
|
|
||
| impl DagId { | ||
| pub fn from_in_index(n: NodeIndex) -> Self { |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Feb 2, 2017
Contributor
where does the in in from_in_index come from? Wouldn't from_node_index be clearer?
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Feb 2, 2017
Author
Contributor
Hmm, I meant in as in "the index in the INPUT graph". Perhaps input_index?
| ]); | ||
| } | ||
|
|
||
| //#[test] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -178,7 +179,9 @@ pub fn encode_dep_graph(preds: &Predecessors, | |||
| // Create a flat list of (Input, WorkProduct) edges for | |||
This comment has been minimized.
This comment has been minimized.
nikomatsakis
added some commits
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister I addressed (I think) your feedback w/ exception of commented out test, jfyi. |
This comment has been minimized.
This comment has been minimized.
|
@michaelwoerister ok, ported the test. |
nikomatsakis
referenced this pull request
Feb 3, 2017
Closed
Refactor dependency graph reduction to allow for more work-products #39494
michaelwoerister
reviewed
Feb 3, 2017
| let mut reduce = GraphReduce::new(&graph, |n| inputs.contains(n), |n| outputs.contains(n)); | ||
| Classify::new(&mut reduce).walk(); | ||
|
|
||
| assert!(reduce.in_cycle(nodes("B"), nodes("C"))); |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Feb 3, 2017
Contributor
Can you also add assert!(reduce.in_cycle(nodes("A"), nodes("C"))); and assert!(reduce.in_cycle(nodes("A"), nodes("B")));?
This comment has been minimized.
This comment has been minimized.
|
OK, I did another pass. Looks good to me. The graph reduction algorithm is very nice! |
This comment has been minimized.
This comment has been minimized.
|
@bors r=mw |
This comment has been minimized.
This comment has been minimized.
|
|
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this pull request
Feb 4, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this pull request
Feb 4, 2017
bors
added a commit
that referenced
this pull request
Feb 4, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 4, 2017
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis commentedJan 31, 2017
•
edited
The old code created a flat listing of "HIR -> WorkProduct" edges.
While perfectly general, this could lead to a lot of repetition if the
same HIR nodes affect many work-products. This is set to be a problem
when we start to skip typeck, since we will be adding a lot more
"work-product"-like nodes.
The newer code uses an alternative strategy: it "reduces" the graph
instead. Basically we walk the dep-graph and convert it to a DAG, where
we only keep intermediate nodes if they are used by multiple
work-products.
This DAG does not contain the same set of nodes as the original graph,
but it is guaranteed that (a) every output node is included in the graph
and (b) the set of input nodes that can reach each output node is
unchanged.
(Input nodes are basically HIR nodes and foreign metadata; output nodes
are nodes that have assocaited state which we will persist to disk in
some way. These are assumed to be disjoint sets.)
r? @michaelwoerister
Fixes #39494