1+ //! This module holds the logic to convert rustc internal ADTs into stable mir ADTs.
2+ //!
3+ //! The conversion from stable to internal is not meant to be complete,
4+ //! and it should be added as when needed to be passed as input to rustc_smir functions.
5+ //!
6+ //! For contributors, please make sure to avoid calling rustc's internal functions and queries.
7+ //! These should be done via `rustc_smir` APIs, but it's possible to access ADT fields directly.
8+
19use std:: ops:: RangeInclusive ;
210
11+
312use rustc_smir:: Tables ;
413use rustc_smir:: context:: SmirCtxt ;
514
6- use super :: compiler_interface:: BridgeTys ;
7- use crate :: rustc_smir;
15+ use stable_mir:: compiler_interface:: BridgeTys ;
16+
17+ use crate :: { rustc_smir, stable_mir} ;
18+
19+ use super :: Stable ;
20+
821
922mod internal;
1023mod stable;
@@ -15,10 +28,10 @@ where
1528{
1629 type T = T :: T ;
1730
18- fn stable (
31+ fn stable < ' cx > (
1932 & self ,
20- tables : & mut Tables < ' tcx , BridgeTys > ,
21- cx : & SmirCtxt < ' tcx , BridgeTys > ,
33+ tables : & mut Tables < ' cx , BridgeTys > ,
34+ cx : & SmirCtxt < ' cx , BridgeTys > ,
2235 ) -> Self :: T {
2336 ( * self ) . stable ( tables, cx)
2437 }
@@ -30,10 +43,10 @@ where
3043{
3144 type T = Option < T :: T > ;
3245
33- fn stable (
46+ fn stable < ' cx > (
3447 & self ,
35- tables : & mut Tables < ' tcx , BridgeTys > ,
36- cx : & SmirCtxt < ' tcx , BridgeTys > ,
48+ tables : & mut Tables < ' cx , BridgeTys > ,
49+ cx : & SmirCtxt < ' cx , BridgeTys > ,
3750 ) -> Self :: T {
3851 self . as_ref ( ) . map ( |value| value. stable ( tables, cx) )
3952 }
@@ -46,10 +59,10 @@ where
4659{
4760 type T = Result < T :: T , E :: T > ;
4861
49- fn stable (
62+ fn stable < ' cx > (
5063 & self ,
51- tables : & mut Tables < ' tcx , BridgeTys > ,
52- cx : & SmirCtxt < ' tcx , BridgeTys > ,
64+ tables : & mut Tables < ' cx , BridgeTys > ,
65+ cx : & SmirCtxt < ' cx , BridgeTys > ,
5366 ) -> Self :: T {
5467 match self {
5568 Ok ( val) => Ok ( val. stable ( tables, cx) ) ,
@@ -63,10 +76,10 @@ where
6376 T : Stable < ' tcx > ,
6477{
6578 type T = Vec < T :: T > ;
66- fn stable (
79+ fn stable < ' cx > (
6780 & self ,
68- tables : & mut Tables < ' tcx , BridgeTys > ,
69- cx : & SmirCtxt < ' tcx , BridgeTys > ,
81+ tables : & mut Tables < ' cx , BridgeTys > ,
82+ cx : & SmirCtxt < ' cx , BridgeTys > ,
7083 ) -> Self :: T {
7184 self . iter ( ) . map ( |e| e. stable ( tables, cx) ) . collect ( )
7285 }
@@ -78,10 +91,10 @@ where
7891 U : Stable < ' tcx > ,
7992{
8093 type T = ( T :: T , U :: T ) ;
81- fn stable (
94+ fn stable < ' cx > (
8295 & self ,
83- tables : & mut Tables < ' tcx , BridgeTys > ,
84- cx : & SmirCtxt < ' tcx , BridgeTys > ,
96+ tables : & mut Tables < ' cx , BridgeTys > ,
97+ cx : & SmirCtxt < ' cx , BridgeTys > ,
8598 ) -> Self :: T {
8699 ( self . 0 . stable ( tables, cx) , self . 1 . stable ( tables, cx) )
87100 }
@@ -92,35 +105,11 @@ where
92105 T : Stable < ' tcx > ,
93106{
94107 type T = RangeInclusive < T :: T > ;
95- fn stable (
108+ fn stable < ' cx > (
96109 & self ,
97- tables : & mut Tables < ' tcx , BridgeTys > ,
98- cx : & SmirCtxt < ' tcx , BridgeTys > ,
110+ tables : & mut Tables < ' cx , BridgeTys > ,
111+ cx : & SmirCtxt < ' cx , BridgeTys > ,
99112 ) -> Self :: T {
100113 RangeInclusive :: new ( self . start ( ) . stable ( tables, cx) , self . end ( ) . stable ( tables, cx) )
101114 }
102115}
103-
104- /// Trait used to convert between an internal MIR type to a Stable MIR type.
105- pub trait Stable < ' tcx > {
106- /// The stable representation of the type implementing Stable.
107- type T ;
108- /// Converts an object to the equivalent Stable MIR representation.
109- fn stable (
110- & self ,
111- tables : & mut Tables < ' tcx , BridgeTys > ,
112- cx : & SmirCtxt < ' tcx , BridgeTys > ,
113- ) -> Self :: T ;
114- }
115-
116- /// Trait used to translate a stable construct to its rustc counterpart.
117- ///
118- /// This is basically a mirror of [Stable].
119- pub trait RustcInternal {
120- type T < ' tcx > ;
121- fn internal < ' tcx > (
122- & self ,
123- tables : & mut Tables < ' _ , BridgeTys > ,
124- cx : & SmirCtxt < ' tcx , BridgeTys > ,
125- ) -> Self :: T < ' tcx > ;
126- }
0 commit comments