Skip to content
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 caching normalization results with a cycle #80246

Merged
merged 2 commits into from
Dec 26, 2020

Conversation

matthewjasper
Copy link
Contributor

When normalizing a projection which results in a cycle, we would cache the result of project_type without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. get_paranoid_cache_value_obligation used to add an obligation that resulted in a cycle in this case previously, but was removed by #73905.

This PR makes the projection cache not cache the value of a projection if it was ever normalized in a cycle (except in a snapshot that's rolled back).

Fixes #79714.

r? @nikomatsakis

When normalizing a projection which results in a cycle, we would
cache the result of `project_type` without the nested obligations
(because they're not needed for inference). This would result in
the nested obligations only being handled once in fulfill, which
would avoid the cycle error.

Fixes rust-lang#79714, a regresion from rust-lang#79305 caused by the removal of
`get_paranoid_cache_value_obligation`.
@matthewjasper matthewjasper added beta-nominated Nominated for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 20, 2020
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2020
@@ -90,6 +90,7 @@ impl ProjectionCacheKey<'tcx> {
pub enum ProjectionCacheEntry<'tcx> {
InProgress,
Ambiguous,
Recur,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Recur,
Recursive,

I had to read the doc comment on the recur method to understand what this meant.

/// Indicates that while trying to normalize `key`, `key` was required to
/// be normalized again. Selection or evaluation should eventually report
/// an error here.
pub fn recur(&mut self, key: ProjectionCacheKey<'tcx>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn recur(&mut self, key: ProjectionCacheKey<'tcx>) {
pub fn recursive(&mut self, key: ProjectionCacheKey<'tcx>) {

@Mark-Simulacrum Mark-Simulacrum added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Dec 25, 2020
@Mark-Simulacrum
Copy link
Member

@bors r+ p=5 rollup=never

I would like this to get some testing on master before we promote it to beta (and in short order, beta to stable). The patch has received some amount of eyes on it.

@bors
Copy link
Contributor

bors commented Dec 25, 2020

📌 Commit 2e92b13 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 25, 2020
@bors
Copy link
Contributor

bors commented Dec 26, 2020

⌛ Testing commit 2e92b13 with merge 931aa27...

@bors
Copy link
Contributor

bors commented Dec 26, 2020

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 931aa27 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 26, 2020
@bors bors merged commit 931aa27 into rust-lang:master Dec 26, 2020
@rustbot rustbot added this to the 1.51.0 milestone Dec 26, 2020
@Mark-Simulacrum
Copy link
Member

Backported to 1.49 in #80417, but leaving accepted for beta backport to 1.50 (this landed after that branched).

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2020
…ulacrum

[beta] backports

This backports the following to 1.49:

*  Revert change to trait evaluation order rust-lang#80132
*  Don't allow `const` to begin a nonterminal rust-lang#80135
*  Prevent caching normalization results with a cycle rust-lang#80246

r? `@Mark-Simulacrum`
@matthewjasper matthewjasper deleted the projection-cycle-caching branch December 28, 2020 10:16
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.51.0, 1.49.0 Dec 31, 2020
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Dec 31, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 31, 2020
…ulacrum

[beta] backports

This backports accepted PRs and switches to bootstrapping from the released compiler:

* de-stabilize unsized raw ptr methods for Weak rust-lang#80422
* Use package name for top-level directory in bare tarballs rust-lang#80397
* Prevent caching normalization results with a cycle rust-lang#80246

r? `@Mark-Simulacrum`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jan 28, 2021
…=nikomatsakis

Make hitting the recursion limit in projection non-fatal

This change was originally made in rust-lang#80246 to avoid future (effectively) infinite loop bugs in projections,
but wundergraph relies on rustc recovering here.

cc rust-lang#80953

r? `@nikomatsakis`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2021
…ikomatsakis

Make hitting the recursion limit in projection non-fatal

This change was originally made in rust-lang#80246 to avoid future (effectively) infinite loop bugs in projections,
but wundergraph relies on rustc recovering here.

cc rust-lang#80953

r? `@nikomatsakis`
ehuss pushed a commit to ehuss/rust that referenced this pull request Feb 5, 2021
…ikomatsakis

Make hitting the recursion limit in projection non-fatal

This change was originally made in rust-lang#80246 to avoid future (effectively) infinite loop bugs in projections,
but wundergraph relies on rustc recovering here.

cc rust-lang#80953

r? `@nikomatsakis`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustc hangs and leaks memory
7 participants