3
3
4
4
use rustc:: hir:: def:: DefKind ;
5
5
use rustc:: mir:: {
6
- AggregateKind , Constant , Location , Place , PlaceBase , Body , Operand , Rvalue , Local ,
7
- NullOp , UnOp , StatementKind , Statement , LocalKind , Static , StaticKind ,
6
+ AggregateKind , Constant , Location , Place , PlaceBase , Body , Operand , Rvalue ,
7
+ Local , NullOp , UnOp , StatementKind , Statement , LocalKind , Static , StaticKind ,
8
8
TerminatorKind , Terminator , ClearCrossCrate , SourceInfo , BinOp , ProjectionElem ,
9
9
SourceScope , SourceScopeLocalData , LocalDecl , Promoted ,
10
10
} ;
@@ -21,7 +21,9 @@ use rustc::ty::layout::{
21
21
HasTyCtxt , TargetDataLayout , HasDataLayout ,
22
22
} ;
23
23
24
- use crate :: interpret:: { self , InterpretCx , ScalarMaybeUndef , Immediate , OpTy , ImmTy , MemoryKind } ;
24
+ use crate :: interpret:: {
25
+ self , InterpretCx , ScalarMaybeUndef , Immediate , OpTy , ImmTy , MemoryKind ,
26
+ } ;
25
27
use crate :: const_eval:: {
26
28
CompileTimeInterpreter , error_to_const_error, eval_promoted, mk_eval_cx,
27
29
} ;
@@ -516,7 +518,12 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
516
518
) )
517
519
}
518
520
519
- fn replace_with_const ( & self , rval : & mut Rvalue < ' tcx > , value : Const < ' tcx > , span : Span ) {
521
+ fn replace_with_const (
522
+ & mut self ,
523
+ rval : & mut Rvalue < ' tcx > ,
524
+ value : Const < ' tcx > ,
525
+ source_info : SourceInfo ,
526
+ ) {
520
527
trace ! ( "attepting to replace {:?} with {:?}" , rval, value) ;
521
528
self . ecx . validate_operand (
522
529
value,
@@ -525,10 +532,16 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
525
532
true ,
526
533
) . expect ( "value should already be a valid const" ) ;
527
534
528
- if let interpret:: Operand :: Immediate ( im) = * value {
529
- match im {
535
+ // FIXME> figure out what tho do when try_read_immediate fails
536
+ let imm = self . use_ecx ( source_info, |this| {
537
+ this. ecx . try_read_immediate ( value)
538
+ } ) ;
539
+
540
+ if let Some ( Ok ( imm) ) = imm {
541
+ match imm {
530
542
interpret:: Immediate :: Scalar ( ScalarMaybeUndef :: Scalar ( scalar) ) => {
531
- * rval = Rvalue :: Use ( self . operand_from_scalar ( scalar, value. layout . ty , span) ) ;
543
+ * rval = Rvalue :: Use (
544
+ self . operand_from_scalar ( scalar, value. layout . ty , source_info. span ) ) ;
532
545
} ,
533
546
Immediate :: ScalarPair (
534
547
ScalarMaybeUndef :: Scalar ( one) ,
@@ -539,8 +552,12 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
539
552
* rval = Rvalue :: Aggregate (
540
553
Box :: new ( AggregateKind :: Tuple ) ,
541
554
vec ! [
542
- self . operand_from_scalar( one, substs[ 0 ] . expect_ty( ) , span) ,
543
- self . operand_from_scalar( two, substs[ 1 ] . expect_ty( ) , span) ,
555
+ self . operand_from_scalar(
556
+ one, substs[ 0 ] . expect_ty( ) , source_info. span
557
+ ) ,
558
+ self . operand_from_scalar(
559
+ two, substs[ 1 ] . expect_ty( ) , source_info. span
560
+ ) ,
544
561
] ,
545
562
) ;
546
563
}
@@ -655,7 +672,11 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
655
672
self . places [ local] = Some ( value) ;
656
673
657
674
if self . should_const_prop ( ) {
658
- self . replace_with_const ( rval, value, statement. source_info . span ) ;
675
+ self . replace_with_const (
676
+ rval,
677
+ value,
678
+ statement. source_info ,
679
+ ) ;
659
680
}
660
681
}
661
682
}
0 commit comments