Skip to content

Create dummy_{source,sink} lazily. #110520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// (dummy_sink). In `dummy -> a -> b -> dummy`, using one
// dummy node leads one to think (erroneously) there exists a
// path from `b` to `a`. Two dummy nodes sidesteps the issue.
let dummy_source = graph.add_node(());
let dummy_sink = graph.add_node(());
// Construct them lazily because they're rarely needed and this
// code is hot enough for that to matter.
let mut dummy_source = None;
let mut dummy_sink = None;

for constraint in self.data.constraints.keys() {
match *constraint {
Expand All @@ -705,10 +707,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
);
}
Constraint::RegSubVar(_, b_id) => {
graph.add_edge(dummy_source, NodeIndex(b_id.index() as usize), *constraint);
let d = dummy_source.get_or_insert_with(|| graph.add_node(()));
graph.add_edge(*d, NodeIndex(b_id.index() as usize), *constraint);
}
Constraint::VarSubReg(a_id, _) => {
graph.add_edge(NodeIndex(a_id.index() as usize), dummy_sink, *constraint);
let d = dummy_sink.get_or_insert_with(|| graph.add_node(()));
graph.add_edge(NodeIndex(a_id.index() as usize), *d, *constraint);
}
Constraint::RegSubReg(..) => {
// this would be an edge from `dummy_source` to
Expand Down