99
1010use crate :: rustc_internal:: { self , opaque} ;
1111use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection , VariantIdx } ;
12- use crate :: stable_mir:: ty:: {
13- allocation_filter, new_allocation, Const , FloatTy , GenericParamDef , IntTy , Movability , RigidTy ,
14- TyKind , UintTy ,
15- } ;
12+ use crate :: stable_mir:: ty:: { FloatTy , GenericParamDef , IntTy , Movability , RigidTy , TyKind , UintTy } ;
1613use crate :: stable_mir:: { self , Context } ;
1714use rustc_hir as hir;
1815use rustc_middle:: mir:: interpret:: alloc_range;
@@ -22,6 +19,8 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
2219use rustc_target:: abi:: FieldIdx ;
2320use tracing:: debug;
2421
22+ mod alloc;
23+
2524impl < ' tcx > Context for Tables < ' tcx > {
2625 fn local_crate ( & self ) -> stable_mir:: Crate {
2726 smir_crate ( self . tcx , LOCAL_CRATE )
@@ -205,8 +204,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
205204 match self {
206205 Use ( op) => stable_mir:: mir:: Rvalue :: Use ( op. stable ( tables) ) ,
207206 Repeat ( op, len) => {
208- let cnst = ConstantKind :: from_const ( * len, tables. tcx ) ;
209- let len = Const { literal : cnst. stable ( tables) } ;
207+ let len = len. stable ( tables) ;
210208 stable_mir:: mir:: Rvalue :: Repeat ( op. stable ( tables) , len)
211209 }
212210 Ref ( region, kind, place) => stable_mir:: mir:: Rvalue :: Ref (
@@ -394,8 +392,7 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
394392 match self {
395393 ty:: TermKind :: Ty ( ty) => TermKind :: Type ( tables. intern_ty ( * ty) ) ,
396394 ty:: TermKind :: Const ( cnst) => {
397- let cnst = ConstantKind :: from_const ( * cnst, tables. tcx ) ;
398- let cnst = Const { literal : cnst. stable ( tables) } ;
395+ let cnst = cnst. stable ( tables) ;
399396 TermKind :: Const ( cnst)
400397 }
401398 }
@@ -1083,8 +1080,32 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
10831080 type T = stable_mir:: ty:: Const ;
10841081
10851082 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1086- let cnst = ConstantKind :: from_const ( * self , tables. tcx ) ;
1087- stable_mir:: ty:: Const { literal : cnst. stable ( tables) }
1083+ stable_mir:: ty:: Const {
1084+ literal : match self . kind ( ) {
1085+ ty:: Value ( val) => {
1086+ let const_val = tables. tcx . valtree_to_const_val ( ( self . ty ( ) , val) ) ;
1087+ stable_mir:: ty:: ConstantKind :: Allocated ( alloc:: new_allocation (
1088+ self . ty ( ) ,
1089+ const_val,
1090+ tables,
1091+ ) )
1092+ }
1093+ ty:: ParamCt ( param) => stable_mir:: ty:: ConstantKind :: ParamCt ( opaque ( & param) ) ,
1094+ ty:: ErrorCt ( _) => unreachable ! ( ) ,
1095+ ty:: InferCt ( _) => unreachable ! ( ) ,
1096+ ty:: BoundCt ( _, _) => unimplemented ! ( ) ,
1097+ ty:: PlaceholderCt ( _) => unimplemented ! ( ) ,
1098+ ty:: Unevaluated ( uv) => {
1099+ stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
1100+ ty : tables. intern_ty ( self . ty ( ) ) ,
1101+ def : tables. const_def ( uv. def ) ,
1102+ args : uv. args . stable ( tables) ,
1103+ promoted : None ,
1104+ } )
1105+ }
1106+ ty:: ExprCt ( _) => unimplemented ! ( ) ,
1107+ } ,
1108+ }
10881109 }
10891110}
10901111
@@ -1108,7 +1129,11 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
11081129 type T = stable_mir:: ty:: Allocation ;
11091130
11101131 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1111- allocation_filter ( self , alloc_range ( rustc_target:: abi:: Size :: ZERO , self . size ( ) ) , tables)
1132+ alloc:: allocation_filter (
1133+ self ,
1134+ alloc_range ( rustc_target:: abi:: Size :: ZERO , self . size ( ) ) ,
1135+ tables,
1136+ )
11121137 }
11131138}
11141139
@@ -1155,26 +1180,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
11551180 type T = stable_mir:: ty:: ConstantKind ;
11561181
11571182 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1158- match self {
1159- ConstantKind :: Ty ( c) => match c. kind ( ) {
1160- ty:: Value ( val) => {
1161- let const_val = tables. tcx . valtree_to_const_val ( ( c. ty ( ) , val) ) ;
1162- stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation ( self , const_val, tables) )
1163- }
1164- ty:: ParamCt ( param) => stable_mir:: ty:: ConstantKind :: ParamCt ( opaque ( & param) ) ,
1165- ty:: ErrorCt ( _) => unreachable ! ( ) ,
1166- _ => unimplemented ! ( ) ,
1167- } ,
1183+ match * self {
1184+ ConstantKind :: Ty ( c) => c. stable ( tables) . literal ,
11681185 ConstantKind :: Unevaluated ( unev_const, ty) => {
11691186 stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
1170- ty : tables. intern_ty ( * ty) ,
1187+ ty : tables. intern_ty ( ty) ,
11711188 def : tables. const_def ( unev_const. def ) ,
11721189 args : unev_const. args . stable ( tables) ,
11731190 promoted : unev_const. promoted . map ( |u| u. as_u32 ( ) ) ,
11741191 } )
11751192 }
1176- ConstantKind :: Val ( val, _ ) => {
1177- stable_mir:: ty:: ConstantKind :: Allocated ( new_allocation ( self , * val, tables) )
1193+ ConstantKind :: Val ( val, ty ) => {
1194+ stable_mir:: ty:: ConstantKind :: Allocated ( alloc :: new_allocation ( ty , val, tables) )
11781195 }
11791196 }
11801197 }
0 commit comments