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