@@ -9,10 +9,12 @@ use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
9
9
use rustc_span:: Symbol ;
10
10
use stable_mir:: mir:: alloc:: AllocId ;
11
11
use stable_mir:: mir:: mono:: { Instance , MonoItem , StaticDef } ;
12
+ use stable_mir:: mir:: { Mutability , Safety } ;
12
13
use stable_mir:: ty:: {
13
- AdtDef , Binder , BoundRegionKind , BoundTyKind , BoundVariableKind , ClosureKind , Const ,
14
- ExistentialTraitRef , FloatTy , GenericArgKind , GenericArgs , IntTy , Region , RigidTy , Span ,
15
- TraitRef , Ty , UintTy ,
14
+ Abi , AdtDef , Binder , BoundRegionKind , BoundTyKind , BoundVariableKind , ClosureKind , Const ,
15
+ DynKind , ExistentialPredicate , ExistentialProjection , ExistentialTraitRef , FloatTy , FnSig ,
16
+ GenericArgKind , GenericArgs , IndexedVal , IntTy , Movability , Region , RigidTy , Span , TermKind ,
17
+ TraitRef , Ty , UintTy , VariantDef , VariantIdx ,
16
18
} ;
17
19
use stable_mir:: { CrateItem , DefId } ;
18
20
@@ -84,17 +86,38 @@ impl<'tcx> RustcInternal<'tcx> for RigidTy {
84
86
}
85
87
RigidTy :: Str => rustc_ty:: TyKind :: Str ,
86
88
RigidTy :: Slice ( ty) => rustc_ty:: TyKind :: Slice ( ty. internal ( tables) ) ,
87
- RigidTy :: RawPtr ( ..)
88
- | RigidTy :: Ref ( ..)
89
- | RigidTy :: Foreign ( _)
90
- | RigidTy :: FnDef ( _, _)
91
- | RigidTy :: FnPtr ( _)
92
- | RigidTy :: Closure ( ..)
93
- | RigidTy :: Coroutine ( ..)
94
- | RigidTy :: CoroutineWitness ( ..)
95
- | RigidTy :: Dynamic ( ..)
96
- | RigidTy :: Tuple ( ..) => {
97
- todo ! ( )
89
+ RigidTy :: RawPtr ( ty, mutability) => rustc_ty:: TyKind :: RawPtr ( rustc_ty:: TypeAndMut {
90
+ ty : ty. internal ( tables) ,
91
+ mutbl : mutability. internal ( tables) ,
92
+ } ) ,
93
+ RigidTy :: Ref ( region, ty, mutability) => rustc_ty:: TyKind :: Ref (
94
+ region. internal ( tables) ,
95
+ ty. internal ( tables) ,
96
+ mutability. internal ( tables) ,
97
+ ) ,
98
+ RigidTy :: Foreign ( def) => rustc_ty:: TyKind :: Foreign ( def. 0 . internal ( tables) ) ,
99
+ RigidTy :: FnDef ( def, args) => {
100
+ rustc_ty:: TyKind :: FnDef ( def. 0 . internal ( tables) , args. internal ( tables) )
101
+ }
102
+ RigidTy :: FnPtr ( sig) => rustc_ty:: TyKind :: FnPtr ( sig. internal ( tables) ) ,
103
+ RigidTy :: Closure ( def, args) => {
104
+ rustc_ty:: TyKind :: Closure ( def. 0 . internal ( tables) , args. internal ( tables) )
105
+ }
106
+ RigidTy :: Coroutine ( def, args, mov) => rustc_ty:: TyKind :: Coroutine (
107
+ def. 0 . internal ( tables) ,
108
+ args. internal ( tables) ,
109
+ mov. internal ( tables) ,
110
+ ) ,
111
+ RigidTy :: CoroutineWitness ( def, args) => {
112
+ rustc_ty:: TyKind :: CoroutineWitness ( def. 0 . internal ( tables) , args. internal ( tables) )
113
+ }
114
+ RigidTy :: Dynamic ( predicate, region, dyn_kind) => rustc_ty:: TyKind :: Dynamic (
115
+ tables. tcx . mk_poly_existential_predicates ( & predicate. internal ( tables) ) ,
116
+ region. internal ( tables) ,
117
+ dyn_kind. internal ( tables) ,
118
+ ) ,
119
+ RigidTy :: Tuple ( tys) => {
120
+ rustc_ty:: TyKind :: Tuple ( tables. tcx . mk_type_list ( & tys. internal ( tables) ) )
98
121
}
99
122
}
100
123
}
@@ -141,6 +164,57 @@ impl<'tcx> RustcInternal<'tcx> for FloatTy {
141
164
}
142
165
}
143
166
167
+ impl < ' tcx > RustcInternal < ' tcx > for Mutability {
168
+ type T = rustc_ty:: Mutability ;
169
+
170
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
171
+ match self {
172
+ Mutability :: Not => rustc_ty:: Mutability :: Not ,
173
+ Mutability :: Mut => rustc_ty:: Mutability :: Mut ,
174
+ }
175
+ }
176
+ }
177
+
178
+ impl < ' tcx > RustcInternal < ' tcx > for Movability {
179
+ type T = rustc_ty:: Movability ;
180
+
181
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
182
+ match self {
183
+ Movability :: Static => rustc_ty:: Movability :: Static ,
184
+ Movability :: Movable => rustc_ty:: Movability :: Movable ,
185
+ }
186
+ }
187
+ }
188
+
189
+ impl < ' tcx > RustcInternal < ' tcx > for FnSig {
190
+ type T = rustc_ty:: FnSig < ' tcx > ;
191
+
192
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
193
+ rustc_ty:: FnSig {
194
+ inputs_and_output : tables. tcx . mk_type_list ( & self . inputs_and_output . internal ( tables) ) ,
195
+ c_variadic : self . c_variadic ,
196
+ unsafety : self . unsafety . internal ( tables) ,
197
+ abi : self . abi . internal ( tables) ,
198
+ }
199
+ }
200
+ }
201
+
202
+ impl < ' tcx > RustcInternal < ' tcx > for VariantIdx {
203
+ type T = rustc_target:: abi:: VariantIdx ;
204
+
205
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
206
+ rustc_target:: abi:: VariantIdx :: from ( self . to_index ( ) )
207
+ }
208
+ }
209
+
210
+ impl < ' tcx > RustcInternal < ' tcx > for VariantDef {
211
+ type T = & ' tcx rustc_ty:: VariantDef ;
212
+
213
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
214
+ self . adt_def . internal ( tables) . variant ( self . idx . internal ( tables) )
215
+ }
216
+ }
217
+
144
218
fn ty_const < ' tcx > ( constant : & Const , tables : & mut Tables < ' tcx > ) -> rustc_ty:: Const < ' tcx > {
145
219
match constant. internal ( tables) {
146
220
rustc_middle:: mir:: Const :: Ty ( c) => c,
@@ -230,6 +304,58 @@ impl<'tcx> RustcInternal<'tcx> for BoundVariableKind {
230
304
}
231
305
}
232
306
307
+ impl < ' tcx > RustcInternal < ' tcx > for DynKind {
308
+ type T = rustc_ty:: DynKind ;
309
+
310
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
311
+ match self {
312
+ DynKind :: Dyn => rustc_ty:: DynKind :: Dyn ,
313
+ DynKind :: DynStar => rustc_ty:: DynKind :: DynStar ,
314
+ }
315
+ }
316
+ }
317
+
318
+ impl < ' tcx > RustcInternal < ' tcx > for ExistentialPredicate {
319
+ type T = rustc_ty:: ExistentialPredicate < ' tcx > ;
320
+
321
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
322
+ match self {
323
+ ExistentialPredicate :: Trait ( trait_ref) => {
324
+ rustc_ty:: ExistentialPredicate :: Trait ( trait_ref. internal ( tables) )
325
+ }
326
+ ExistentialPredicate :: Projection ( proj) => {
327
+ rustc_ty:: ExistentialPredicate :: Projection ( proj. internal ( tables) )
328
+ }
329
+ ExistentialPredicate :: AutoTrait ( trait_def) => {
330
+ rustc_ty:: ExistentialPredicate :: AutoTrait ( trait_def. 0 . internal ( tables) )
331
+ }
332
+ }
333
+ }
334
+ }
335
+
336
+ impl < ' tcx > RustcInternal < ' tcx > for ExistentialProjection {
337
+ type T = rustc_ty:: ExistentialProjection < ' tcx > ;
338
+
339
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
340
+ rustc_ty:: ExistentialProjection {
341
+ def_id : self . def_id . 0 . internal ( tables) ,
342
+ args : self . generic_args . internal ( tables) ,
343
+ term : self . term . internal ( tables) ,
344
+ }
345
+ }
346
+ }
347
+
348
+ impl < ' tcx > RustcInternal < ' tcx > for TermKind {
349
+ type T = rustc_ty:: Term < ' tcx > ;
350
+
351
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
352
+ match self {
353
+ TermKind :: Type ( ty) => ty. internal ( tables) . into ( ) ,
354
+ TermKind :: Const ( const_) => ty_const ( const_, tables) . into ( ) ,
355
+ }
356
+ }
357
+ }
358
+
233
359
impl < ' tcx > RustcInternal < ' tcx > for ExistentialTraitRef {
234
360
type T = rustc_ty:: ExistentialTraitRef < ' tcx > ;
235
361
@@ -279,6 +405,53 @@ impl<'tcx> RustcInternal<'tcx> for AdtDef {
279
405
}
280
406
}
281
407
408
+ impl < ' tcx > RustcInternal < ' tcx > for Abi {
409
+ type T = rustc_target:: spec:: abi:: Abi ;
410
+
411
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
412
+ match * self {
413
+ Abi :: Rust => rustc_target:: spec:: abi:: Abi :: Rust ,
414
+ Abi :: C { unwind } => rustc_target:: spec:: abi:: Abi :: C { unwind } ,
415
+ Abi :: Cdecl { unwind } => rustc_target:: spec:: abi:: Abi :: Cdecl { unwind } ,
416
+ Abi :: Stdcall { unwind } => rustc_target:: spec:: abi:: Abi :: Stdcall { unwind } ,
417
+ Abi :: Fastcall { unwind } => rustc_target:: spec:: abi:: Abi :: Fastcall { unwind } ,
418
+ Abi :: Vectorcall { unwind } => rustc_target:: spec:: abi:: Abi :: Vectorcall { unwind } ,
419
+ Abi :: Thiscall { unwind } => rustc_target:: spec:: abi:: Abi :: Thiscall { unwind } ,
420
+ Abi :: Aapcs { unwind } => rustc_target:: spec:: abi:: Abi :: Aapcs { unwind } ,
421
+ Abi :: Win64 { unwind } => rustc_target:: spec:: abi:: Abi :: Win64 { unwind } ,
422
+ Abi :: SysV64 { unwind } => rustc_target:: spec:: abi:: Abi :: SysV64 { unwind } ,
423
+ Abi :: PtxKernel => rustc_target:: spec:: abi:: Abi :: PtxKernel ,
424
+ Abi :: Msp430Interrupt => rustc_target:: spec:: abi:: Abi :: Msp430Interrupt ,
425
+ Abi :: X86Interrupt => rustc_target:: spec:: abi:: Abi :: X86Interrupt ,
426
+ Abi :: AmdGpuKernel => rustc_target:: spec:: abi:: Abi :: AmdGpuKernel ,
427
+ Abi :: EfiApi => rustc_target:: spec:: abi:: Abi :: EfiApi ,
428
+ Abi :: AvrInterrupt => rustc_target:: spec:: abi:: Abi :: AvrInterrupt ,
429
+ Abi :: AvrNonBlockingInterrupt => rustc_target:: spec:: abi:: Abi :: AvrNonBlockingInterrupt ,
430
+ Abi :: CCmseNonSecureCall => rustc_target:: spec:: abi:: Abi :: CCmseNonSecureCall ,
431
+ Abi :: Wasm => rustc_target:: spec:: abi:: Abi :: Wasm ,
432
+ Abi :: System { unwind } => rustc_target:: spec:: abi:: Abi :: System { unwind } ,
433
+ Abi :: RustIntrinsic => rustc_target:: spec:: abi:: Abi :: RustIntrinsic ,
434
+ Abi :: RustCall => rustc_target:: spec:: abi:: Abi :: RustCall ,
435
+ Abi :: PlatformIntrinsic => rustc_target:: spec:: abi:: Abi :: PlatformIntrinsic ,
436
+ Abi :: Unadjusted => rustc_target:: spec:: abi:: Abi :: Unadjusted ,
437
+ Abi :: RustCold => rustc_target:: spec:: abi:: Abi :: RustCold ,
438
+ Abi :: RiscvInterruptM => rustc_target:: spec:: abi:: Abi :: RiscvInterruptM ,
439
+ Abi :: RiscvInterruptS => rustc_target:: spec:: abi:: Abi :: RiscvInterruptS ,
440
+ }
441
+ }
442
+ }
443
+
444
+ impl < ' tcx > RustcInternal < ' tcx > for Safety {
445
+ type T = rustc_hir:: Unsafety ;
446
+
447
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
448
+ match self {
449
+ Safety :: Unsafe => rustc_hir:: Unsafety :: Unsafe ,
450
+ Safety :: Normal => rustc_hir:: Unsafety :: Normal ,
451
+ }
452
+ }
453
+ }
454
+
282
455
impl < ' tcx > RustcInternal < ' tcx > for Span {
283
456
type T = rustc_span:: Span ;
284
457
@@ -297,6 +470,7 @@ where
297
470
( * self ) . internal ( tables)
298
471
}
299
472
}
473
+
300
474
impl < ' tcx , T > RustcInternal < ' tcx > for Option < T >
301
475
where
302
476
T : RustcInternal < ' tcx > ,
@@ -307,3 +481,14 @@ where
307
481
self . as_ref ( ) . map ( |inner| inner. internal ( tables) )
308
482
}
309
483
}
484
+
485
+ impl < ' tcx , T > RustcInternal < ' tcx > for Vec < T >
486
+ where
487
+ T : RustcInternal < ' tcx > ,
488
+ {
489
+ type T = Vec < T :: T > ;
490
+
491
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
492
+ self . iter ( ) . map ( |e| e. internal ( tables) ) . collect ( )
493
+ }
494
+ }
0 commit comments