-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix exponential projection complexity on nested types #48296
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
0b84c09
to
91d7792
Compare
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.
Here are some self-reminders.
src/librustc/traits/project.rs
Outdated
@@ -818,55 +822,74 @@ fn project_type<'cx, 'gcx, 'tcx>( | |||
&obligation_trait_ref, | |||
&mut candidates); | |||
|
|||
let decide_commit = |candidates: &mut ProjectionTyCandidateSet<'tcx>| { |
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 have no way but to reorder this before the error handling. It looks non intuitive.
src/librustc/traits/project.rs
Outdated
}); | ||
debug!("resulting candidate set: {:?}", candidates.vec); | ||
if candidates.vec.len() != 1 { | ||
candidates.ambiguous = true; |
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 is nearly a hack.
src/librustc/traits/project.rs
Outdated
} | ||
}; | ||
|
||
match vtable { | ||
match vtable.clone() { |
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 copy can be avoided.
91d7792
to
365bf21
Compare
The other part of the blowup (typeck related) is yet to be solved, but I think the code is ready for a round of review. I have removed whitespace changes and clarified the description. |
365bf21
to
3d81698
Compare
@kennytm A reminder for you to change the review labels. |
@bors try Let’s do a perf check while we’re waiting for review :) |
⌛ Trying commit 3d81698 with merge e35a3273278915e65cf22237f934456a55a438b6... |
@ishitatsuyuki please remove the |
Well, I'm currently tackling another part of the exponential issue (so this is WIP), but I need comments on improving the code organization. |
☀️ Test successful - status-travis |
By deduplicating the obligations the issue is completely resolved. I'm not sure if this approach is the best way though, and I copied the dumb deduplication becuase I didn't want to implement Ord everywhere. I will fix them later. |
@kennytm I need another try. |
@bors try |
@bors r+ @ishitatsuyuki -- it'd be great to add at least one of these exponential blow-up cases to the perf website so we can monitor for regressions. Perhaps @Mark-Simulacrum can walk you through it. |
📌 Commit 5a2bec9 has been approved by |
…sakis Fix exponential projection complexity on nested types This implements solution 1 from rust-lang#38528 (comment). The code quality is currently extremely poor, but we can improve them during review. Blocking issues: - we probably don't want a quadratic deduplication for obligations. - is there an alternative to deduplication? Based on rust-lang#48315. Needs changelog. Noticable improvement on compile time is expected. Fix rust-lang#38528 Close rust-lang#39684 Close rust-lang#43757
This effectively reverts rust-lang#43546 as it seems that it does affect performance more than the PR has anticipated. Follow-up changes from rust-lang#44269 are also reverted. This also removes the deduplication code from rust-lang#48296 as duplications were primarily coming from rust-lang#43546 and after removing that code it probably doesn't worth paying the cost of using a hash map.
This implements solution 1 from #38528 (comment).
The code quality was extremely poor, but it has improved during review.
Blocking issues:
Based on #48315.
Needs changelog. Noticable improvement on compile time is expected.
Fix #38528
Close #39684
Close #43757