Skip to content

Commit 23f47fb

Browse files
committed
rustc_codegen_llvm: create DIFiles from just SourceFiles.
1 parent 71d70a4 commit 23f47fb

File tree

6 files changed

+21
-54
lines changed

6 files changed

+21
-54
lines changed

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn make_mir_scope(
6767
}
6868

6969
let loc = cx.lookup_debug_loc(scope_data.span.lo());
70-
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);
70+
let file_metadata = file_metadata(cx, &loc.file);
7171

7272
let scope_metadata = unsafe {
7373
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(

src/librustc_codegen_llvm/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.

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ use rustc_data_structures::fx::FxHashMap;
3939
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4040
use rustc_fs_util::path_to_c_string;
4141
use rustc_hir::def::CtorKind;
42-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
42+
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
4343
use rustc_index::vec::{Idx, IndexVec};
4444
use rustc_session::config::{self, DebugInfo};
4545
use rustc_span::symbol::{Interner, Symbol};
46-
use rustc_span::{self, FileName, Span};
46+
use rustc_span::{self, Span};
4747
use rustc_target::abi::HasDataLayout;
4848

4949
use libc::{c_longlong, c_uint};
@@ -751,15 +751,11 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
751751
metadata
752752
}
753753

754-
pub fn file_metadata(
755-
cx: &CodegenCx<'ll, '_>,
756-
file_name: &FileName,
757-
defining_crate: CrateNum,
758-
) -> &'ll DIFile {
759-
debug!("file_metadata: file_name: {}, defining_crate: {}", file_name, defining_crate);
754+
pub fn file_metadata(cx: &CodegenCx<'ll, '_>, file: &rustc_span::SourceFile) -> &'ll DIFile {
755+
debug!("file_metadata({:?})", file);
760756

761-
let file_name = Some(file_name.to_string());
762-
let directory = if defining_crate == LOCAL_CRATE {
757+
let file_name = Some(file.name.to_string());
758+
let directory = if file.is_real_file() && !file.is_imported() {
763759
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
764760
} else {
765761
// If the path comes from an upstream crate we assume it has been made
@@ -2310,7 +2306,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
23102306

23112307
let (file_metadata, line_number) = if !span.is_dummy() {
23122308
let loc = cx.lookup_debug_loc(span.lo());
2313-
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line)
2309+
(file_metadata(cx, &loc.file), loc.line)
23142310
} else {
23152311
(unknown_file_metadata(cx), None)
23162312
};
@@ -2412,8 +2408,7 @@ pub fn extend_scope_to_file(
24122408
cx: &CodegenCx<'ll, '_>,
24132409
scope_metadata: &'ll DIScope,
24142410
file: &rustc_span::SourceFile,
2415-
defining_crate: CrateNum,
24162411
) -> &'ll DILexicalBlock {
2417-
let file_metadata = file_metadata(cx, &file.name, defining_crate);
2412+
let file_metadata = file_metadata(cx, file);
24182413
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
24192414
}

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::llvm::debuginfo::{
1313
DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType, DIVariable,
1414
};
1515
use rustc::ty::subst::{GenericArgKind, SubstsRef};
16-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
16+
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
1717

1818
use crate::abi::FnAbi;
1919
use crate::builder::Builder;
@@ -249,7 +249,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
249249
let def_id = instance.def_id();
250250
let containing_scope = get_containing_scope(self, instance);
251251
let loc = self.lookup_debug_loc(span.lo());
252-
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);
252+
let file_metadata = file_metadata(self, &loc.file);
253253

254254
let function_type_metadata = unsafe {
255255
let fn_signature = get_function_signature(self, fn_abi);
@@ -322,10 +322,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
322322
file_start_pos: BytePos(0),
323323
file_end_pos: BytePos(0),
324324
};
325-
let mut fn_debug_context = FunctionDebugContext {
326-
scopes: IndexVec::from_elem(null_scope, &mir.source_scopes),
327-
defining_crate: def_id.krate,
328-
};
325+
let mut fn_debug_context =
326+
FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) };
329327

330328
// Fill in all the scopes, with the information from the MIR body.
331329
compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context);
@@ -510,9 +508,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
510508
&self,
511509
scope_metadata: &'ll DIScope,
512510
file: &rustc_span::SourceFile,
513-
defining_crate: CrateNum,
514511
) -> &'ll DILexicalBlock {
515-
metadata::extend_scope_to_file(&self, scope_metadata, file, defining_crate)
512+
metadata::extend_scope_to_file(&self, scope_metadata, file)
516513
}
517514

518515
fn debuginfo_finalize(&self) {
@@ -523,15 +520,14 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
523520
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
524521
fn create_dbg_var(
525522
&self,
526-
dbg_context: &FunctionDebugContext<&'ll DIScope>,
527523
variable_name: ast::Name,
528524
variable_type: Ty<'tcx>,
529525
scope_metadata: &'ll DIScope,
530526
variable_kind: VariableKind,
531527
span: Span,
532528
) -> &'ll DIVariable {
533529
let loc = self.lookup_debug_loc(span.lo());
534-
let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);
530+
let file_metadata = file_metadata(self, &loc.file);
535531

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

src/librustc_codegen_ssa/mir/debuginfo.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::traits::*;
22
use rustc::mir;
33
use rustc::ty;
44
use rustc::ty::layout::{LayoutOf, Size};
5-
use rustc_hir::def_id::CrateNum;
65
use rustc_index::vec::IndexVec;
76
use rustc_session::config::DebugInfo;
87

@@ -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)]
@@ -94,19 +92,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9492
pos: BytePos,
9593
) -> Option<Bx::DIScope> {
9694
let debug_context = self.debug_context.as_ref()?;
97-
let scope_metadata = debug_context.scopes[scope_id].scope_metadata;
95+
let scope_metadata = debug_context.scopes[scope_id].scope_metadata?;
9896
if pos < debug_context.scopes[scope_id].file_start_pos
9997
|| pos >= debug_context.scopes[scope_id].file_end_pos
10098
{
10199
let sm = self.cx.sess().source_map();
102-
let defining_crate = debug_context.defining_crate;
103-
Some(self.cx.extend_scope_to_file(
104-
scope_metadata.unwrap(),
105-
&sm.lookup_char_pos(pos).file,
106-
defining_crate,
107-
))
100+
Some(self.cx.extend_scope_to_file(scope_metadata, &sm.lookup_char_pos(pos).file))
108101
} else {
109-
scope_metadata
102+
Some(scope_metadata)
110103
}
111104
}
112105

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

159-
self.cx.create_dbg_var(
160-
self.debug_context.as_ref().unwrap(),
161-
name,
162-
self.monomorphize(&decl.ty),
163-
scope,
164-
kind,
165-
span,
166-
)
152+
self.cx.create_dbg_var(name, self.monomorphize(&decl.ty), scope, kind, span)
167153
});
168154

169155
Some(PerLocalVarDebugInfo {
@@ -331,14 +317,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
331317
} else {
332318
VariableKind::LocalVariable
333319
};
334-
self.cx.create_dbg_var(
335-
self.debug_context.as_ref().unwrap(),
336-
var.name,
337-
var_ty,
338-
scope,
339-
var_kind,
340-
span,
341-
)
320+
self.cx.create_dbg_var(var.name, var_ty, scope, var_kind, span)
342321
});
343322

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

src/librustc_codegen_ssa/traits/debuginfo.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::mir;
44
use rustc::ty::layout::Size;
55
use rustc::ty::{Instance, Ty};
66
use rustc_ast::ast::Name;
7-
use rustc_hir::def_id::CrateNum;
87
use rustc_span::{SourceFile, Span};
98
use rustc_target::abi::call::FnAbi;
109

@@ -27,15 +26,13 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
2726
&self,
2827
scope_metadata: Self::DIScope,
2928
file: &SourceFile,
30-
defining_crate: CrateNum,
3129
) -> Self::DIScope;
3230
fn debuginfo_finalize(&self);
3331

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

0 commit comments

Comments
 (0)