@@ -20,7 +20,6 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
2020 cx : & CodegenCx < ' ll , ' tcx > ,
2121 instance : Instance < ' tcx > ,
2222 mir : & Body < ' tcx > ,
23- fn_dbg_scope : & ' ll DIScope ,
2423 debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
2524) {
2625 // Find all scopes with variables defined in them.
@@ -38,47 +37,49 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
3837 // Nothing to emit, of course.
3938 None
4039 } ;
41-
40+ let mut instantiated = BitSet :: new_empty ( mir . source_scopes . len ( ) ) ;
4241 // Instantiate all scopes.
4342 for idx in 0 ..mir. source_scopes . len ( ) {
4443 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) ;
4645 }
46+ assert ! ( instantiated. count( ) == mir. source_scopes. len( ) ) ;
4747}
4848
4949fn make_mir_scope < ' ll , ' tcx > (
5050 cx : & CodegenCx < ' ll , ' tcx > ,
5151 instance : Instance < ' tcx > ,
5252 mir : & Body < ' tcx > ,
53- fn_dbg_scope : & ' ll DIScope ,
5453 variables : & Option < BitSet < SourceScope > > ,
5554 debug_context : & mut FunctionDebugContext < & ' ll DIScope , & ' ll DILocation > ,
55+ instantiated : & mut BitSet < SourceScope > ,
5656 scope : SourceScope ,
5757) {
58- if debug_context . scopes [ scope ] . dbg_scope . is_some ( ) {
58+ if instantiated . contains ( scope ) {
5959 return ;
6060 }
6161
6262 let scope_data = & mir. source_scopes [ scope] ;
6363 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) ;
6565 debug_context. scopes [ parent]
6666 } else {
6767 // The root is the function itself.
6868 let loc = cx. lookup_debug_loc ( mir. span . lo ( ) ) ;
6969 debug_context. scopes [ scope] = DebugScope {
70- dbg_scope : Some ( fn_dbg_scope) ,
71- inlined_at : None ,
7270 file_start_pos : loc. file . start_pos ,
7371 file_end_pos : loc. file . end_pos ,
72+ ..debug_context. scopes [ scope]
7473 } ;
74+ instantiated. insert ( scope) ;
7575 return ;
7676 } ;
7777
7878 if let Some ( vars) = variables && !vars. contains ( scope) && scope_data. inlined . is_none ( ) {
7979 // Do not create a DIScope if there are no variables defined in this
8080 // MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
8181 debug_context. scopes [ scope] = parent_scope;
82+ instantiated. insert ( scope) ;
8283 return ;
8384 }
8485
@@ -100,7 +101,7 @@ fn make_mir_scope<'ll, 'tcx>(
100101 None => unsafe {
101102 llvm:: LLVMRustDIBuilderCreateLexicalBlock (
102103 DIB ( cx) ,
103- parent_scope. dbg_scope . unwrap ( ) ,
104+ parent_scope. dbg_scope ,
104105 file_metadata,
105106 loc. line ,
106107 loc. col ,
@@ -116,9 +117,10 @@ fn make_mir_scope<'ll, 'tcx>(
116117 } ) ;
117118
118119 debug_context. scopes [ scope] = DebugScope {
119- dbg_scope : Some ( dbg_scope ) ,
120+ dbg_scope,
120121 inlined_at : inlined_at. or ( parent_scope. inlined_at ) ,
121122 file_start_pos : loc. file . start_pos ,
122123 file_end_pos : loc. file . end_pos ,
123124 } ;
125+ instantiated. insert ( scope) ;
124126}
0 commit comments