@@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{alloc_range, AllocId};
15
15
use rustc_middle:: ty:: { self , Ty , TyCtxt , Variance } ;
16
16
use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
17
17
use rustc_target:: abi:: FieldIdx ;
18
- use stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection , VariantIdx } ;
18
+ use stable_mir:: mir:: { CopyNonOverlapping , Statement , UserTypeProjection , VariantIdx } ;
19
19
use stable_mir:: ty:: { FloatTy , GenericParamDef , IntTy , Movability , RigidTy , Span , TyKind , UintTy } ;
20
20
use stable_mir:: { self , opaque, Context } ;
21
21
use tracing:: debug;
@@ -106,7 +106,14 @@ impl<'tcx> Context for Tables<'tcx> {
106
106
. collect ( ) ,
107
107
} )
108
108
. collect ( ) ,
109
- locals : mir. local_decls . iter ( ) . map ( |decl| self . intern_ty ( decl. ty ) ) . collect ( ) ,
109
+ locals : mir
110
+ . local_decls
111
+ . iter ( )
112
+ . map ( |decl| stable_mir:: mir:: LocalDecl {
113
+ ty : self . intern_ty ( decl. ty ) ,
114
+ span : decl. source_info . span . stable ( self ) ,
115
+ } )
116
+ . collect ( ) ,
110
117
}
111
118
}
112
119
@@ -223,41 +230,64 @@ pub(crate) trait Stable<'tcx> {
223
230
impl < ' tcx > Stable < ' tcx > for mir:: Statement < ' tcx > {
224
231
type T = stable_mir:: mir:: Statement ;
225
232
fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
226
- use rustc_middle:: mir:: StatementKind :: * ;
227
- match & self . kind {
228
- Assign ( assign) => {
229
- stable_mir:: mir:: Statement :: Assign ( assign. 0 . stable ( tables) , assign. 1 . stable ( tables) )
230
- }
231
- FakeRead ( fake_read_place) => stable_mir:: mir:: Statement :: FakeRead (
232
- fake_read_place. 0 . stable ( tables) ,
233
- fake_read_place. 1 . stable ( tables) ,
233
+ Statement { kind : self . kind . stable ( tables) , span : self . source_info . span . stable ( tables) }
234
+ }
235
+ }
236
+
237
+ impl < ' tcx > Stable < ' tcx > for mir:: StatementKind < ' tcx > {
238
+ type T = stable_mir:: mir:: StatementKind ;
239
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
240
+ match self {
241
+ mir:: StatementKind :: Assign ( assign) => stable_mir:: mir:: StatementKind :: Assign (
242
+ assign. 0 . stable ( tables) ,
243
+ assign. 1 . stable ( tables) ,
234
244
) ,
235
- SetDiscriminant { place : plc, variant_index : idx } => {
236
- stable_mir:: mir:: Statement :: SetDiscriminant {
237
- place : plc. as_ref ( ) . stable ( tables) ,
238
- variant_index : idx. stable ( tables) ,
245
+ mir:: StatementKind :: FakeRead ( fake_read_place) => {
246
+ stable_mir:: mir:: StatementKind :: FakeRead (
247
+ fake_read_place. 0 . stable ( tables) ,
248
+ fake_read_place. 1 . stable ( tables) ,
249
+ )
250
+ }
251
+ mir:: StatementKind :: SetDiscriminant { place, variant_index } => {
252
+ stable_mir:: mir:: StatementKind :: SetDiscriminant {
253
+ place : place. as_ref ( ) . stable ( tables) ,
254
+ variant_index : variant_index. stable ( tables) ,
239
255
}
240
256
}
241
- Deinit ( place) => stable_mir:: mir:: Statement :: Deinit ( place. stable ( tables) ) ,
242
- StorageLive ( place) => stable_mir:: mir:: Statement :: StorageLive ( place. stable ( tables) ) ,
243
- StorageDead ( place) => stable_mir:: mir:: Statement :: StorageDead ( place. stable ( tables) ) ,
244
- Retag ( retag, place) => {
245
- stable_mir:: mir:: Statement :: Retag ( retag. stable ( tables) , place. stable ( tables) )
257
+ mir:: StatementKind :: Deinit ( place) => {
258
+ stable_mir:: mir:: StatementKind :: Deinit ( place. stable ( tables) )
259
+ }
260
+
261
+ mir:: StatementKind :: StorageLive ( place) => {
262
+ stable_mir:: mir:: StatementKind :: StorageLive ( place. stable ( tables) )
263
+ }
264
+
265
+ mir:: StatementKind :: StorageDead ( place) => {
266
+ stable_mir:: mir:: StatementKind :: StorageDead ( place. stable ( tables) )
267
+ }
268
+ mir:: StatementKind :: Retag ( retag, place) => {
269
+ stable_mir:: mir:: StatementKind :: Retag ( retag. stable ( tables) , place. stable ( tables) )
270
+ }
271
+ mir:: StatementKind :: PlaceMention ( place) => {
272
+ stable_mir:: mir:: StatementKind :: PlaceMention ( place. stable ( tables) )
246
273
}
247
- PlaceMention ( place) => stable_mir:: mir:: Statement :: PlaceMention ( place. stable ( tables) ) ,
248
- AscribeUserType ( place_projection, variance) => {
249
- stable_mir:: mir:: Statement :: AscribeUserType {
274
+ mir:: StatementKind :: AscribeUserType ( place_projection, variance) => {
275
+ stable_mir:: mir:: StatementKind :: AscribeUserType {
250
276
place : place_projection. as_ref ( ) . 0 . stable ( tables) ,
251
277
projections : place_projection. as_ref ( ) . 1 . stable ( tables) ,
252
278
variance : variance. stable ( tables) ,
253
279
}
254
280
}
255
- Coverage ( coverage) => stable_mir:: mir:: Statement :: Coverage ( opaque ( coverage) ) ,
256
- Intrinsic ( intrinstic) => {
257
- stable_mir:: mir:: Statement :: Intrinsic ( intrinstic. stable ( tables) )
281
+ mir:: StatementKind :: Coverage ( coverage) => {
282
+ stable_mir:: mir:: StatementKind :: Coverage ( opaque ( coverage) )
283
+ }
284
+ mir:: StatementKind :: Intrinsic ( intrinstic) => {
285
+ stable_mir:: mir:: StatementKind :: Intrinsic ( intrinstic. stable ( tables) )
286
+ }
287
+ mir:: StatementKind :: ConstEvalCounter => {
288
+ stable_mir:: mir:: StatementKind :: ConstEvalCounter
258
289
}
259
- ConstEvalCounter => stable_mir:: mir:: Statement :: ConstEvalCounter ,
260
- Nop => stable_mir:: mir:: Statement :: Nop ,
290
+ mir:: StatementKind :: Nop => stable_mir:: mir:: StatementKind :: Nop ,
261
291
}
262
292
}
263
293
}
@@ -806,11 +836,20 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
806
836
impl < ' tcx > Stable < ' tcx > for mir:: Terminator < ' tcx > {
807
837
type T = stable_mir:: mir:: Terminator ;
808
838
fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
809
- use rustc_middle:: mir:: TerminatorKind :: * ;
810
839
use stable_mir:: mir:: Terminator ;
811
- match & self . kind {
812
- Goto { target } => Terminator :: Goto { target : target. as_usize ( ) } ,
813
- SwitchInt { discr, targets } => Terminator :: SwitchInt {
840
+ Terminator { kind : self . kind . stable ( tables) , span : self . source_info . span . stable ( tables) }
841
+ }
842
+ }
843
+
844
+ impl < ' tcx > Stable < ' tcx > for mir:: TerminatorKind < ' tcx > {
845
+ type T = stable_mir:: mir:: TerminatorKind ;
846
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
847
+ use stable_mir:: mir:: TerminatorKind ;
848
+ match self {
849
+ mir:: TerminatorKind :: Goto { target } => {
850
+ TerminatorKind :: Goto { target : target. as_usize ( ) }
851
+ }
852
+ mir:: TerminatorKind :: SwitchInt { discr, targets } => TerminatorKind :: SwitchInt {
814
853
discr : discr. stable ( tables) ,
815
854
targets : targets
816
855
. iter ( )
@@ -821,42 +860,60 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
821
860
. collect ( ) ,
822
861
otherwise : targets. otherwise ( ) . as_usize ( ) ,
823
862
} ,
824
- UnwindResume => Terminator :: Resume ,
825
- UnwindTerminate ( _) => Terminator :: Abort ,
826
- Return => Terminator :: Return ,
827
- Unreachable => Terminator :: Unreachable ,
828
- Drop { place, target, unwind, replace : _ } => Terminator :: Drop {
829
- place : place. stable ( tables) ,
830
- target : target. as_usize ( ) ,
831
- unwind : unwind. stable ( tables) ,
832
- } ,
833
- Call { func, args, destination, target, unwind, call_source : _, fn_span : _ } => {
834
- Terminator :: Call {
835
- func : func. stable ( tables) ,
836
- args : args. iter ( ) . map ( |arg| arg. stable ( tables) ) . collect ( ) ,
837
- destination : destination. stable ( tables) ,
838
- target : target. map ( |t| t. as_usize ( ) ) ,
863
+ mir:: TerminatorKind :: UnwindResume => TerminatorKind :: Resume ,
864
+ mir:: TerminatorKind :: UnwindTerminate ( _) => TerminatorKind :: Abort ,
865
+ mir:: TerminatorKind :: Return => TerminatorKind :: Return ,
866
+ mir:: TerminatorKind :: Unreachable => TerminatorKind :: Unreachable ,
867
+ mir:: TerminatorKind :: Drop { place, target, unwind, replace : _ } => {
868
+ TerminatorKind :: Drop {
869
+ place : place. stable ( tables) ,
870
+ target : target. as_usize ( ) ,
839
871
unwind : unwind. stable ( tables) ,
840
872
}
841
873
}
842
- Assert { cond, expected, msg, target, unwind } => Terminator :: Assert {
843
- cond : cond. stable ( tables) ,
844
- expected : * expected,
845
- msg : msg. stable ( tables) ,
846
- target : target. as_usize ( ) ,
874
+ mir:: TerminatorKind :: Call {
875
+ func,
876
+ args,
877
+ destination,
878
+ target,
879
+ unwind,
880
+ call_source : _,
881
+ fn_span : _,
882
+ } => TerminatorKind :: Call {
883
+ func : func. stable ( tables) ,
884
+ args : args. iter ( ) . map ( |arg| arg. stable ( tables) ) . collect ( ) ,
885
+ destination : destination. stable ( tables) ,
886
+ target : target. map ( |t| t. as_usize ( ) ) ,
847
887
unwind : unwind. stable ( tables) ,
848
888
} ,
849
- InlineAsm { template, operands, options, line_spans, destination, unwind } => {
850
- Terminator :: InlineAsm {
851
- template : format ! ( "{template:?}" ) ,
852
- operands : operands. iter ( ) . map ( |operand| operand. stable ( tables) ) . collect ( ) ,
853
- options : format ! ( "{options:?}" ) ,
854
- line_spans : format ! ( "{line_spans:?}" ) ,
855
- destination : destination. map ( |d| d. as_usize ( ) ) ,
889
+ mir:: TerminatorKind :: Assert { cond, expected, msg, target, unwind } => {
890
+ TerminatorKind :: Assert {
891
+ cond : cond. stable ( tables) ,
892
+ expected : * expected,
893
+ msg : msg. stable ( tables) ,
894
+ target : target. as_usize ( ) ,
856
895
unwind : unwind. stable ( tables) ,
857
896
}
858
897
}
859
- Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable ! ( ) ,
898
+ mir:: TerminatorKind :: InlineAsm {
899
+ template,
900
+ operands,
901
+ options,
902
+ line_spans,
903
+ destination,
904
+ unwind,
905
+ } => TerminatorKind :: InlineAsm {
906
+ template : format ! ( "{template:?}" ) ,
907
+ operands : operands. iter ( ) . map ( |operand| operand. stable ( tables) ) . collect ( ) ,
908
+ options : format ! ( "{options:?}" ) ,
909
+ line_spans : format ! ( "{line_spans:?}" ) ,
910
+ destination : destination. map ( |d| d. as_usize ( ) ) ,
911
+ unwind : unwind. stable ( tables) ,
912
+ } ,
913
+ mir:: TerminatorKind :: Yield { .. }
914
+ | mir:: TerminatorKind :: GeneratorDrop
915
+ | mir:: TerminatorKind :: FalseEdge { .. }
916
+ | mir:: TerminatorKind :: FalseUnwind { .. } => unreachable ! ( ) ,
860
917
}
861
918
}
862
919
}
0 commit comments