Skip to content

Commit 23a76a8

Browse files
committed
Auto merge of rust-lang#110527 - nnethercote:lazy-graph, r=lqd
In `LexicalResolver`, don't construct graph unless necessary. A small but easy perf win. r? `@jackh726`
2 parents 7fde083 + 8e6c9e0 commit 23a76a8

File tree

1 file changed

+7
-4
lines changed
  • compiler/rustc_infer/src/infer/lexical_region_resolve

1 file changed

+7
-4
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
131131
self.dump_constraints();
132132
}
133133

134-
let graph = self.construct_graph();
135134
self.expansion(&mut var_data);
136135
self.collect_errors(&mut var_data, errors);
137-
self.collect_var_errors(&var_data, &graph, errors);
136+
self.collect_var_errors(&var_data, errors);
138137
var_data
139138
}
140139

@@ -622,7 +621,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
622621
fn collect_var_errors(
623622
&self,
624623
var_data: &LexicalRegionResolutions<'tcx>,
625-
graph: &RegionGraph<'tcx>,
626624
errors: &mut Vec<RegionResolutionError<'tcx>>,
627625
) {
628626
debug!("collect_var_errors, var_data = {:#?}", var_data.values);
@@ -640,6 +638,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
640638
// overlapping locations.
641639
let mut dup_vec = IndexVec::from_elem_n(None, self.num_vars());
642640

641+
// Only construct the graph when necessary, because it's moderately
642+
// expensive.
643+
let mut graph = None;
644+
643645
for (node_vid, value) in var_data.values.iter_enumerated() {
644646
match *value {
645647
VarValue::Empty(_) | VarValue::Value(_) => { /* Inference successful */ }
@@ -672,7 +674,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
672674
// influence the constraints on this value for
673675
// richer diagnostics in `static_impl_trait`.
674676

675-
self.collect_error_for_expanding_node(graph, &mut dup_vec, node_vid, errors);
677+
let g = graph.get_or_insert_with(|| self.construct_graph());
678+
self.collect_error_for_expanding_node(g, &mut dup_vec, node_vid, errors);
676679
}
677680
}
678681
}

0 commit comments

Comments
 (0)