Skip to content

remove intercrate ambiguity hints - #47738

Merged
bors merged 4 commits into
rust-lang:masterfrom
nikomatsakis:issue-47139-master
Feb 1, 2018
Merged

remove intercrate ambiguity hints#47738
bors merged 4 commits into
rust-lang:masterfrom
nikomatsakis:issue-47139-master

Conversation

@nikomatsakis

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

er, oops -- let me add a test!

@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

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

Copy link
Copy Markdown
Contributor

r=me

@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

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

@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

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

@bors

bors commented Jan 25, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit cb4aa5f has been approved by nikomatsakis

@kennytmkennytm 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
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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

@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

@bors r- // travis failures, will investigate

@kennytmkennytm 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
@nikomatsakisnikomatsakis added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 25, 2018
@arielb1

arielb1 commented Jan 25, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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

@arielb1

arielb1 commented Jan 26, 2018

Copy link
Copy Markdown
Contributor

I'll review with the two-pass thing

@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

A squash would be nice.

@arielb1

arielb1 commented Jan 27, 2018

Copy link
Copy Markdown
Contributor

@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.
fncan_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(){
returnfalse;
}
// 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.
ifself.intercrate.is_some(){
returnfalse;
}
// 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
Copy Markdown
ContributorAuthor

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

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

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 2fc5739 with merge fb4d05e0e9c83a68626168b86e0fd26fc3aa736d...

@bors

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-appveyor

@kennytm

Copy link
Copy Markdown
Member

@bors retry #46903

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

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-appveyor

@kennytm

Copy link
Copy Markdown
Member

@bors retry #46903

@sgrif

Copy link
Copy Markdown
Contributor

I can confirm that this PR fixes Diesel's build

@sgrif

Copy link
Copy Markdown
Contributor

It doesn't look like bors recognized the retry request

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors retry #46903

@bors

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Jan 31, 2018

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

@nikomatsakisnikomatsakis mentioned this pull request Feb 1, 2018
@nikomatsakis

Copy link
Copy Markdown
ContributorAuthor

@kennytm

Copy link
Copy Markdown
Member

@bors retry

@bors

bors commented Feb 1, 2018

Copy link
Copy Markdown
Collaborator

⌛ 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

bors commented Feb 1, 2018

Copy link
Copy Markdown
Collaborator

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

@bors
bors merged commit 2fc5739 into rust-lang:masterFeb 1, 2018
@nikomatsakisnikomatsakis 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.
@matthewjaspermatthewjasper mentioned this pull request Mar 5, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-acceptedAccepted for backporting to the compiler in the beta channel.S-waiting-on-borsStatus: 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

@nikomatsakis@eddyb@bors@qnighy@arielb1@kennytm@sgrif@Mark-Simulacrum