@@ -5,6 +5,7 @@ use std::fmt::Debug;
55
66use rustc_const_eval:: interpret:: { ImmTy , Projectable } ;
77use rustc_const_eval:: interpret:: { InterpCx , InterpResult , OpTy , Scalar } ;
8+ use rustc_data_structures:: fx:: FxHashSet ;
89use rustc_hir:: def:: DefKind ;
910use rustc_hir:: HirId ;
1011use rustc_index:: bit_set:: BitSet ;
@@ -76,6 +77,8 @@ struct ConstPropagator<'mir, 'tcx> {
7677 visited_blocks : BitSet < BasicBlock > ,
7778 locals : IndexVec < Local , Value < ' tcx > > ,
7879 body : & ' mir Body < ' tcx > ,
80+ written_only_inside_own_block_locals : FxHashSet < Local > ,
81+ can_const_prop : IndexVec < Local , ConstPropMode > ,
7982}
8083
8184#[ derive( Debug , Clone ) ]
@@ -181,12 +184,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
181184 let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
182185
183186 let can_const_prop = CanConstProp :: check ( tcx, param_env, body) ;
184- let ecx = InterpCx :: new (
185- tcx,
186- tcx. def_span ( def_id) ,
187- param_env,
188- ConstPropMachine :: new ( can_const_prop) ,
189- ) ;
187+ let ecx = InterpCx :: new ( tcx, tcx. def_span ( def_id) , param_env, ConstPropMachine ) ;
190188
191189 ConstPropagator {
192190 ecx,
@@ -196,6 +194,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
196194 visited_blocks : BitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
197195 locals : IndexVec :: from_elem_n ( Value :: Uninit , body. local_decls . len ( ) ) ,
198196 body,
197+ can_const_prop,
198+ written_only_inside_own_block_locals : Default :: default ( ) ,
199199 }
200200 }
201201
@@ -212,14 +212,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
212212 /// but not reading from them anymore.
213213 fn remove_const ( & mut self , local : Local ) {
214214 self . locals [ local] = Value :: Uninit ;
215- self . ecx . machine . written_only_inside_own_block_locals . remove ( & local) ;
215+ self . written_only_inside_own_block_locals . remove ( & local) ;
216216 }
217217
218218 fn access_mut ( & mut self , place : & Place < ' _ > ) -> Option < & mut Value < ' tcx > > {
219- match self . ecx . machine . can_const_prop [ place. local ] {
219+ match self . can_const_prop [ place. local ] {
220220 ConstPropMode :: NoPropagation => return None ,
221221 ConstPropMode :: OnlyInsideOwnBlock => {
222- self . ecx . machine . written_only_inside_own_block_locals . insert ( place. local ) ;
222+ self . written_only_inside_own_block_locals . insert ( place. local ) ;
223223 }
224224 ConstPropMode :: FullConstProp => { }
225225 }
@@ -776,7 +776,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
776776
777777 let Some ( ( ) ) = self . check_rvalue ( rvalue, location) else { return } ;
778778
779- match self . ecx . machine . can_const_prop [ place. local ] {
779+ match self . can_const_prop [ place. local ] {
780780 // Do nothing if the place is indirect.
781781 _ if place. is_indirect ( ) => { }
782782 ConstPropMode :: NoPropagation => self . ensure_not_propagated ( place. local ) ,
@@ -812,7 +812,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
812812
813813 match statement. kind {
814814 StatementKind :: SetDiscriminant { ref place, variant_index } => {
815- match self . ecx . machine . can_const_prop [ place. local ] {
815+ match self . can_const_prop [ place. local ] {
816816 // Do nothing if the place is indirect.
817817 _ if place. is_indirect ( ) => { }
818818 ConstPropMode :: NoPropagation => self . ensure_not_propagated ( place. local ) ,
@@ -879,23 +879,19 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
879879 // which were modified in the current block.
880880 // Take it out of the ecx so we can get a mutable reference to the ecx for `remove_const`.
881881 let mut written_only_inside_own_block_locals =
882- std:: mem:: take ( & mut self . ecx . machine . written_only_inside_own_block_locals ) ;
882+ std:: mem:: take ( & mut self . written_only_inside_own_block_locals ) ;
883883
884884 // This loop can get very hot for some bodies: it check each local in each bb.
885885 // To avoid this quadratic behaviour, we only clear the locals that were modified inside
886886 // the current block.
887887 for local in written_only_inside_own_block_locals. drain ( ) {
888- debug_assert_eq ! (
889- self . ecx. machine. can_const_prop[ local] ,
890- ConstPropMode :: OnlyInsideOwnBlock
891- ) ;
888+ debug_assert_eq ! ( self . can_const_prop[ local] , ConstPropMode :: OnlyInsideOwnBlock ) ;
892889 self . remove_const ( local) ;
893890 }
894- self . ecx . machine . written_only_inside_own_block_locals =
895- written_only_inside_own_block_locals;
891+ self . written_only_inside_own_block_locals = written_only_inside_own_block_locals;
896892
897893 if cfg ! ( debug_assertions) {
898- for ( local, & mode) in self . ecx . machine . can_const_prop . iter_enumerated ( ) {
894+ for ( local, & mode) in self . can_const_prop . iter_enumerated ( ) {
899895 match mode {
900896 ConstPropMode :: FullConstProp => { }
901897 ConstPropMode :: NoPropagation | ConstPropMode :: OnlyInsideOwnBlock => {
0 commit comments