-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Create a canonical trait query for evaluate_obligation
#48995
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/librustc/traits/select.rs
Outdated
@@ -617,6 +625,17 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { | |||
}) | |||
} | |||
|
|||
/// Evaluates whether the obligation `obligation` can be satisfied and returns | |||
/// an `EvaluationResult`. | |||
pub fn evaluate_obligation_recursively(&mut self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if exposing this new API is a good thing to have done, but it was the cleanest way without also exposing TraitObligationStackList
(which is even more of an implementation detail).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems OK -- I might prefer to remove evaluate_obligation_conservatively
and evaluation_obligation
in favor of just offering this, though. Or at least have them invoke it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The only caller of the originals now is in coherence, so I'll just switch that to use this and remove both the originals. And rename this to just evaluate_obligation
to boot.
Hmm, travis is unhappy |
The Travis error is unrelated, hopefully it'll go away on a retry: [00:52:40] Documenting core v0.0.0 (file:///checkout/src/libcore)
[00:52:40] Compiling core v0.0.0 (file:///checkout/src/libcore)
[00:52:52] error: internal compiler error: librustc/ich/impls_ty.rs:907: ty::TypeVariants::hash_stable() - Unexpected variant TyInfer(?0).
[00:52:52]
[00:52:52] thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:538:9 Edit: was wrong, see below |
cbd3600
to
9b9c44e
Compare
☔ The latest upstream changes (presumably #47630) made this pull request unmergeable. Please resolve the merge conflicts. |
3da95d7
to
87ce396
Compare
Heads up: this breaks clippy, but the following diff should fix it once this lands (haven't tested though). cc @Manishearth, @llogiq --- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -306,11 +306,10 @@ pub fn implements_trait<'a, 'tcx>(
ty_params: &[Ty<'tcx>],
) -> bool {
let ty = cx.tcx.erase_regions(&ty);
- let obligation =
- cx.tcx
- .predicate_for_trait_def(cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
+ let trait_ref = ty::TraitRef::new(trait_id,
+ cx.tcx.mk_substs_trait(ty, ty_params);
cx.tcx.infer_ctxt().enter(|infcx| {
- traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation)
+ infcx.predicate_must_hold(cx.param_env, trait_ref.to_predicate())
})
} |
Thanks for providing the diff! I'm not going to be able to fix it yet but
someone else will probably.
…On Mar 15, 2018 12:21 AM, "Aravind Gollakota" ***@***.***> wrote:
Heads up: this breaks clippy, but the following diff should fix it
(haven't tested though). cc @Manishearth <https://github.com/manishearth>,
@llogiq <https://github.com/llogiq>
--- a/clippy_lints/src/utils/mod.rs+++ b/clippy_lints/src/utils/mod.rs@@ -306,11 +306,10 @@ pub fn implements_trait<'a, 'tcx>(
ty_params: &[Ty<'tcx>],
) -> bool {
let ty = cx.tcx.erase_regions(&ty);- let obligation =- cx.tcx- .predicate_for_trait_def(cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);+ let trait_ref = ty::TraitRef::new(trait_id,+ cx.tcx.mk_substs_trait(ty, ty_params);
cx.tcx.infer_ctxt().enter(|infcx| {- traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation)+ infcx.predicate_must_hold(cx.param_env, trait_ref.to_predicate())
})
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#48995 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABivSD428mWUo9c59ZZkJjTQvLp3I5Hvks5teexlgaJpZM4SpgHP>
.
|
Ah so the Travis error isn't spurious. It looks like somehow I've introduced a codepath that causes incr.comp. to attempt (and fail) to hash type inference variables, i.e. we're hitting rust/src/librustc/ich/impls_ty.rs Lines 892 to 894 in ae379bd
|
I may look into it in a few hours. |
@aravind-pg very curious. Might be a bug in the canonicalizer. |
☔ The latest upstream changes (presumably #48985) made this pull request unmergeable. Please resolve the merge conflicts. |
87ce396
to
3939fba
Compare
Rebased to pick up #49091. |
3939fba
to
2ee933d
Compare
src/librustc/ty/maps/config.rs
Outdated
@@ -73,6 +73,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::normalize_ty_after_erasing_region | |||
} | |||
} | |||
|
|||
impl<'tcx> QueryDescription<'tcx> for queries::evaluate_obligation<'tcx> { | |||
fn describe(_tcx: TyCtxt, goal: CanonicalPredicateGoal<'tcx>) -> String { | |||
format!("evaluating trait selection obligation `{:?}`", goal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the failing test impl-trait/auto-trait-leak.rs
is now including this message in its output. In general, {:?}
should be avoided here, as this a message that may be shown to the user. That said, nicely formatting this message could be kind of annoying. I guess something like this might be good enough for now:
format!("evaluating trait selection obligation `{}`", goal.value.value)
I'm trying this locally. This will just skip over the canonical binders and the param-env.
evaluate_obligation
evaluate_obligation
I pushed a commit that should fix the travis errors for now, but one of the fixes is not something I am yet comfortable landing (hence the update on the PR title to prevent accidental landing). I just wanted to see if there are further errors, and measure perf impact. |
4f250a6
to
f37a1d2
Compare
@bors try |
[WIP] Create a canonical trait query for `evaluate_obligation` This builds on the canonical query machinery introduced in #48411 to introduce a new canonical trait query for `evaluate_obligation` in the trait selector. Also ports most callers of the original `evaluate_obligation` to the new system (except in coherence, which requires support for intercrate mode). Closes #48537. r? @nikomatsakis
💔 Test failed - status-travis |
I implemented the query mode idea and our error messages are back in good shape -- modulo this slightly unfortunate situation. Overall I think the trait selection error reporting setup has definitely gotten a little hairier, sadly, but it's the best we could think of. Later refactoring might be able to clean things up. Anyhow, ready for a re-review. |
evaluate_obligation
evaluate_obligation
☔ The latest upstream changes (presumably #49837) made this pull request unmergeable. Please resolve the merge conflicts. |
r=me post rebase @bors delegate=aravind-pg |
✌️ @aravind-pg can now approve this pull request |
@sgrif didn't seem too terrified of the error regression. =) And it's hopefully a corner case. |
Oh I'm sure I have code that hits it |
…stead of aborting eagerly We store the obligation that caused the overflow as part of the OverflowError, and report it at the public API endpoints (rather than in the implementation internals).
…rait query Except the one in coherence, which needs support for intercrate mode.
…policy in traits::select
We will shortly refactor things so that it is no longer needed
This is slightly hacky and hopefully only a somewhat temporary solution.
752e831
to
e423dcc
Compare
@bors r=nikomatsakis Let's land for now, and if any annoyances come up then we can gate this setup with |
📌 Commit e423dcc has been approved by |
Create a canonical trait query for `evaluate_obligation` This builds on the canonical query machinery introduced in #48411 to introduce a new canonical trait query for `evaluate_obligation` in the trait selector. Also ports most callers of the original `evaluate_obligation` to the new system (except in coherence, which requires support for intercrate mode). Closes #48537. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
This builds on the canonical query machinery introduced in #48411 to introduce a new canonical trait query for
evaluate_obligation
in the trait selector. Also ports most callers of the originalevaluate_obligation
to the new system (except in coherence, which requires support for intercrate mode). Closes #48537.r? @nikomatsakis