[Polonius] Timeout while compiling handcrafted example
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the handcrafted Rust example at increasing N values with -Zpolonius and -Zpolonius=next, then compare against compilation without Polonius using the linked Compiler Explorer cases. Investigate the Polonius fixed-point behavior described in the report; done means the large examples no longer exhibit the reported extreme compilation-time growth.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100