@@ -17,12 +17,13 @@ use rustc_middle::mir::mono::MonoItem;
17
17
use rustc_middle:: ty:: { self , Instance , ParamEnv , ScalarInt , 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
23
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 ,
24
+ AdtDef , AdtKind , Allocation , ClosureDef , ClosureKind , Const , ConstId , ConstantKind ,
25
+ EarlyParamRegion , FloatTy , FnDef , GenericArgs , GenericParamDef , IntTy , LineInfo , Movability ,
26
+ RigidTy , Span , TyKind , UintTy ,
26
27
} ;
27
28
use stable_mir:: { self , opaque, Context , CrateItem , Error , Filename , ItemKind } ;
28
29
use std:: cell:: RefCell ;
@@ -317,6 +318,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
317
318
. ok_or_else ( || Error :: new ( format ! ( "Const `{cnst:?}` cannot be encoded as u64" ) ) )
318
319
}
319
320
321
+ fn eval_static_initializer ( & self , def : StaticDef ) -> Result < Allocation , Error > {
322
+ let mut tables = self . 0 . borrow_mut ( ) ;
323
+ let def_id = def. 0 . internal ( & mut * tables) ;
324
+ tables. tcx . eval_static_initializer ( def_id) . stable ( & mut * tables)
325
+ }
326
+
327
+ fn global_alloc ( & self , alloc : stable_mir:: mir:: alloc:: AllocId ) -> GlobalAlloc {
328
+ let mut tables = self . 0 . borrow_mut ( ) ;
329
+ let alloc_id = alloc. internal ( & mut * tables) ;
330
+ tables. tcx . global_alloc ( alloc_id) . stable ( & mut * tables)
331
+ }
332
+
320
333
fn usize_to_const ( & self , val : u64 ) -> Result < Const , Error > {
321
334
let mut tables = self . 0 . borrow_mut ( ) ;
322
335
let ty = tables. tcx . types . usize ;
@@ -341,7 +354,7 @@ pub(crate) struct TablesWrapper<'tcx>(pub(crate) RefCell<Tables<'tcx>>);
341
354
pub struct Tables < ' tcx > {
342
355
pub ( crate ) tcx : TyCtxt < ' tcx > ,
343
356
pub ( crate ) def_ids : IndexMap < DefId , stable_mir:: DefId > ,
344
- pub ( crate ) alloc_ids : IndexMap < AllocId , stable_mir:: AllocId > ,
357
+ pub ( crate ) alloc_ids : IndexMap < AllocId , stable_mir:: mir :: alloc :: AllocId > ,
345
358
pub ( crate ) spans : IndexMap < rustc_span:: Span , Span > ,
346
359
pub ( crate ) types : IndexMap < Ty < ' tcx > , stable_mir:: ty:: Ty > ,
347
360
pub ( crate ) instances : IndexMap < ty:: Instance < ' tcx > , InstanceDef > ,
@@ -1539,6 +1552,14 @@ impl<'tcx> Stable<'tcx> for ty::BoundTy {
1539
1552
}
1540
1553
}
1541
1554
1555
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: ConstAllocation < ' tcx > {
1556
+ type T = Allocation ;
1557
+
1558
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1559
+ self . inner ( ) . stable ( tables)
1560
+ }
1561
+ }
1562
+
1542
1563
impl < ' tcx > Stable < ' tcx > for mir:: interpret:: Allocation {
1543
1564
type T = stable_mir:: ty:: Allocation ;
1544
1565
@@ -1551,6 +1572,25 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
1551
1572
}
1552
1573
}
1553
1574
1575
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: GlobalAlloc < ' tcx > {
1576
+ type T = GlobalAlloc ;
1577
+
1578
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1579
+ match self {
1580
+ mir:: interpret:: GlobalAlloc :: Function ( instance) => {
1581
+ GlobalAlloc :: Function ( instance. stable ( tables) )
1582
+ }
1583
+ mir:: interpret:: GlobalAlloc :: VTable ( ty, trait_ref) => {
1584
+ GlobalAlloc :: VTable ( ty. stable ( tables) , trait_ref. stable ( tables) )
1585
+ }
1586
+ mir:: interpret:: GlobalAlloc :: Static ( def) => {
1587
+ GlobalAlloc :: Static ( tables. static_def ( * def) )
1588
+ }
1589
+ mir:: interpret:: GlobalAlloc :: Memory ( alloc) => GlobalAlloc :: Memory ( alloc. stable ( tables) ) ,
1590
+ }
1591
+ }
1592
+ }
1593
+
1554
1594
impl < ' tcx > Stable < ' tcx > for ty:: trait_def:: TraitSpecializationKind {
1555
1595
type T = stable_mir:: ty:: TraitSpecializationKind ;
1556
1596
fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -1938,6 +1978,14 @@ impl<'tcx> Stable<'tcx> for MonoItem<'tcx> {
1938
1978
}
1939
1979
}
1940
1980
1981
+ impl < ' tcx > Stable < ' tcx > for mir:: interpret:: ErrorHandled {
1982
+ type T = Error ;
1983
+
1984
+ fn stable ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
1985
+ Error :: new ( format ! ( "{self:?}" ) )
1986
+ }
1987
+ }
1988
+
1941
1989
impl < ' tcx , T > Stable < ' tcx > for & T
1942
1990
where
1943
1991
T : Stable < ' tcx > ,
@@ -1959,3 +2007,18 @@ where
1959
2007
self . as_ref ( ) . map ( |value| value. stable ( tables) )
1960
2008
}
1961
2009
}
2010
+
2011
+ impl < ' tcx , T , E > Stable < ' tcx > for Result < T , E >
2012
+ where
2013
+ T : Stable < ' tcx > ,
2014
+ E : Stable < ' tcx > ,
2015
+ {
2016
+ type T = Result < T :: T , E :: T > ;
2017
+
2018
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
2019
+ match self {
2020
+ Ok ( val) => Ok ( val. stable ( tables) ) ,
2021
+ Err ( error) => Err ( error. stable ( tables) ) ,
2022
+ }
2023
+ }
2024
+ }
0 commit comments