Skip to content

Commit 9d57c41

Browse files
committed
rustc_codegen_llvm: create DIFiles from just SourceFiles.
1 parent 2bfb462 commit 9d57c41

File tree

6 files changed

+21
-54
lines changed

6 files changed

+21
-54
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn make_mir_scope(
7676
}
7777

7878
let loc = cx.lookup_debug_loc(scope_data.span.lo());
79-
let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate);
79+
let file_metadata = file_metadata(cx, &loc.file);
8080

8181
let scope_metadata = unsafe {
8282
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(

compiler/rustc_codegen_llvm/src/debuginfo/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! utilizing a cache. The way to get a shared metadata node when needed is
2929
//! thus to just call the corresponding function in this module:
3030
//!
31-
//! let file_metadata = file_metadata(crate_context, path);
31+
//! let file_metadata = file_metadata(cx, file);
3232
//!
3333
//! The function will take care of probing the cache for an existing node for
3434
//! that exact file path.

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_data_structures::fx::FxHashMap;
2626
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2727
use rustc_fs_util::path_to_c_string;
2828
use rustc_hir::def::CtorKind;
29-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
29+
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
3030
use rustc_index::vec::{Idx, IndexVec};
3131
use rustc_middle::ich::NodeIdHashingMode;
3232
use rustc_middle::mir::interpret::truncate;
@@ -760,16 +760,12 @@ fn hex_encode(data: &[u8]) -> String {
760760
hex_string
761761
}
762762

763-
pub fn file_metadata(
764-
cx: &CodegenCx<'ll, '_>,
765-
source_file: &SourceFile,
766-
defining_crate: CrateNum,
767-
) -> &'ll DIFile {
768-
debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate);
763+
pub fn file_metadata(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile {
764+
debug!("file_metadata: file_name: {}", source_file.name);
769765

770766
let hash = Some(&source_file.src_hash);
771767
let file_name = Some(source_file.name.to_string());
772-
let directory = if defining_crate == LOCAL_CRATE {
768+
let directory = if source_file.is_real_file() && !source_file.is_imported() {
773769
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
774770
} else {
775771
// If the path comes from an upstream crate we assume it has been made
@@ -1835,7 +1831,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
18351831
if !span.is_dummy() {
18361832
let loc = cx.lookup_debug_loc(span.lo());
18371833
return Some(SourceInfo {
1838-
file: file_metadata(cx, &loc.file, def_id.krate),
1834+
file: file_metadata(cx, &loc.file),
18391835
line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER),
18401836
});
18411837
}
@@ -2474,7 +2470,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
24742470

24752471
let (file_metadata, line_number) = if !span.is_dummy() {
24762472
let loc = cx.lookup_debug_loc(span.lo());
2477-
(file_metadata(cx, &loc.file, LOCAL_CRATE), loc.line)
2473+
(file_metadata(cx, &loc.file), loc.line)
24782474
} else {
24792475
(unknown_file_metadata(cx), None)
24802476
};
@@ -2576,9 +2572,8 @@ pub fn create_vtable_metadata(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, vtable: &
25762572
pub fn extend_scope_to_file(
25772573
cx: &CodegenCx<'ll, '_>,
25782574
scope_metadata: &'ll DIScope,
2579-
file: &rustc_span::SourceFile,
2580-
defining_crate: CrateNum,
2575+
file: &SourceFile,
25812576
) -> &'ll DILexicalBlock {
2582-
let file_metadata = file_metadata(cx, &file, defining_crate);
2577+
let file_metadata = file_metadata(cx, file);
25832578
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
25842579
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_codegen_ssa::debuginfo::type_names;
2121
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
2222
use rustc_codegen_ssa::traits::*;
2323
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
24-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
24+
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
2525
use rustc_index::vec::IndexVec;
2626
use rustc_middle::mir;
2727
use rustc_middle::ty::layout::HasTyCtxt;
@@ -246,7 +246,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
246246
let def_id = instance.def_id();
247247
let containing_scope = get_containing_scope(self, instance);
248248
let loc = self.lookup_debug_loc(span.lo());
249-
let file_metadata = file_metadata(self, &loc.file, def_id.krate);
249+
let file_metadata = file_metadata(self, &loc.file);
250250

251251
let function_type_metadata = unsafe {
252252
let fn_signature = get_function_signature(self, fn_abi);
@@ -318,10 +318,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
318318
file_start_pos: BytePos(0),
319319
file_end_pos: BytePos(0),
320320
};
321-
let mut fn_debug_context = FunctionDebugContext {
322-
scopes: IndexVec::from_elem(null_scope, &mir.source_scopes),
323-
defining_crate: def_id.krate,
324-
};
321+
let mut fn_debug_context =
322+
FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) };
325323

326324
// Fill in all the scopes, with the information from the MIR body.
327325
compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context);
@@ -509,9 +507,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
509507
&self,
510508
scope_metadata: &'ll DIScope,
511509
file: &rustc_span::SourceFile,
512-
defining_crate: CrateNum,
513510
) -> &'ll DILexicalBlock {
514-
metadata::extend_scope_to_file(&self, scope_metadata, file, defining_crate)
511+
metadata::extend_scope_to_file(&self, scope_metadata, file)
515512
}
516513

517514
fn debuginfo_finalize(&self) {
@@ -522,15 +519,14 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
522519
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
523520
fn create_dbg_var(
524521
&self,
525-
dbg_context: &FunctionDebugContext<&'ll DIScope>,
526522
variable_name: Symbol,
527523
variable_type: Ty<'tcx>,
528524
scope_metadata: &'ll DIScope,
529525
variable_kind: VariableKind,
530526
span: Span,
531527
) -> &'ll DIVariable {
532528
let loc = self.lookup_debug_loc(span.lo());
533-
let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate);
529+
let file_metadata = file_metadata(self, &loc.file);
534530

535531
let type_metadata = type_metadata(self, variable_type, span);
536532

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::traits::*;
2-
use rustc_hir::def_id::CrateNum;
32
use rustc_index::vec::IndexVec;
43
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
54
use rustc_middle::mir;
@@ -15,7 +14,6 @@ use super::{FunctionCx, LocalRef};
1514

1615
pub struct FunctionDebugContext<D> {
1716
pub scopes: IndexVec<mir::SourceScope, DebugScope<D>>,
18-
pub defining_crate: CrateNum,
1917
}
2018

2119
#[derive(Copy, Clone)]
@@ -95,19 +93,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9593
pos: BytePos,
9694
) -> Option<Bx::DIScope> {
9795
let debug_context = self.debug_context.as_ref()?;
98-
let scope_metadata = debug_context.scopes[scope_id].scope_metadata;
96+
let scope_metadata = debug_context.scopes[scope_id].scope_metadata?;
9997
if pos < debug_context.scopes[scope_id].file_start_pos
10098
|| pos >= debug_context.scopes[scope_id].file_end_pos
10199
{
102100
let sm = self.cx.sess().source_map();
103-
let defining_crate = debug_context.defining_crate;
104-
Some(self.cx.extend_scope_to_file(
105-
scope_metadata.unwrap(),
106-
&sm.lookup_char_pos(pos).file,
107-
defining_crate,
108-
))
101+
Some(self.cx.extend_scope_to_file(scope_metadata, &sm.lookup_char_pos(pos).file))
109102
} else {
110-
scope_metadata
103+
Some(scope_metadata)
111104
}
112105
}
113106

@@ -158,14 +151,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
158151
// FIXME(eddyb) is this `+ 1` needed at all?
159152
let kind = VariableKind::ArgumentVariable(arg_index + 1);
160153

161-
self.cx.create_dbg_var(
162-
self.debug_context.as_ref().unwrap(),
163-
name,
164-
self.monomorphize(&decl.ty),
165-
scope,
166-
kind,
167-
span,
168-
)
154+
self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span)
169155
});
170156

171157
Some(PerLocalVarDebugInfo {
@@ -340,14 +326,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
340326
} else {
341327
VariableKind::LocalVariable
342328
};
343-
self.cx.create_dbg_var(
344-
self.debug_context.as_ref().unwrap(),
345-
var.name,
346-
var_ty,
347-
scope,
348-
var_kind,
349-
span,
350-
)
329+
self.cx.create_dbg_var(var.name, var_ty, scope, var_kind, span)
351330
});
352331

353332
per_local[var.place.local].push(PerLocalVarDebugInfo {

compiler/rustc_codegen_ssa/src/traits/debuginfo.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::BackendTypes;
22
use crate::mir::debuginfo::{FunctionDebugContext, VariableKind};
3-
use rustc_hir::def_id::CrateNum;
43
use rustc_middle::mir;
54
use rustc_middle::ty::{Instance, Ty};
65
use rustc_span::{SourceFile, Span, Symbol};
@@ -26,15 +25,13 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
2625
&self,
2726
scope_metadata: Self::DIScope,
2827
file: &SourceFile,
29-
defining_crate: CrateNum,
3028
) -> Self::DIScope;
3129
fn debuginfo_finalize(&self);
3230

3331
// FIXME(eddyb) find a common convention for all of the debuginfo-related
3432
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
3533
fn create_dbg_var(
3634
&self,
37-
dbg_context: &FunctionDebugContext<Self::DIScope>,
3835
variable_name: Symbol,
3936
variable_type: Ty<'tcx>,
4037
scope_metadata: Self::DIScope,

0 commit comments

Comments
 (0)