Fix MemCategorization and ExprUse visitors for new solver (this time it's better)#124902
Fix MemCategorization and ExprUse visitors for new solver (this time it's better)#124902bors merged 8 commits intorust-lang:masterfrom
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
@bors try @rust-timer queue since i am using |
This comment has been minimized.
This comment has been minimized.
…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
9af26d0 to
8b060ab
Compare
| @@ -1,774 +0,0 @@ | |||
| //! # Categorization | |||
There was a problem hiding this comment.
Goodbye to this comment. I could possibly pull all of the fn cat_* that I moved into expr_use_visitor.rs into a separate impl and copy this comment over. Let me know if necessary.
| Copy, | ||
| /// reference to x where x has a type that moves | ||
| Move, | ||
| impl<'tcx, D: Delegate<'tcx>> Delegate<'tcx> for &mut D { |
There was a problem hiding this comment.
All call sites pass in &mut Delegate but I don't want to store a lifetime in the ExprUseVisitor struct lol
| } | ||
|
|
||
| pub trait TypeInformationCtxt<'tcx> { | ||
| type TypeckResults<'a>: Deref<Target = ty::TypeckResults<'tcx>> |
There was a problem hiding this comment.
Need to abstract over &'tcx TypeckResults (clippy) and RefCell<TypeckResults> (typeck)
| } | ||
| } | ||
|
|
||
| impl<'tcx> TypeInformationCtxt<'tcx> for (&LateContext<'tcx>, LocalDefId) { |
There was a problem hiding this comment.
We store the body id separately rather than trying to get it from the LateContext because although that stores the body, we're often calling the ExprUseVisitor on an inner closure, so the def id would be wrong (which affects upvar analysis!)
There was a problem hiding this comment.
Too lazy to make this into a separate type but I could be convinced otherwise.
|
@bors try |
…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
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (74abdbd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.856s -> 674.94s (-0.14%) |
| /// Like `pat_ty`, but ignores implicit `&` patterns. | ||
| #[instrument(level = "debug", skip(self), ret)] | ||
| fn pat_ty_unadjusted(&self, pat: &hir::Pat<'_>) -> McResult<Ty<'tcx>> { | ||
| let base_ty = self.node_ty(pat.hir_id)?; |
There was a problem hiding this comment.
does that ICE?
| let base_ty = self.node_ty(pat.hir_id)?; | |
| let base_ty = self.typeck_results.pat_ty(pat); |
There was a problem hiding this comment.
We need to call resolve_type_vars_or_error still
904ad62 to
c6d875c
Compare
This comment has been minimized.
This comment has been minimized.
c6d875c to
e46f870
Compare
| #![feature(never_type)] | ||
| #![feature(rustc_private)] | ||
| #![feature(assert_matches)] | ||
| #![feature(unwrap_infallible)] |
There was a problem hiding this comment.
Hi @rust-lang/clippy; I'm pinging you to let y'all know I added a new #![feature(..)] for Result::into_ok() to make the ExprUseVisitor that's being employed by clippy a bit more resilient to error reporting.
None of this error reporting matters for clippy, since we've typechecked the function we're visiting already, so it needs to handle Result<(), !> everywhere and into_ok() is the easiest way to do this.
e46f870 to
e465aba
Compare
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #124972) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ok I understand why this change has fixed #123901. We used to silently swallow errors when recursing here: rust/compiler/rustc_hir_typeck/src/expr_use_visitor.rs Lines 500 to 510 in 3349155 Which now we propagate as an error all the way up the stack. I believe this is totally fine to do. |
e465aba to
03fb1ca
Compare
This comment has been minimized.
This comment has been minimized.
0534f66 to
3aef2f5
Compare
This comment has been minimized.
This comment has been minimized.
3aef2f5 to
c697ec4
Compare
|
@bors r+ rollup=iffy |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (852a78e): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 676.904s -> 676.465s (-0.06%) |
flip1995
left a comment
There was a problem hiding this comment.
Thanks for the extra ping to the Clippy team. But I got here late anyway. All of this looks fine, only one question for better understanding.
| pub fn for_clippy(cx: &'a LateContext<'tcx>, body_def_id: LocalDefId, delegate: D) -> Self { | ||
| Self::new((cx, body_def_id), delegate) | ||
| } |
There was a problem hiding this comment.
Late to the party: Why does Clippy require special treatment?
There was a problem hiding this comment.
Because I want to hide the the Self::new constructor so clippy users won't be tempted to either 1. implementa a manual TypeInformationContext and/or FnCtxt, and 2. so that users will know exactly what data to pass to make a ExprUseVisitor.
There was a problem hiding this comment.
I could've equally called it for_lint, or from_late_ctxt, or something instead.
There was a problem hiding this comment.
Clippy was fundamentally using ExprUseVisitor differently from the only usage in the compiler, though, so that's why the separate constructor exists.
There was a problem hiding this comment.
I see, thanks for the explanation. Generally naming a function for_clippy or for_<tool> gives me the impression, that the function is a hack that only exists because Clippy/the tool doesn't use it as intended. This is also why I asked this question.
In rust-lang#124902, mem-categorization got merged into ExprUseVisitor itself. Adjust the comments that have become misleading or confusing following this change.
In rust-lang#124902, mem-categorization got merged into ExprUseVisitor itself. Adjust the comments that have become misleading or confusing following this change.
Best reviewed by each commit. Supersedes #124859.
r? lcnr