Skip to content

Commit 67ed30c

Browse files
committed
auto merge of #9097 : michaelwoerister/rust/namespaces, r=jdm
Who would have thought that namespaces are such a can of worms `:P` This is mostly because of some GDB idiosyncrasies (does not use namespace information but linkage-name attributes for displaying items contained in namespaces, also cannot handle functions lexically nested within functions), monomorphization, and information about external items only available from metadata. This pull request tries to tackle the problem anyway: * The `DW_AT_linkage_name` for functions is generated just to make GDB display a proper namespace-enabled function name. To this end, a pseudo-mangled name is generated, not corresponding to the real linkage name. This approach shows some success and could be extended to make GDB also show proper parameter types. * As GDB won't accept subprogram DIEs nested within other subprogram DIEs, the `debuginfo` module now generates a *companion namespace* for each functions (iff needed). A function `fn abc()` will get a companion namespace with name `abc()`, which contains all items (modules, types, functions) declared within the functions scope. The real, proper solution, in my opinion, would be to faithfully reflect the program's lexical structure within DWARF (which allows arbitrary nesting of DIEs, afaik), but I am not sure LLVM's source level debugging implementation would like that and I am pretty sure GDB won't support this in the foreseeable future. * Monomorphization leads to functions and companion namespaces like `somelib::some_func<int, float>()::some_other_function<bool, bool, bool>()`, which I think is the desired behaviour. There is some design space here, however. Maybe you people prefer `somelib::some_func()::some_other_function<bool, bool, bool>()` or `somelib::some_func()::some_other_function::<int, float, bool, bool, bool>()`. The solution will work for now but there are a few things on my 'far future wish list': * A real specification somewhere, what language constructs are mapped to what DWARF structures. * Proper tests that directly compare the generated DWARF information to the expected results (possibly using something like [pyelftools](https://github.com/eliben/pyelftools) or llvm-dwarfdump) * A unified implementation for crate-local and crate-external items (which would possibly involve beefing up `ast_map::path` and metadata a bit) Any comments are welcome! Closes #1541 Closes #1542 (there might be other issues with function name prettiness, but this specific issue should be fixed) Closes #7715 (source locations for structs and enums are now read correctly from the AST)
2 parents d14bd08 + eb32ec1 commit 67ed30c

File tree

82 files changed

+670
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+670
-228
lines changed

src/librustc/lib/llvm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,14 @@ pub mod llvm {
21092109
ArgNo: c_uint)
21102110
-> ValueRef;
21112111

2112+
#[fast_ffi]
2113+
pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2114+
Scope: ValueRef,
2115+
Name: *c_char,
2116+
File: ValueRef,
2117+
LineNo: c_uint)
2118+
-> ValueRef;
2119+
21122120
#[fast_ffi]
21132121
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
21142122

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,10 @@ pub fn trans_crate(sess: session::Session,
30213021
link_meta,
30223022
analysis.reachable);
30233023

3024+
if ccx.sess.opts.debuginfo {
3025+
debuginfo::initialize(ccx, crate);
3026+
}
3027+
30243028
{
30253029
let _icx = push_ctxt("text");
30263030
trans_mod(ccx, &crate.module);

0 commit comments

Comments
 (0)