-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Prevent very long compilation runtimes in LateBoundRegionNameCollector #83406
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
@@ -0,0 +1,9 @@ | |||
fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes for an unexplainable reason. When I compile this file I get the expected error:
error[E0275]: overflow evaluating the requirement `Map<&mut Map<&mut Map<&mut Map<&mut Map<.....
But the test suite cannot find an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i expect you to need at least // build-pass
here, as the overly large types should only get created during mono item collection
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that using type length limit is the best approach here.
The issue here is that the type T
is &mut Map<T_prev, closure [T_prev]>
so the type size scales by 2^depth
instead of just depth
.
Using https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/sso/struct.SsoHashSet.html in visit_ty
seems like a potentially better solution to me
@@ -0,0 +1,9 @@ | |||
fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i expect you to need at least // build-pass
here, as the overly large types should only get created during mono item collection
} | ||
r.super_visit_with(self) | ||
} | ||
|
||
// In order to prohibit infinite recursion on infinitely recursed types we count the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
infinitely recursed types
nit: there are no infinite types. Types are finite trees, so infinite types are impossible.
We can get very large types though, which causes the hang here.
@lcnr Thanks for the review. I don't understand how you would want to use |
I don't want to break control at all here. Afaict this is not an infinite hang, this is a finite, but incredibly large perf regression. I want to use a |
@lcnr Thanks, that clarifies things. You're right, this isn't a hang. I updated the PR to use the |
This comment has been minimized.
This comment has been minimized.
There's also a problem with another test, seems as if `LateBoundRegionNameCollector' has different functionality if we skip types we've seen before. |
@lcnr Can you take another look? What do we do about the tests? |
This comment has been minimized.
This comment has been minimized.
i think the correct attribute here is |
@lcnr Yes, that's the correct attribute. Thanks for the review and the help. |
let mut collector = LateBoundRegionNameCollector(&mut self.used_region_names); | ||
let mut collector = LateBoundRegionNameCollector { | ||
used_region_names: &mut self.used_region_names, | ||
type_collector: SsoHashSet::with_capacity(1000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type_collector: SsoHashSet::with_capacity(1000), | |
type_collector: SsoHashSet::new(), |
we don't want to allocate here by default.
src/test/ui/recursion/issue-83150.rs
Outdated
@@ -0,0 +1,11 @@ | |||
// build-fail | |||
//~^ overflow evaluating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//~^ overflow evaluating | |
//~^ overflow evaluating |
please update the PR name and description, then this should be ready after a perf run. |
@lcnr This is ready for the perf run. |
☔ The latest upstream changes (presumably #76814) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 3194b26 with merge 9fb1f198bce56ca989b0203c337bedffb89b96a1... |
☀️ Try build successful - checks-actions |
Queued 9fb1f198bce56ca989b0203c337bedffb89b96a1 with parent b1b0a15, future comparison URL. |
Finished benchmarking try commit (9fb1f198bce56ca989b0203c337bedffb89b96a1): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
@bors r+ |
📌 Commit 3194b26 has been approved by |
☀️ Test successful - checks-actions |
Should this be backported to 1.52? @rust-lang/compiler Context: this fixes a t-hang stable-to-stable regression that has been reported multiple times caused by big type names, the latest report being #84102 |
Fixes #83150
On recursive types such as in the example given in #83150, the current implementation of
LateBoundRegionNameCollector
has very long compilation runtimes. To prevent those we store the types visited in themiddle::ty::Visitor
implementation ofLateBoundRegionNameCollector
in aSsoHashSet
.