]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/debuginfo/namespace.rs
Rollup merge of #69697 - GuillaumeGomez:explanation-e0380, r=Dylan-DPC
[rust.git] / src / librustc_codegen_llvm / debuginfo / namespace.rs
1 // Namespace Handling.
2
3 use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
4 use super::utils::{debug_context, DIB};
5 use rustc::ty::{self, Instance};
6
7 use crate::common::CodegenCx;
8 use crate::llvm;
9 use crate::llvm::debuginfo::DIScope;
10 use rustc::hir::map::DefPathData;
11 use rustc_hir::def_id::DefId;
12
13 use rustc_data_structures::small_c_str::SmallCStr;
14
15 pub fn mangled_name_of_instance<'a, 'tcx>(
16     cx: &CodegenCx<'a, 'tcx>,
17     instance: Instance<'tcx>,
18 ) -> ty::SymbolName {
19     let tcx = cx.tcx;
20     tcx.symbol_name(instance)
21 }
22
23 pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
24     if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
25         return scope;
26     }
27
28     let def_key = cx.tcx.def_key(def_id);
29     let parent_scope = def_key
30         .parent
31         .map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
32
33     let namespace_name = match def_key.disambiguated_data.data {
34         DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
35         data => data.as_symbol(),
36     };
37
38     let namespace_name = SmallCStr::new(&namespace_name.as_str());
39
40     let scope = unsafe {
41         llvm::LLVMRustDIBuilderCreateNameSpace(
42             DIB(cx),
43             parent_scope,
44             namespace_name.as_ptr(),
45             unknown_file_metadata(cx),
46             UNKNOWN_LINE_NUMBER,
47         )
48     };
49
50     debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
51     scope
52 }