Skip to content

Commit 0e64ce7

Browse files
committed
Do not track span in ConstProp.
1 parent 2247cd6 commit 0e64ce7

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::*;
1717
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
1818
use rustc_middle::ty::InternalSubsts;
1919
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt};
20-
use rustc_span::{def_id::DefId, Span};
20+
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
2121
use rustc_target::abi::{self, Align, HasDataLayout, Size, TargetDataLayout};
2222
use rustc_target::spec::abi::Abi as CallAbi;
2323
use rustc_trait_selection::traits;
@@ -328,9 +328,6 @@ struct ConstPropagator<'mir, 'tcx> {
328328
tcx: TyCtxt<'tcx>,
329329
param_env: ParamEnv<'tcx>,
330330
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>,
331-
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
332-
// the last known `SourceInfo` here and just keep revisiting it.
333-
source_info: Option<SourceInfo>,
334331
}
335332

336333
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {
@@ -411,13 +408,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
411408
)
412409
.expect("failed to push initial stack frame");
413410

414-
ConstPropagator {
415-
ecx,
416-
tcx,
417-
param_env,
418-
local_decls: &dummy_body.local_decls,
419-
source_info: None,
420-
}
411+
ConstPropagator { ecx, tcx, param_env, local_decls: &dummy_body.local_decls }
421412
}
422413

423414
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
@@ -495,7 +486,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
495486
*operand = self.operand_from_scalar(
496487
scalar,
497488
value.layout.ty,
498-
self.source_info.unwrap().span,
489+
DUMMY_SP,
499490
);
500491
}
501492
}
@@ -629,12 +620,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
629620
}))
630621
}
631622

632-
fn replace_with_const(
633-
&mut self,
634-
rval: &mut Rvalue<'tcx>,
635-
value: &OpTy<'tcx>,
636-
source_info: SourceInfo,
637-
) {
623+
fn replace_with_const(&mut self, rval: &mut Rvalue<'tcx>, value: &OpTy<'tcx>) {
638624
if let Rvalue::Use(Operand::Constant(c)) = rval {
639625
match c.literal {
640626
ConstantKind::Ty(c) if matches!(c.kind(), ConstKind::Unevaluated(..)) => {}
@@ -664,11 +650,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
664650
if let Some(Right(imm)) = imm {
665651
match *imm {
666652
interpret::Immediate::Scalar(scalar) => {
667-
*rval = Rvalue::Use(self.operand_from_scalar(
668-
scalar,
669-
value.layout.ty,
670-
source_info.span,
671-
));
653+
*rval =
654+
Rvalue::Use(self.operand_from_scalar(scalar, value.layout.ty, DUMMY_SP));
672655
}
673656
Immediate::ScalarPair(..) => {
674657
// 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> {
701684
let const_val = ConstValue::ByRef { alloc, offset: Size::ZERO };
702685
let literal = ConstantKind::Val(const_val, ty);
703686
*rval = Rvalue::Use(Operand::Constant(Box::new(Constant {
704-
span: source_info.span,
687+
span: DUMMY_SP,
705688
user_ty: None,
706689
literal,
707690
})));
@@ -894,8 +877,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
894877

895878
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
896879
trace!("visit_statement: {:?}", statement);
897-
let source_info = statement.source_info;
898-
self.source_info = Some(source_info);
899880
match statement.kind {
900881
StatementKind::Assign(box (place, ref mut rval)) => {
901882
let can_const_prop = self.ecx.machine.can_const_prop[place.local];
@@ -905,7 +886,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
905886
// consists solely of uninitialized memory (so it doesn't capture any locals).
906887
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
907888
trace!("replacing {:?} with {:?}", rval, value);
908-
self.replace_with_const(rval, value, source_info);
889+
self.replace_with_const(rval, value);
909890
if can_const_prop == ConstPropMode::FullConstProp
910891
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
911892
{
@@ -977,8 +958,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
977958
}
978959

979960
fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) {
980-
let source_info = terminator.source_info;
981-
self.source_info = Some(source_info);
982961
self.super_terminator(terminator, location);
983962

984963
match &mut terminator.kind {
@@ -991,7 +970,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
991970
*cond = self.operand_from_scalar(
992971
value_const,
993972
self.tcx.types.bool,
994-
source_info.span,
973+
DUMMY_SP,
995974
);
996975
}
997976
}

tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- switchInt(move _4) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
2323
+ _3 = const Option::<bool>::Some(true); // scope 2 at $DIR/discriminant.rs:+1:34: +1:44
2424
+ // mir::Constant
25-
+ // + span: $DIR/discriminant.rs:12:34: 12:44
25+
+ // + span: no-location
2626
+ // + literal: Const { ty: Option<bool>, val: Value(Scalar(0x01)) }
2727
+ _4 = const 1_isize; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31
2828
+ switchInt(const 1_isize) -> [1: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:+1:21: +1:31

tests/mir-opt/const_prop/invalid_constant.main.ConstProp.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
- _3 = [move _4]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
4545
+ _4 = const Scalar(0x00000004): E; // scope 4 at $DIR/invalid_constant.rs:+13:34: +13:57
4646
+ // mir::Constant
47-
+ // + span: $DIR/invalid_constant.rs:28:34: 28:57
47+
+ // + span: no-location
4848
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
4949
+ _3 = [const Scalar(0x00000004): E]; // scope 1 at $DIR/invalid_constant.rs:+13:24: +13:60
5050
+ // mir::Constant
51-
+ // + span: $DIR/invalid_constant.rs:28:24: 28:60
51+
+ // + span: no-location
5252
+ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) }
5353
StorageDead(_4); // scope 1 at $DIR/invalid_constant.rs:+13:59: +13:60
5454
StorageDead(_5); // scope 1 at $DIR/invalid_constant.rs:+13:60: +13:61

tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
- _6 = MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
5555
+ _6 = const MinusPlus; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
5656
+ // mir::Constant
57-
+ // + span: $DIR/funky_arms.rs:21:17: 21:41
57+
+ // + span: no-location
5858
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x01)) }
5959
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+10:17: +10:41
6060
}
@@ -63,7 +63,7 @@
6363
- _6 = Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
6464
+ _6 = const Minus; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
6565
+ // mir::Constant
66-
+ // + span: $DIR/funky_arms.rs:20:18: 20:38
66+
+ // + span: no-location
6767
+ // + literal: Const { ty: Sign, val: Value(Scalar(0x00)) }
6868
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:+9:18: +9:38
6969
}

0 commit comments

Comments
 (0)