Skip to content

Commit 4e6b178

Browse files
committed
trans: use DefKey directly in debuginfo for paths.
1 parent e945b28 commit 4e6b178

File tree

6 files changed

+113
-193
lines changed

6 files changed

+113
-193
lines changed

src/librustc_trans/base.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,15 +1400,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14001400
pub fn new(ccx: &'blk CrateContext<'blk, 'tcx>,
14011401
llfndecl: ValueRef,
14021402
fn_ty: FnType,
1403-
definition: Option<(Instance<'tcx>,
1404-
&ty::FnSig<'tcx>,
1405-
Abi,
1406-
&ty::Generics<'tcx>,
1407-
Option<ast::Name>)>,
1403+
definition: Option<(Instance<'tcx>, &ty::FnSig<'tcx>, Abi)>,
14081404
block_arena: &'blk TypedArena<common::BlockS<'blk, 'tcx>>)
14091405
-> FunctionContext<'blk, 'tcx> {
14101406
let (param_substs, def_id) = match definition {
1411-
Some((instance, _, _, _, _)) => {
1407+
Some((instance, _, _)) => {
14121408
common::validate_substs(instance.substs);
14131409
(instance.substs, Some(instance.def))
14141410
}
@@ -1450,14 +1446,9 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14501446
None
14511447
};
14521448

1453-
let span = inlined_id.and_then(|id| ccx.tcx().map.opt_span(id));
1454-
14551449
let debug_context = if let (false, Some(definition)) = (no_debug, definition) {
1456-
let (instance, sig, abi, generics, name) = definition;
1457-
debuginfo::create_function_debug_context(ccx, instance, sig,
1458-
abi, generics, name,
1459-
span.unwrap_or(DUMMY_SP),
1460-
llfndecl)
1450+
let (instance, sig, abi) = definition;
1451+
debuginfo::create_function_debug_context(ccx, instance, sig, abi, llfndecl)
14611452
} else {
14621453
debuginfo::empty_function_debug_context(ccx)
14631454
};
@@ -1476,7 +1467,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14761467
lldropflag_hints: RefCell::new(DropFlagHintsMap::new()),
14771468
fn_ty: fn_ty,
14781469
param_substs: param_substs,
1479-
span: span,
1470+
span: inlined_id.and_then(|id| ccx.tcx().map.opt_span(id)),
14801471
block_arena: block_arena,
14811472
lpad_arena: TypedArena::new(),
14821473
ccx: ccx,
@@ -1831,8 +1822,6 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18311822
inlined_id: ast::NodeId,
18321823
sig: &ty::FnSig<'tcx>,
18331824
abi: Abi,
1834-
generics: &ty::Generics<'tcx>,
1835-
name: Option<ast::Name>,
18361825
closure_env: closure::ClosureEnv) {
18371826
ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);
18381827

@@ -1849,8 +1838,7 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18491838

18501839
let (arena, fcx): (TypedArena<_>, FunctionContext);
18511840
arena = TypedArena::new();
1852-
fcx = FunctionContext::new(ccx, llfndecl, fn_ty,
1853-
Some((instance, sig, abi, generics, name)), &arena);
1841+
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, Some((instance, sig, abi)), &arena);
18541842

18551843
if fcx.mir.is_some() {
18561844
return mir::trans_mir(&fcx);
@@ -1931,8 +1919,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19311919
} else {
19321920
ccx.tcx().map.local_def_id(id)
19331921
};
1934-
let scheme = ccx.tcx().lookup_item_type(def_id);
1935-
let fn_ty = scheme.ty;
1922+
let fn_ty = ccx.tcx().lookup_item_type(def_id).ty;
19361923
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &fn_ty);
19371924
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
19381925
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
@@ -1945,8 +1932,6 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19451932
id,
19461933
&sig,
19471934
abi,
1948-
&scheme.generics,
1949-
Some(ccx.tcx().item_name(def_id)),
19501935
closure::ClosureEnv::NotClosure);
19511936
}
19521937

src/librustc_trans/closure.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
235235
variadic: false
236236
};
237237

238-
// This is not quite right. It should actually inherit
239-
// the generics of the enclosing function.
240-
let generics = ty::Generics::empty();
241-
242238
trans_closure(ccx,
243239
decl,
244240
body,
@@ -247,8 +243,6 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
247243
id,
248244
&sig,
249245
Abi::RustCall,
250-
&generics,
251-
None,
252246
ClosureEnv::Closure(closure_def_id, id));
253247

254248
// Don't hoist this to the top of the function. It's perfectly legitimate

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use self::EnumDiscriminantInfo::*;
1616
use super::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align_of,
1717
get_namespace_and_span_for_item, create_DIArray,
1818
fn_should_be_ignored, is_node_local_to_unit};
19-
use super::namespace::namespace_for_item;
19+
use super::namespace::mangled_name_of_item;
2020
use super::type_names::{compute_debuginfo_type_name, push_debuginfo_type_name};
2121
use super::{declare_local, VariableKind, VariableAccess};
2222

@@ -68,8 +68,8 @@ pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
6868
pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
6969

7070
// ptr::null() doesn't work :(
71-
const NO_FILE_METADATA: DIFile = (0 as DIFile);
72-
const NO_SCOPE_METADATA: DIScope = (0 as DIScope);
71+
pub const NO_FILE_METADATA: DIFile = (0 as DIFile);
72+
pub const NO_SCOPE_METADATA: DIScope = (0 as DIScope);
7373

7474
const FLAGS_NONE: c_uint = 0;
7575

@@ -1846,28 +1846,8 @@ pub fn create_global_var_metadata(cx: &CrateContext,
18461846
return;
18471847
}
18481848

1849-
let var_item = cx.tcx().map.get(node_id);
1850-
1851-
let (name, span) = match var_item {
1852-
hir_map::NodeItem(item) => {
1853-
match item.node {
1854-
hir::ItemStatic(..) => (item.name, item.span),
1855-
hir::ItemConst(..) => (item.name, item.span),
1856-
_ => {
1857-
span_bug!(item.span,
1858-
"debuginfo::\
1859-
create_global_var_metadata() -
1860-
Captured var-id refers to \
1861-
unexpected ast_item variant: {:?}",
1862-
var_item)
1863-
}
1864-
}
1865-
},
1866-
_ => bug!("debuginfo::create_global_var_metadata() \
1867-
- Captured var-id refers to unexpected \
1868-
hir_map variant: {:?}",
1869-
var_item)
1870-
};
1849+
let node_def_id = cx.tcx().map.local_def_id(node_id);
1850+
let (var_scope, span) = get_namespace_and_span_for_item(cx, node_def_id);
18711851

18721852
let (file_metadata, line_number) = if span != codemap::DUMMY_SP {
18731853
let loc = span_start(cx, span);
@@ -1879,12 +1859,8 @@ pub fn create_global_var_metadata(cx: &CrateContext,
18791859
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
18801860
let variable_type = cx.tcx().node_id_to_type(node_id);
18811861
let type_metadata = type_metadata(cx, variable_type, span);
1882-
let node_def_id = cx.tcx().map.local_def_id(node_id);
1883-
let namespace_node = namespace_for_item(cx, node_def_id);
1884-
let var_name = name.to_string();
1885-
let linkage_name =
1886-
namespace_node.mangled_name_of_contained_item(&var_name[..]);
1887-
let var_scope = namespace_node.scope;
1862+
let var_name = cx.tcx().item_name(node_def_id).to_string();
1863+
let linkage_name = mangled_name_of_item(cx, node_def_id, "");
18881864

18891865
let var_name = CString::new(var_name).unwrap();
18901866
let linkage_name = CString::new(linkage_name).unwrap();

src/librustc_trans/debuginfo/mod.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ mod doc;
1414
use self::VariableAccess::*;
1515
use self::VariableKind::*;
1616

17-
use self::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit};
18-
use self::namespace::{namespace_for_item, NamespaceTreeNode};
17+
use self::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit,
18+
get_namespace_and_span_for_item};
19+
use self::namespace::mangled_name_of_item;
1920
use self::type_names::compute_debuginfo_type_name;
2021
use self::metadata::{type_metadata, diverging_type_metadata};
2122
use self::metadata::{file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
@@ -26,6 +27,7 @@ use llvm::{ModuleRef, ContextRef, ValueRef};
2627
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray,
2728
FlagPrototyped};
2829
use rustc::hir::def_id::DefId;
30+
use rustc::hir::map::DefPathData;
2931
use rustc::ty::subst::Substs;
3032
use rustc::hir;
3133

@@ -34,18 +36,16 @@ use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
3436
use monomorphize::Instance;
3537
use rustc::ty::{self, Ty};
3638
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
37-
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
39+
use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
3840

3941
use libc::c_uint;
4042
use std::cell::{Cell, RefCell};
4143
use std::ffi::CString;
4244
use std::ptr;
43-
use std::rc::Rc;
4445

4546
use syntax::codemap::{Span, Pos};
4647
use syntax::{ast, codemap};
4748
use syntax::attr::IntType;
48-
use syntax::parse::token;
4949

5050
pub mod gdb;
5151
mod utils;
@@ -80,7 +80,7 @@ pub struct CrateDebugContext<'tcx> {
8080
created_enum_disr_types: RefCell<FnvHashMap<(DefId, IntType), DIType>>,
8181

8282
type_map: RefCell<TypeMap<'tcx>>,
83-
namespace_map: RefCell<FnvHashMap<Vec<ast::Name>, Rc<NamespaceTreeNode>>>,
83+
namespace_map: RefCell<DefIdMap<DIScope>>,
8484

8585
// This collection is used to assert that composite types (structs, enums,
8686
// ...) have their members only set once:
@@ -100,7 +100,7 @@ impl<'tcx> CrateDebugContext<'tcx> {
100100
created_files: RefCell::new(FnvHashMap()),
101101
created_enum_disr_types: RefCell::new(FnvHashMap()),
102102
type_map: RefCell::new(TypeMap::new()),
103-
namespace_map: RefCell::new(FnvHashMap()),
103+
namespace_map: RefCell::new(DefIdMap()),
104104
composite_types_completed: RefCell::new(FnvHashSet()),
105105
};
106106
}
@@ -232,9 +232,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
232232
instance: Instance<'tcx>,
233233
sig: &ty::FnSig<'tcx>,
234234
abi: Abi,
235-
generics: &ty::Generics<'tcx>,
236-
name: Option<ast::Name>,
237-
span: Span,
238235
llfn: ValueRef) -> FunctionDebugContext {
239236
if cx.sess().opts.debuginfo == NoDebugInfo {
240237
return FunctionDebugContext::DebugInfoDisabled;
@@ -245,6 +242,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
245242
source_loc::set_debug_location(cx, InternalDebugLocation::UnknownLocation);
246243

247244
// This can be the case for functions inlined from another crate
245+
let (containing_scope, span) = get_namespace_and_span_for_item(cx, instance.def);
248246
if span == codemap::DUMMY_SP {
249247
return FunctionDebugContext::FunctionWithoutDebugInfo;
250248
}
@@ -257,38 +255,34 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
257255
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
258256
};
259257

258+
// Find the enclosing function, in case this is a closure.
259+
let mut fn_def_id = instance.def;
260+
let mut def_key = cx.tcx().def_key(fn_def_id);
261+
let mut name = def_key.disambiguated_data.data.to_string();
262+
let name_len = name.len();
263+
while def_key.disambiguated_data.data == DefPathData::ClosureExpr {
264+
fn_def_id.index = def_key.parent.expect("closure without a parent?");
265+
def_key = cx.tcx().def_key(fn_def_id);
266+
}
267+
260268
// Get_template_parameters() will append a `<...>` clause to the function
261269
// name if necessary.
262-
let mut function_name = name.map(|name| name.to_string()).unwrap_or_else(|| {
263-
// We do this only for closures atm.
264-
format!("fn{}", token::gensym("fn"))
265-
});
270+
let generics = cx.tcx().lookup_item_type(fn_def_id).generics;
266271
let template_parameters = get_template_parameters(cx,
267-
generics,
272+
&generics,
268273
instance.substs,
269274
file_metadata,
270-
&mut function_name);
271-
272-
// There is no hir_map::Path for hir::ExprClosure-type functions. For now,
273-
// just don't put them into a namespace. In the future this could be improved
274-
// somehow (storing a path in the hir_map, or construct a path using the
275-
// enclosing function).
276-
let (linkage_name, containing_scope) = if name.is_some() {
277-
let namespace_node = namespace_for_item(cx, instance.def);
278-
let linkage_name = namespace_node.mangled_name_of_contained_item(
279-
&function_name[..]);
280-
let containing_scope = namespace_node.scope;
281-
(linkage_name, containing_scope)
282-
} else {
283-
(function_name.clone(), file_metadata)
284-
};
275+
&mut name);
276+
277+
// Build the linkage_name out of the item path and "template" parameters.
278+
let linkage_name = mangled_name_of_item(cx, instance.def, &name[name_len..]);
285279

286280
let scope_line = span_start(cx, span).line;
287281

288282
let local_id = cx.tcx().map.as_local_node_id(instance.def);
289283
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
290284

291-
let function_name = CString::new(function_name).unwrap();
285+
let function_name = CString::new(name).unwrap();
292286
let linkage_name = CString::new(linkage_name).unwrap();
293287
let fn_metadata = unsafe {
294288
llvm::LLVMDIBuilderCreateFunction(

0 commit comments

Comments
 (0)