@@ -20,7 +20,6 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
20
20
cx : & CodegenCx < ' ll , ' tcx > ,
21
21
instance : Instance < ' tcx > ,
22
22
mir : & Body < ' tcx > ,
23
- fn_dbg_scope : & ' ll DIScope ,
24
23
debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
25
24
) {
26
25
// Find all scopes with variables defined in them.
@@ -38,47 +37,49 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
38
37
// Nothing to emit, of course.
39
38
None
40
39
} ;
41
-
40
+ let mut instantiated = BitSet :: new_empty ( mir . source_scopes . len ( ) ) ;
42
41
// Instantiate all scopes.
43
42
for idx in 0 ..mir. source_scopes . len ( ) {
44
43
let scope = SourceScope :: new ( idx) ;
45
- make_mir_scope ( cx, instance, mir, fn_dbg_scope , & variables, debug_context, scope) ;
44
+ make_mir_scope ( cx, instance, mir, & variables, debug_context, & mut instantiated , scope) ;
46
45
}
46
+ assert ! ( instantiated. count( ) == mir. source_scopes. len( ) ) ;
47
47
}
48
48
49
49
fn make_mir_scope < ' ll , ' tcx > (
50
50
cx : & CodegenCx < ' ll , ' tcx > ,
51
51
instance : Instance < ' tcx > ,
52
52
mir : & Body < ' tcx > ,
53
- fn_dbg_scope : & ' ll DIScope ,
54
53
variables : & Option < BitSet < SourceScope > > ,
55
54
debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
55
+ instantiated : & mut BitSet < SourceScope > ,
56
56
scope : SourceScope ,
57
57
) {
58
- if debug_context . scopes [ scope ] . dbg_scope . is_some ( ) {
58
+ if instantiated . contains ( scope ) {
59
59
return ;
60
60
}
61
61
62
62
let scope_data = & mir. source_scopes [ scope] ;
63
63
let parent_scope = if let Some ( parent) = scope_data. parent_scope {
64
- make_mir_scope ( cx, instance, mir, fn_dbg_scope , variables, debug_context, parent) ;
64
+ make_mir_scope ( cx, instance, mir, variables, debug_context, instantiated , parent) ;
65
65
debug_context. scopes [ parent]
66
66
} else {
67
67
// The root is the function itself.
68
68
let loc = cx. lookup_debug_loc ( mir. span . lo ( ) ) ;
69
69
debug_context. scopes [ scope] = DebugScope {
70
- dbg_scope : Some ( fn_dbg_scope) ,
71
- inlined_at : None ,
72
70
file_start_pos : loc. file . start_pos ,
73
71
file_end_pos : loc. file . end_pos ,
72
+ ..debug_context. scopes [ scope]
74
73
} ;
74
+ instantiated. insert ( scope) ;
75
75
return ;
76
76
} ;
77
77
78
78
if let Some ( vars) = variables && !vars. contains ( scope) && scope_data. inlined . is_none ( ) {
79
79
// Do not create a DIScope if there are no variables defined in this
80
80
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
81
81
debug_context. scopes [ scope] = parent_scope;
82
+ instantiated. insert ( scope) ;
82
83
return ;
83
84
}
84
85
@@ -100,7 +101,7 @@ fn make_mir_scope<'ll, 'tcx>(
100
101
None => unsafe {
101
102
llvm:: LLVMRustDIBuilderCreateLexicalBlock (
102
103
DIB ( cx) ,
103
- parent_scope. dbg_scope . unwrap ( ) ,
104
+ parent_scope. dbg_scope ,
104
105
file_metadata,
105
106
loc. line ,
106
107
loc. col ,
@@ -116,9 +117,10 @@ fn make_mir_scope<'ll, 'tcx>(
116
117
} ) ;
117
118
118
119
debug_context. scopes [ scope] = DebugScope {
119
- dbg_scope : Some ( dbg_scope ) ,
120
+ dbg_scope,
120
121
inlined_at : inlined_at. or ( parent_scope. inlined_at ) ,
121
122
file_start_pos : loc. file . start_pos ,
122
123
file_end_pos : loc. file . end_pos ,
123
124
} ;
125
+ instantiated. insert ( scope) ;
124
126
}
0 commit comments