Skip to content

[Polonius] Timeout while compiling handcrafted example #140454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
usx95 opened this issue Apr 29, 2025 · 0 comments
Open

[Polonius] Timeout while compiling handcrafted example #140454

usx95 opened this issue Apr 29, 2025 · 0 comments
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. NLL-polonius Issues related for using Polonius in the borrow checker requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@usx95
Copy link

usx95 commented Apr 29, 2025

(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
@usx95 usx95 added the C-bug Category: This is a bug. label Apr 29, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 29, 2025
@lolbinarycat lolbinarycat added I-compiletime Issue: Problems and improvements with respect to compile times. NLL-polonius Issues related for using Polonius in the borrow checker T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. NLL-polonius Issues related for using Polonius in the borrow checker requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants