@@ -360,6 +360,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
360
360
ConstPropagator { ecx, tcx, param_env, local_decls : & body. local_decls , patch }
361
361
}
362
362
363
+ #[ instrument( skip( self ) , level = "debug" ) ]
363
364
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
364
365
let op = match self . ecx . eval_place_to_op ( place, None ) {
365
366
Ok ( op) => {
@@ -381,10 +382,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
381
382
382
383
// Try to read the local as an immediate so that if it is representable as a scalar, we can
383
384
// handle it as such, but otherwise, just return the value as is.
384
- Some ( match self . ecx . read_immediate_raw ( & op) {
385
+ let r = Some ( match self . ecx . read_immediate_raw ( & op) {
385
386
Ok ( Right ( imm) ) => imm. into ( ) ,
386
387
_ => op,
387
- } )
388
+ } ) ;
389
+
390
+ trace ! ( "found = {r:?}" ) ;
391
+
392
+ r
388
393
}
389
394
390
395
/// Remove `local` from the pool of `Locals`. Allows writing to them,
@@ -394,6 +399,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
394
399
ecx. machine . written_only_inside_own_block_locals . remove ( & local) ;
395
400
}
396
401
402
+ #[ instrument( skip( self ) , level = "debug" ) ]
397
403
fn check_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > ) -> Option < ( ) > {
398
404
// Perform any special handling for specific Rvalue types.
399
405
// Generally, checks here fall into one of two categories:
@@ -509,6 +515,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
509
515
}
510
516
}
511
517
518
+ #[ instrument( skip( self ) , level = "debug" ) ]
512
519
fn replace_with_const ( & mut self , place : Place < ' tcx > ) -> Option < Const < ' tcx > > {
513
520
// This will return None if the above `const_prop` invocation only "wrote" a
514
521
// type whose creation requires no write. E.g. a coroutine whose initial state
@@ -611,6 +618,7 @@ impl CanConstProp {
611
618
}
612
619
613
620
impl < ' tcx > Visitor < ' tcx > for CanConstProp {
621
+ #[ instrument( skip( self ) , level = "debug" ) ]
614
622
fn visit_place ( & mut self , place : & Place < ' tcx > , mut context : PlaceContext , loc : Location ) {
615
623
use rustc_middle:: mir:: visit:: PlaceContext :: * ;
616
624
@@ -623,6 +631,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
623
631
self . visit_projection ( place. as_ref ( ) , context, loc) ;
624
632
}
625
633
634
+ #[ instrument( skip( self ) , level = "debug" ) ]
626
635
fn visit_local ( & mut self , local : Local , context : PlaceContext , _: Location ) {
627
636
use rustc_middle:: mir:: visit:: PlaceContext :: * ;
628
637
match context {
@@ -681,15 +690,22 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
681
690
}
682
691
683
692
impl < ' tcx > Visitor < ' tcx > for ConstPropagator < ' _ , ' tcx > {
693
+ #[ instrument( skip( self ) , level = "debug" ) ]
684
694
fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
685
695
self . super_operand ( operand, location) ;
696
+
697
+ trace ! ( "about to do it" ) ;
698
+
686
699
if let Some ( place) = operand. place ( )
687
700
&& let Some ( value) = self . replace_with_const ( place)
688
701
{
702
+ trace ! ( ?place, ?value, "know whats going on" ) ;
689
703
self . patch . before_effect . insert ( ( location, place) , value) ;
690
704
}
691
705
}
692
706
707
+ #[ instrument( skip( self ) , level = "debug" ) ]
708
+
693
709
fn visit_projection_elem (
694
710
& mut self ,
695
711
_: PlaceRef < ' tcx > ,
@@ -704,6 +720,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
704
720
}
705
721
}
706
722
723
+ #[ instrument( skip( self ) , level = "debug" ) ]
707
724
fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
708
725
self . super_assign ( place, rvalue, location) ;
709
726
@@ -714,14 +731,14 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
714
731
_ if place. is_indirect ( ) => { }
715
732
ConstPropMode :: NoPropagation => self . ensure_not_propagated ( place. local ) ,
716
733
ConstPropMode :: OnlyInsideOwnBlock | ConstPropMode :: FullConstProp => {
734
+ trace ! ( "trying to do some const-prop" ) ;
717
735
if let Some ( ( ) ) = self . eval_rvalue_with_identities ( rvalue, * place) {
718
736
// If this was already an evaluated constant, keep it.
719
737
if let Rvalue :: Use ( Operand :: Constant ( c) ) = rvalue
720
738
&& let Const :: Val ( ..) = c. const_
721
739
{
722
740
trace ! (
723
- "skipping replace of Rvalue::Use({:?} because it is already a const" ,
724
- c
741
+ "skipping replace of Rvalue::Use({c:?}) because it is already a const"
725
742
) ;
726
743
} else if let Some ( operand) = self . replace_with_const ( * place) {
727
744
self . patch . assignments . insert ( location, operand) ;
@@ -748,8 +765,12 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
748
765
}
749
766
}
750
767
768
+ #[ instrument( skip( self ) , level = "trace" ) ]
751
769
fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
752
- trace ! ( "visit_statement: {:?}" , statement) ;
770
+ {
771
+ let frame = & self . ecx . frame ( ) . locals ;
772
+ trace ! ( ?frame, "initial frame" ) ;
773
+ }
753
774
754
775
// We want to evaluate operands before any change to the assigned-to value,
755
776
// so we recurse first.
@@ -790,6 +811,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
790
811
// In both cases, this does not matter, as those reads would be UB anyway.
791
812
_ => { }
792
813
}
814
+
815
+ {
816
+ let frame = & self . ecx . frame ( ) . locals ;
817
+ trace ! ( ?frame, "final frame" ) ;
818
+ }
793
819
}
794
820
795
821
fn visit_basic_block_data ( & mut self , block : BasicBlock , data : & BasicBlockData < ' tcx > ) {
0 commit comments