@@ -84,7 +84,7 @@ impl<'a, 'tcx> Qualif {
84
84
}
85
85
86
86
/// What kind of item we are in.
87
- #[ derive( Copy , Clone , PartialEq , Eq ) ]
87
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
88
88
enum Mode {
89
89
Const ,
90
90
Static ,
@@ -383,6 +383,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
383
383
// Collect all the temps we need to promote.
384
384
let mut promoted_temps = BitSet :: new_empty ( self . temp_promotion_state . len ( ) ) ;
385
385
386
+ debug ! ( "qualify_const: promotion_candidates={:?}" , self . promotion_candidates) ;
386
387
for candidate in & self . promotion_candidates {
387
388
match * candidate {
388
389
Candidate :: Ref ( Location { block : bb, statement_index : stmt_idx } ) => {
@@ -414,6 +415,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
414
415
& local: & Local ,
415
416
_: PlaceContext < ' tcx > ,
416
417
_: Location ) {
418
+ debug ! ( "visit_local: local={:?}" , local) ;
417
419
let kind = self . mir . local_kind ( local) ;
418
420
match kind {
419
421
LocalKind :: ReturnPointer => {
@@ -435,6 +437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
435
437
}
436
438
437
439
if !self . temp_promotion_state [ local] . is_promotable ( ) {
440
+ debug ! ( "visit_local: (not promotable) local={:?}" , local) ;
438
441
self . add ( Qualif :: NOT_PROMOTABLE ) ;
439
442
}
440
443
@@ -451,6 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
451
454
place : & Place < ' tcx > ,
452
455
context : PlaceContext < ' tcx > ,
453
456
location : Location ) {
457
+ debug ! ( "visit_place: place={:?} context={:?} location={:?}" , place, context, location) ;
454
458
match * place {
455
459
Place :: Local ( ref local) => self . visit_local ( local, context, location) ,
456
460
Place :: Promoted ( _) => bug ! ( "promoting already promoted MIR" ) ,
@@ -557,6 +561,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
557
561
}
558
562
559
563
fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
564
+ debug ! ( "visit_operand: operand={:?} location={:?}" , operand, location) ;
560
565
self . super_operand ( operand, location) ;
561
566
562
567
match * operand {
@@ -591,6 +596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
591
596
}
592
597
593
598
fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
599
+ debug ! ( "visit_rvalue: rvalue={:?} location={:?}" , rvalue, location) ;
594
600
// Recurse through operands and places.
595
601
if let Rvalue :: Ref ( region, kind, ref place) = * rvalue {
596
602
let mut is_reborrow = false ;
@@ -696,6 +702,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
696
702
}
697
703
}
698
704
705
+ debug ! ( "visit_rvalue: forbidden_mut={:?}" , forbidden_mut) ;
699
706
if forbidden_mut {
700
707
self . add ( Qualif :: NOT_CONST ) ;
701
708
} else {
@@ -709,15 +716,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
709
716
}
710
717
place = & proj. base ;
711
718
}
719
+ debug ! ( "visit_rvalue: place={:?}" , place) ;
712
720
if let Place :: Local ( local) = * place {
713
721
if self . mir . local_kind ( local) == LocalKind :: Temp {
722
+ debug ! ( "visit_rvalue: local={:?}" , local) ;
714
723
if let Some ( qualif) = self . local_qualif [ local] {
715
724
// `forbidden_mut` is false, so we can safely ignore
716
725
// `MUTABLE_INTERIOR` from the local's qualifications.
717
726
// This allows borrowing fields which don't have
718
727
// `MUTABLE_INTERIOR`, from a type that does, e.g.:
719
728
// `let _: &'static _ = &(Cell::new(1), 2).1;`
729
+ debug ! ( "visit_rvalue: qualif={:?}" , qualif) ;
720
730
if ( qualif - Qualif :: MUTABLE_INTERIOR ) . is_empty ( ) {
731
+ debug ! ( "visit_rvalue: candidate={:?}" , candidate) ;
721
732
self . promotion_candidates . push ( candidate) ;
722
733
}
723
734
}
@@ -815,6 +826,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
815
826
bb : BasicBlock ,
816
827
kind : & TerminatorKind < ' tcx > ,
817
828
location : Location ) {
829
+ debug ! ( "visit_terminator_kind: bb={:?} kind={:?} location={:?}" , bb, kind, location) ;
818
830
if let TerminatorKind :: Call { ref func, ref args, ref destination, .. } = * kind {
819
831
self . visit_operand ( func, location) ;
820
832
@@ -972,6 +984,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
972
984
let candidate = Candidate :: Argument { bb, index : i } ;
973
985
if is_shuffle && i == 2 {
974
986
if this. qualif . is_empty ( ) {
987
+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
975
988
this. promotion_candidates . push ( candidate) ;
976
989
} else {
977
990
span_err ! ( this. tcx. sess, this. span, E0526 ,
@@ -998,6 +1011,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
998
1011
// We can error out with a hard error if the argument is not
999
1012
// constant here.
1000
1013
if ( this. qualif - Qualif :: NOT_PROMOTABLE ) . is_empty ( ) {
1014
+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
1001
1015
this. promotion_candidates . push ( candidate) ;
1002
1016
} else {
1003
1017
this. tcx . sess . span_err ( this. span ,
@@ -1075,6 +1089,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1075
1089
dest : & Place < ' tcx > ,
1076
1090
rvalue : & Rvalue < ' tcx > ,
1077
1091
location : Location ) {
1092
+ debug ! ( "visit_assign: dest={:?} rvalue={:?} location={:?}" , dest, rvalue, location) ;
1078
1093
self . visit_rvalue ( rvalue, location) ;
1079
1094
1080
1095
// Check the allowed const fn argument forms.
@@ -1123,10 +1138,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1123
1138
}
1124
1139
1125
1140
fn visit_source_info ( & mut self , source_info : & SourceInfo ) {
1141
+ debug ! ( "visit_source_info: source_info={:?}" , source_info) ;
1126
1142
self . span = source_info. span ;
1127
1143
}
1128
1144
1129
1145
fn visit_statement ( & mut self , bb : BasicBlock , statement : & Statement < ' tcx > , location : Location ) {
1146
+ debug ! ( "visit_statement: bb={:?} statement={:?} location={:?}" , bb, statement, location) ;
1130
1147
self . nest ( |this| {
1131
1148
this. visit_source_info ( & statement. source_info ) ;
1132
1149
match statement. kind {
@@ -1150,6 +1167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1150
1167
bb : BasicBlock ,
1151
1168
terminator : & Terminator < ' tcx > ,
1152
1169
location : Location ) {
1170
+ debug ! ( "visit_terminator: bb={:?} terminator={:?} location={:?}" , bb, terminator, location) ;
1153
1171
self . nest ( |this| this. super_terminator ( bb, terminator, location) ) ;
1154
1172
}
1155
1173
}
@@ -1216,6 +1234,7 @@ impl MirPass for QualifyAndPromoteConstants {
1216
1234
hir:: BodyOwnerKind :: Static ( hir:: MutMutable ) => Mode :: StaticMut ,
1217
1235
} ;
1218
1236
1237
+ debug ! ( "run_pass: mode={:?}" , mode) ;
1219
1238
if mode == Mode :: Fn || mode == Mode :: ConstFn {
1220
1239
// This is ugly because Qualifier holds onto mir,
1221
1240
// which can't be mutated until its scope ends.
@@ -1258,6 +1277,7 @@ impl MirPass for QualifyAndPromoteConstants {
1258
1277
// In `const` and `static` everything without `StorageDead`
1259
1278
// is `'static`, we don't have to create promoted MIR fragments,
1260
1279
// just remove `Drop` and `StorageDead` on "promoted" locals.
1280
+ debug ! ( "run_pass: promoted_temps={:?}" , promoted_temps) ;
1261
1281
for block in mir. basic_blocks_mut ( ) {
1262
1282
block. statements . retain ( |statement| {
1263
1283
match statement. kind {
0 commit comments