88//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010use crate :: rustc_internal:: { self , opaque} ;
11+ use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection } ;
1112use crate :: stable_mir:: ty:: { FloatTy , IntTy , Movability , RigidTy , TyKind , UintTy } ;
1213use crate :: stable_mir:: { self , Context } ;
1314use rustc_hir as hir;
14- use rustc_middle:: mir;
15- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
15+ use rustc_middle:: mir:: coverage:: CodeRegion ;
16+ use rustc_middle:: mir:: { self } ;
17+ use rustc_middle:: ty:: { self , Ty , TyCtxt , Variance } ;
1618use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
1719use rustc_target:: abi:: FieldIdx ;
1820use tracing:: debug;
@@ -110,17 +112,43 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
110112 Assign ( assign) => {
111113 stable_mir:: mir:: Statement :: Assign ( assign. 0 . stable ( tables) , assign. 1 . stable ( tables) )
112114 }
113- FakeRead ( _) => todo ! ( ) ,
114- SetDiscriminant { .. } => todo ! ( ) ,
115- Deinit ( _) => todo ! ( ) ,
116- StorageLive ( _) => todo ! ( ) ,
117- StorageDead ( _) => todo ! ( ) ,
118- Retag ( _, _) => todo ! ( ) ,
119- PlaceMention ( _) => todo ! ( ) ,
120- AscribeUserType ( _, _) => todo ! ( ) ,
121- Coverage ( _) => todo ! ( ) ,
122- Intrinsic ( _) => todo ! ( ) ,
123- ConstEvalCounter => todo ! ( ) ,
115+ FakeRead ( fake_read_place) => stable_mir:: mir:: Statement :: FakeRead (
116+ fake_read_place. 0 . stable ( tables) ,
117+ fake_read_place. 1 . stable ( tables) ,
118+ ) ,
119+ SetDiscriminant { place : plc, variant_index : idx } => {
120+ stable_mir:: mir:: Statement :: SetDiscriminant {
121+ place : plc. as_ref ( ) . stable ( tables) ,
122+ variant_index : idx. stable ( tables) ,
123+ }
124+ }
125+ Deinit ( place) => stable_mir:: mir:: Statement :: Deinit ( place. stable ( tables) ) ,
126+ StorageLive ( place) => stable_mir:: mir:: Statement :: StorageLive ( place. stable ( tables) ) ,
127+ StorageDead ( place) => stable_mir:: mir:: Statement :: StorageDead ( place. stable ( tables) ) ,
128+ Retag ( retag, place) => {
129+ stable_mir:: mir:: Statement :: Retag ( retag. stable ( tables) , place. stable ( tables) )
130+ }
131+ PlaceMention ( place) => stable_mir:: mir:: Statement :: PlaceMention ( place. stable ( tables) ) ,
132+ AscribeUserType ( place_projection, variance) => {
133+ stable_mir:: mir:: Statement :: AscribeUserType (
134+ (
135+ place_projection. as_ref ( ) . 0 . stable ( tables) ,
136+ UserTypeProjection {
137+ base : place_projection. as_ref ( ) . 1 . base . stable ( tables) ,
138+ projection : format ! ( "{:?}" , place_projection. as_ref( ) . 1 . projs) ,
139+ } ,
140+ ) ,
141+ variance. stable ( tables) ,
142+ )
143+ }
144+ Coverage ( coverage) => stable_mir:: mir:: Statement :: Coverage ( stable_mir:: mir:: Coverage {
145+ kind : coverage. kind . stable ( tables) ,
146+ code_region : coverage. code_region . as_ref ( ) . map ( |reg| reg. stable ( tables) ) ,
147+ } ) ,
148+ Intrinsic ( intrinstic) => {
149+ stable_mir:: mir:: Statement :: Intrinsic ( intrinstic. stable ( tables) )
150+ }
151+ ConstEvalCounter => stable_mir:: mir:: Statement :: ConstEvalCounter ,
124152 Nop => stable_mir:: mir:: Statement :: Nop ,
125153 }
126154 }
@@ -364,6 +392,24 @@ impl<'tcx> Stable<'tcx> for rustc_hir::Unsafety {
364392 }
365393}
366394
395+ impl < ' tcx > Stable < ' tcx > for mir:: FakeReadCause {
396+ type T = stable_mir:: mir:: FakeReadCause ;
397+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
398+ use mir:: FakeReadCause :: * ;
399+ match self {
400+ ForMatchGuard => stable_mir:: mir:: FakeReadCause :: ForMatchGuard ,
401+ ForMatchedPlace ( local_def_id) => stable_mir:: mir:: FakeReadCause :: ForMatchedPlace (
402+ local_def_id. map ( |id| id. to_def_id ( ) . index . index ( ) ) ,
403+ ) ,
404+ ForGuardBinding => stable_mir:: mir:: FakeReadCause :: ForGuardBinding ,
405+ ForLet ( local_def_id) => stable_mir:: mir:: FakeReadCause :: ForLet (
406+ local_def_id. map ( |id| id. to_def_id ( ) . index . index ( ) ) ,
407+ ) ,
408+ ForIndex => stable_mir:: mir:: FakeReadCause :: ForIndex ,
409+ }
410+ }
411+ }
412+
367413impl < ' tcx > Stable < ' tcx > for FieldIdx {
368414 type T = usize ;
369415 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -393,6 +439,104 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
393439 }
394440}
395441
442+ impl < ' tcx > Stable < ' tcx > for mir:: coverage:: CoverageKind {
443+ type T = stable_mir:: mir:: CoverageKind ;
444+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
445+ use rustc_middle:: mir:: coverage:: CoverageKind ;
446+ match self {
447+ CoverageKind :: Counter { function_source_hash, id } => {
448+ stable_mir:: mir:: CoverageKind :: Counter {
449+ function_source_hash : * function_source_hash as usize ,
450+ id : id. as_usize ( ) ,
451+ }
452+ }
453+ CoverageKind :: Expression { id, lhs, op, rhs } => {
454+ stable_mir:: mir:: CoverageKind :: Expression {
455+ id : id. as_usize ( ) ,
456+ lhs : lhs. as_usize ( ) ,
457+ op : op. stable ( tables) ,
458+ rhs : rhs. as_usize ( ) ,
459+ }
460+ }
461+ CoverageKind :: Unreachable => stable_mir:: mir:: CoverageKind :: Unreachable ,
462+ }
463+ }
464+ }
465+
466+ impl < ' tcx > Stable < ' tcx > for mir:: coverage:: Op {
467+ type T = stable_mir:: mir:: Op ;
468+
469+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
470+ use rustc_middle:: mir:: coverage:: Op :: * ;
471+ match self {
472+ Subtract => stable_mir:: mir:: Op :: Subtract ,
473+ Add => stable_mir:: mir:: Op :: Add ,
474+ }
475+ }
476+ }
477+
478+ impl < ' tcx > Stable < ' tcx > for mir:: Local {
479+ type T = usize ;
480+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
481+ self . as_usize ( )
482+ }
483+ }
484+
485+ impl < ' tcx > Stable < ' tcx > for rustc_target:: abi:: VariantIdx {
486+ type T = usize ;
487+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
488+ self . as_usize ( )
489+ }
490+ }
491+
492+ impl < ' tcx > Stable < ' tcx > for Variance {
493+ type T = stable_mir:: mir:: Variance ;
494+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
495+ match self {
496+ Variance :: Bivariant => stable_mir:: mir:: Variance :: Bivariant ,
497+ Variance :: Contravariant => stable_mir:: mir:: Variance :: Contravariant ,
498+ Variance :: Covariant => stable_mir:: mir:: Variance :: Covariant ,
499+ Variance :: Invariant => stable_mir:: mir:: Variance :: Invariant ,
500+ }
501+ }
502+ }
503+
504+ impl < ' tcx > Stable < ' tcx > for mir:: RetagKind {
505+ type T = stable_mir:: mir:: RetagKind ;
506+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
507+ use rustc_middle:: mir:: RetagKind ;
508+ match self {
509+ RetagKind :: FnEntry => stable_mir:: mir:: RetagKind :: FnEntry ,
510+ RetagKind :: TwoPhase => stable_mir:: mir:: RetagKind :: TwoPhase ,
511+ RetagKind :: Raw => stable_mir:: mir:: RetagKind :: Raw ,
512+ RetagKind :: Default => stable_mir:: mir:: RetagKind :: Default ,
513+ }
514+ }
515+ }
516+
517+ impl < ' tcx > Stable < ' tcx > for rustc_middle:: ty:: UserTypeAnnotationIndex {
518+ type T = usize ;
519+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
520+ self . as_usize ( )
521+ }
522+ }
523+
524+ impl < ' tcx > Stable < ' tcx > for CodeRegion {
525+ type T = stable_mir:: mir:: CodeRegion ;
526+
527+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
528+ match self {
529+ _ => stable_mir:: mir:: CodeRegion {
530+ file_name : self . file_name . as_u32 ( ) as usize ,
531+ start_line : self . start_line as usize ,
532+ start_col : self . start_col as usize ,
533+ end_line : self . end_line as usize ,
534+ end_col : self . end_col as usize ,
535+ } ,
536+ }
537+ }
538+ }
539+
396540impl < ' tcx > Stable < ' tcx > for mir:: UnwindAction {
397541 type T = stable_mir:: mir:: UnwindAction ;
398542 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -406,6 +550,26 @@ impl<'tcx> Stable<'tcx> for mir::UnwindAction {
406550 }
407551}
408552
553+ impl < ' tcx > Stable < ' tcx > for mir:: NonDivergingIntrinsic < ' tcx > {
554+ type T = stable_mir:: mir:: NonDivergingIntrinsic ;
555+
556+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
557+ use rustc_middle:: mir:: NonDivergingIntrinsic ;
558+ match self {
559+ NonDivergingIntrinsic :: Assume ( op) => {
560+ stable_mir:: mir:: NonDivergingIntrinsic :: Assume ( op. stable ( tables) )
561+ }
562+ NonDivergingIntrinsic :: CopyNonOverlapping ( copy_non_overlapping) => {
563+ stable_mir:: mir:: NonDivergingIntrinsic :: CopyNonOverlapping ( CopyNonOverlapping {
564+ src : copy_non_overlapping. src . stable ( tables) ,
565+ dst : copy_non_overlapping. dst . stable ( tables) ,
566+ count : copy_non_overlapping. count . stable ( tables) ,
567+ } )
568+ }
569+ }
570+ }
571+ }
572+
409573impl < ' tcx > Stable < ' tcx > for mir:: AssertMessage < ' tcx > {
410574 type T = stable_mir:: mir:: AssertMessage ;
411575 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
0 commit comments