88//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010use crate :: rustc_internal:: { self , opaque} ;
11- use crate :: stable_mir:: ty:: { AdtSubsts , FloatTy , GenericArgKind , IntTy , RigidTy , TyKind , UintTy } ;
11+ use crate :: stable_mir:: ty:: {
12+ FloatTy , GenericArgKind , GenericArgs , IntTy , Movability , RigidTy , TyKind , UintTy ,
13+ } ;
1214use crate :: stable_mir:: { self , Context } ;
15+ use rustc_hir as hir;
1316use rustc_middle:: mir;
1417use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1518use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
@@ -94,26 +97,13 @@ impl<'tcx> Tables<'tcx> {
9497 ty:: FloatTy :: F32 => TyKind :: RigidTy ( RigidTy :: Float ( FloatTy :: F32 ) ) ,
9598 ty:: FloatTy :: F64 => TyKind :: RigidTy ( RigidTy :: Float ( FloatTy :: F64 ) ) ,
9699 } ,
97- ty:: Adt ( adt_def, substs ) => TyKind :: RigidTy ( RigidTy :: Adt (
100+ ty:: Adt ( adt_def, generic_args ) => TyKind :: RigidTy ( RigidTy :: Adt (
98101 rustc_internal:: adt_def ( adt_def. did ( ) ) ,
99- AdtSubsts (
100- substs
101- . iter ( )
102- . map ( |arg| match arg. unpack ( ) {
103- ty:: GenericArgKind :: Lifetime ( region) => {
104- GenericArgKind :: Lifetime ( opaque ( & region) )
105- }
106- ty:: GenericArgKind :: Type ( ty) => {
107- GenericArgKind :: Type ( self . intern_ty ( ty) )
108- }
109- ty:: GenericArgKind :: Const ( const_) => {
110- GenericArgKind :: Const ( opaque ( & const_) )
111- }
112- } )
113- . collect ( ) ,
114- ) ,
102+ self . generic_args ( generic_args) ,
115103 ) ) ,
116- ty:: Foreign ( _) => todo ! ( ) ,
104+ ty:: Foreign ( def_id) => {
105+ TyKind :: RigidTy ( RigidTy :: Foreign ( rustc_internal:: foreign_def ( * def_id) ) )
106+ }
117107 ty:: Str => TyKind :: RigidTy ( RigidTy :: Str ) ,
118108 ty:: Array ( ty, constant) => {
119109 TyKind :: RigidTy ( RigidTy :: Array ( self . intern_ty ( * ty) , opaque ( constant) ) )
@@ -125,12 +115,25 @@ impl<'tcx> Tables<'tcx> {
125115 ty:: Ref ( region, ty, mutbl) => {
126116 TyKind :: RigidTy ( RigidTy :: Ref ( opaque ( region) , self . intern_ty ( * ty) , mutbl. stable ( ) ) )
127117 }
128- ty:: FnDef ( _, _) => todo ! ( ) ,
118+ ty:: FnDef ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: FnDef (
119+ rustc_internal:: fn_def ( * def_id) ,
120+ self . generic_args ( generic_args) ,
121+ ) ) ,
129122 ty:: FnPtr ( _) => todo ! ( ) ,
130123 ty:: Dynamic ( _, _, _) => todo ! ( ) ,
131- ty:: Closure ( _, _) => todo ! ( ) ,
132- ty:: Generator ( _, _, _) => todo ! ( ) ,
133- ty:: Never => todo ! ( ) ,
124+ ty:: Closure ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: Closure (
125+ rustc_internal:: closure_def ( * def_id) ,
126+ self . generic_args ( generic_args) ,
127+ ) ) ,
128+ ty:: Generator ( def_id, generic_args, movability) => TyKind :: RigidTy ( RigidTy :: Generator (
129+ rustc_internal:: generator_def ( * def_id) ,
130+ self . generic_args ( generic_args) ,
131+ match movability {
132+ hir:: Movability :: Static => Movability :: Static ,
133+ hir:: Movability :: Movable => Movability :: Movable ,
134+ } ,
135+ ) ) ,
136+ ty:: Never => TyKind :: RigidTy ( RigidTy :: Never ) ,
134137 ty:: Tuple ( fields) => TyKind :: RigidTy ( RigidTy :: Tuple (
135138 fields. iter ( ) . map ( |ty| self . intern_ty ( ty) ) . collect ( ) ,
136139 ) ) ,
@@ -155,6 +158,24 @@ impl<'tcx> Tables<'tcx> {
155158 self . types . push ( ty) ;
156159 stable_mir:: ty:: Ty ( id)
157160 }
161+
162+ fn generic_args (
163+ & mut self ,
164+ generic_args : & ty:: GenericArgs < ' tcx > ,
165+ ) -> stable_mir:: ty:: GenericArgs {
166+ GenericArgs (
167+ generic_args
168+ . iter ( )
169+ . map ( |arg| match arg. unpack ( ) {
170+ ty:: GenericArgKind :: Lifetime ( region) => {
171+ GenericArgKind :: Lifetime ( opaque ( & region) )
172+ }
173+ ty:: GenericArgKind :: Type ( ty) => GenericArgKind :: Type ( self . intern_ty ( ty) ) ,
174+ ty:: GenericArgKind :: Const ( const_) => GenericArgKind :: Const ( opaque ( & const_) ) ,
175+ } )
176+ . collect ( ) ,
177+ )
178+ }
158179}
159180
160181/// Build a stable mir crate from a given crate number.
0 commit comments