Skip to content

Commit 01be0dd

Browse files
committed
Move FunctionDebugContext creation to codegen_fn
1 parent dbf5457 commit 01be0dd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/base.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::ty::SymbolName;
1010
use indexmap::IndexSet;
1111

1212
use crate::constant::ConstantCx;
13+
use crate::debuginfo::FunctionDebugContext;
1314
use crate::prelude::*;
1415
use crate::pretty_clif::CommentWriter;
1516

@@ -18,6 +19,7 @@ struct CodegenedFunction<'tcx> {
1819
func_id: FuncId,
1920
func: Function,
2021
clif_comments: CommentWriter,
22+
func_debug_cx: Option<FunctionDebugContext>,
2123
function_span: Span,
2224
source_info_set: IndexSet<SourceInfo>,
2325
}
@@ -82,13 +84,20 @@ fn codegen_fn<'tcx>(
8284
let pointer_type = target_config.pointer_type();
8385
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
8486

87+
let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
88+
Some(debug_context.define_function(symbol_name.name))
89+
} else {
90+
None
91+
};
92+
8593
let mut fx = FunctionCx {
8694
cx,
8795
module,
8896
tcx,
8997
target_config,
9098
pointer_type,
9199
constants_cx: ConstantCx::new(),
100+
func_debug_cx,
92101

93102
instance,
94103
symbol_name,
@@ -109,6 +118,7 @@ fn codegen_fn<'tcx>(
109118

110119
// Recover all necessary data from fx, before accessing func will prevent future access to it.
111120
let clif_comments = fx.clif_comments;
121+
let func_debug_cx = fx.func_debug_cx;
112122
let function_span = fx.mir.span;
113123
let source_info_set = fx.source_info_set;
114124

@@ -128,7 +138,15 @@ fn codegen_fn<'tcx>(
128138
// Verify function
129139
verify_func(tcx, &clif_comments, &func);
130140

131-
CodegenedFunction { symbol_name, func_id, func, clif_comments, function_span, source_info_set }
141+
CodegenedFunction {
142+
symbol_name,
143+
func_id,
144+
func,
145+
clif_comments,
146+
func_debug_cx,
147+
function_span,
148+
source_info_set,
149+
}
132150
}
133151

134152
fn compile_fn<'tcx>(
@@ -214,7 +232,7 @@ fn compile_fn<'tcx>(
214232
let unwind_context = &mut cx.unwind_context;
215233
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
216234
if let Some(debug_context) = debug_context {
217-
debug_context.define_function(codegened_func.symbol_name.name).finalize(
235+
codegened_func.func_debug_cx.unwrap().finalize(
218236
debug_context,
219237
tcx,
220238
codegened_func.func_id,

src/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_target::abi::{Integer, Primitive};
99
use rustc_target::spec::{HasTargetSpec, Target};
1010

1111
use crate::constant::ConstantCx;
12+
use crate::debuginfo::FunctionDebugContext;
1213
use crate::prelude::*;
1314

1415
pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type {
@@ -238,6 +239,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
238239
pub(crate) target_config: TargetFrontendConfig, // Cached from module
239240
pub(crate) pointer_type: Type, // Cached from module
240241
pub(crate) constants_cx: ConstantCx,
242+
pub(crate) func_debug_cx: Option<FunctionDebugContext>,
241243

242244
pub(crate) instance: Instance<'tcx>,
243245
pub(crate) symbol_name: SymbolName<'tcx>,

0 commit comments

Comments
 (0)