@@ -360,6 +360,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
360360 ConstPropagator { ecx, tcx, param_env, local_decls : & body. local_decls , patch }
361361 }
362362
363+ #[ instrument( skip( self ) , level = "debug" ) ]
363364 fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
364365 let op = match self . ecx . eval_place_to_op ( place, None ) {
365366 Ok ( op) => {
@@ -381,10 +382,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
381382
382383 // Try to read the local as an immediate so that if it is representable as a scalar, we can
383384 // 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) {
385386 Ok ( Right ( imm) ) => imm. into ( ) ,
386387 _ => op,
387- } )
388+ } ) ;
389+
390+ trace ! ( "found = {r:?}" ) ;
391+
392+ r
388393 }
389394
390395 /// Remove `local` from the pool of `Locals`. Allows writing to them,
@@ -394,6 +399,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
394399 ecx. machine . written_only_inside_own_block_locals . remove ( & local) ;
395400 }
396401
402+ #[ instrument( skip( self ) , level = "debug" ) ]
397403 fn check_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > ) -> Option < ( ) > {
398404 // Perform any special handling for specific Rvalue types.
399405 // Generally, checks here fall into one of two categories:
@@ -509,6 +515,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
509515 }
510516 }
511517
518+ #[ instrument( skip( self ) , level = "debug" ) ]
512519 fn replace_with_const ( & mut self , place : Place < ' tcx > ) -> Option < Const < ' tcx > > {
513520 // This will return None if the above `const_prop` invocation only "wrote" a
514521 // type whose creation requires no write. E.g. a coroutine whose initial state
@@ -611,6 +618,7 @@ impl CanConstProp {
611618}
612619
613620impl < ' tcx > Visitor < ' tcx > for CanConstProp {
621+ #[ instrument( skip( self ) , level = "debug" ) ]
614622 fn visit_place ( & mut self , place : & Place < ' tcx > , mut context : PlaceContext , loc : Location ) {
615623 use rustc_middle:: mir:: visit:: PlaceContext :: * ;
616624
@@ -623,6 +631,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
623631 self . visit_projection ( place. as_ref ( ) , context, loc) ;
624632 }
625633
634+ #[ instrument( skip( self ) , level = "debug" ) ]
626635 fn visit_local ( & mut self , local : Local , context : PlaceContext , _: Location ) {
627636 use rustc_middle:: mir:: visit:: PlaceContext :: * ;
628637 match context {
@@ -681,15 +690,22 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
681690}
682691
683692impl < ' tcx > Visitor < ' tcx > for ConstPropagator < ' _ , ' tcx > {
693+ #[ instrument( skip( self ) , level = "debug" ) ]
684694 fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
685695 self . super_operand ( operand, location) ;
696+
697+ trace ! ( "about to do it" ) ;
698+
686699 if let Some ( place) = operand. place ( )
687700 && let Some ( value) = self . replace_with_const ( place)
688701 {
702+ trace ! ( ?place, ?value, "know whats going on" ) ;
689703 self . patch . before_effect . insert ( ( location, place) , value) ;
690704 }
691705 }
692706
707+ #[ instrument( skip( self ) , level = "debug" ) ]
708+
693709 fn visit_projection_elem (
694710 & mut self ,
695711 _: PlaceRef < ' tcx > ,
@@ -704,6 +720,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
704720 }
705721 }
706722
723+ #[ instrument( skip( self ) , level = "debug" ) ]
707724 fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
708725 self . super_assign ( place, rvalue, location) ;
709726
@@ -714,14 +731,14 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
714731 _ if place. is_indirect ( ) => { }
715732 ConstPropMode :: NoPropagation => self . ensure_not_propagated ( place. local ) ,
716733 ConstPropMode :: OnlyInsideOwnBlock | ConstPropMode :: FullConstProp => {
734+ trace ! ( "trying to do some const-prop" ) ;
717735 if let Some ( ( ) ) = self . eval_rvalue_with_identities ( rvalue, * place) {
718736 // If this was already an evaluated constant, keep it.
719737 if let Rvalue :: Use ( Operand :: Constant ( c) ) = rvalue
720738 && let Const :: Val ( ..) = c. const_
721739 {
722740 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"
725742 ) ;
726743 } else if let Some ( operand) = self . replace_with_const ( * place) {
727744 self . patch . assignments . insert ( location, operand) ;
@@ -748,8 +765,12 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
748765 }
749766 }
750767
768+ #[ instrument( skip( self ) , level = "trace" ) ]
751769 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+ }
753774
754775 // We want to evaluate operands before any change to the assigned-to value,
755776 // so we recurse first.
@@ -790,6 +811,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
790811 // In both cases, this does not matter, as those reads would be UB anyway.
791812 _ => { }
792813 }
814+
815+ {
816+ let frame = & self . ecx . frame ( ) . locals ;
817+ trace ! ( ?frame, "final frame" ) ;
818+ }
793819 }
794820
795821 fn visit_basic_block_data ( & mut self , block : BasicBlock , data : & BasicBlockData < ' tcx > ) {
0 commit comments