Auto merge of #108944 - cjgillot:clear-local-info, r=oli-obk
Wrap the whole LocalInfo in ClearCrossCrate. MIR contains a lot of information about locals. The primary purpose of this information is the quality of borrowck diagnostics. This PR aims to drop this information after MIR analyses are finished, ie. starting from post-cleanup runtime MIR.
This commit is contained in:
commit
511364e787
30 changed files with 188 additions and 214 deletions
|
@ -24,7 +24,7 @@ struct ConstMutationChecker<'a, 'tcx> {
|
|||
|
||||
impl<'tcx> ConstMutationChecker<'_, 'tcx> {
|
||||
fn is_const_item(&self, local: Local) -> Option<DefId> {
|
||||
if let Some(box LocalInfo::ConstRef { def_id }) = self.body.local_decls[local].local_info {
|
||||
if let LocalInfo::ConstRef { def_id } = *self.body.local_decls[local].local_info() {
|
||||
Some(def_id)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -182,7 +182,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
|
|||
// If the projection root is an artificial local that we introduced when
|
||||
// desugaring `static`, give a more specific error message
|
||||
// (avoid the general "raw pointer" clause below, that would only be confusing).
|
||||
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
|
||||
if let LocalInfo::StaticRef { def_id, .. } = *decl.local_info() {
|
||||
if self.tcx.is_mutable_static(def_id) {
|
||||
self.require_unsafe(
|
||||
UnsafetyViolationKind::General,
|
||||
|
|
|
@ -40,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
|
|||
let temp = self.patcher.new_internal_with_info(
|
||||
ty,
|
||||
self.local_decls[p_ref.local].source_info.span,
|
||||
Some(Box::new(LocalInfo::DerefTemp)),
|
||||
LocalInfo::DerefTemp,
|
||||
);
|
||||
|
||||
// We are adding current p_ref's projections to our
|
||||
|
|
|
@ -788,7 +788,7 @@ impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> {
|
|||
fn is_local_required(local: Local, body: &Body<'_>) -> bool {
|
||||
match body.local_kind(local) {
|
||||
LocalKind::Arg | LocalKind::ReturnPointer => true,
|
||||
LocalKind::Var | LocalKind::Temp => false,
|
||||
LocalKind::Temp => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -924,13 +924,19 @@ fn compute_layout<'tcx>(
|
|||
debug!(?decl);
|
||||
|
||||
let ignore_for_traits = if tcx.sess.opts.unstable_opts.drop_tracking_mir {
|
||||
// Do not `assert_crate_local` here, as post-borrowck cleanup may have already cleared
|
||||
// the information. This is alright, since `ignore_for_traits` is only relevant when
|
||||
// this code runs on pre-cleanup MIR, and `ignore_for_traits = false` is the safer
|
||||
// default.
|
||||
match decl.local_info {
|
||||
// Do not include raw pointers created from accessing `static` items, as those could
|
||||
// well be re-created by another access to the same static.
|
||||
Some(box LocalInfo::StaticRef { is_thread_local, .. }) => !is_thread_local,
|
||||
ClearCrossCrate::Set(box LocalInfo::StaticRef { is_thread_local, .. }) => {
|
||||
!is_thread_local
|
||||
}
|
||||
// Fake borrows are only read by fake reads, so do not have any reality in
|
||||
// post-analysis MIR.
|
||||
Some(box LocalInfo::FakeBorrow) => true,
|
||||
ClearCrossCrate::Set(box LocalInfo::FakeBorrow) => true,
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -29,9 +29,9 @@ use rustc_hir::intravisit::{self, Visitor};
|
|||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::visit::Visitor as _;
|
||||
use rustc_middle::mir::{
|
||||
traversal, AnalysisPhase, Body, ConstQualifs, Constant, LocalDecl, MirPass, MirPhase, Operand,
|
||||
Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo, Statement, StatementKind,
|
||||
TerminatorKind,
|
||||
traversal, AnalysisPhase, Body, ClearCrossCrate, ConstQualifs, Constant, LocalDecl, MirPass,
|
||||
MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, SourceInfo,
|
||||
Statement, StatementKind, TerminatorKind,
|
||||
};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
|
||||
|
@ -532,6 +532,12 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
&[&lower_intrinsics::LowerIntrinsics, &simplify::SimplifyCfg::new("elaborate-drops")];
|
||||
|
||||
pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup)));
|
||||
|
||||
// Clear this by anticipation. Optimizations and runtime MIR have no reason to look
|
||||
// into this information, which is meant for borrowck diagnostics.
|
||||
for decl in &mut body.local_decls {
|
||||
decl.local_info = ClearCrossCrate::Clear;
|
||||
}
|
||||
}
|
||||
|
||||
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
|
|
|
@ -102,7 +102,7 @@ fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> {
|
|||
mir::LocalKind::Arg => return None,
|
||||
|
||||
mir::LocalKind::ReturnPointer => bug!("Return place was assigned to itself?"),
|
||||
mir::LocalKind::Var | mir::LocalKind::Temp => {}
|
||||
mir::LocalKind::Temp => {}
|
||||
}
|
||||
|
||||
// If multiple different locals are copied to the return place. We can't pick a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue