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 , VariantIdx } ;
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,38 @@ 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+ place : place_projection. as_ref ( ) . 0 . stable ( tables) ,
135+ projections : place_projection. as_ref ( ) . 1 . stable ( tables) ,
136+ variance : variance. stable ( tables) ,
137+ }
138+ }
139+ Coverage ( coverage) => stable_mir:: mir:: Statement :: Coverage ( stable_mir:: mir:: Coverage {
140+ kind : coverage. kind . stable ( tables) ,
141+ code_region : coverage. code_region . as_ref ( ) . map ( |reg| reg. stable ( tables) ) ,
142+ } ) ,
143+ Intrinsic ( intrinstic) => {
144+ stable_mir:: mir:: Statement :: Intrinsic ( intrinstic. stable ( tables) )
145+ }
146+ ConstEvalCounter => stable_mir:: mir:: Statement :: ConstEvalCounter ,
124147 Nop => stable_mir:: mir:: Statement :: Nop ,
125148 }
126149 }
@@ -364,6 +387,22 @@ impl<'tcx> Stable<'tcx> for rustc_hir::Unsafety {
364387 }
365388}
366389
390+ impl < ' tcx > Stable < ' tcx > for mir:: FakeReadCause {
391+ type T = stable_mir:: mir:: FakeReadCause ;
392+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
393+ use mir:: FakeReadCause :: * ;
394+ match self {
395+ ForMatchGuard => stable_mir:: mir:: FakeReadCause :: ForMatchGuard ,
396+ ForMatchedPlace ( local_def_id) => {
397+ stable_mir:: mir:: FakeReadCause :: ForMatchedPlace ( opaque ( local_def_id) )
398+ }
399+ ForGuardBinding => stable_mir:: mir:: FakeReadCause :: ForGuardBinding ,
400+ ForLet ( local_def_id) => stable_mir:: mir:: FakeReadCause :: ForLet ( opaque ( local_def_id) ) ,
401+ ForIndex => stable_mir:: mir:: FakeReadCause :: ForIndex ,
402+ }
403+ }
404+ }
405+
367406impl < ' tcx > Stable < ' tcx > for FieldIdx {
368407 type T = usize ;
369408 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -393,6 +432,110 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {
393432 }
394433}
395434
435+ impl < ' tcx > Stable < ' tcx > for mir:: coverage:: CoverageKind {
436+ type T = stable_mir:: mir:: CoverageKind ;
437+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
438+ use rustc_middle:: mir:: coverage:: CoverageKind ;
439+ match self {
440+ CoverageKind :: Counter { function_source_hash, id } => {
441+ stable_mir:: mir:: CoverageKind :: Counter {
442+ function_source_hash : * function_source_hash as usize ,
443+ id : opaque ( id) ,
444+ }
445+ }
446+ CoverageKind :: Expression { id, lhs, op, rhs } => {
447+ stable_mir:: mir:: CoverageKind :: Expression {
448+ id : opaque ( id) ,
449+ lhs : opaque ( lhs) ,
450+ op : op. stable ( tables) ,
451+ rhs : opaque ( rhs) ,
452+ }
453+ }
454+ CoverageKind :: Unreachable => stable_mir:: mir:: CoverageKind :: Unreachable ,
455+ }
456+ }
457+ }
458+
459+ impl < ' tcx > Stable < ' tcx > for mir:: UserTypeProjection {
460+ type T = stable_mir:: mir:: UserTypeProjection ;
461+
462+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
463+ UserTypeProjection { base : self . base . as_usize ( ) , projection : format ! ( "{:?}" , self . projs) }
464+ }
465+ }
466+
467+ impl < ' tcx > Stable < ' tcx > for mir:: coverage:: Op {
468+ type T = stable_mir:: mir:: Op ;
469+
470+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
471+ use rustc_middle:: mir:: coverage:: Op :: * ;
472+ match self {
473+ Subtract => stable_mir:: mir:: Op :: Subtract ,
474+ Add => stable_mir:: mir:: Op :: Add ,
475+ }
476+ }
477+ }
478+
479+ impl < ' tcx > Stable < ' tcx > for mir:: Local {
480+ type T = stable_mir:: mir:: Local ;
481+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
482+ self . as_usize ( )
483+ }
484+ }
485+
486+ impl < ' tcx > Stable < ' tcx > for rustc_target:: abi:: VariantIdx {
487+ type T = VariantIdx ;
488+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
489+ self . as_usize ( )
490+ }
491+ }
492+
493+ impl < ' tcx > Stable < ' tcx > for Variance {
494+ type T = stable_mir:: mir:: Variance ;
495+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
496+ match self {
497+ Variance :: Bivariant => stable_mir:: mir:: Variance :: Bivariant ,
498+ Variance :: Contravariant => stable_mir:: mir:: Variance :: Contravariant ,
499+ Variance :: Covariant => stable_mir:: mir:: Variance :: Covariant ,
500+ Variance :: Invariant => stable_mir:: mir:: Variance :: Invariant ,
501+ }
502+ }
503+ }
504+
505+ impl < ' tcx > Stable < ' tcx > for mir:: RetagKind {
506+ type T = stable_mir:: mir:: RetagKind ;
507+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
508+ use rustc_middle:: mir:: RetagKind ;
509+ match self {
510+ RetagKind :: FnEntry => stable_mir:: mir:: RetagKind :: FnEntry ,
511+ RetagKind :: TwoPhase => stable_mir:: mir:: RetagKind :: TwoPhase ,
512+ RetagKind :: Raw => stable_mir:: mir:: RetagKind :: Raw ,
513+ RetagKind :: Default => stable_mir:: mir:: RetagKind :: Default ,
514+ }
515+ }
516+ }
517+
518+ impl < ' tcx > Stable < ' tcx > for rustc_middle:: ty:: UserTypeAnnotationIndex {
519+ type T = usize ;
520+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
521+ self . as_usize ( )
522+ }
523+ }
524+
525+ impl < ' tcx > Stable < ' tcx > for CodeRegion {
526+ type T = stable_mir:: mir:: CodeRegion ;
527+
528+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
529+ stable_mir:: mir:: CodeRegion {
530+ file_name : self . file_name . as_str ( ) . to_string ( ) ,
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+
396539impl < ' tcx > Stable < ' tcx > for mir:: UnwindAction {
397540 type T = stable_mir:: mir:: UnwindAction ;
398541 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -406,6 +549,26 @@ impl<'tcx> Stable<'tcx> for mir::UnwindAction {
406549 }
407550}
408551
552+ impl < ' tcx > Stable < ' tcx > for mir:: NonDivergingIntrinsic < ' tcx > {
553+ type T = stable_mir:: mir:: NonDivergingIntrinsic ;
554+
555+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
556+ use rustc_middle:: mir:: NonDivergingIntrinsic ;
557+ match self {
558+ NonDivergingIntrinsic :: Assume ( op) => {
559+ stable_mir:: mir:: NonDivergingIntrinsic :: Assume ( op. stable ( tables) )
560+ }
561+ NonDivergingIntrinsic :: CopyNonOverlapping ( copy_non_overlapping) => {
562+ stable_mir:: mir:: NonDivergingIntrinsic :: CopyNonOverlapping ( CopyNonOverlapping {
563+ src : copy_non_overlapping. src . stable ( tables) ,
564+ dst : copy_non_overlapping. dst . stable ( tables) ,
565+ count : copy_non_overlapping. count . stable ( tables) ,
566+ } )
567+ }
568+ }
569+ }
570+ }
571+
409572impl < ' tcx > Stable < ' tcx > for mir:: AssertMessage < ' tcx > {
410573 type T = stable_mir:: mir:: AssertMessage ;
411574 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
0 commit comments