-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Memory leak when declaring a higher order function #7680
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
Comments
Looks like a chalk issue, since the solver gets stuck in a loop. Relevant logs with
No further output with
|
Does this mean that the only way to resolve this issue is to wait for it to be resolved by chalk? Or could the memory leak be resolved so that at least rust-analyzer doesn't becomes unusable? |
It means the way to resolve this issue is to fix it in Chalk. (The first step towards that would be writing a Chalk test to reproduce it, and making an issue there.) |
I believe this Chalk test corresponds to the code below (which leads to the same memory leak as in the initial example), though that Chalk test succeeds which could indicate the fault is actually in the data sent to Chalk by rust-analyzer (with reservation for the Chalk test testing the wrong thing). #[test]
fn associated() {
test! {
program {
#[lang(fn_once)]
trait FnOnce<Args> {
type Output;
}
struct Box<T> {}
closure foo<T, U>(self, t: T) -> U {}
}
goal {
forall <T, U> {
exists<R, S> {
if ( Normalize(<S as FnOnce<()>>::Output -> R) ) {
Normalize(<foo<T, U> as FnOnce<(Box<S>,)>>::Output -> R)
}
}
}
} yields {
r"Unique"
}
}
} fn f<R>(_: impl FnOnce(Box<dyn FnOnce() -> R>) -> R) {}
fn main() {
f(|_| ());
} |
The modeling of closures in Chalk's test framework is somewhat different from ours, and often it's not possible to reproduce issues with them, in particular if variables are involved. So it might work better to do struct MyClosure<F> {}
impl<T, U> FnOnce<(T,)> for MyClosure<fn(T) -> U> {
type Output = U;
} The other reason why the test doesn't reproduce the issue could be that there are some impls somewhere that are affecting what happens, though it doesn't look like that to me from the output detrumi posted. |
It seems this just results in an error claiming the impl is not well-formed. |
Steps to reproduce:
This causes a memory leak that makes rust-analyzer use 100 % CPU (on one core) and an ever increasing amount of memory, being completely unreachable to the VSCode plugin. I believe the leak occurs because rust-analyzer infinitely tries to determine the type of R, though the code compiles and runs just fine.
Rust-analyzer version: 2021-02-08 (newest stable version)
VSCode version: 1.53.2
OS: Ubuntu 20.04
The text was updated successfully, but these errors were encountered: