-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make type_implements_trait not a query #86901
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
let trait_ref = | ||
ty::TraitRef { def_id: trait_def_id, substs: self.mk_substs_trait(ty, params) }; | ||
|
||
if (trait_ref, param_env).needs_infer() { |
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.
if (trait_ref, param_env).needs_infer() { | |
// FIXME(#86868): If there are inference variables anywhere, just assume | |
// we don't know the answer. This works around the ICEs that would result | |
// from using those inference variables within the `infer_ctxt` we create below. | |
// Really this should be a method on `InferCtxt` instead, which would fix this | |
// problem. | |
if (trait_ref, param_env).needs_infer() { |
@@ -0,0 +1,47 @@ | |||
// edition:2018 | |||
// check-pass | |||
// compile-flags: -C incremental=tmp/migration_2229_incr_issue_86753 |
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.
Hmm, this doesn't seem right, let me poke at this...
// FIXME(#86868): If there are inference variables anywhere, just assume | ||
// we don't know the answer. This works around the ICEs that would result | ||
// from using those inference variables within the `infer_ctxt` we create below. | ||
// Really this should be a method on `InferCtxt` instead, which would fix this | ||
// problem. | ||
if (trait_ref, param_env).needs_infer() { | ||
return traits::EvaluationResult::EvaluatedToUnknown; | ||
} |
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.
// FIXME(#86868): If there are inference variables anywhere, just assume | |
// we don't know the answer. This works around the ICEs that would result | |
// from using those inference variables within the `infer_ctxt` we create below. | |
// Really this should be a method on `InferCtxt` instead, which would fix this | |
// problem. | |
if (trait_ref, param_env).needs_infer() { | |
return traits::EvaluationResult::EvaluatedToUnknown; | |
} |
We don't need this anymore! The problem was that we were creating a fresh inference context, and hence those type variables and things were out of scope in that fresh infrence context. Since we're not doing that, it's the callers problem to pass up types that are appropriate for this inference context.
@@ -128,9 +129,10 @@ pub fn implements_trait<'tcx>( | |||
return false; | |||
} | |||
let ty_params = cx.tcx.mk_substs(ty_params.iter()); | |||
cx.tcx | |||
.type_implements_trait((trait_id, ty, ty_params, cx.param_env)) | |||
cx.tcx.infer_ctxt().enter(|infcx| |
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.
Can you modify the ty.has_infer_types
above to ty.needs_infer
, which is a more complete fix? (Actually, I think I'd prefer an assertion, but that's more of a matter for @rust-lang/clippy to decide -- I would be surprised though if inference variables make their way here)
For that matter, I think the function should have a comment explaining that it returns false in the case of inference variables, as that is not obvious (also not obviously correct)
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.
The ty.has_infer_types()
was added as a fix for a ICE: #72775
Clippy changes LGTM, if needs_infer
also works 👍
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.
Makes sense -- needs_infer
would probably avoid more ICEs :)
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.
Note though @flip1995 that there's probably a "better fix" that just makes the code work
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.
Oh, I see, but the ICE in question was #72766 and is not part of clippy, right?
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.
it might well be that this can be an assert!
in the clippy code
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.
I really don't know if this is required in Clippy, I've never tested it without it since it was added. We call this utils function in many places, so it's likely that this actually prevents an ICE, even if it is just there as a precaution, so that this function can just be used without checking preconditions.
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ab3889223a29f3b2b5dad1dfc8c55b389f7332ab with merge c841cc53e27582dd5b02321f0f8d603cbd1076ed... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
woops i realized i forgot to push my changes |
This comment has been minimized.
This comment has been minimized.
Weird |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 1bcbc18 with merge 87b32b6144dfeec8b0cf9c1ad5dff144df3823ac... |
☀️ Try build successful - checks-actions |
Queued 87b32b6144dfeec8b0cf9c1ad5dff144df3823ac with parent 238fd72, future comparison URL. |
Finished benchmarking try commit (87b32b6144dfeec8b0cf9c1ad5dff144df3823ac): comparison url. Summary: This benchmark run did not return any significant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. @bors rollup=never |
@bors r+ |
📌 Commit 1bcbc18 has been approved by |
☀️ Test successful - checks-actions |
r? @nikomatsakis