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

Replace the global fulfillment cache with the evaluation cache #42840

Merged
merged 4 commits into from
Jul 7, 2017

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented Jun 22, 2017

This uses the new "Chalk" ParamEnv refactoring to check "global" predicates in an empty environment, which should be correct because global predicates aren't affected by a consistent environment.

Fixes #39970.
Fixes #42796.

r? @nikomatsakis

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 23, 2017
@arielb1 arielb1 changed the title [WIP] replace the global fulfillment cache with the evaluation cache Replace the global fulfillment cache with the evaluation cache Jun 27, 2017
} else {
debug!("evaluate_stack({:?}) --> recursive, inductive",
stack.fresh_trait_ref);
return EvaluatedToErr;
Copy link
Contributor

Choose a reason for hiding this comment

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

So we've been working through this logic in the context of chalk -- it turns out that error isn't really the right answer here. In particular, it can lead you to "overconfidence". The correct answer probably requires iteration (at least, that's what we're doing in chalk). Maybe might be tolerable for now, but may break stuff, I'm not sure.

PR rust-lang/chalk#47 by @scalexm outlines the chalk strategy, which is based on a technique called tabling. In short, you start out by saying error, but then -- if you find solutions -- you iterate again, and this time, on the cycle, you return the solution that you found. This may allow you to find a second solution, in which case you can report ambiguity (no unique solution).

This example test is relevant -- on the first iteration, we encounter a cycle testing whether exists<T> { T: Foo } (that is, S<T>: Foo inquires whether S<T>: Foo), but we also encounter a solution -- T = i32. This then enables (on the second round) us to uncover that S<i32>: Foo is another solution. (Indeed, there are infinitely many, iirc.)

Copy link
Contributor Author

@arielb1 arielb1 Jun 29, 2017

Choose a reason for hiding this comment

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

The current logic actually reports an overflow error in this case, which aborts compilation. Maybe it's better to do that here too?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we return "OK" for the "evaluation" result, but abort in the fulfillment cx..? If we aborted in both, it might cause trouble? Maybe worth a try though.

Copy link
Contributor

Choose a reason for hiding this comment

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

The other option is EvaluatedToAmbiguity.

@arielb1 arielb1 force-pushed the poison-smoke-and-mirrors branch 3 times, most recently from 6fc1b35 to d66f6c6 Compare July 1, 2017 16:13
@aidanhs aidanhs 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 Jul 5, 2017
@bors
Copy link
Contributor

bors commented Jul 6, 2017

☔ The latest upstream changes (presumably #43008) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

@arielb1 sorry for delay, I promise a review soon. =)

@nikomatsakis
Copy link
Contributor

r=me after rebase

Previously, coinductive matching was only blocked on the fulfillment
path, and ignored on the evaluation path.
This is just duplicating the logic from the old fulfillment cache, so
I'm not sure it is 100% correct, but it should not be more wrong than
the old logic.
The evaluation cache already exists, and it can handle differing
parameter environments natively.

Fixes rust-lang#39970.
Fixes rust-lang#42796.
This helps avoid cache pollution. Also add more comments explaining
that.
@nikomatsakis
Copy link
Contributor

@arielb1 I did the rebase locally because I wanted to check some experiments; just pushed it, hope you don't mind. =)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 7, 2017

📌 Commit b7b965a has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jul 7, 2017

⌛ Testing commit b7b965a with merge 9b85e1c...

bors added a commit that referenced this pull request Jul 7, 2017
Replace the global fulfillment cache with the evaluation cache

This uses the new "Chalk" ParamEnv refactoring to check "global" predicates in an empty environment, which should be correct because global predicates aren't affected by a consistent environment.

Fixes #39970.
Fixes #42796.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Jul 7, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 9b85e1c to master...

@bors bors merged commit b7b965a into rust-lang:master Jul 7, 2017
arielb1 added a commit to arielb1/rust that referenced this pull request Aug 17, 2017
…ors, r=nikomatsakis"

This reverts commit 9b85e1c, reversing
changes made to 13157c4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants