-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Explosive memory usage in type checker #15244
Comments
I updated the gist to deal with recent changes to rustc and libstd. The bug still reproduces. |
Based on advice on irc, cc @nikomatsakis and @pcwalton I should also note that code very similar to this compiled a couple weeks ago, so this is probably a recent regression. |
I went back and tried older versions of rustc all the way to the start of June, and all of them exhibited unbounded memory growth, so it isn't a regression after all. |
cc me |
I've trimmed down the test case a little bit. On my system, it runs until rustc aborts with oom. If I simplify the expression in certain ways, it will manage to actually build (although it will consume up to 4GB of RAM). So I don't think I'm hitting an infinite loop, just a pathological edge case in the type checker. Title updated to reflect this. |
After some experimenting, I now have a substantially reduced test case. Something about having a trait bound on the generic type parameter is what causes the crazy memory usage. |
Inlined for posterity: struct Base;
struct Wrapper<B>(B);
trait Bug {}
impl Bug for Base {}
impl<B> Bug for Wrapper<B> {}
// Removing the bound on B makes the bug go away.
// So does turning wrap into a free function and
// changing the expression below appropriately.
impl<B:Bug> Wrapper<B> {
fn wrap(self) -> Wrapper<Wrapper<B>> {
Wrapper(self)
}
}
fn main() {
// This easily crashes rustc with oom on my laptop
let _expr = Wrapper(Base).wrap().wrap().wrap().wrap().wrap().wrap().wrap()
.wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap()
.wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap().wrap();
} |
cc me |
The new inference scheme fixes the reduced test case. Unfortunately it also causes my library to no longer typecheck, but that's a separate issue (#16870). Closing. |
Support read_via_copy intrinsic
Test Case
To reproduce, download the two files in this gist and attempt to build
mkrust.rs
:https://gist.github.com/bkoropoff/537951c596ba24166f06
Analysis
The complex
json.query(...)
expression inmkrust.rs
seems to be the culprit. Progressively simplifying the expression will eventually cause the bug to no longer reproduce.Running rustc under massif yields the following (truncated for space) stack for the primary memory hog, which appears to be a hash map associated with region inference:
The text was updated successfully, but these errors were encountered: