9
9
10
10
use crate :: rustc_internal:: { self , opaque} ;
11
11
use 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 } ;
16
13
use crate :: stable_mir:: { self , Context } ;
17
14
use rustc_hir as hir;
18
15
use rustc_middle:: mir:: interpret:: alloc_range;
@@ -22,6 +19,8 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
22
19
use rustc_target:: abi:: FieldIdx ;
23
20
use tracing:: debug;
24
21
22
+ mod alloc;
23
+
25
24
impl < ' tcx > Context for Tables < ' tcx > {
26
25
fn local_crate ( & self ) -> stable_mir:: Crate {
27
26
smir_crate ( self . tcx , LOCAL_CRATE )
@@ -205,8 +204,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
205
204
match self {
206
205
Use ( op) => stable_mir:: mir:: Rvalue :: Use ( op. stable ( tables) ) ,
207
206
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) ;
210
208
stable_mir:: mir:: Rvalue :: Repeat ( op. stable ( tables) , len)
211
209
}
212
210
Ref ( region, kind, place) => stable_mir:: mir:: Rvalue :: Ref (
@@ -394,8 +392,7 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
394
392
match self {
395
393
ty:: TermKind :: Ty ( ty) => TermKind :: Type ( tables. intern_ty ( * ty) ) ,
396
394
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) ;
399
396
TermKind :: Const ( cnst)
400
397
}
401
398
}
@@ -1083,8 +1080,32 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
1083
1080
type T = stable_mir:: ty:: Const ;
1084
1081
1085
1082
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
+ }
1088
1109
}
1089
1110
}
1090
1111
@@ -1108,7 +1129,11 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
1108
1129
type T = stable_mir:: ty:: Allocation ;
1109
1130
1110
1131
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
+ )
1112
1137
}
1113
1138
}
1114
1139
@@ -1155,26 +1180,18 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
1155
1180
type T = stable_mir:: ty:: ConstantKind ;
1156
1181
1157
1182
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 ,
1168
1185
ConstantKind :: Unevaluated ( unev_const, ty) => {
1169
1186
stable_mir:: ty:: ConstantKind :: Unevaluated ( stable_mir:: ty:: UnevaluatedConst {
1170
- ty : tables. intern_ty ( * ty) ,
1187
+ ty : tables. intern_ty ( ty) ,
1171
1188
def : tables. const_def ( unev_const. def ) ,
1172
1189
args : unev_const. args . stable ( tables) ,
1173
1190
promoted : unev_const. promoted . map ( |u| u. as_u32 ( ) ) ,
1174
1191
} )
1175
1192
}
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) )
1178
1195
}
1179
1196
}
1180
1197
}
0 commit comments