@@ -10,12 +10,11 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
10
10
use crate :: ty:: fold:: { TypeFoldable , TypeFolder , TypeVisitor } ;
11
11
use crate :: ty:: print:: { FmtPrinter , Printer } ;
12
12
use crate :: ty:: subst:: { Subst , SubstsRef } ;
13
- use crate :: ty:: {
14
- self , AdtDef , CanonicalUserTypeAnnotations , List , Region , Ty , TyCtxt , UserTypeAnnotationIndex ,
15
- } ;
13
+ use crate :: ty:: { self , List , Ty , TyCtxt } ;
14
+ use crate :: ty:: { AdtDef , InstanceDef , Region , UserTypeAnnotationIndex } ;
16
15
use rustc_hir as hir;
17
16
use rustc_hir:: def:: { CtorKind , Namespace } ;
18
- use rustc_hir:: def_id:: DefId ;
17
+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX } ;
19
18
use rustc_hir:: { self , GeneratorKind } ;
20
19
use rustc_target:: abi:: VariantIdx ;
21
20
@@ -112,6 +111,38 @@ impl MirPhase {
112
111
}
113
112
}
114
113
114
+ /// Where a specific `mir::Body` comes from.
115
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
116
+ #[ derive( HashStable , TyEncodable , TyDecodable , TypeFoldable ) ]
117
+ pub struct MirSource < ' tcx > {
118
+ pub instance : InstanceDef < ' tcx > ,
119
+
120
+ /// If `Some`, this is a promoted rvalue within the parent function.
121
+ pub promoted : Option < Promoted > ,
122
+ }
123
+
124
+ impl < ' tcx > MirSource < ' tcx > {
125
+ pub fn item ( def_id : DefId ) -> Self {
126
+ MirSource {
127
+ instance : InstanceDef :: Item ( ty:: WithOptConstParam :: unknown ( def_id) ) ,
128
+ promoted : None ,
129
+ }
130
+ }
131
+
132
+ pub fn from_instance ( instance : InstanceDef < ' tcx > ) -> Self {
133
+ MirSource { instance, promoted : None }
134
+ }
135
+
136
+ pub fn with_opt_param ( self ) -> ty:: WithOptConstParam < DefId > {
137
+ self . instance . with_opt_param ( )
138
+ }
139
+
140
+ #[ inline]
141
+ pub fn def_id ( & self ) -> DefId {
142
+ self . instance . def_id ( )
143
+ }
144
+ }
145
+
115
146
/// The lowered representation of a single function.
116
147
#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable ) ]
117
148
pub struct Body < ' tcx > {
@@ -126,6 +157,8 @@ pub struct Body<'tcx> {
126
157
/// us to see the difference and forego optimization on the inlined promoted items.
127
158
pub phase : MirPhase ,
128
159
160
+ pub source : MirSource < ' tcx > ,
161
+
129
162
/// A list of source scopes; these are referenced by statements
130
163
/// and used for debuginfo. Indexed by a `SourceScope`.
131
164
pub source_scopes : IndexVec < SourceScope , SourceScopeData > ,
@@ -151,7 +184,7 @@ pub struct Body<'tcx> {
151
184
pub local_decls : LocalDecls < ' tcx > ,
152
185
153
186
/// User type annotations.
154
- pub user_type_annotations : CanonicalUserTypeAnnotations < ' tcx > ,
187
+ pub user_type_annotations : ty :: CanonicalUserTypeAnnotations < ' tcx > ,
155
188
156
189
/// The number of arguments this function takes.
157
190
///
@@ -209,10 +242,11 @@ pub struct Body<'tcx> {
209
242
210
243
impl < ' tcx > Body < ' tcx > {
211
244
pub fn new (
245
+ source : MirSource < ' tcx > ,
212
246
basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
213
247
source_scopes : IndexVec < SourceScope , SourceScopeData > ,
214
248
local_decls : LocalDecls < ' tcx > ,
215
- user_type_annotations : CanonicalUserTypeAnnotations < ' tcx > ,
249
+ user_type_annotations : ty :: CanonicalUserTypeAnnotations < ' tcx > ,
216
250
arg_count : usize ,
217
251
var_debug_info : Vec < VarDebugInfo < ' tcx > > ,
218
252
span : Span ,
@@ -228,6 +262,7 @@ impl<'tcx> Body<'tcx> {
228
262
229
263
let mut body = Body {
230
264
phase : MirPhase :: Build ,
265
+ source,
231
266
basic_blocks,
232
267
source_scopes,
233
268
yield_ty : None ,
@@ -257,6 +292,7 @@ impl<'tcx> Body<'tcx> {
257
292
pub fn new_cfg_only ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ) -> Self {
258
293
let mut body = Body {
259
294
phase : MirPhase :: Build ,
295
+ source : MirSource :: item ( DefId :: local ( CRATE_DEF_INDEX ) ) ,
260
296
basic_blocks,
261
297
source_scopes : IndexVec :: new ( ) ,
262
298
yield_ty : None ,
0 commit comments