Skip to content

Commit d5ed655

Browse files
Use DefId instead of NodeId while generating debuginfo for statics.
1 parent 27a046e commit d5ed655

File tree

5 files changed

+14
-28
lines changed

5 files changed

+14
-28
lines changed

src/librustc_trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub fn trans_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
304304
}
305305
}
306306

307-
debuginfo::create_global_var_metadata(cx, id, g);
307+
debuginfo::create_global_var_metadata(cx, def_id, g);
308308

309309
if attr::contains_name(attrs, "thread_local") {
310310
llvm::set_thread_local_mode(g, cx.tls_model);

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use self::EnumDiscriminantInfo::*;
1414

1515
use super::utils::{debug_context, DIB, span_start,
1616
get_namespace_for_item, create_DIArray, is_node_local_to_unit};
17-
use super::namespace::mangled_name_of_item;
17+
use super::namespace::mangled_name_of_instance;
1818
use super::type_names::compute_debuginfo_type_name;
1919
use super::{CrateDebugContext};
2020
use abi;
@@ -1634,19 +1634,18 @@ fn create_union_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
16341634
///
16351635
/// Adds the created metadata nodes directly to the crate's IR.
16361636
pub fn create_global_var_metadata(cx: &CodegenCx,
1637-
node_id: ast::NodeId,
1637+
def_id: DefId,
16381638
global: ValueRef) {
16391639
if cx.dbg_cx.is_none() {
16401640
return;
16411641
}
16421642

16431643
let tcx = cx.tcx;
1644-
let node_def_id = tcx.hir.local_def_id(node_id);
1645-
let no_mangle = attr::contains_name(&tcx.get_attrs(node_def_id), "no_mangle");
1644+
let no_mangle = attr::contains_name(&tcx.get_attrs(def_id), "no_mangle");
16461645
// We may want to remove the namespace scope if we're in an extern block, see:
16471646
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952
1648-
let var_scope = get_namespace_for_item(cx, node_def_id);
1649-
let span = cx.tcx.def_span(node_def_id);
1647+
let var_scope = get_namespace_for_item(cx, def_id);
1648+
let span = cx.tcx.def_span(def_id);
16501649

16511650
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
16521651
let loc = span_start(cx, span);
@@ -1655,15 +1654,15 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
16551654
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
16561655
};
16571656

1658-
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
1659-
let variable_type = Instance::mono(cx.tcx, node_def_id).ty(cx.tcx);
1657+
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
1658+
let variable_type = Instance::mono(cx.tcx, def_id).ty(cx.tcx);
16601659
let type_metadata = type_metadata(cx, variable_type, span);
1661-
let var_name = tcx.item_name(node_def_id).to_string();
1660+
let var_name = tcx.item_name(def_id).to_string();
16621661
let var_name = CString::new(var_name).unwrap();
16631662
let linkage_name = if no_mangle {
16641663
None
16651664
} else {
1666-
let linkage_name = mangled_name_of_item(cx, node_id);
1665+
let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id));
16671666
Some(CString::new(linkage_name.to_string()).unwrap())
16681667
};
16691668

src/librustc_trans/debuginfo/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
254254
let linkage_name = mangled_name_of_instance(cx, instance);
255255

256256
let scope_line = span_start(cx, span).line;
257-
258-
let local_id = cx.tcx.hir.as_local_node_id(instance.def_id());
259-
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
257+
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
260258

261259
let function_name = CString::new(name).unwrap();
262260
let linkage_name = CString::new(linkage_name.to_string()).unwrap();
263261

264262
let mut flags = DIFlags::FlagPrototyped;
263+
264+
let local_id = cx.tcx.hir.as_local_node_id(def_id);
265265
match *cx.sess().entry_fn.borrow() {
266266
Some((id, _)) => {
267267
if local_id == Some(id) {

src/librustc_trans/debuginfo/namespace.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
1414
use super::utils::{DIB, debug_context};
1515
use monomorphize::Instance;
1616
use rustc::ty;
17-
use syntax::ast;
1817

1918
use llvm;
2019
use llvm::debuginfo::DIScope;
@@ -33,16 +32,6 @@ pub fn mangled_name_of_instance<'a, 'tcx>(
3332
tcx.symbol_name(instance)
3433
}
3534

36-
pub fn mangled_name_of_item<'a, 'tcx>(
37-
cx: &CodegenCx<'a, 'tcx>,
38-
node_id: ast::NodeId,
39-
) -> ty::SymbolName {
40-
let tcx = cx.tcx;
41-
let node_def_id = tcx.hir.local_def_id(node_id);
42-
let instance = Instance::mono(tcx, node_def_id);
43-
tcx.symbol_name(instance)
44-
}
45-
4635
pub fn item_namespace(cx: &CodegenCx, def_id: DefId) -> DIScope {
4736
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
4837
return scope;

src/librustc_trans/debuginfo/utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
2121
use common::{CodegenCx};
2222

2323
use syntax_pos::{self, Span};
24-
use syntax::ast;
2524

26-
pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
25+
pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
2726
{
2827
// The is_local_to_unit flag indicates whether a function is local to the
2928
// current compilation unit (i.e. if it is *static* in the C-sense). The
@@ -33,7 +32,6 @@ pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
3332
// visible). It might better to use the `exported_items` set from
3433
// `driver::CrateAnalysis` in the future, but (atm) this set is not
3534
// available in the translation pass.
36-
let def_id = cx.tcx.hir.local_def_id(node_id);
3735
!cx.tcx.is_exported_symbol(def_id)
3836
}
3937

0 commit comments

Comments
 (0)