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

Make type_implements_trait not a query #86901

Merged
merged 2 commits into from
Jul 7, 2021
Merged

Conversation

arora-aman
Copy link
Member

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

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...

Comment on lines 117 to 124
// 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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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|
Copy link
Contributor

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)

Copy link
Member

@flip1995 flip1995 Jul 6, 2021

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 👍

Copy link
Contributor

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 :)

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Member

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.

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 6, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 6, 2021
@bors
Copy link
Contributor

bors commented Jul 6, 2021

⌛ Trying commit ab3889223a29f3b2b5dad1dfc8c55b389f7332ab with merge c841cc53e27582dd5b02321f0f8d603cbd1076ed...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 6, 2021

💔 Test failed - checks-actions

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2021
@arora-aman
Copy link
Member Author

woops i realized i forgot to push my changes

@rust-log-analyzer

This comment has been minimized.

@arora-aman
Copy link
Member Author

Weird x.py check and x.py test --bless --stage 2 passed

@nikomatsakis
Copy link
Contributor

@bors rollup-

I guess @oli-obk is concerned about performance (I am not), but let's ensure it can be isolated.

@nikomatsakis
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Jul 6, 2021

⌛ Trying commit 1bcbc18 with merge 87b32b6144dfeec8b0cf9c1ad5dff144df3823ac...

@bors
Copy link
Contributor

bors commented Jul 6, 2021

☀️ Try build successful - checks-actions
Build commit: 87b32b6144dfeec8b0cf9c1ad5dff144df3823ac (87b32b6144dfeec8b0cf9c1ad5dff144df3823ac)

@rust-timer
Copy link
Collaborator

Queued 87b32b6144dfeec8b0cf9c1ad5dff144df3823ac with parent 238fd72, future comparison URL.

@rust-timer
Copy link
Collaborator

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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 6, 2021
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 7, 2021

📌 Commit 1bcbc18 has been approved by nikomatsakis

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 7, 2021
@bors
Copy link
Contributor

bors commented Jul 7, 2021

⌛ Testing commit 1bcbc18 with merge c0bd5a5...

@bors
Copy link
Contributor

bors commented Jul 7, 2021

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing c0bd5a5 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

9 participants