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

Merged
merged 4 commits into from Feb 25, 2018

Conversation

Projects
None yet
7 participants
@ishitatsuyuki
Member

ishitatsuyuki commented Feb 17, 2018

This implements solution 1 from #38528 (comment).

The code quality was extremely poor, but it has improved during review.

Blocking issues:

  • we probably don't want a quadratic deduplication for obligations.
  • is there an alternative to deduplication?

Based on #48315.

Needs changelog. Noticable improvement on compile time is expected.

Fix #38528
Close #39684
Close #43757

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Feb 17, 2018

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@ishitatsuyuki ishitatsuyuki changed the title from [wip] (PoC) Fix exponential blowup on nested types to [wip] (PoC) Fix exponential projection complexity on nested types Feb 17, 2018

@ishitatsuyuki

Here are some self-reminders.

@@ -818,55 +822,74 @@ fn project_type<'cx, 'gcx, 'tcx>(
&obligation_trait_ref,
&mut candidates);
let decide_commit = |candidates: &mut ProjectionTyCandidateSet<'tcx>| {

This comment has been minimized.

@ishitatsuyuki

ishitatsuyuki Feb 17, 2018

Member

I have no way but to reorder this before the error handling. It looks non intuitive.

});
debug!("resulting candidate set: {:?}", candidates.vec);
if candidates.vec.len() != 1 {
candidates.ambiguous = true;

This comment has been minimized.

@ishitatsuyuki

ishitatsuyuki Feb 17, 2018

Member

This is nearly a hack.

}
};
match vtable {
match vtable.clone() {

This comment has been minimized.

@ishitatsuyuki

ishitatsuyuki Feb 17, 2018

Member

This copy can be avoided.

@ishitatsuyuki ishitatsuyuki changed the title from [wip] (PoC) Fix exponential projection complexity on nested types to [wip] Fix exponential projection complexity on nested types Feb 18, 2018

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

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.

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

@kennytm A reminder for you to change the review labels.

@kennytm

This comment has been minimized.

Member

kennytm commented Feb 18, 2018

@bors try

Let’s do a perf check while we’re waiting for review :)

@bors

This comment has been minimized.

Contributor

bors commented Feb 18, 2018

⌛️ Trying commit 3d81698 with merge e35a327...

bors added a commit that referenced this pull request Feb 18, 2018

Auto merge of #48296 - ishitatsuyuki:exp-unblow, r=<try>
[wip] Fix exponential projection complexity on nested types

This implements solution 1 from #38528 (comment).

The code quality is currently extremely poor, but we can improve them during review.

Based on #48315.

Needs changelog. Noticable improvement on compile time is expected.

Fix #38528 (in progress, another exponential blowup exist)
Close #39684
Close #43757
@kennytm

This comment has been minimized.

Member

kennytm commented Feb 18, 2018

@ishitatsuyuki please remove the [wip] from the PR title if it is ready for review.

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

Well, I'm currently tackling another part of the exponential issue (so this is WIP), but I need comments on improving the code organization.

@bors

This comment has been minimized.

Contributor

bors commented Feb 18, 2018

☀️ Test successful - status-travis
State: approved= try=True

@ishitatsuyuki ishitatsuyuki changed the title from [wip] Fix exponential projection complexity on nested types to Fix exponential projection complexity on nested types Feb 18, 2018

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

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.

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

@kennytm I need another try.

@Mark-Simulacrum

This comment has been minimized.

Member

Mark-Simulacrum commented Feb 18, 2018

@bors try

@bors

This comment has been minimized.

Contributor

bors commented Feb 18, 2018

⌛️ Trying commit 4a40c55 with merge 4ac2425...

bors added a commit that referenced this pull request Feb 18, 2018

Auto merge of #48296 - ishitatsuyuki:exp-unblow, r=<try>
Fix exponential projection complexity on nested types

This implements solution 1 from #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 #48315.

Needs changelog. Noticable improvement on compile time is expected.

Fix #38528
Close #39684
Close #43757
@bors

This comment has been minimized.

Contributor

bors commented Feb 18, 2018

☀️ Test successful - status-travis
State: approved= try=True

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 18, 2018

@Mark-Simulacrum can you queue a perf run?

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 22, 2018

Ready for review.

@ishitatsuyuki

This comment has been minimized.

Member

ishitatsuyuki commented Feb 22, 2018

r? @nikomatsakis

Please change the label...

@nikomatsakis

Looks great =)

} else {
Err(())
}
});

This comment has been minimized.

@nikomatsakis

nikomatsakis Feb 22, 2018

Contributor

I like the change to push errors into the candidate set. This is less confusing this way.

This comment has been minimized.

@ishitatsuyuki

ishitatsuyuki Feb 22, 2018

Member

I'm not sure if I understand. I already handle SelectionError above, and these Ok and Err is the return value to commit_if_ok.

// unknown. What we know is that the deduplication avoids exponential
// amount of predicates being propogated when processing deeply nested
// types.
let mut seen = FxHashSet();

This comment has been minimized.

@nikomatsakis

nikomatsakis Feb 22, 2018

Contributor

Oh, it seems like duplicates could come from many sources -- in particular, normalization might introduce the same obligation a few times.

@nikomatsakis

This comment has been minimized.

Contributor

nikomatsakis commented Feb 22, 2018

@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.

@bors

This comment has been minimized.

Contributor

bors commented Feb 22, 2018

📌 Commit 5a2bec9 has been approved by nikomatsakis

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 24, 2018

Rollup merge of rust-lang#48296 - ishitatsuyuki:exp-unblow, r=nikomat…
…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

bors added a commit that referenced this pull request Feb 24, 2018

Auto merge of #48520 - Manishearth:rollup, r=Manishearth
Rollup of 15 pull requests

- Successful merges: #47689, #48110, #48197, #48296, #48386, #48392, #48404, #48415, #48441, #48448, #48452, #48481, #48490, #48499, #48503
- Failed merges:

bors added a commit that referenced this pull request Feb 25, 2018

Auto merge of #48520 - Manishearth:rollup, r=Manishearth
Rollup of 15 pull requests

- Successful merges: #47689, #48110, #48197, #48296, #48386, #48392, #48404, #48415, #48441, #48448, #48452, #48481, #48490, #48499, #48503
- Failed merges:

@bors bors merged commit 5a2bec9 into rust-lang:master Feb 25, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ishitatsuyuki ishitatsuyuki deleted the ishitatsuyuki:exp-unblow branch Mar 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment