@@ -14,8 +14,9 @@ mod doc;
1414use self :: VariableAccess :: * ;
1515use 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;
1920use self :: type_names:: compute_debuginfo_type_name;
2021use self :: metadata:: { type_metadata, diverging_type_metadata} ;
2122use self :: metadata:: { file_metadata, scope_metadata, TypeMap , compile_unit_metadata} ;
@@ -26,6 +27,7 @@ use llvm::{ModuleRef, ContextRef, ValueRef};
2627use llvm:: debuginfo:: { DIFile , DIType , DIScope , DIBuilderRef , DISubprogram , DIArray ,
2728 FlagPrototyped } ;
2829use rustc:: hir:: def_id:: DefId ;
30+ use rustc:: hir:: map:: DefPathData ;
2931use rustc:: ty:: subst:: Substs ;
3032use rustc:: hir;
3133
@@ -34,18 +36,16 @@ use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
3436use monomorphize:: Instance ;
3537use rustc:: ty:: { self , Ty } ;
3638use session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
37- use util:: nodemap:: { NodeMap , FnvHashMap , FnvHashSet } ;
39+ use util:: nodemap:: { DefIdMap , NodeMap , FnvHashMap , FnvHashSet } ;
3840
3941use libc:: c_uint;
4042use std:: cell:: { Cell , RefCell } ;
4143use std:: ffi:: CString ;
4244use std:: ptr;
43- use std:: rc:: Rc ;
4445
4546use syntax:: codemap:: { Span , Pos } ;
4647use syntax:: { ast, codemap} ;
4748use syntax:: attr:: IntType ;
48- use syntax:: parse:: token;
4949
5050pub mod gdb;
5151mod 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