Do not track span in ConstProp.
This commit is contained in:
parent
2247cd6643
commit
0e64ce7c5e
4 changed files with 14 additions and 35 deletions
|
@ -17,7 +17,7 @@ use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||||
use rustc_middle::ty::InternalSubsts;
|
use rustc_middle::ty::InternalSubsts;
|
||||||
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt};
|
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt};
|
||||||
use rustc_span::{def_id::DefId, Span};
|
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
|
||||||
use rustc_target::abi::{self, Align, HasDataLayout, Size, TargetDataLayout};
|
use rustc_target::abi::{self, Align, HasDataLayout, Size, TargetDataLayout};
|
||||||
use rustc_target::spec::abi::Abi as CallAbi;
|
use rustc_target::spec::abi::Abi as CallAbi;
|
||||||
use rustc_trait_selection::traits;
|
use rustc_trait_selection::traits;
|
||||||
|
@ -328,9 +328,6 @@ struct ConstPropagator<'mir, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ParamEnv<'tcx>,
|
param_env: ParamEnv<'tcx>,
|
||||||
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>,
|
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>,
|
||||||
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
|
|
||||||
// the last known `SourceInfo` here and just keep revisiting it.
|
|
||||||
source_info: Option<SourceInfo>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
|
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
|
@ -411,13 +408,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
)
|
)
|
||||||
.expect("failed to push initial stack frame");
|
.expect("failed to push initial stack frame");
|
||||||
|
|
||||||
ConstPropagator {
|
ConstPropagator { ecx, tcx, param_env, local_decls: &dummy_body.local_decls }
|
||||||
ecx,
|
|
||||||
tcx,
|
|
||||||
param_env,
|
|
||||||
local_decls: &dummy_body.local_decls,
|
|
||||||
source_info: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||||
|
@ -495,7 +486,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
*operand = self.operand_from_scalar(
|
*operand = self.operand_from_scalar(
|
||||||
scalar,
|
scalar,
|
||||||
value.layout.ty,
|
value.layout.ty,
|
||||||
self.source_info.unwrap().span,
|
DUMMY_SP,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -629,12 +620,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_with_const(
|
fn replace_with_const(&mut self, rval: &mut Rvalue<'tcx>, value: &OpTy<'tcx>) {
|
||||||
&mut self,
|
|
||||||
rval: &mut Rvalue<'tcx>,
|
|
||||||
value: &OpTy<'tcx>,
|
|
||||||
source_info: SourceInfo,
|
|
||||||
) {
|
|
||||||
if let Rvalue::Use(Operand::Constant(c)) = rval {
|
if let Rvalue::Use(Operand::Constant(c)) = rval {
|
||||||
match c.literal {
|
match c.literal {
|
||||||
ConstantKind::Ty(c) if matches!(c.kind(), ConstKind::Unevaluated(..)) => {}
|
ConstantKind::Ty(c) if matches!(c.kind(), ConstKind::Unevaluated(..)) => {}
|
||||||
|
@ -664,11 +650,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
if let Some(Right(imm)) = imm {
|
if let Some(Right(imm)) = imm {
|
||||||
match *imm {
|
match *imm {
|
||||||
interpret::Immediate::Scalar(scalar) => {
|
interpret::Immediate::Scalar(scalar) => {
|
||||||
*rval = Rvalue::Use(self.operand_from_scalar(
|
*rval =
|
||||||
scalar,
|
Rvalue::Use(self.operand_from_scalar(scalar, value.layout.ty, DUMMY_SP));
|
||||||
value.layout.ty,
|
|
||||||
source_info.span,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Immediate::ScalarPair(..) => {
|
Immediate::ScalarPair(..) => {
|
||||||
// Found a value represented as a pair. For now only do const-prop if the type
|
// Found a value represented as a pair. For now only do const-prop if the type
|
||||||
|
@ -701,7 +684,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
let const_val = ConstValue::ByRef { alloc, offset: Size::ZERO };
|
let const_val = ConstValue::ByRef { alloc, offset: Size::ZERO };
|
||||||
let literal = ConstantKind::Val(const_val, ty);
|
let literal = ConstantKind::Val(const_val, ty);
|
||||||
*rval = Rvalue::Use(Operand::Constant(Box::new(Constant {
|
*rval = Rvalue::Use(Operand::Constant(Box::new(Constant {
|
||||||
span: source_info.span,
|
span: DUMMY_SP,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
literal,
|
literal,
|
||||||
})));
|
})));
|
||||||
|
@ -894,8 +877,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
|
|
||||||
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
|
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
|
||||||
trace!("visit_statement: {:?}", statement);
|
trace!("visit_statement: {:?}", statement);
|
||||||
let source_info = statement.source_info;
|
|
||||||
self.source_info = Some(source_info);
|
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::Assign(box (place, ref mut rval)) => {
|
StatementKind::Assign(box (place, ref mut rval)) => {
|
||||||
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
|
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
|
||||||
|
@ -905,7 +886,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
// consists solely of uninitialized memory (so it doesn't capture any locals).
|
// consists solely of uninitialized memory (so it doesn't capture any locals).
|
||||||
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
|
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
|
||||||
trace!("replacing {:?} with {:?}", rval, value);
|
trace!("replacing {:?} with {:?}", rval, value);
|
||||||
self.replace_with_const(rval, value, source_info);
|
self.replace_with_const(rval, value);
|
||||||
if can_const_prop == ConstPropMode::FullConstProp
|
if can_const_prop == ConstPropMode::FullConstProp
|
||||||
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
|
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
|
||||||
{
|
{
|
||||||
|
@ -977,8 +958,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
|
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
|
||||||
let source_info = terminator.source_info;
|
|
||||||
self.source_info = Some(source_info);
|
|
||||||
self.super_terminator(terminator, location);
|
self.super_terminator(terminator, location);
|
||||||
|
|
||||||
match &mut terminator.kind {
|
match &mut terminator.kind {
|
||||||
|
@ -991,7 +970,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
*cond = self.operand_from_scalar(
|
*cond = self.operand_from_scalar(
|
||||||
value_const,
|
value_const,
|
||||||
self.tcx.types.bool,
|
self.tcx.types.bool,
|
||||||
source_info.span,
|
DUMMY_SP,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
- switchInt(move _4) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
- switchInt(move _4) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
||||||
+ _3 = const Option::<bool>::Some(true); // scope 2 at $DIR/discriminant.rs:+1:34: +1:44
|
+ _3 = const Option::<bool>::Some(true); // scope 2 at $DIR/discriminant.rs:+1:34: +1:44
|
||||||
+ // mir::Constant
|
+ // mir::Constant
|
||||||
+ // + span: $DIR/discriminant.rs:12:34: 12:44
|
+ // + span: no-location
|
||||||
+ // + literal: Const { ty: Option<bool>, val: Value(Scalar(0x01)) }
|
+ // + literal: Const { ty: Option<bool>, val: Value(Scalar(0x01)) }
|
||||||
+ _4 = const 1_isize; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
+ _4 = const 1_isize; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
||||||
+ switchInt(const 1_isize) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
+ switchInt(const 1_isize) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
|
||||||
|
|
|
@ -44,11 +44,11 @@
|
||||||
- _3 = [move _4]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
|
- _3 = [move _4]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
|
||||||
+ _4 = const Scalar(0x00000004): E; // scope 4 at $DIR/invalid_constant.rs:+13:34: +13:57
|
+ _4 = const Scalar(0x00000004): E; // scope 4 at $DIR/invalid_constant.rs:+13:34: +13:57
|
||||||
+ // mir::Constant
|
+ // mir::Constant
|
||||||
+ // + span: $DIR/invalid_constant.rs:28:34: 28:57
|
+ // + span: no-location
|
||||||
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
|
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
|
||||||
+ _3 = [const Scalar(0x00000004): E]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
|
+ _3 = [const Scalar(0x00000004): E]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
|
||||||
+ // mir::Constant
|
+ // mir::Constant
|
||||||
+ // + span: $DIR/invalid_constant.rs:28:24: 28:60
|
+ // + span: no-location
|
||||||
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
|
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
|
||||||
StorageDead(_4); // scope 1 at $DIR/invalid_constant.rs:+13:59: +13:60
|
StorageDead(_4); // scope 1 at $DIR/invalid_constant.rs:+13:59: +13:60
|
||||||
StorageDead(_5); // scope 1 at $DIR/invalid_constant.rs:+13:60: +13:61
|
StorageDead(_5); // scope 1 at $DIR/invalid_constant.rs:+13:60: +13:61
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
- _6 = MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
- _6 = MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
||||||
+ _6 = const MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
+ _6 = const MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
||||||
+ // mir::Constant
|
+ // mir::Constant
|
||||||
+ // + span: $DIR/funky_arms.rs:21:17: 21:41
|
+ // + span: no-location
|
||||||
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x01)) }
|
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x01)) }
|
||||||
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
- _6 = Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
- _6 = Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
||||||
+ _6 = const Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
+ _6 = const Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
||||||
+ // mir::Constant
|
+ // mir::Constant
|
||||||
+ // + span: $DIR/funky_arms.rs:20:18: 20:38
|
+ // + span: no-location
|
||||||
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x00)) }
|
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x00)) }
|
||||||
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue