@@ -29,12 +29,6 @@ enum EdgeKind {
29
29
pub ( super ) struct Validator {
30
30
/// Describes at which point in the pipeline this validation is happening.
31
31
pub when : String ,
32
- /// The phase for which we are upholding the dialect. If the given phase forbids a specific
33
- /// element, this validator will now emit errors if that specific element is encountered.
34
- /// Note that phases that change the dialect cause all *following* phases to check the
35
- /// invariants of the new dialect. A phase that changes dialects never checks the new invariants
36
- /// itself.
37
- pub mir_phase : MirPhase ,
38
32
}
39
33
40
34
impl < ' tcx > crate :: MirPass < ' tcx > for Validator {
@@ -46,11 +40,9 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
46
40
if matches ! ( body. source. instance, InstanceKind :: Intrinsic ( ..) | InstanceKind :: Virtual ( ..) ) {
47
41
return ;
48
42
}
49
- debug_assert_eq ! ( self . mir_phase, body. phase) ;
50
43
let def_id = body. source . def_id ( ) ;
51
- let mir_phase = body. phase ;
52
44
let typing_env = body. typing_env ( tcx) ;
53
- let can_unwind = if mir_phase <= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
45
+ let can_unwind = if body . phase <= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
54
46
// In this case `AbortUnwindingCalls` haven't yet been executed.
55
47
true
56
48
} else if !tcx. def_kind ( def_id) . is_fn_like ( ) {
@@ -64,9 +56,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
64
56
ty:: Coroutine ( ..) => ExternAbi :: Rust ,
65
57
// No need to do MIR validation on error bodies
66
58
ty:: Error ( _) => return ,
67
- _ => {
68
- span_bug ! ( body. span, "unexpected body ty: {:?} phase {:?}" , body_ty, mir_phase)
69
- }
59
+ _ => span_bug ! ( body. span, "unexpected body ty: {body_ty:?}" ) ,
70
60
} ;
71
61
72
62
ty:: layout:: fn_can_unwind ( tcx, Some ( def_id) , body_abi)
@@ -76,7 +66,6 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
76
66
when : & self . when ,
77
67
body,
78
68
tcx,
79
- mir_phase,
80
69
unwind_edge_count : 0 ,
81
70
reachable_blocks : traversal:: reachable_as_bitset ( body) ,
82
71
value_cache : FxHashSet :: default ( ) ,
@@ -86,7 +75,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
86
75
cfg_checker. check_cleanup_control_flow ( ) ;
87
76
88
77
// Also run the TypeChecker.
89
- for ( location, msg) in validate_types ( tcx, self . mir_phase , typing_env, body, body) {
78
+ for ( location, msg) in validate_types ( tcx, typing_env, body, body) {
90
79
cfg_checker. fail ( location, msg) ;
91
80
}
92
81
@@ -107,7 +96,6 @@ struct CfgChecker<'a, 'tcx> {
107
96
when : & ' a str ,
108
97
body : & ' a Body < ' tcx > ,
109
98
tcx : TyCtxt < ' tcx > ,
110
- mir_phase : MirPhase ,
111
99
unwind_edge_count : usize ,
112
100
reachable_blocks : BitSet < BasicBlock > ,
113
101
value_cache : FxHashSet < u128 > ,
@@ -294,41 +282,41 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
294
282
fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
295
283
match & statement. kind {
296
284
StatementKind :: AscribeUserType ( ..) => {
297
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
285
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
298
286
self . fail (
299
287
location,
300
288
"`AscribeUserType` should have been removed after drop lowering phase" ,
301
289
) ;
302
290
}
303
291
}
304
292
StatementKind :: FakeRead ( ..) => {
305
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
293
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
306
294
self . fail (
307
295
location,
308
296
"`FakeRead` should have been removed after drop lowering phase" ,
309
297
) ;
310
298
}
311
299
}
312
300
StatementKind :: SetDiscriminant { .. } => {
313
- if self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
301
+ if self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
314
302
self . fail ( location, "`SetDiscriminant`is not allowed until deaggregation" ) ;
315
303
}
316
304
}
317
305
StatementKind :: Deinit ( ..) => {
318
- if self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
306
+ if self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
319
307
self . fail ( location, "`Deinit`is not allowed until deaggregation" ) ;
320
308
}
321
309
}
322
310
StatementKind :: Retag ( kind, _) => {
323
- // FIXME(JakobDegen) The validator should check that `self.mir_phase <
311
+ // FIXME(JakobDegen) The validator should check that `self.body.phase <
324
312
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
325
313
// seem to fail to set their `MirPhase` correctly.
326
314
if matches ! ( kind, RetagKind :: TwoPhase ) {
327
315
self . fail ( location, format ! ( "explicit `{kind:?}` is forbidden" ) ) ;
328
316
}
329
317
}
330
318
StatementKind :: Coverage ( kind) => {
331
- if self . mir_phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup )
319
+ if self . body . phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup )
332
320
&& let CoverageKind :: BlockMarker { .. } | CoverageKind :: SpanMarker { .. } = kind
333
321
{
334
322
self . fail (
@@ -391,7 +379,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
391
379
// the return edge from the call. FIXME(tmiasko): Since this is a strictly code
392
380
// generation concern, the code generation should be responsible for handling
393
381
// it.
394
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Optimized )
382
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Optimized )
395
383
&& self . is_critical_call_edge ( target, unwind)
396
384
{
397
385
self . fail (
@@ -440,7 +428,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
440
428
if self . body . coroutine . is_none ( ) {
441
429
self . fail ( location, "`Yield` cannot appear outside coroutine bodies" ) ;
442
430
}
443
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
431
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
444
432
self . fail ( location, "`Yield` should have been replaced by coroutine lowering" ) ;
445
433
}
446
434
self . check_edge ( location, * resume, EdgeKind :: Normal ) ;
@@ -449,7 +437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
449
437
}
450
438
}
451
439
TerminatorKind :: FalseEdge { real_target, imaginary_target } => {
452
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
440
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
453
441
self . fail (
454
442
location,
455
443
"`FalseEdge` should have been removed after drop elaboration" ,
@@ -459,7 +447,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
459
447
self . check_edge ( location, * imaginary_target, EdgeKind :: Normal ) ;
460
448
}
461
449
TerminatorKind :: FalseUnwind { real_target, unwind } => {
462
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
450
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
463
451
self . fail (
464
452
location,
465
453
"`FalseUnwind` should have been removed after drop elaboration" ,
@@ -478,7 +466,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
478
466
if self . body . coroutine . is_none ( ) {
479
467
self . fail ( location, "`CoroutineDrop` cannot appear outside coroutine bodies" ) ;
480
468
}
481
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
469
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
482
470
self . fail (
483
471
location,
484
472
"`CoroutineDrop` should have been replaced by coroutine lowering" ,
@@ -532,13 +520,11 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
532
520
/// `optimized_mir` is available.
533
521
pub ( super ) fn validate_types < ' tcx > (
534
522
tcx : TyCtxt < ' tcx > ,
535
- mir_phase : MirPhase ,
536
523
typing_env : ty:: TypingEnv < ' tcx > ,
537
524
body : & Body < ' tcx > ,
538
525
caller_body : & Body < ' tcx > ,
539
526
) -> Vec < ( Location , String ) > {
540
- let mut type_checker =
541
- TypeChecker { body, caller_body, tcx, typing_env, mir_phase, failures : Vec :: new ( ) } ;
527
+ let mut type_checker = TypeChecker { body, caller_body, tcx, typing_env, failures : Vec :: new ( ) } ;
542
528
type_checker. visit_body ( body) ;
543
529
type_checker. failures
544
530
}
@@ -548,7 +534,6 @@ struct TypeChecker<'a, 'tcx> {
548
534
caller_body : & ' a Body < ' tcx > ,
549
535
tcx : TyCtxt < ' tcx > ,
550
536
typing_env : ty:: TypingEnv < ' tcx > ,
551
- mir_phase : MirPhase ,
552
537
failures : Vec < ( Location , String ) > ,
553
538
}
554
539
@@ -577,7 +562,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
577
562
578
563
// After borrowck subtyping should be fully explicit via
579
564
// `Subtype` projections.
580
- let variance = if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
565
+ let variance = if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
581
566
Variance :: Invariant
582
567
} else {
583
568
Variance :: Covariant
@@ -618,7 +603,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
618
603
fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
619
604
// This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
620
605
if self . tcx . sess . opts . unstable_opts . validate_mir
621
- && self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial )
606
+ && self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial )
622
607
{
623
608
// `Operand::Copy` is only supposed to be used with `Copy` types.
624
609
if let Operand :: Copy ( place) = operand {
@@ -642,7 +627,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
642
627
) {
643
628
match elem {
644
629
ProjectionElem :: OpaqueCast ( ty)
645
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) =>
630
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) =>
646
631
{
647
632
self . fail (
648
633
location,
@@ -656,7 +641,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
656
641
}
657
642
}
658
643
ProjectionElem :: Deref
659
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: PostCleanup ) =>
644
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: PostCleanup ) =>
660
645
{
661
646
let base_ty = place_ref. ty ( & self . body . local_decls , self . tcx ) . ty ;
662
647
@@ -856,7 +841,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
856
841
// Set off any `bug!`s in the type computation code
857
842
let _ = place. ty ( & self . body . local_decls , self . tcx ) ;
858
843
859
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial )
844
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial )
860
845
&& place. projection . len ( ) > 1
861
846
&& cntxt != PlaceContext :: NonUse ( NonUseContext :: VarDebugInfo )
862
847
&& place. projection [ 1 ..] . contains ( & ProjectionElem :: Deref )
@@ -974,7 +959,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
974
959
}
975
960
}
976
961
AggregateKind :: RawPtr ( pointee_ty, mutability) => {
977
- if !matches ! ( self . mir_phase , MirPhase :: Runtime ( _) ) {
962
+ if !matches ! ( self . body . phase , MirPhase :: Runtime ( _) ) {
978
963
// It would probably be fine to support this in earlier phases, but at the
979
964
// time of writing it's only ever introduced from intrinsic lowering, so
980
965
// earlier things just `bug!` on it.
@@ -1016,7 +1001,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1016
1001
}
1017
1002
} ,
1018
1003
Rvalue :: Ref ( _, BorrowKind :: Fake ( _) , _) => {
1019
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1004
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1020
1005
self . fail (
1021
1006
location,
1022
1007
"`Assign` statement with a `Fake` borrow should have been removed in runtime MIR" ,
@@ -1130,7 +1115,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1130
1115
) ;
1131
1116
}
1132
1117
UnOp :: PtrMetadata => {
1133
- if !matches ! ( self . mir_phase , MirPhase :: Runtime ( _) ) {
1118
+ if !matches ! ( self . body . phase , MirPhase :: Runtime ( _) ) {
1134
1119
// It would probably be fine to support this in earlier phases, but at
1135
1120
// the time of writing it's only ever introduced from intrinsic
1136
1121
// lowering or other runtime-phase optimization passes, so earlier
@@ -1206,7 +1191,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1206
1191
"CastKind::{kind:?} output must be a raw const pointer, not {:?}" ,
1207
1192
ty:: RawPtr ( _, Mutability :: Not )
1208
1193
) ;
1209
- if self . mir_phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) {
1194
+ if self . body . phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) {
1210
1195
self . fail ( location, format ! ( "After borrowck, MIR disallows {kind:?}" ) ) ;
1211
1196
}
1212
1197
}
@@ -1222,7 +1207,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1222
1207
"CastKind::{kind:?} output must be a raw pointer, not {:?}" ,
1223
1208
ty:: RawPtr ( ..)
1224
1209
) ;
1225
- if self . mir_phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) {
1210
+ if self . body . phase >= MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) {
1226
1211
self . fail ( location, format ! ( "After borrowck, MIR disallows {kind:?}" ) ) ;
1227
1212
}
1228
1213
}
@@ -1288,7 +1273,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1288
1273
}
1289
1274
}
1290
1275
CastKind :: Transmute => {
1291
- if let MirPhase :: Runtime ( ..) = self . mir_phase {
1276
+ if let MirPhase :: Runtime ( ..) = self . body . phase {
1292
1277
// Unlike `mem::transmute`, a MIR `Transmute` is well-formed
1293
1278
// for any two `Sized` types, just potentially UB to run.
1294
1279
@@ -1317,7 +1302,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1317
1302
location,
1318
1303
format ! (
1319
1304
"Transmute is not supported in non-runtime phase {:?}." ,
1320
- self . mir_phase
1305
+ self . body . phase
1321
1306
) ,
1322
1307
) ;
1323
1308
}
@@ -1404,15 +1389,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1404
1389
}
1405
1390
}
1406
1391
StatementKind :: AscribeUserType ( ..) => {
1407
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1392
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1408
1393
self . fail (
1409
1394
location,
1410
1395
"`AscribeUserType` should have been removed after drop lowering phase" ,
1411
1396
) ;
1412
1397
}
1413
1398
}
1414
1399
StatementKind :: FakeRead ( ..) => {
1415
- if self . mir_phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1400
+ if self . body . phase >= MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1416
1401
self . fail (
1417
1402
location,
1418
1403
"`FakeRead` should have been removed after drop lowering phase" ,
@@ -1463,7 +1448,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1463
1448
}
1464
1449
}
1465
1450
StatementKind :: SetDiscriminant { place, .. } => {
1466
- if self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1451
+ if self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1467
1452
self . fail ( location, "`SetDiscriminant`is not allowed until deaggregation" ) ;
1468
1453
}
1469
1454
let pty = place. ty ( & self . body . local_decls , self . tcx ) . ty . kind ( ) ;
@@ -1477,12 +1462,12 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1477
1462
}
1478
1463
}
1479
1464
StatementKind :: Deinit ( ..) => {
1480
- if self . mir_phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1465
+ if self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1481
1466
self . fail ( location, "`Deinit`is not allowed until deaggregation" ) ;
1482
1467
}
1483
1468
}
1484
1469
StatementKind :: Retag ( kind, _) => {
1485
- // FIXME(JakobDegen) The validator should check that `self.mir_phase <
1470
+ // FIXME(JakobDegen) The validator should check that `self.body.phase <
1486
1471
// DropsLowered`. However, this causes ICEs with generation of drop shims, which
1487
1472
// seem to fail to set their `MirPhase` correctly.
1488
1473
if matches ! ( kind, RetagKind :: TwoPhase ) {
0 commit comments