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
+
1
9
use std:: ops:: RangeInclusive ;
2
10
11
+
3
12
use rustc_smir:: Tables ;
4
13
use rustc_smir:: context:: SmirCtxt ;
5
14
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
+
8
21
9
22
mod internal;
10
23
mod stable;
@@ -15,10 +28,10 @@ where
15
28
{
16
29
type T = T :: T ;
17
30
18
- fn stable (
31
+ fn stable < ' cx > (
19
32
& self ,
20
- tables : & mut Tables < ' tcx , BridgeTys > ,
21
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
33
+ tables : & mut Tables < ' cx , BridgeTys > ,
34
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
22
35
) -> Self :: T {
23
36
( * self ) . stable ( tables, cx)
24
37
}
@@ -30,10 +43,10 @@ where
30
43
{
31
44
type T = Option < T :: T > ;
32
45
33
- fn stable (
46
+ fn stable < ' cx > (
34
47
& self ,
35
- tables : & mut Tables < ' tcx , BridgeTys > ,
36
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
48
+ tables : & mut Tables < ' cx , BridgeTys > ,
49
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
37
50
) -> Self :: T {
38
51
self . as_ref ( ) . map ( |value| value. stable ( tables, cx) )
39
52
}
@@ -46,10 +59,10 @@ where
46
59
{
47
60
type T = Result < T :: T , E :: T > ;
48
61
49
- fn stable (
62
+ fn stable < ' cx > (
50
63
& self ,
51
- tables : & mut Tables < ' tcx , BridgeTys > ,
52
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
64
+ tables : & mut Tables < ' cx , BridgeTys > ,
65
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
53
66
) -> Self :: T {
54
67
match self {
55
68
Ok ( val) => Ok ( val. stable ( tables, cx) ) ,
@@ -63,10 +76,10 @@ where
63
76
T : Stable < ' tcx > ,
64
77
{
65
78
type T = Vec < T :: T > ;
66
- fn stable (
79
+ fn stable < ' cx > (
67
80
& self ,
68
- tables : & mut Tables < ' tcx , BridgeTys > ,
69
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
81
+ tables : & mut Tables < ' cx , BridgeTys > ,
82
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
70
83
) -> Self :: T {
71
84
self . iter ( ) . map ( |e| e. stable ( tables, cx) ) . collect ( )
72
85
}
@@ -78,10 +91,10 @@ where
78
91
U : Stable < ' tcx > ,
79
92
{
80
93
type T = ( T :: T , U :: T ) ;
81
- fn stable (
94
+ fn stable < ' cx > (
82
95
& self ,
83
- tables : & mut Tables < ' tcx , BridgeTys > ,
84
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
96
+ tables : & mut Tables < ' cx , BridgeTys > ,
97
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
85
98
) -> Self :: T {
86
99
( self . 0 . stable ( tables, cx) , self . 1 . stable ( tables, cx) )
87
100
}
@@ -92,35 +105,11 @@ where
92
105
T : Stable < ' tcx > ,
93
106
{
94
107
type T = RangeInclusive < T :: T > ;
95
- fn stable (
108
+ fn stable < ' cx > (
96
109
& self ,
97
- tables : & mut Tables < ' tcx , BridgeTys > ,
98
- cx : & SmirCtxt < ' tcx , BridgeTys > ,
110
+ tables : & mut Tables < ' cx , BridgeTys > ,
111
+ cx : & SmirCtxt < ' cx , BridgeTys > ,
99
112
) -> Self :: T {
100
113
RangeInclusive :: new ( self . start ( ) . stable ( tables, cx) , self . end ( ) . stable ( tables, cx) )
101
114
}
102
115
}
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