@@ -23,25 +23,26 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
23
23
fn_dbg_scope : & ' ll DIScope ,
24
24
debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
25
25
) {
26
- // Find all the scopes with variables defined in them.
27
- let mut has_variables = BitSet :: new_empty ( mir. source_scopes . len ( ) ) ;
28
-
29
- // Only consider variables when they're going to be emitted.
30
- // FIXME(eddyb) don't even allocate `has_variables` otherwise.
31
- if cx. sess ( ) . opts . debuginfo == DebugInfo :: Full {
26
+ // Find all scopes with variables defined in them.
27
+ let variables = if cx. sess ( ) . opts . debuginfo == DebugInfo :: Full {
28
+ let mut vars = BitSet :: new_empty ( mir. source_scopes . len ( ) ) ;
32
29
// FIXME(eddyb) take into account that arguments always have debuginfo,
33
30
// irrespective of their name (assuming full debuginfo is enabled).
34
31
// NOTE(eddyb) actually, on second thought, those are always in the
35
32
// function scope, which always exists.
36
33
for var_debug_info in & mir. var_debug_info {
37
- has_variables . insert ( var_debug_info. source_info . scope ) ;
34
+ vars . insert ( var_debug_info. source_info . scope ) ;
38
35
}
39
- }
36
+ Some ( vars)
37
+ } else {
38
+ // Nothing to emit, of course.
39
+ None
40
+ } ;
40
41
41
42
// Instantiate all scopes.
42
43
for idx in 0 ..mir. source_scopes . len ( ) {
43
44
let scope = SourceScope :: new ( idx) ;
44
- make_mir_scope ( cx, instance, mir, fn_dbg_scope, & has_variables , debug_context, scope) ;
45
+ make_mir_scope ( cx, instance, mir, fn_dbg_scope, & variables , debug_context, scope) ;
45
46
}
46
47
}
47
48
@@ -50,7 +51,7 @@ fn make_mir_scope<'ll, 'tcx>(
50
51
instance : Instance < ' tcx > ,
51
52
mir : & Body < ' tcx > ,
52
53
fn_dbg_scope : & ' ll DIScope ,
53
- has_variables : & BitSet < SourceScope > ,
54
+ variables : & Option < BitSet < SourceScope > > ,
54
55
debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
55
56
scope : SourceScope ,
56
57
) {
@@ -60,7 +61,7 @@ fn make_mir_scope<'ll, 'tcx>(
60
61
61
62
let scope_data = & mir. source_scopes [ scope] ;
62
63
let parent_scope = if let Some ( parent) = scope_data. parent_scope {
63
- make_mir_scope ( cx, instance, mir, fn_dbg_scope, has_variables , debug_context, parent) ;
64
+ make_mir_scope ( cx, instance, mir, fn_dbg_scope, variables , debug_context, parent) ;
64
65
debug_context. scopes [ parent]
65
66
} else {
66
67
// The root is the function itself.
@@ -74,7 +75,7 @@ fn make_mir_scope<'ll, 'tcx>(
74
75
return ;
75
76
} ;
76
77
77
- if !has_variables . contains ( scope) && scope_data. inlined . is_none ( ) {
78
+ if let Some ( vars ) = variables && !vars . contains ( scope) && scope_data. inlined . is_none ( ) {
78
79
// Do not create a DIScope if there are no variables defined in this
79
80
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
80
81
debug_context. scopes [ scope] = parent_scope;
0 commit comments