11use crate :: mir:: pretty:: { function_body, pretty_statement, pretty_terminator} ;
22use crate :: ty:: {
33 AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , RigidTy , Ty , TyKind ,
4+ VariantIdx ,
45} ;
56use crate :: { Error , Opaque , Span , Symbol } ;
67use std:: io;
@@ -9,17 +10,17 @@ use std::io;
910pub struct Body {
1011 pub blocks : Vec < BasicBlock > ,
1112
12- // Declarations of locals within the function.
13- //
14- // The first local is the return value pointer, followed by `arg_count`
15- // locals for the function arguments, followed by any user-declared
16- // variables and temporaries.
13+ /// Declarations of locals within the function.
14+ ///
15+ /// The first local is the return value pointer, followed by `arg_count`
16+ /// locals for the function arguments, followed by any user-declared
17+ /// variables and temporaries.
1718 pub ( super ) locals : LocalDecls ,
1819
19- // The number of arguments this function takes.
20+ /// The number of arguments this function takes.
2021 pub ( super ) arg_count : usize ,
2122
22- // Debug information pertaining to user variables, including captures.
23+ /// Debug information pertaining to user variables, including captures.
2324 pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
2425}
2526
@@ -69,6 +70,11 @@ impl Body {
6970 & self . locals
7071 }
7172
73+ /// Get the local declaration for this local.
74+ pub fn local_decl ( & self , local : Local ) -> Option < & LocalDecl > {
75+ self . locals . get ( local)
76+ }
77+
7278 pub fn dump < W : io:: Write > ( & self , w : & mut W ) -> io:: Result < ( ) > {
7379 writeln ! ( w, "{}" , function_body( self ) ) ?;
7480 self . blocks
@@ -492,12 +498,32 @@ pub struct Place {
492498 pub projection : Vec < ProjectionElem > ,
493499}
494500
501+ impl From < Local > for Place {
502+ fn from ( local : Local ) -> Self {
503+ Place { local, projection : vec ! [ ] }
504+ }
505+ }
506+
507+ /// Debug information pertaining to a user variable.
495508#[ derive( Clone , Debug , Eq , PartialEq ) ]
496509pub struct VarDebugInfo {
510+ /// The variable name.
497511 pub name : Symbol ,
512+
513+ /// Source info of the user variable, including the scope
514+ /// within which the variable is visible (to debuginfo)
498515 pub source_info : SourceInfo ,
516+
517+ /// The user variable's data is split across several fragments,
518+ /// each described by a `VarDebugInfoFragment`.
499519 pub composite : Option < VarDebugInfoFragment > ,
520+
521+ /// Where the data for this user variable is to be found.
500522 pub value : VarDebugInfoContents ,
523+
524+ /// When present, indicates what argument number this variable is in the function that it
525+ /// originated from (starting from 1). Note, if MIR inlining is enabled, then this is the
526+ /// argument number in the original function before it was inlined.
501527 pub argument_index : Option < u16 > ,
502528}
503529
@@ -634,21 +660,6 @@ pub const RETURN_LOCAL: Local = 0;
634660/// `g`'s `FieldIdx` is `2`.
635661type FieldIdx = usize ;
636662
637- /// The source-order index of a variant in a type.
638- ///
639- /// For example, in the following types,
640- /// ```ignore(illustrative)
641- /// enum Demo1 {
642- /// Variant0 { a: bool, b: i32 },
643- /// Variant1 { c: u8, d: u64 },
644- /// }
645- /// struct Demo2 { e: u8, f: u16, g: u8 }
646- /// ```
647- /// `a` is in the variant with the `VariantIdx` of `0`,
648- /// `c` is in the variant with the `VariantIdx` of `1`, and
649- /// `g` is in the variant with the `VariantIdx` of `0`.
650- pub type VariantIdx = usize ;
651-
652663type UserTypeAnnotationIndex = usize ;
653664
654665#[ derive( Clone , Debug , Eq , PartialEq ) ]
0 commit comments