]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs
Rollup merge of #106886 - dtolnay:fastinstall, r=Mark-Simulacrum
[rust.git] / compiler / rustc_codegen_llvm / src / debuginfo / namespace.rs
1 // Namespace Handling.
2
3 use super::utils::{debug_context, DIB};
4 use rustc_codegen_ssa::debuginfo::type_names;
5 use rustc_middle::ty::{self, Instance};
6
7 use crate::common::CodegenCx;
8 use crate::llvm;
9 use crate::llvm::debuginfo::DIScope;
10 use rustc_hir::def_id::DefId;
11
12 pub fn mangled_name_of_instance<'a, 'tcx>(
13     cx: &CodegenCx<'a, 'tcx>,
14     instance: Instance<'tcx>,
15 ) -> ty::SymbolName<'tcx> {
16     let tcx = cx.tcx;
17     tcx.symbol_name(instance)
18 }
19
20 pub fn item_namespace<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
21     if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
22         return scope;
23     }
24
25     let def_key = cx.tcx.def_key(def_id);
26     let parent_scope = def_key
27         .parent
28         .map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
29
30     let namespace_name_string = {
31         let mut output = String::new();
32         type_names::push_item_name(cx.tcx, def_id, false, &mut output);
33         output
34     };
35
36     let scope = unsafe {
37         llvm::LLVMRustDIBuilderCreateNameSpace(
38             DIB(cx),
39             parent_scope,
40             namespace_name_string.as_ptr().cast(),
41             namespace_name_string.len(),
42             false, // ExportSymbols (only relevant for C++ anonymous namespaces)
43         )
44     };
45
46     debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
47     scope
48 }