Skip to content

Commit d956d01

Browse files
authored
Rollup merge of #96432 - SparrowLii:dbg_scope, r=davidtwco
not need `Option` for `dbg_scope` This PR fixes a few FIXME about not using `Option` in `dbg_scope` field of `DebugScope`, during `create_function_debug_context` func in codegen parts. Added a `BitSet<SourceScope>` parameter to `make_mir_scope` to indicate whether the `DebugScope` has been instantiated. cc ````@eddyb````
2 parents 80045d6 + 843e8d1 commit d956d01

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -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

4949
fn 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
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
286286
}
287287

288288
// Initialize fn debug context (including scopes).
289-
// FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`.
290289
let empty_scope = DebugScope {
291-
dbg_scope: None,
290+
dbg_scope: self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
292291
inlined_at: None,
293292
file_start_pos: BytePos(0),
294293
file_end_pos: BytePos(0),
@@ -297,13 +296,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
297296
FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) };
298297

299298
// Fill in all the scopes, with the information from the MIR body.
300-
compute_mir_scopes(
301-
self,
302-
instance,
303-
mir,
304-
self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
305-
&mut fn_debug_context,
306-
);
299+
compute_mir_scopes(self, instance, mir, &mut fn_debug_context);
307300

308301
Some(fn_debug_context)
309302
}

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {
3939

4040
#[derive(Clone, Copy, Debug)]
4141
pub struct DebugScope<S, L> {
42-
// FIXME(eddyb) this should never be `None`, after initialization.
43-
pub dbg_scope: Option<S>,
42+
pub dbg_scope: S,
4443

4544
/// Call site location, if this scope was inlined from another function.
4645
pub inlined_at: Option<L>,
@@ -61,17 +60,12 @@ impl<'tcx, S: Copy, L: Copy> DebugScope<S, L> {
6160
cx: &Cx,
6261
span: Span,
6362
) -> S {
64-
// FIXME(eddyb) this should never be `None`.
65-
let dbg_scope = self
66-
.dbg_scope
67-
.unwrap_or_else(|| bug!("`dbg_scope` is only `None` during initialization"));
68-
6963
let pos = span.lo();
7064
if pos < self.file_start_pos || pos >= self.file_end_pos {
7165
let sm = cx.sess().source_map();
72-
cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file)
66+
cx.extend_scope_to_file(self.dbg_scope, &sm.lookup_char_pos(pos).file)
7367
} else {
74-
dbg_scope
68+
self.dbg_scope
7569
}
7670
}
7771
}

0 commit comments

Comments
 (0)