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

remove intercrate ambiguity hints #47738

Merged
merged 4 commits into from
Feb 1, 2018

Conversation

nikomatsakis
Copy link
Contributor

The scheme was causing overflows during coherence checking (e.g. #47139). This is sort of a temporary fix; the proper fix I think involves reworking trait selection in deeper ways.

cc @sgrif -- this should fix diesel

cc @qnighy -- I'd like to discuss you with alternative techniques for achieving the same end. =) Actually, it might be good to put some energy into refactoring traits first.

r? @eddyb

@nikomatsakis
Copy link
Contributor Author

er, oops -- let me add a test!

@nikomatsakis
Copy link
Contributor Author

I actually have to figure out how to formulate one. The test I have which reproduces diesel's problem isn't, I think, affected by this change.

@nikomatsakis
Copy link
Contributor Author

(Also, the problem was sort of order dependent, but I might be able to fix that.)

@nikomatsakis nikomatsakis added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jan 25, 2018
@eddyb
Copy link
Member

eddyb commented Jan 25, 2018

r=me

@nikomatsakis
Copy link
Contributor Author

ok, added a test that fails on beta/nightly and which I believe is representative of the diesel error

@nikomatsakis
Copy link
Contributor Author

@bors r+ p=1 -- important to get diesel up and going again

@bors
Copy link
Contributor

bors commented Jan 25, 2018

📌 Commit cb4aa5f has been approved by nikomatsakis

@kennytm kennytm added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 25, 2018
@qnighy
Copy link
Contributor

qnighy commented Jan 25, 2018

@nikomatsakis oh bad 😞 Anyway I'm interested in both refactoring trait selection and reintroducing the hints. It may take time for me to remember things around trait selection though...

@qnighy
Copy link
Contributor

qnighy commented Jan 25, 2018

For reference: the PR that introduced the hints is #43426

@nikomatsakis
Copy link
Contributor Author

@bors r- // travis failures, will investigate

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 25, 2018
@nikomatsakis nikomatsakis added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 25, 2018
@arielb1
Copy link
Contributor

arielb1 commented Jan 25, 2018

I can't say I like this fix - this regresses from beta because it removes the coherence problem detection feature.

Maybe we should just disable intercrate ambiguity hints "initially", and then call trait selection again with them enabled only if there was a coherence error. That's it, add a report_intercrate_hints: bool flag to the SelectionContext, do the first overlap check with it being false, and if there is overlap, call selection again with the flag set to true.

That way the error detection code will not be called unless there is an actual coherence error, in which case we don't care as much if there is an overflow.

@nikomatsakis
Copy link
Contributor Author

It is a brute force fix, that's true. Doing it in two passes is a decent idea.

@arielb1
Copy link
Contributor

arielb1 commented Jan 26, 2018

I'll review with the two-pass thing

@nikomatsakis
Copy link
Contributor Author

I did the two-pass change but for .. some reason I do not know I am not getting the full range of hints yet. I'll debug in a bit, but pushing intermediate status.

@arielb1
Copy link
Contributor

arielb1 commented Jan 27, 2018

A squash would be nice.

@arielb1
Copy link
Contributor

arielb1 commented Jan 27, 2018

@nikomatsakis

The missing errors might be caused by the infcx evaluation_cache caching the evaluations, so that the selection context does not go through evaluating these predicates again, and therefore does not add them to the intercrate ambiguity causes.

The reason this worked before is because intercrate mode only uses the per-infcx evaluation cache:

/// Returns true if the global caches can be used.
/// Do note that if the type itself is not in the
/// global tcx, the local caches will be used.
fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
// If there are any where-clauses in scope, then we always use
// a cache local to this particular scope. Otherwise, we
// switch to a global cache. We used to try and draw
// finer-grained distinctions, but that led to a serious of
// annoying and weird bugs like #22019 and #18290. This simple
// rule seems to be pretty clearly safe and also still retains
// a very high hit rate (~95% when compiling rustc).
if !param_env.caller_bounds.is_empty() {
return false;
}
// Avoid using the master cache during coherence and just rely
// on the local cache. This effectively disables caching
// during coherence. It is really just a simplification to
// avoid us having to fear that coherence results "pollute"
// the master cache. Since coherence executes pretty quickly,
// it's not worth going to more trouble to increase the
// hit-rate I don't think.
if self.intercrate.is_some() {
return false;
}
// Otherwise, we can use the global cache.
true
}

And coherence uses a fresh inference context for each overlap check, starting with an empty evaluation cache:
https://github.com/rust-lang/rust/blob/master/src/librustc/traits/specialize/specialization_graph.rs#L135-L140

To fix this, I think the best way would be to create a fresh inference context for the "error reporting" check.

@nikomatsakis
Copy link
Contributor Author

@arielb1 ok, cleaned up, take a look -- running full tests now but seems to work

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 30, 2018
@bors
Copy link
Contributor

bors commented Jan 31, 2018

⌛ Testing commit 2fc5739 with merge fb4d05e0e9c83a68626168b86e0fd26fc3aa736d...

@bors
Copy link
Contributor

bors commented Jan 31, 2018

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jan 31, 2018

@bors retry #46903

@kennytm kennytm 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 Jan 31, 2018
@bors
Copy link
Contributor

bors commented Jan 31, 2018

⌛ Testing commit 2fc5739 with merge 20d027e9d7d9d50f1eb257fa38c4a2b7dd0cd4ee...

@bors
Copy link
Contributor

bors commented Jan 31, 2018

💔 Test failed - status-appveyor

@kennytm
Copy link
Member

kennytm commented Jan 31, 2018

@bors retry #46903

@sgrif
Copy link
Contributor

sgrif commented Jan 31, 2018

I can confirm that this PR fixes Diesel's build

@sgrif
Copy link
Contributor

sgrif commented Jan 31, 2018

It doesn't look like bors recognized the retry request

@Mark-Simulacrum
Copy link
Member

@bors retry #46903

@bors
Copy link
Contributor

bors commented Jan 31, 2018

⌛ Testing commit 2fc5739 with merge 60e2baaa825fc13e1d1f764e32348ee6af7d3314...

@bors
Copy link
Contributor

bors commented Jan 31, 2018

💔 Test failed - status-travis

@nikomatsakis
Copy link
Contributor Author

@kennytm
Copy link
Member

kennytm commented Feb 1, 2018

@bors retry

@bors
Copy link
Contributor

bors commented Feb 1, 2018

⌛ Testing commit 2fc5739 with merge 56733bc...

bors added a commit that referenced this pull request Feb 1, 2018
remove intercrate ambiguity hints

The scheme was causing overflows during coherence checking (e.g. #47139). This is sort of a temporary fix; the proper fix I think involves reworking trait selection in deeper ways.

cc @sgrif -- this *should* fix diesel

cc @qnighy -- I'd like to discuss you with alternative techniques for achieving the same end. =) Actually, it might be good to put some energy into refactoring traits first.

r? @eddyb
@bors
Copy link
Contributor

bors commented Feb 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 56733bc to master...

@bors bors merged commit 2fc5739 into rust-lang:master Feb 1, 2018
@nikomatsakis nikomatsakis removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Feb 1, 2018
bors added a commit that referenced this pull request Feb 2, 2018
Backport 47738 to beta

Backport of #47738 to beta branch.
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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants