77//!
88//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10- use std:: ops:: RangeInclusive ;
1110use std:: cell:: RefCell ;
1211use std:: fmt:: Debug ;
1312
@@ -17,8 +16,6 @@ use rustc_middle::mir;
1716use rustc_middle:: mir:: interpret:: AllocId ;
1817use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
1918use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
20- use stable_mir:: { CtorKind , ItemKind } ;
21- use tracing:: debug;
2219
2320use crate :: rustc_internal:: IndexMap ;
2421use crate :: stable_mir;
@@ -152,124 +149,3 @@ where
152149 . collect ( )
153150 }
154151}
155-
156- /// Build a stable mir crate from a given crate number.
157- pub ( crate ) fn smir_crate ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) -> stable_mir:: Crate {
158- let crate_name = tcx. crate_name ( crate_num) . to_string ( ) ;
159- let is_local = crate_num == LOCAL_CRATE ;
160- debug ! ( ?crate_name, ?crate_num, "smir_crate" ) ;
161- stable_mir:: Crate { id : crate_num. into ( ) , name : crate_name, is_local }
162- }
163-
164- pub ( crate ) fn new_item_kind ( kind : DefKind ) -> ItemKind {
165- match kind {
166- DefKind :: Mod
167- | DefKind :: Struct
168- | DefKind :: Union
169- | DefKind :: Enum
170- | DefKind :: Variant
171- | DefKind :: Trait
172- | DefKind :: TyAlias
173- | DefKind :: ForeignTy
174- | DefKind :: TraitAlias
175- | DefKind :: AssocTy
176- | DefKind :: TyParam
177- | DefKind :: ConstParam
178- | DefKind :: Macro ( _)
179- | DefKind :: ExternCrate
180- | DefKind :: Use
181- | DefKind :: ForeignMod
182- | DefKind :: OpaqueTy
183- | DefKind :: Field
184- | DefKind :: LifetimeParam
185- | DefKind :: Impl { .. }
186- | DefKind :: GlobalAsm => {
187- unreachable ! ( "Not a valid item kind: {kind:?}" ) ;
188- }
189- DefKind :: Closure | DefKind :: AssocFn | DefKind :: Fn | DefKind :: SyntheticCoroutineBody => {
190- ItemKind :: Fn
191- }
192- DefKind :: Const | DefKind :: InlineConst | DefKind :: AssocConst | DefKind :: AnonConst => {
193- ItemKind :: Const
194- }
195- DefKind :: Static { .. } => ItemKind :: Static ,
196- DefKind :: Ctor ( _, rustc_hir:: def:: CtorKind :: Const ) => ItemKind :: Ctor ( CtorKind :: Const ) ,
197- DefKind :: Ctor ( _, rustc_hir:: def:: CtorKind :: Fn ) => ItemKind :: Ctor ( CtorKind :: Fn ) ,
198- }
199- }
200-
201- /// Trait used to convert between an internal MIR type to a Stable MIR type.
202- pub trait Stable < ' cx > {
203- /// The stable representation of the type implementing Stable.
204- type T ;
205- /// Converts an object to the equivalent Stable MIR representation.
206- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T ;
207- }
208-
209- impl < ' tcx , T > Stable < ' tcx > for & T
210- where
211- T : Stable < ' tcx > ,
212- {
213- type T = T :: T ;
214-
215- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
216- ( * self ) . stable ( tables)
217- }
218- }
219-
220- impl < ' tcx , T > Stable < ' tcx > for Option < T >
221- where
222- T : Stable < ' tcx > ,
223- {
224- type T = Option < T :: T > ;
225-
226- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
227- self . as_ref ( ) . map ( |value| value. stable ( tables) )
228- }
229- }
230-
231- impl < ' tcx , T , E > Stable < ' tcx > for Result < T , E >
232- where
233- T : Stable < ' tcx > ,
234- E : Stable < ' tcx > ,
235- {
236- type T = Result < T :: T , E :: T > ;
237-
238- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
239- match self {
240- Ok ( val) => Ok ( val. stable ( tables) ) ,
241- Err ( error) => Err ( error. stable ( tables) ) ,
242- }
243- }
244- }
245-
246- impl < ' tcx , T > Stable < ' tcx > for & [ T ]
247- where
248- T : Stable < ' tcx > ,
249- {
250- type T = Vec < T :: T > ;
251- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
252- self . iter ( ) . map ( |e| e. stable ( tables) ) . collect ( )
253- }
254- }
255-
256- impl < ' tcx , T , U > Stable < ' tcx > for ( T , U )
257- where
258- T : Stable < ' tcx > ,
259- U : Stable < ' tcx > ,
260- {
261- type T = ( T :: T , U :: T ) ;
262- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
263- ( self . 0 . stable ( tables) , self . 1 . stable ( tables) )
264- }
265- }
266-
267- impl < ' tcx , T > Stable < ' tcx > for RangeInclusive < T >
268- where
269- T : Stable < ' tcx > ,
270- {
271- type T = RangeInclusive < T :: T > ;
272- fn stable ( & self , tables : & mut Tables < ' _ > ) -> Self :: T {
273- RangeInclusive :: new ( self . start ( ) . stable ( tables) , self . end ( ) . stable ( tables) )
274- }
275- }
0 commit comments