1
1
use crate :: mir:: pretty:: { function_body, pretty_statement, pretty_terminator} ;
2
2
use crate :: ty:: {
3
3
AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , RigidTy , Ty , TyKind ,
4
+ VariantIdx ,
4
5
} ;
5
6
use crate :: { Error , Opaque , Span , Symbol } ;
6
7
use std:: io;
@@ -9,17 +10,17 @@ use std::io;
9
10
pub struct Body {
10
11
pub blocks : Vec < BasicBlock > ,
11
12
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.
17
18
pub ( super ) locals : LocalDecls ,
18
19
19
- // The number of arguments this function takes.
20
+ /// The number of arguments this function takes.
20
21
pub ( super ) arg_count : usize ,
21
22
22
- // Debug information pertaining to user variables, including captures.
23
+ /// Debug information pertaining to user variables, including captures.
23
24
pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
24
25
}
25
26
@@ -69,6 +70,11 @@ impl Body {
69
70
& self . locals
70
71
}
71
72
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
+
72
78
pub fn dump < W : io:: Write > ( & self , w : & mut W ) -> io:: Result < ( ) > {
73
79
writeln ! ( w, "{}" , function_body( self ) ) ?;
74
80
self . blocks
@@ -492,12 +498,32 @@ pub struct Place {
492
498
pub projection : Vec < ProjectionElem > ,
493
499
}
494
500
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.
495
508
#[ derive( Clone , Debug , Eq , PartialEq ) ]
496
509
pub struct VarDebugInfo {
510
+ /// The variable name.
497
511
pub name : Symbol ,
512
+
513
+ /// Source info of the user variable, including the scope
514
+ /// within which the variable is visible (to debuginfo)
498
515
pub source_info : SourceInfo ,
516
+
517
+ /// The user variable's data is split across several fragments,
518
+ /// each described by a `VarDebugInfoFragment`.
499
519
pub composite : Option < VarDebugInfoFragment > ,
520
+
521
+ /// Where the data for this user variable is to be found.
500
522
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.
501
527
pub argument_index : Option < u16 > ,
502
528
}
503
529
@@ -634,21 +660,6 @@ pub const RETURN_LOCAL: Local = 0;
634
660
/// `g`'s `FieldIdx` is `2`.
635
661
type FieldIdx = usize ;
636
662
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
-
652
663
type UserTypeAnnotationIndex = usize ;
653
664
654
665
#[ derive( Clone , Debug , Eq , PartialEq ) ]
0 commit comments