11use crate :: ty:: { AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , Ty } ;
2- use crate :: Opaque ;
32use crate :: Span ;
3+ use crate :: { Opaque , Symbol } ;
44
55/// The SMIR representation of a single function.
66#[ derive( Clone , Debug ) ]
@@ -16,21 +16,29 @@ pub struct Body {
1616
1717 // The number of arguments this function takes.
1818 pub ( super ) arg_count : usize ,
19+
20+ // Debug information pertaining to user variables, including captures.
21+ pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
1922}
2023
2124impl Body {
2225 /// Constructs a `Body`.
2326 ///
2427 /// A constructor is required to build a `Body` from outside the crate
2528 /// because the `arg_count` and `locals` fields are private.
26- pub fn new ( blocks : Vec < BasicBlock > , locals : LocalDecls , arg_count : usize ) -> Self {
29+ pub fn new (
30+ blocks : Vec < BasicBlock > ,
31+ locals : LocalDecls ,
32+ arg_count : usize ,
33+ var_debug_info : Vec < VarDebugInfo > ,
34+ ) -> Self {
2735 // If locals doesn't contain enough entries, it can lead to panics in
2836 // `ret_local`, `arg_locals`, and `inner_locals`.
2937 assert ! (
3038 locals. len( ) > arg_count,
3139 "A Body must contain at least a local for the return value and each of the function's arguments"
3240 ) ;
33- Self { blocks, locals, arg_count }
41+ Self { blocks, locals, arg_count, var_debug_info }
3442 }
3543
3644 /// Return local that holds this function's return value.
@@ -401,6 +409,42 @@ pub struct Place {
401409 pub projection : Vec < ProjectionElem > ,
402410}
403411
412+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
413+ pub struct VarDebugInfo {
414+ pub name : Symbol ,
415+ pub source_info : SourceInfo ,
416+ pub composite : Option < VarDebugInfoFragment > ,
417+ pub value : VarDebugInfoContents ,
418+ pub argument_index : Option < u16 > ,
419+ }
420+
421+ pub type SourceScope = u32 ;
422+
423+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
424+ pub struct SourceInfo {
425+ pub span : Span ,
426+ pub scope : SourceScope ,
427+ }
428+
429+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
430+ pub struct VarDebugInfoFragment {
431+ pub ty : Ty ,
432+ pub projection : Vec < ProjectionElem > ,
433+ }
434+
435+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
436+ pub enum VarDebugInfoContents {
437+ Place ( Place ) ,
438+ Const ( ConstOperand ) ,
439+ }
440+
441+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
442+ pub struct ConstOperand {
443+ pub span : Span ,
444+ pub user_ty : Option < UserTypeAnnotationIndex > ,
445+ pub const_ : Const ,
446+ }
447+
404448// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
405449// is so it can be used for both Places (for which the projection elements are of type
406450// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
0 commit comments