1
1
use crate :: mir:: pretty:: { function_body, pretty_statement} ;
2
2
use crate :: ty:: { AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , Ty } ;
3
- use crate :: Opaque ;
4
- use crate :: Span ;
3
+ use crate :: { Opaque , Span , Symbol } ;
5
4
use std:: io;
6
5
/// The SMIR representation of a single function.
7
6
#[ derive( Clone , Debug ) ]
@@ -17,21 +16,29 @@ pub struct Body {
17
16
18
17
// The number of arguments this function takes.
19
18
pub ( super ) arg_count : usize ,
19
+
20
+ // Debug information pertaining to user variables, including captures.
21
+ pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
20
22
}
21
23
22
24
impl Body {
23
25
/// Constructs a `Body`.
24
26
///
25
27
/// A constructor is required to build a `Body` from outside the crate
26
28
/// because the `arg_count` and `locals` fields are private.
27
- 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 {
28
35
// If locals doesn't contain enough entries, it can lead to panics in
29
36
// `ret_local`, `arg_locals`, and `inner_locals`.
30
37
assert ! (
31
38
locals. len( ) > arg_count,
32
39
"A Body must contain at least a local for the return value and each of the function's arguments"
33
40
) ;
34
- Self { blocks, locals, arg_count }
41
+ Self { blocks, locals, arg_count, var_debug_info }
35
42
}
36
43
37
44
/// Return local that holds this function's return value.
@@ -425,6 +432,42 @@ pub struct Place {
425
432
pub projection : Vec < ProjectionElem > ,
426
433
}
427
434
435
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
436
+ pub struct VarDebugInfo {
437
+ pub name : Symbol ,
438
+ pub source_info : SourceInfo ,
439
+ pub composite : Option < VarDebugInfoFragment > ,
440
+ pub value : VarDebugInfoContents ,
441
+ pub argument_index : Option < u16 > ,
442
+ }
443
+
444
+ pub type SourceScope = u32 ;
445
+
446
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
447
+ pub struct SourceInfo {
448
+ pub span : Span ,
449
+ pub scope : SourceScope ,
450
+ }
451
+
452
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
453
+ pub struct VarDebugInfoFragment {
454
+ pub ty : Ty ,
455
+ pub projection : Vec < ProjectionElem > ,
456
+ }
457
+
458
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
459
+ pub enum VarDebugInfoContents {
460
+ Place ( Place ) ,
461
+ Const ( ConstOperand ) ,
462
+ }
463
+
464
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
465
+ pub struct ConstOperand {
466
+ pub span : Span ,
467
+ pub user_ty : Option < UserTypeAnnotationIndex > ,
468
+ pub const_ : Const ,
469
+ }
470
+
428
471
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
429
472
// is so it can be used for both Places (for which the projection elements are of type
430
473
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
0 commit comments