Skip to content

Commit 259b21f

Browse files
committed
Remove TyCtxt from DebugContext
And explicitly thread it through everwhere it is needed.
1 parent e5493a5 commit 259b21f

File tree

8 files changed

+28
-27
lines changed

8 files changed

+28
-27
lines changed

src/base.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct CodegenedFunction<'tcx> {
2424

2525
pub(crate) fn codegen_and_compile_fn<'tcx>(
2626
tcx: TyCtxt<'tcx>,
27-
cx: &mut crate::CodegenCx<'tcx>,
27+
cx: &mut crate::CodegenCx,
2828
cached_context: &mut Context,
2929
module: &mut dyn Module,
3030
instance: Instance<'tcx>,
@@ -35,12 +35,12 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
3535
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
3636
let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance);
3737

38-
compile_fn(cx, cached_context, module, codegened_func);
38+
compile_fn(tcx, cx, cached_context, module, codegened_func);
3939
}
4040

4141
fn codegen_fn<'tcx>(
4242
tcx: TyCtxt<'tcx>,
43-
cx: &mut crate::CodegenCx<'tcx>,
43+
cx: &mut crate::CodegenCx,
4444
cached_func: Function,
4545
module: &mut dyn Module,
4646
instance: Instance<'tcx>,
@@ -132,7 +132,8 @@ fn codegen_fn<'tcx>(
132132
}
133133

134134
fn compile_fn<'tcx>(
135-
cx: &mut crate::CodegenCx<'tcx>,
135+
tcx: TyCtxt<'tcx>,
136+
cx: &mut crate::CodegenCx,
136137
cached_context: &mut Context,
137138
module: &mut dyn Module,
138139
codegened_func: CodegenedFunction<'tcx>,
@@ -214,6 +215,7 @@ fn compile_fn<'tcx>(
214215
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
215216
if let Some(debug_context) = debug_context {
216217
debug_context.define_function(
218+
tcx,
217219
codegened_func.func_id,
218220
codegened_func.symbol_name.name,
219221
context,

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool {
232232
}
233233

234234
pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
235-
pub(crate) cx: &'clif mut crate::CodegenCx<'tcx>,
235+
pub(crate) cx: &'clif mut crate::CodegenCx,
236236
pub(crate) module: &'m mut dyn Module,
237237
pub(crate) tcx: TyCtxt<'tcx>,
238238
pub(crate) target_config: TargetFrontendConfig, // Cached from module

src/debuginfo/emit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use gimli::{RunTimeEndian, SectionId};
99
use super::object::WriteDebugInfo;
1010
use super::DebugContext;
1111

12-
impl DebugContext<'_> {
12+
impl DebugContext {
1313
pub(crate) fn emit(&mut self, product: &mut ObjectProduct) {
1414
let unit_range_list_id = self.dwarf.unit.ranges.add(self.unit_range_list.clone());
1515
let root = self.dwarf.unit.root();

src/debuginfo/line_info.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ fn line_program_add_file(
9696
}
9797
}
9898

99-
impl<'tcx> DebugContext<'tcx> {
100-
pub(super) fn emit_location(&mut self, entry_id: UnitEntryId, span: Span) {
101-
let loc = self.tcx.sess.source_map().lookup_char_pos(span.lo());
99+
impl DebugContext {
100+
fn emit_location(&mut self, tcx: TyCtxt<'_>, entry_id: UnitEntryId, span: Span) {
101+
let loc = tcx.sess.source_map().lookup_char_pos(span.lo());
102102

103103
let file_id = line_program_add_file(
104104
&mut self.dwarf.unit.line_program,
@@ -115,13 +115,13 @@ impl<'tcx> DebugContext<'tcx> {
115115

116116
pub(super) fn create_debug_lines(
117117
&mut self,
118+
tcx: TyCtxt<'_>,
118119
symbol: usize,
119120
entry_id: UnitEntryId,
120121
context: &Context,
121122
function_span: Span,
122123
source_info_set: &indexmap::IndexSet<SourceInfo>,
123124
) -> CodeOffset {
124-
let tcx = self.tcx;
125125
let line_program = &mut self.dwarf.unit.line_program;
126126

127127
let line_strings = &mut self.dwarf.line_strings;
@@ -211,7 +211,7 @@ impl<'tcx> DebugContext<'tcx> {
211211
);
212212
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(func_end)));
213213

214-
self.emit_location(entry_id, function_span);
214+
self.emit_location(tcx, entry_id, function_span);
215215

216216
func_end
217217
}

src/debuginfo/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
1616
pub(crate) use emit::{DebugReloc, DebugRelocName};
1717
pub(crate) use unwind::UnwindContext;
1818

19-
pub(crate) struct DebugContext<'tcx> {
20-
tcx: TyCtxt<'tcx>,
21-
19+
pub(crate) struct DebugContext {
2220
endian: RunTimeEndian,
2321

2422
dwarf: DwarfUnit,
2523
unit_range_list: RangeList,
2624
}
2725

28-
impl<'tcx> DebugContext<'tcx> {
29-
pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
26+
impl DebugContext {
27+
pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa) -> Self {
3028
let encoding = Encoding {
3129
format: Format::Dwarf32,
3230
// FIXME this should be configurable
@@ -92,11 +90,12 @@ impl<'tcx> DebugContext<'tcx> {
9290
root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0)));
9391
}
9492

95-
DebugContext { tcx, endian, dwarf, unit_range_list: RangeList(Vec::new()) }
93+
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
9694
}
9795

9896
pub(crate) fn define_function(
9997
&mut self,
98+
tcx: TyCtxt<'_>,
10099
func_id: FuncId,
101100
name: &str,
102101
context: &Context,
@@ -116,7 +115,7 @@ impl<'tcx> DebugContext<'tcx> {
116115
entry.set(gimli::DW_AT_linkage_name, AttributeValue::StringRef(name_id));
117116

118117
let end =
119-
self.create_debug_lines(symbol, entry_id, context, function_span, source_info_set);
118+
self.create_debug_lines(tcx, symbol, entry_id, context, function_span, source_info_set);
120119

121120
self.unit_range_list.0.push(Range::StartLength {
122121
begin: Address::Symbol { symbol, addend: 0 },

src/driver/aot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn emit_cgu(
120120
prof: &SelfProfilerRef,
121121
name: String,
122122
module: ObjectModule,
123-
debug: Option<DebugContext<'_>>,
123+
debug: Option<DebugContext>,
124124
unwind_context: UnwindContext,
125125
global_asm_object_file: Option<PathBuf>,
126126
) -> Result<ModuleCodegenResult, String> {

src/driver/jit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ impl UnsafeMessage {
6161
}
6262
}
6363

64-
fn create_jit_module<'tcx>(
65-
tcx: TyCtxt<'tcx>,
64+
fn create_jit_module(
65+
tcx: TyCtxt<'_>,
6666
backend_config: &BackendConfig,
6767
hotswap: bool,
68-
) -> (JITModule, CodegenCx<'tcx>) {
68+
) -> (JITModule, CodegenCx) {
6969
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
7070
let imported_symbols = load_imported_symbols_for_jit(tcx.sess, crate_info);
7171

@@ -353,7 +353,7 @@ fn load_imported_symbols_for_jit(
353353

354354
fn codegen_shim<'tcx>(
355355
tcx: TyCtxt<'tcx>,
356-
cx: &mut CodegenCx<'tcx>,
356+
cx: &mut CodegenCx,
357357
cached_context: &mut Context,
358358
module: &mut JITModule,
359359
inst: Instance<'tcx>,

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
122122

123123
/// The codegen context holds any information shared between the codegen of individual functions
124124
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
125-
struct CodegenCx<'tcx> {
125+
struct CodegenCx {
126126
profiler: SelfProfilerRef,
127127
output_filenames: Arc<OutputFilenames>,
128128
should_write_ir: bool,
129129
global_asm: String,
130130
inline_asm_index: Cell<usize>,
131-
debug_context: Option<DebugContext<'tcx>>,
131+
debug_context: Option<DebugContext>,
132132
unwind_context: UnwindContext,
133133
cgu_name: Symbol,
134134
}
135135

136-
impl<'tcx> CodegenCx<'tcx> {
136+
impl CodegenCx {
137137
fn new(
138-
tcx: TyCtxt<'tcx>,
138+
tcx: TyCtxt<'_>,
139139
backend_config: BackendConfig,
140140
isa: &dyn TargetIsa,
141141
debug_info: bool,

0 commit comments

Comments
 (0)