@@ -10,12 +10,11 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
1010use crate :: ty:: fold:: { TypeFoldable , TypeFolder , TypeVisitor } ;
1111use crate :: ty:: print:: { FmtPrinter , Printer } ;
1212use 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 } ;
1615use rustc_hir as hir;
1716use rustc_hir:: def:: { CtorKind , Namespace } ;
18- use rustc_hir:: def_id:: DefId ;
17+ use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX } ;
1918use rustc_hir:: { self , GeneratorKind } ;
2019use rustc_target:: abi:: VariantIdx ;
2120
@@ -112,6 +111,38 @@ impl MirPhase {
112111 }
113112}
114113
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+
115146/// The lowered representation of a single function.
116147#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable ) ]
117148pub struct Body < ' tcx > {
@@ -126,6 +157,8 @@ pub struct Body<'tcx> {
126157 /// us to see the difference and forego optimization on the inlined promoted items.
127158 pub phase : MirPhase ,
128159
160+ pub source : MirSource < ' tcx > ,
161+
129162 /// A list of source scopes; these are referenced by statements
130163 /// and used for debuginfo. Indexed by a `SourceScope`.
131164 pub source_scopes : IndexVec < SourceScope , SourceScopeData > ,
@@ -151,7 +184,7 @@ pub struct Body<'tcx> {
151184 pub local_decls : LocalDecls < ' tcx > ,
152185
153186 /// User type annotations.
154- pub user_type_annotations : CanonicalUserTypeAnnotations < ' tcx > ,
187+ pub user_type_annotations : ty :: CanonicalUserTypeAnnotations < ' tcx > ,
155188
156189 /// The number of arguments this function takes.
157190 ///
@@ -209,10 +242,11 @@ pub struct Body<'tcx> {
209242
210243impl < ' tcx > Body < ' tcx > {
211244 pub fn new (
245+ source : MirSource < ' tcx > ,
212246 basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
213247 source_scopes : IndexVec < SourceScope , SourceScopeData > ,
214248 local_decls : LocalDecls < ' tcx > ,
215- user_type_annotations : CanonicalUserTypeAnnotations < ' tcx > ,
249+ user_type_annotations : ty :: CanonicalUserTypeAnnotations < ' tcx > ,
216250 arg_count : usize ,
217251 var_debug_info : Vec < VarDebugInfo < ' tcx > > ,
218252 span : Span ,
@@ -228,6 +262,7 @@ impl<'tcx> Body<'tcx> {
228262
229263 let mut body = Body {
230264 phase : MirPhase :: Build ,
265+ source,
231266 basic_blocks,
232267 source_scopes,
233268 yield_ty : None ,
@@ -257,6 +292,7 @@ impl<'tcx> Body<'tcx> {
257292 pub fn new_cfg_only ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ) -> Self {
258293 let mut body = Body {
259294 phase : MirPhase :: Build ,
295+ source : MirSource :: item ( DefId :: local ( CRATE_DEF_INDEX ) ) ,
260296 basic_blocks,
261297 source_scopes : IndexVec :: new ( ) ,
262298 yield_ty : None ,
0 commit comments