Description
(Lower priority: Trying to break compiler after reading polonius algorithm)
I tried this code. N
Pointers pointing with N
loans. Cyclic swap content of pointers in a for loop. Following is an example for N = 3
.
fn main() {
let s0 = String::from("String 0");
let s1 = String::from("String 1");
let s2 = String::from("String 2");
let mut r0: &String = &s0;
let mut r1: &String = &s1;
let mut r2: &String = &s2;
for _ in 0..1 {
let t = r0;
r0 = r1;
r1 = r2;
r2 = t;
}
println!("r0 points to: {}", r0);
println!("r1 points to: {}", r1);
println!("r2 points to: {}", r2);
}
(generator script)
N = 10
: https://godbolt.org/z/6Garo4jh9 takes <1s
N = 100
: https://godbolt.org/z/Gnrr6rqrr takes about 27s with -Zpolononius
, 14s with -Zpolonius=next
.
N = 200
: https://godbolt.org/z/Gnrr6rqrr takes about 156s with -Zpolononius
, 131s with -Zpolonius=next
.
N = 1000
takes >20 min
Note that all the above examples compile in <1 s without -Zpolonius
. Example: https://godbolt.org/z/GTMGdf1hr
IIUC, the algorithm would converge when all the N
region/origin variables would contain (require
) all the N
loans!
I feel the owners must be aware about this already. The fixed point iteration looks O(R * L)
where R
is the number of region variables and L
is the number of loans/borrow expressions.
Meta
rustc --version --verbose
:
rustc 1.88.0-nightly (25cdf1f67 2025-04-28)
binary: rustc
commit-hash: 25cdf1f67463c9365d8d83778c933ec7480e940b
commit-date: 2025-04-28
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2