8
8
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
9
9
10
10
use 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
+ } ;
12
14
use crate :: stable_mir:: { self , Context } ;
15
+ use rustc_hir as hir;
13
16
use rustc_middle:: mir;
14
17
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
15
18
use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
@@ -94,26 +97,13 @@ impl<'tcx> Tables<'tcx> {
94
97
ty:: FloatTy :: F32 => TyKind :: RigidTy ( RigidTy :: Float ( FloatTy :: F32 ) ) ,
95
98
ty:: FloatTy :: F64 => TyKind :: RigidTy ( RigidTy :: Float ( FloatTy :: F64 ) ) ,
96
99
} ,
97
- ty:: Adt ( adt_def, substs ) => TyKind :: RigidTy ( RigidTy :: Adt (
100
+ ty:: Adt ( adt_def, generic_args ) => TyKind :: RigidTy ( RigidTy :: Adt (
98
101
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) ,
115
103
) ) ,
116
- ty:: Foreign ( _) => todo ! ( ) ,
104
+ ty:: Foreign ( def_id) => {
105
+ TyKind :: RigidTy ( RigidTy :: Foreign ( rustc_internal:: foreign_def ( * def_id) ) )
106
+ }
117
107
ty:: Str => TyKind :: RigidTy ( RigidTy :: Str ) ,
118
108
ty:: Array ( ty, constant) => {
119
109
TyKind :: RigidTy ( RigidTy :: Array ( self . intern_ty ( * ty) , opaque ( constant) ) )
@@ -125,12 +115,25 @@ impl<'tcx> Tables<'tcx> {
125
115
ty:: Ref ( region, ty, mutbl) => {
126
116
TyKind :: RigidTy ( RigidTy :: Ref ( opaque ( region) , self . intern_ty ( * ty) , mutbl. stable ( ) ) )
127
117
}
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
+ ) ) ,
129
122
ty:: FnPtr ( _) => todo ! ( ) ,
130
123
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 ) ,
134
137
ty:: Tuple ( fields) => TyKind :: RigidTy ( RigidTy :: Tuple (
135
138
fields. iter ( ) . map ( |ty| self . intern_ty ( ty) ) . collect ( ) ,
136
139
) ) ,
@@ -155,6 +158,24 @@ impl<'tcx> Tables<'tcx> {
155
158
self . types . push ( ty) ;
156
159
stable_mir:: ty:: Ty ( id)
157
160
}
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
+ }
158
179
}
159
180
160
181
/// Build a stable mir crate from a given crate number.
0 commit comments