Skip to content

Commit 35e622d

Browse files
committed
Do not keep extra references to scopes and decls.
1 parent b2b676d commit 35e622d

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

compiler/rustc_mir_transform/src/const_prop_lint.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_const_eval::interpret::{
99
};
1010
use rustc_hir::def::DefKind;
1111
use rustc_hir::HirId;
12-
use rustc_index::vec::IndexSlice;
1312
use rustc_middle::mir::visit::Visitor;
1413
use rustc_middle::mir::*;
1514
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
@@ -130,8 +129,6 @@ struct ConstPropagator<'mir, 'tcx> {
130129
ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>,
131130
tcx: TyCtxt<'tcx>,
132131
param_env: ParamEnv<'tcx>,
133-
source_scopes: &'mir IndexSlice<SourceScope, SourceScopeData<'tcx>>,
134-
local_decls: &'mir IndexSlice<Local, LocalDecl<'tcx>>,
135132
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
136133
// the last known `SourceInfo` here and just keep revisiting it.
137134
source_info: Option<SourceInfo>,
@@ -209,14 +206,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
209206
)
210207
.expect("failed to push initial stack frame");
211208

212-
ConstPropagator {
213-
ecx,
214-
tcx,
215-
param_env,
216-
source_scopes: &dummy_body.source_scopes,
217-
local_decls: &dummy_body.local_decls,
218-
source_info: None,
219-
}
209+
ConstPropagator { ecx, tcx, param_env, source_info: None }
210+
}
211+
212+
fn body(&self) -> &'mir Body<'tcx> {
213+
self.ecx.frame().body
214+
}
215+
216+
fn local_decls(&self) -> &'mir LocalDecls<'tcx> {
217+
&self.body().local_decls
220218
}
221219

222220
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
@@ -251,7 +249,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
251249
}
252250

253251
fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> {
254-
source_info.scope.lint_root(self.source_scopes)
252+
source_info.scope.lint_root(&self.body().source_scopes)
255253
}
256254

257255
fn use_ecx<F, T>(&mut self, source_info: SourceInfo, f: F) -> Option<T>
@@ -368,7 +366,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
368366
let r = r.clone()?;
369367
// We need the type of the LHS. We cannot use `place_layout` as that is the type
370368
// of the result, which for checked binops is not the same!
371-
let left_ty = left.ty(self.local_decls, self.tcx);
369+
let left_ty = left.ty(self.local_decls(), self.tcx);
372370
let left_size = self.ecx.layout_of(left_ty).ok()?.size;
373371
let right_size = r.layout.size;
374372
let r_bits = r.to_scalar().to_bits(right_size).ok();
@@ -481,10 +479,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481479
if rvalue.needs_subst() {
482480
return None;
483481
}
484-
if !rvalue
485-
.ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx)
486-
.is_sized(*self.ecx.tcx, self.param_env)
487-
{
482+
if !rvalue.ty(self.local_decls(), self.tcx).is_sized(self.tcx, self.param_env) {
488483
// the interpreter doesn't support unsized locals (only unsized arguments),
489484
// but rustc does (in a kinda broken way), so we have to skip them here
490485
return None;
@@ -498,7 +493,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
498493
assert!(
499494
self.get_const(local.into()).is_none()
500495
|| self
501-
.layout_of(self.local_decls[local].ty)
496+
.layout_of(self.local_decls()[local].ty)
502497
.map_or(true, |layout| layout.is_zst()),
503498
"failed to remove values for `{local:?}`, value={:?}",
504499
self.get_const(local.into()),

0 commit comments

Comments
 (0)