@@ -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
@@ -967,6 +979,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
967
979
let candidate = Candidate :: Argument { bb, index : i } ;
968
980
if is_shuffle && i == 2 {
969
981
if this. qualif . is_empty ( ) {
982
+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
970
983
this. promotion_candidates . push ( candidate) ;
971
984
} else {
972
985
span_err ! ( this. tcx. sess, this. span, E0526 ,
@@ -983,6 +996,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
983
996
return
984
997
}
985
998
if this. qualif . is_empty ( ) {
999
+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
986
1000
this. promotion_candidates . push ( candidate) ;
987
1001
} else {
988
1002
this. tcx . sess . span_err ( this. span ,
@@ -1056,6 +1070,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1056
1070
dest : & Place < ' tcx > ,
1057
1071
rvalue : & Rvalue < ' tcx > ,
1058
1072
location : Location ) {
1073
+ debug ! ( "visit_assign: dest={:?} rvalue={:?} location={:?}" , dest, rvalue, location) ;
1059
1074
self . visit_rvalue ( rvalue, location) ;
1060
1075
1061
1076
// Check the allowed const fn argument forms.
@@ -1104,10 +1119,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1104
1119
}
1105
1120
1106
1121
fn visit_source_info ( & mut self , source_info : & SourceInfo ) {
1122
+ debug ! ( "visit_source_info: source_info={:?}" , source_info) ;
1107
1123
self . span = source_info. span ;
1108
1124
}
1109
1125
1110
1126
fn visit_statement ( & mut self , bb : BasicBlock , statement : & Statement < ' tcx > , location : Location ) {
1127
+ debug ! ( "visit_statement: bb={:?} statement={:?} location={:?}" , bb, statement, location) ;
1111
1128
self . nest ( |this| {
1112
1129
this. visit_source_info ( & statement. source_info ) ;
1113
1130
match statement. kind {
@@ -1131,6 +1148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1131
1148
bb : BasicBlock ,
1132
1149
terminator : & Terminator < ' tcx > ,
1133
1150
location : Location ) {
1151
+ debug ! ( "visit_terminator: bb={:?} terminator={:?} location={:?}" , bb, terminator, location) ;
1134
1152
self . nest ( |this| this. super_terminator ( bb, terminator, location) ) ;
1135
1153
}
1136
1154
}
@@ -1197,6 +1215,7 @@ impl MirPass for QualifyAndPromoteConstants {
1197
1215
hir:: BodyOwnerKind :: Static ( hir:: MutMutable ) => Mode :: StaticMut ,
1198
1216
} ;
1199
1217
1218
+ debug ! ( "run_pass: mode={:?}" , mode) ;
1200
1219
if mode == Mode :: Fn || mode == Mode :: ConstFn {
1201
1220
// This is ugly because Qualifier holds onto mir,
1202
1221
// which can't be mutated until its scope ends.
@@ -1239,6 +1258,7 @@ impl MirPass for QualifyAndPromoteConstants {
1239
1258
// In `const` and `static` everything without `StorageDead`
1240
1259
// is `'static`, we don't have to create promoted MIR fragments,
1241
1260
// just remove `Drop` and `StorageDead` on "promoted" locals.
1261
+ debug ! ( "run_pass: promoted_temps={:?}" , promoted_temps) ;
1242
1262
for block in mir. basic_blocks_mut ( ) {
1243
1263
block. statements . retain ( |statement| {
1244
1264
match statement. kind {
0 commit comments