@@ -14,8 +14,9 @@ mod doc;
14
14
use self :: VariableAccess :: * ;
15
15
use self :: VariableKind :: * ;
16
16
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;
19
20
use self :: type_names:: compute_debuginfo_type_name;
20
21
use self :: metadata:: { type_metadata, diverging_type_metadata} ;
21
22
use self :: metadata:: { file_metadata, scope_metadata, TypeMap , compile_unit_metadata} ;
@@ -26,6 +27,7 @@ use llvm::{ModuleRef, ContextRef, ValueRef};
26
27
use llvm:: debuginfo:: { DIFile , DIType , DIScope , DIBuilderRef , DISubprogram , DIArray ,
27
28
FlagPrototyped } ;
28
29
use rustc:: hir:: def_id:: DefId ;
30
+ use rustc:: hir:: map:: DefPathData ;
29
31
use rustc:: ty:: subst:: Substs ;
30
32
use rustc:: hir;
31
33
@@ -34,18 +36,16 @@ use common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
34
36
use monomorphize:: Instance ;
35
37
use rustc:: ty:: { self , Ty } ;
36
38
use session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
37
- use util:: nodemap:: { NodeMap , FnvHashMap , FnvHashSet } ;
39
+ use util:: nodemap:: { DefIdMap , NodeMap , FnvHashMap , FnvHashSet } ;
38
40
39
41
use libc:: c_uint;
40
42
use std:: cell:: { Cell , RefCell } ;
41
43
use std:: ffi:: CString ;
42
44
use std:: ptr;
43
- use std:: rc:: Rc ;
44
45
45
46
use syntax:: codemap:: { Span , Pos } ;
46
47
use syntax:: { ast, codemap} ;
47
48
use syntax:: attr:: IntType ;
48
- use syntax:: parse:: token;
49
49
50
50
pub mod gdb;
51
51
mod utils;
@@ -80,7 +80,7 @@ pub struct CrateDebugContext<'tcx> {
80
80
created_enum_disr_types : RefCell < FnvHashMap < ( DefId , IntType ) , DIType > > ,
81
81
82
82
type_map : RefCell < TypeMap < ' tcx > > ,
83
- namespace_map : RefCell < FnvHashMap < Vec < ast :: Name > , Rc < NamespaceTreeNode > > > ,
83
+ namespace_map : RefCell < DefIdMap < DIScope > > ,
84
84
85
85
// This collection is used to assert that composite types (structs, enums,
86
86
// ...) have their members only set once:
@@ -100,7 +100,7 @@ impl<'tcx> CrateDebugContext<'tcx> {
100
100
created_files : RefCell :: new ( FnvHashMap ( ) ) ,
101
101
created_enum_disr_types : RefCell :: new ( FnvHashMap ( ) ) ,
102
102
type_map : RefCell :: new ( TypeMap :: new ( ) ) ,
103
- namespace_map : RefCell :: new ( FnvHashMap ( ) ) ,
103
+ namespace_map : RefCell :: new ( DefIdMap ( ) ) ,
104
104
composite_types_completed : RefCell :: new ( FnvHashSet ( ) ) ,
105
105
} ;
106
106
}
@@ -232,9 +232,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
232
232
instance : Instance < ' tcx > ,
233
233
sig : & ty:: FnSig < ' tcx > ,
234
234
abi : Abi ,
235
- generics : & ty:: Generics < ' tcx > ,
236
- name : Option < ast:: Name > ,
237
- span : Span ,
238
235
llfn : ValueRef ) -> FunctionDebugContext {
239
236
if cx. sess ( ) . opts . debuginfo == NoDebugInfo {
240
237
return FunctionDebugContext :: DebugInfoDisabled ;
@@ -245,6 +242,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
245
242
source_loc:: set_debug_location ( cx, InternalDebugLocation :: UnknownLocation ) ;
246
243
247
244
// 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 ) ;
248
246
if span == codemap:: DUMMY_SP {
249
247
return FunctionDebugContext :: FunctionWithoutDebugInfo ;
250
248
}
@@ -257,38 +255,34 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
257
255
llvm:: LLVMDIBuilderCreateSubroutineType ( DIB ( cx) , file_metadata, fn_signature)
258
256
} ;
259
257
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
+
260
268
// Get_template_parameters() will append a `<...>` clause to the function
261
269
// 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 ;
266
271
let template_parameters = get_template_parameters ( cx,
267
- generics,
272
+ & generics,
268
273
instance. substs ,
269
274
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..] ) ;
285
279
286
280
let scope_line = span_start ( cx, span) . line ;
287
281
288
282
let local_id = cx. tcx ( ) . map . as_local_node_id ( instance. def ) ;
289
283
let is_local_to_unit = local_id. map_or ( false , |id| is_node_local_to_unit ( cx, id) ) ;
290
284
291
- let function_name = CString :: new ( function_name ) . unwrap ( ) ;
285
+ let function_name = CString :: new ( name ) . unwrap ( ) ;
292
286
let linkage_name = CString :: new ( linkage_name) . unwrap ( ) ;
293
287
let fn_metadata = unsafe {
294
288
llvm:: LLVMDIBuilderCreateFunction (
0 commit comments