Skip to content

Commit 4d89292

Browse files
Avoid exhausting stack space in dominator compression
1 parent c651ba8 commit 4d89292

File tree

1 file changed

+13
-3
lines changed
  • compiler/rustc_data_structures/src/graph/dominators

1 file changed

+13
-3
lines changed

compiler/rustc_data_structures/src/graph/dominators/mod.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,19 @@ fn compress(
241241
v: PreorderIndex,
242242
) {
243243
assert!(is_processed(v, lastlinked));
244-
let u = ancestor[v];
245-
if is_processed(u, lastlinked) {
246-
compress(ancestor, lastlinked, semi, label, u);
244+
// Compute the processed list of ancestors
245+
//
246+
// We use a heap stack here to avoid recursing too deeply, exhausting the
247+
// stack space.
248+
let mut stack: smallvec::SmallVec<[_; 8]> = smallvec::smallvec![v];
249+
let mut u = ancestor[v];
250+
while is_processed(u, lastlinked) {
251+
stack.push(u);
252+
u = ancestor[u];
253+
}
254+
255+
// Then in reverse order, popping the stack
256+
for &[v, u] in stack.array_windows().rev() {
247257
if semi[label[u]] < semi[label[v]] {
248258
label[v] = label[u];
249259
}

0 commit comments

Comments
 (0)