mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Rollup merge of #94306 - Mark-Simulacrum:dom-fixups, r=jackh726
Avoid exhausting stack space in dominator compression Doesn't add a test case -- I ended up running into this while playing with the generated example from #43578, which we could do with a run-make test (to avoid checking a large code snippet into tree), but I suspect we don't want to wait for it to compile (locally it takes ~14s -- not terrible, but doesn't seem worth it to me). In practice stack space exhaustion is difficult to test for, too, since if we set the bound too low a different call structure above us (e.g., a nearer ensure_sufficient_stack call) would let the test pass even with the old impl, most likely. Locally it seems like this manages to perform approximately equivalently to the recursion, but will run perf to confirm.
This commit is contained in:
commit
648a8e314a
@ -241,9 +241,19 @@ fn compress(
|
||||
v: PreorderIndex,
|
||||
) {
|
||||
assert!(is_processed(v, lastlinked));
|
||||
let u = ancestor[v];
|
||||
if is_processed(u, lastlinked) {
|
||||
compress(ancestor, lastlinked, semi, label, u);
|
||||
// Compute the processed list of ancestors
|
||||
//
|
||||
// We use a heap stack here to avoid recursing too deeply, exhausting the
|
||||
// stack space.
|
||||
let mut stack: smallvec::SmallVec<[_; 8]> = smallvec::smallvec![v];
|
||||
let mut u = ancestor[v];
|
||||
while is_processed(u, lastlinked) {
|
||||
stack.push(u);
|
||||
u = ancestor[u];
|
||||
}
|
||||
|
||||
// Then in reverse order, popping the stack
|
||||
for &[v, u] in stack.array_windows().rev() {
|
||||
if semi[label[u]] < semi[label[v]] {
|
||||
label[v] = label[u];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user