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

Fix MemCategorization and ExprUse visitors for new solver #124859

Closed
wants to merge 3 commits into from

Conversation

compiler-errors
Copy link
Member

Best reviewed per-commit.

  1. First, we add delayed span bugs for the cases where we previously silently quit in MemCategorization.
  2. Second, we just inline FnCtxt into these visitors. Shouldn't change any behavior.
  3. Actually change behavior (in the new solver) to structurally resolve aliases before calling Ty::kind and Ty::builtin_deref.

This fixes an ICE in icu4x when building it in the new trait solver.

r? lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 7, 2024
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling declare_clippy_lint v0.1.80 (/checkout/src/tools/clippy/declare_clippy_lint)
error[E0624]: associated function `new` is private
   --> src/tools/clippy/clippy_utils/src/sugg.rs:835:25
    |
835 |           ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
    |
   ::: /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:5
    |
125 | /     pub(crate) fn new(
125 | /     pub(crate) fn new(
126 | |         delegate: &'a mut (dyn Delegate<'tcx> + 'a),
127 | |         fcx: &'a FnCtxt<'a, 'tcx>,
128 | |         body_id: LocalDefId,
    | |_____________- private associated function defined here

error[E0061]: this function takes 3 arguments but 5 arguments were supplied
   --> src/tools/clippy/clippy_utils/src/sugg.rs:835:9
   --> src/tools/clippy/clippy_utils/src/sugg.rs:835:9
    |
835 |         ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
    |         ^^^^^^^^^^^^^^^^^^^               ------          ------------  ------------------- unexpected argument of type `&TypeckResults<'_>`
    |                                           |               unexpected argument of type `rustc_middle::ty::ParamEnv<'_>`
    |                                           |               unexpected argument of type `rustc_middle::ty::ParamEnv<'_>`
    |                                           expected `&FnCtxt<'_, '_>`, found `&InferCtxt<'_>`
    = note: expected reference `&rustc_hir_typeck::fn_ctxt::FnCtxt<'_, '_>`
               found reference `&InferCtxt<'_>`
note: associated function defined here
   --> /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:19
   --> /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:19
    |
125 |     pub(crate) fn new(
    |                   ^^^
help: remove the extra arguments
    |
835 -         ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
835 +         ExprUseVisitor::new(&mut visitor, /* &rustc_hir_typeck::fn_ctxt::FnCtxt<'_, '_> */, def_id).consume_body(closure_body);

    Checking url v2.5.0
error[E0624]: associated function `new` is private
   --> src/tools/clippy/clippy_utils/src/usage.rs:21:21
   --> src/tools/clippy/clippy_utils/src/usage.rs:21:21
    |
21  |       ExprUseVisitor::new(
    |                       ^^^ private associated function
    |
   ::: /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:5
    |
125 | /     pub(crate) fn new(
126 | |         delegate: &'a mut (dyn Delegate<'tcx> + 'a),
127 | |         fcx: &'a FnCtxt<'a, 'tcx>,
128 | |         body_id: LocalDefId,
    | |_____________- private associated function defined here

error[E0061]: this function takes 3 arguments but 5 arguments were supplied
   --> src/tools/clippy/clippy_utils/src/usage.rs:21:5
   --> src/tools/clippy/clippy_utils/src/usage.rs:21:5
    |
21  |     ExprUseVisitor::new(
    |     ^^^^^^^^^^^^^^^^^^^
22  |         &mut delegate,
23  |         &infcx,
    |         ------ expected `&FnCtxt<'_, '_>`, found `&InferCtxt<'_>`
24  |         expr.hir_id.owner.def_id,
25  |         cx.param_env,
    |         ------------ unexpected argument of type `rustc_middle::ty::ParamEnv<'tcx>`
26  |         cx.typeck_results(),
    |         ------------------- unexpected argument of type `&TypeckResults<'_>`
    = note: expected reference `&rustc_hir_typeck::fn_ctxt::FnCtxt<'_, '_>`
               found reference `&InferCtxt<'_>`
note: associated function defined here
   --> /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:19
   --> /checkout/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:125:19
    |
125 |     pub(crate) fn new(
    |                   ^^^
help: remove the extra arguments
    |
23  ~         /* &rustc_hir_typeck::fn_ctxt::FnCtxt<'_, '_> */,
24  ~         expr.hir_id.owner.def_id,

   Compiling color-print-proc-macro v0.3.5
    Checking anstyle-wincon v3.0.2
    Checking anstyle-query v1.0.2

@compiler-errors compiler-errors changed the title Mem cat Fix MemCategorization and ExprUse visitors for new solver May 7, 2024
@compiler-errors
Copy link
Member Author

goddamn clippy

@compiler-errors compiler-errors 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 May 7, 2024
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

ignoring clippy CI issues, this looks good 👍 some further suggestions, then r=me

self.tcx()
.dcx()
.span_delayed_bug(self.tcx().hir().span(id), "encountered type variable");
Err(())
Copy link
Contributor

Choose a reason for hiding this comment

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

do we ever return Err(()) in places which should successfully compile? If not, please change McResult to Result<T, ErrorGuaranteed>

@@ -122,18 +122,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// - `delegate` -- who receives the callbacks
/// - `param_env` --- parameter environment for trait lookups (esp. pertaining to `Copy`)
/// - `typeck_results` --- typeck results for the code being analyzed
pub fn new(
pub(crate) fn new(
delegate: &'a mut (dyn Delegate<'tcx> + 'a),
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: pls flip arguments: fcx, body_id, delegate instead of teh current order

Comment on lines +89 to +91
/// The def id of the body that is being categorized.
/// This is **different** from `fcx.body_id`.
pub inner_body_id: LocalDefId,
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels odd, shouldn't we create a separate FnCtxt for nested bodies? I guess is issue is that the scoping is as follows?

typeck_outer {
    typeck_inner {}

    closure_capture_analysis_outer {}
    closure_capture_analysis_inner {}
}

i.e. we already dropped the inner FnCtxt again? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

The old FnCtxt is long gone, though we could create a new one (we don't care about any of the fields in FnCtxt except for the body id).

Copy link
Member Author

Choose a reason for hiding this comment

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

All of this is useless though, because we definitely cannot adapt this with the way that clippy is using ExprUseVisitor, so I'll have to completely rework this PR.

.dcx()
.span_delayed_bug(self.tcx().hir().span(id), "encountered type variable");
.span_delayed_bug(self.tcx.hir().span(id), "encountered type variable");
Err(())
} else {
Ok(ty)
}
}
// FIXME
Copy link
Contributor

Choose a reason for hiding this comment

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

existing: what's that FIXME?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably due to not wanting to rely on InferCtxt taintedness for expr-use-analysis.

@compiler-errors
Copy link
Member Author

I'm going to put up a more involved PR that actually supports clippy's usecases

bors added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2024
…r=<try>

Fix MemCategorization and ExprUse visitors for new solver (this time it's better)

Best reviewed by each commit. Supersedes rust-lang#124859.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request May 8, 2024
…r=<try>

Fix MemCategorization and ExprUse visitors for new solver (this time it's better)

Best reviewed by each commit. Supersedes rust-lang#124859.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2024
…r=lcnr

Fix MemCategorization and ExprUse visitors for new solver (this time it's better)

Best reviewed by each commit. Supersedes rust-lang#124859.

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants