@@ -17,14 +17,11 @@ use rustc_middle::mir::mono::MonoItem;
17
17
use rustc_middle:: ty:: { self , Instance , ParamEnv , Ty , TyCtxt , Variance } ;
18
18
use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
19
19
use rustc_target:: abi:: FieldIdx ;
20
- use stable_mir:: mir:: mono:: InstanceDef ;
20
+ use stable_mir:: mir:: alloc:: GlobalAlloc ;
21
+ use stable_mir:: mir:: mono:: { InstanceDef , StaticDef } ;
21
22
use stable_mir:: mir:: { Body , CopyNonOverlapping , Statement , UserTypeProjection , VariantIdx } ;
22
- use stable_mir:: ty:: {
23
- AdtDef , AdtKind , ClosureDef , ClosureKind , Const , ConstId , ConstantKind , EarlyParamRegion ,
24
- FloatTy , FnDef , GenericArgs , GenericParamDef , IntTy , LineInfo , Movability , RigidTy , Span ,
25
- TyKind , UintTy ,
26
- } ;
27
- use stable_mir:: { self , opaque, Context , CrateItem , Filename , ItemKind } ;
23
+ use stable_mir:: ty:: { AdtDef , AdtKind , Allocation , ClosureDef , ClosureKind , Const , ConstId , ConstantKind , FloatTy , FnDef , GenericArgs , GenericParamDef , IntTy , LineInfo , Movability , RigidTy , Span , TyKind , UintTy , EarlyParamRegion } ;
24
+ use stable_mir:: { self , opaque, Context , CrateItem , Error , Filename , ItemKind } ;
28
25
use std:: cell:: RefCell ;
29
26
use tracing:: debug;
30
27
@@ -91,6 +88,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
91
88
new_item_kind ( tables. tcx . def_kind ( tables[ item. 0 ] ) )
92
89
}
93
90
91
+ fn is_foreign_item ( & self , item : CrateItem ) -> bool {
92
+ let tables = self . 0 . borrow ( ) ;
93
+ tables. tcx . is_foreign_item ( tables[ item. 0 ] )
94
+ }
95
+
94
96
fn adt_kind ( & self , def : AdtDef ) -> AdtKind {
95
97
let mut tables = self . 0 . borrow_mut ( ) ;
96
98
let ty = tables. tcx . type_of ( def. 0 . internal ( & mut * tables) ) . instantiate_identity ( ) . kind ( ) ;
@@ -298,14 +300,26 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
298
300
let closure_kind = kind. internal ( & mut * tables) ;
299
301
Instance :: resolve_closure ( tables. tcx , def_id, args_ref, closure_kind) . stable ( & mut * tables)
300
302
}
303
+
304
+ fn eval_static_initializer ( & self , def : StaticDef ) -> Result < Allocation , Error > {
305
+ let mut tables = self . 0 . borrow_mut ( ) ;
306
+ let def_id = def. 0 . internal ( & mut * tables) ;
307
+ tables. tcx . eval_static_initializer ( def_id) . stable ( & mut * tables)
308
+ }
309
+
310
+ fn global_alloc ( & self , alloc : stable_mir:: mir:: alloc:: AllocId ) -> GlobalAlloc {
311
+ let mut tables = self . 0 . borrow_mut ( ) ;
312
+ let alloc_id = alloc. internal ( & mut * tables) ;
313
+ tables. tcx . global_alloc ( alloc_id) . stable ( & mut * tables)
314
+ }
301
315
}
302
316
303
317
pub ( crate ) struct TablesWrapper < ' tcx > ( pub ( crate ) RefCell < Tables < ' tcx > > ) ;
304
318
305
319
pub struct Tables < ' tcx > {
306
320
pub ( crate ) tcx : TyCtxt < ' tcx > ,
307
321
pub ( crate ) def_ids : IndexMap < DefId , stable_mir:: DefId > ,
308
- pub ( crate ) alloc_ids : IndexMap < AllocId , stable_mir:: AllocId > ,
322
+ pub ( crate ) alloc_ids : IndexMap < AllocId , stable_mir:: mir :: alloc :: AllocId > ,
309
323
pub ( crate ) spans : IndexMap < rustc_span:: Span , Span > ,
310
324
pub ( crate ) types : IndexMap < Ty < ' tcx > , stable_mir:: ty:: Ty > ,
311
325
pub ( crate ) instances : IndexMap < ty:: Instance < ' tcx > , InstanceDef > ,
@@ -1502,6 +1516,14 @@ impl<'tcx> Stable<'tcx> for ty::BoundTy {
1502
1516
}
1503
1517
}
1504
1518
1519
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: ConstAllocation < ' tcx > {
1520
+ type T = Allocation ;
1521
+
1522
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1523
+ self . inner ( ) . stable ( tables)
1524
+ }
1525
+ }
1526
+
1505
1527
impl < ' tcx > Stable < ' tcx > for mir:: interpret:: Allocation {
1506
1528
type T = stable_mir:: ty:: Allocation ;
1507
1529
@@ -1514,6 +1536,25 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
1514
1536
}
1515
1537
}
1516
1538
1539
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: GlobalAlloc < ' tcx > {
1540
+ type T = GlobalAlloc ;
1541
+
1542
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1543
+ match self {
1544
+ mir:: interpret:: GlobalAlloc :: Function ( instance) => {
1545
+ GlobalAlloc :: Function ( instance. stable ( tables) )
1546
+ }
1547
+ mir:: interpret:: GlobalAlloc :: VTable ( ty, trait_ref) => {
1548
+ GlobalAlloc :: VTable ( ty. stable ( tables) , trait_ref. stable ( tables) )
1549
+ }
1550
+ mir:: interpret:: GlobalAlloc :: Static ( def) => {
1551
+ GlobalAlloc :: Static ( tables. static_def ( * def) )
1552
+ }
1553
+ mir:: interpret:: GlobalAlloc :: Memory ( alloc) => GlobalAlloc :: Memory ( alloc. stable ( tables) ) ,
1554
+ }
1555
+ }
1556
+ }
1557
+
1517
1558
impl < ' tcx > Stable < ' tcx > for ty:: trait_def:: TraitSpecializationKind {
1518
1559
type T = stable_mir:: ty:: TraitSpecializationKind ;
1519
1560
fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -1901,6 +1942,14 @@ impl<'tcx> Stable<'tcx> for MonoItem<'tcx> {
1901
1942
}
1902
1943
}
1903
1944
1945
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: ErrorHandled {
1946
+ type T = Error ;
1947
+
1948
+ fn stable ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
1949
+ Error :: new ( format ! ( "{self:?}" ) )
1950
+ }
1951
+ }
1952
+
1904
1953
impl < ' tcx , T > Stable < ' tcx > for & T
1905
1954
where
1906
1955
T : Stable < ' tcx > ,
@@ -1922,3 +1971,18 @@ where
1922
1971
self . as_ref ( ) . map ( |value| value. stable ( tables) )
1923
1972
}
1924
1973
}
1974
+
1975
+ impl < ' tcx , T , E > Stable < ' tcx > for Result < T , E >
1976
+ where
1977
+ T : Stable < ' tcx > ,
1978
+ E : Stable < ' tcx > ,
1979
+ {
1980
+ type T = Result < T :: T , E :: T > ;
1981
+
1982
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1983
+ match self {
1984
+ Ok ( val) => Ok ( val. stable ( tables) ) ,
1985
+ Err ( error) => Err ( error. stable ( tables) ) ,
1986
+ }
1987
+ }
1988
+ }
0 commit comments