@@ -2,7 +2,7 @@ use crate::mir::pretty::{function_body, pretty_statement};
2
2
use crate :: ty:: {
3
3
AdtDef , ClosureDef , Const , CoroutineDef , GenericArgs , Movability , Region , RigidTy , Ty , TyKind ,
4
4
} ;
5
- use crate :: { Error , Opaque , Span } ;
5
+ use crate :: { Error , Opaque , Span , Symbol } ;
6
6
use std:: io;
7
7
8
8
/// The SMIR representation of a single function.
@@ -19,21 +19,29 @@ pub struct Body {
19
19
20
20
// The number of arguments this function takes.
21
21
pub ( super ) arg_count : usize ,
22
+
23
+ // Debug information pertaining to user variables, including captures.
24
+ pub ( super ) var_debug_info : Vec < VarDebugInfo > ,
22
25
}
23
26
24
27
impl Body {
25
28
/// Constructs a `Body`.
26
29
///
27
30
/// A constructor is required to build a `Body` from outside the crate
28
31
/// 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 {
30
38
// If locals doesn't contain enough entries, it can lead to panics in
31
39
// `ret_local`, `arg_locals`, and `inner_locals`.
32
40
assert ! (
33
41
locals. len( ) > arg_count,
34
42
"A Body must contain at least a local for the return value and each of the function's arguments"
35
43
) ;
36
- Self { blocks, locals, arg_count }
44
+ Self { blocks, locals, arg_count, var_debug_info }
37
45
}
38
46
39
47
/// Return local that holds this function's return value.
@@ -427,6 +435,42 @@ pub struct Place {
427
435
pub projection : Vec < ProjectionElem > ,
428
436
}
429
437
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
+
430
474
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
431
475
// is so it can be used for both Places (for which the projection elements are of type
432
476
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
0 commit comments