@@ -2,7 +2,7 @@ use crate::mir::pretty::{function_body, pretty_statement};
22use crate :: ty:: {
33 AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , RigidTy , Ty , TyKind ,
44} ;
5- use crate :: { Error , Opaque , Span } ;
5+ use crate :: { Error , Opaque , Span , Symbol } ;
66use std:: io;
77
88/// The SMIR representation of a single function.
@@ -19,21 +19,29 @@ pub struct Body {
1919
2020 // The number of arguments this function takes.
2121 pub ( super ) arg_count : usize ,
22+
23+ // Debug information pertaining to user variables, including captures.
24+ pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
2225}
2326
2427impl Body {
2528 /// Constructs a `Body`.
2629 ///
2730 /// A constructor is required to build a `Body` from outside the crate
2831 /// because the `arg_count` and `locals` fields are private.
29- pub fn new ( blocks : Vec < BasicBlock > , locals : LocalDecls , arg_count : usize ) -> Self {
32+ pub fn new (
33+ blocks : Vec < BasicBlock > ,
34+ locals : LocalDecls ,
35+ arg_count : usize ,
36+ var_debug_info : Vec < VarDebugInfo > ,
37+ ) -> Self {
3038 // If locals doesn't contain enough entries, it can lead to panics in
3139 // `ret_local`, `arg_locals`, and `inner_locals`.
3240 assert ! (
3341 locals. len( ) > arg_count,
3442 "A Body must contain at least a local for the return value and each of the function's arguments"
3543 ) ;
36- Self { blocks, locals, arg_count }
44+ Self { blocks, locals, arg_count, var_debug_info }
3745 }
3846
3947 /// Return local that holds this function's return value.
@@ -427,6 +435,42 @@ pub struct Place {
427435 pub projection : Vec < ProjectionElem > ,
428436}
429437
438+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
439+ pub struct VarDebugInfo {
440+ pub name : Symbol ,
441+ pub source_info : SourceInfo ,
442+ pub composite : Option < VarDebugInfoFragment > ,
443+ pub value : VarDebugInfoContents ,
444+ pub argument_index : Option < u16 > ,
445+ }
446+
447+ pub type SourceScope = u32 ;
448+
449+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
450+ pub struct SourceInfo {
451+ pub span : Span ,
452+ pub scope : SourceScope ,
453+ }
454+
455+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
456+ pub struct VarDebugInfoFragment {
457+ pub ty : Ty ,
458+ pub projection : Vec < ProjectionElem > ,
459+ }
460+
461+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
462+ pub enum VarDebugInfoContents {
463+ Place ( Place ) ,
464+ Const ( ConstOperand ) ,
465+ }
466+
467+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
468+ pub struct ConstOperand {
469+ pub span : Span ,
470+ pub user_ty : Option < UserTypeAnnotationIndex > ,
471+ pub const_ : Const ,
472+ }
473+
430474// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
431475// is so it can be used for both Places (for which the projection elements are of type
432476// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
0 commit comments