Skip to content

Commit d15ca96

Browse files
committed
Split dummy in region inference graph into distinct source and sink nodes.
Why do this: The RegionGraph representation previously conflated all of the non-variable regions (i.e. the concrete regions such as lifetime parameters to the current function) into a single dummy node. A single dummy node leads DFS on a graph `'a -> '_#1 -> '_#0 -> 'b` to claim that `'_#1` is reachable from `'_#0` (due to `'a` and `'b` being conflated in the graph representation), which is incorrect (and can lead to soundness bugs later on in compilation, see #30438). Splitting the dummy node ensures that DFS will never introduce new ancestor relationships between nodes for variable regions in the graph.
1 parent 36237fc commit d15ca96

File tree

1 file changed

+10
-3
lines changed
  • src/librustc/middle/infer/region_inference

1 file changed

+10
-3
lines changed

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,14 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
11051105
for _ in 0..num_vars {
11061106
graph.add_node(());
11071107
}
1108-
let dummy_idx = graph.add_node(());
1108+
1109+
// Issue #30438: two distinct dummy nodes, one for incoming
1110+
// edges (dummy_source) and another for outgoing edges
1111+
// (dummy_sink). In `dummy -> a -> b -> dummy`, using one
1112+
// dummy node leads one to think (erroneously) there exists a
1113+
// path from `b` to `a`. Two dummy nodes sidesteps the issue.
1114+
let dummy_source = graph.add_node(());
1115+
let dummy_sink = graph.add_node(());
11091116

11101117
for (constraint, _) in constraints.iter() {
11111118
match *constraint {
@@ -1115,10 +1122,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
11151122
*constraint);
11161123
}
11171124
ConstrainRegSubVar(_, b_id) => {
1118-
graph.add_edge(dummy_idx, NodeIndex(b_id.index as usize), *constraint);
1125+
graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint);
11191126
}
11201127
ConstrainVarSubReg(a_id, _) => {
1121-
graph.add_edge(NodeIndex(a_id.index as usize), dummy_idx, *constraint);
1128+
graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint);
11221129
}
11231130
}
11241131
}

0 commit comments

Comments
 (0)