@@ -62,7 +62,8 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
62
62
let def_id = src. def_id ( ) ;
63
63
64
64
let mut rpo = traversal:: reverse_postorder ( body) ;
65
- let ( temps, all_candidates) = collect_temps_and_candidates ( tcx, body, & mut rpo) ;
65
+ let ccx = ConstCx :: new ( tcx, def_id, body) ;
66
+ let ( temps, all_candidates) = collect_temps_and_candidates ( & ccx, & mut rpo) ;
66
67
67
68
let promotable_candidates = validate_candidates ( tcx, body, def_id, & temps, & all_candidates) ;
68
69
@@ -139,8 +140,7 @@ fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
139
140
}
140
141
141
142
struct Collector < ' a , ' tcx > {
142
- tcx : TyCtxt < ' tcx > ,
143
- body : & ' a Body < ' tcx > ,
143
+ ccx : & ' a ConstCx < ' a , ' tcx > ,
144
144
temps : IndexVec < Local , TempState > ,
145
145
candidates : Vec < Candidate > ,
146
146
span : Span ,
@@ -150,7 +150,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
150
150
fn visit_local ( & mut self , & index: & Local , context : PlaceContext , location : Location ) {
151
151
debug ! ( "visit_local: index={:?} context={:?} location={:?}" , index, context, location) ;
152
152
// We're only interested in temporaries and the return place
153
- match self . body . local_kind ( index) {
153
+ match self . ccx . body . local_kind ( index) {
154
154
LocalKind :: Temp | LocalKind :: ReturnPointer => { }
155
155
LocalKind :: Arg | LocalKind :: Var => return ,
156
156
}
@@ -203,7 +203,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
203
203
Rvalue :: Ref ( ..) => {
204
204
self . candidates . push ( Candidate :: Ref ( location) ) ;
205
205
}
206
- Rvalue :: Repeat ( ..) if self . tcx . features ( ) . const_in_array_repeat_expressions => {
206
+ Rvalue :: Repeat ( ..) if self . ccx . tcx . features ( ) . const_in_array_repeat_expressions => {
207
207
// FIXME(#49147) only promote the element when it isn't `Copy`
208
208
// (so that code that can copy it at runtime is unaffected).
209
209
self . candidates . push ( Candidate :: Repeat ( location) ) ;
@@ -216,10 +216,10 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
216
216
self . super_terminator_kind ( kind, location) ;
217
217
218
218
if let TerminatorKind :: Call { ref func, .. } = * kind {
219
- if let ty:: FnDef ( def_id, _) = func. ty ( self . body , self . tcx ) . kind {
220
- let fn_sig = self . tcx . fn_sig ( def_id) ;
219
+ if let ty:: FnDef ( def_id, _) = func. ty ( self . ccx . body , self . ccx . tcx ) . kind {
220
+ let fn_sig = self . ccx . tcx . fn_sig ( def_id) ;
221
221
if let Abi :: RustIntrinsic | Abi :: PlatformIntrinsic = fn_sig. abi ( ) {
222
- let name = self . tcx . item_name ( def_id) ;
222
+ let name = self . ccx . tcx . item_name ( def_id) ;
223
223
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
224
224
if name. as_str ( ) . starts_with ( "simd_shuffle" ) {
225
225
self . candidates . push ( Candidate :: Argument { bb : location. block , index : 2 } ) ;
@@ -228,7 +228,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
228
228
}
229
229
}
230
230
231
- if let Some ( constant_args) = args_required_const ( self . tcx , def_id) {
231
+ if let Some ( constant_args) = args_required_const ( self . ccx . tcx , def_id) {
232
232
for index in constant_args {
233
233
self . candidates . push ( Candidate :: Argument { bb : location. block , index } ) ;
234
234
}
@@ -243,16 +243,14 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
243
243
}
244
244
245
245
pub fn collect_temps_and_candidates (
246
- tcx : TyCtxt < ' tcx > ,
247
- body : & Body < ' tcx > ,
246
+ ccx : & ConstCx < ' mir , ' tcx > ,
248
247
rpo : & mut ReversePostorder < ' _ , ' tcx > ,
249
248
) -> ( IndexVec < Local , TempState > , Vec < Candidate > ) {
250
249
let mut collector = Collector {
251
- tcx,
252
- body,
253
- temps : IndexVec :: from_elem ( TempState :: Undefined , & body. local_decls ) ,
250
+ temps : IndexVec :: from_elem ( TempState :: Undefined , & ccx. body . local_decls ) ,
254
251
candidates : vec ! [ ] ,
255
- span : body. span ,
252
+ span : ccx. body . span ,
253
+ ccx,
256
254
} ;
257
255
for ( bb, data) in rpo {
258
256
collector. visit_basic_block_data ( bb, data) ;
@@ -1151,7 +1149,7 @@ crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>(
1151
1149
operand : & Operand < ' tcx > ,
1152
1150
) -> bool {
1153
1151
let mut rpo = traversal:: reverse_postorder ( & ccx. body ) ;
1154
- let ( temps, _) = collect_temps_and_candidates ( ccx . tcx , & ccx. body , & mut rpo) ;
1152
+ let ( temps, _) = collect_temps_and_candidates ( & ccx, & mut rpo) ;
1155
1153
let validator = Validator { ccx, temps : & temps, explicit : false } ;
1156
1154
1157
1155
let should_promote = validator. validate_operand ( operand) . is_ok ( ) ;
0 commit comments