Auto merge of #110527 - nnethercote:lazy-graph, r=lqd

In `LexicalResolver`, don't construct graph unless necessary.

A small but easy perf win.

r? `@jackh726`
This commit is contained in:
bors 2023-04-20 06:14:55 +00:00
commit 23a76a8ab5

View File

@ -131,10 +131,9 @@ fn infer_variable_values(
self.dump_constraints();
}
let graph = self.construct_graph();
self.expansion(&mut var_data);
self.collect_errors(&mut var_data, errors);
self.collect_var_errors(&var_data, &graph, errors);
self.collect_var_errors(&var_data, errors);
var_data
}
@ -622,7 +621,6 @@ fn collect_errors(
fn collect_var_errors(
&self,
var_data: &LexicalRegionResolutions<'tcx>,
graph: &RegionGraph<'tcx>,
errors: &mut Vec<RegionResolutionError<'tcx>>,
) {
debug!("collect_var_errors, var_data = {:#?}", var_data.values);
@ -640,6 +638,10 @@ fn collect_var_errors(
// overlapping locations.
let mut dup_vec = IndexVec::from_elem_n(None, self.num_vars());
// Only construct the graph when necessary, because it's moderately
// expensive.
let mut graph = None;
for (node_vid, value) in var_data.values.iter_enumerated() {
match *value {
VarValue::Empty(_) | VarValue::Value(_) => { /* Inference successful */ }
@ -672,7 +674,8 @@ fn collect_var_errors(
// influence the constraints on this value for
// richer diagnostics in `static_impl_trait`.
self.collect_error_for_expanding_node(graph, &mut dup_vec, node_vid, errors);
let g = graph.get_or_insert_with(|| self.construct_graph());
self.collect_error_for_expanding_node(g, &mut dup_vec, node_vid, errors);
}
}
}