Skip to content

Commit f0e8e57

Browse files
---
yaml --- r: 85459 b: refs/heads/dist-snap c: 0e7808c h: refs/heads/master i: 85457: 64c8099 85455: b140dfc v: v3
1 parent b3bd053 commit f0e8e57

File tree

2 files changed

+82
-134
lines changed

2 files changed

+82
-134
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 024d644c68fa9758f003260b23834032da1a6613
9+
refs/heads/dist-snap: 0e7808c2e0d7b4c9f2526784566af2745adcf207
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/trans/debuginfo.rs

Lines changed: 81 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use std::libc::{c_uint, c_ulonglong, c_longlong};
6969
use std::ptr;
7070
use std::vec;
7171
use syntax::codemap::span;
72-
use syntax::{ast, codemap, ast_util, ast_map};
72+
use syntax::{ast, codemap, ast_util, ast_map, opt_vec};
7373
use syntax::parse::token::special_idents;
7474

7575
static DW_LANG_RUST: int = 0x9000;
@@ -334,12 +334,14 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
334334
None => { /* fallthrough */}
335335
}
336336

337+
let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty };
338+
337339
let fnitem = cx.tcx.items.get_copy(&fcx.id);
338-
let (ident, fn_decl, generics, span, is_trait_default_impl) = match fnitem {
340+
let (ident, fn_decl, generics, span) = match fnitem {
339341
ast_map::node_item(ref item, _) => {
340342
match item.node {
341343
ast::item_fn(ref fn_decl, _, _, ref generics, _) => {
342-
(item.ident, fn_decl, Some(generics), item.span, false)
344+
(item.ident, fn_decl, generics, item.span)
343345
}
344346
_ => fcx.ccx.sess.span_bug(item.span,
345347
"create_function_metadata: item bound to non-function")
@@ -355,7 +357,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
355357
},
356358
_,
357359
_) => {
358-
(ident, fn_decl, Some(generics), span, false)
360+
(ident, fn_decl, generics, span)
359361
}
360362
ast_map::node_expr(ref expr) => {
361363
match expr.node {
@@ -364,9 +366,8 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
364366
(name, fn_decl,
365367
// This is not quite right. It should actually inherit the generics of the
366368
// enclosing function.
367-
None,
368-
expr.span,
369-
false)
369+
&empty_generics,
370+
expr.span)
370371
}
371372
_ => fcx.ccx.sess.span_bug(expr.span,
372373
"create_function_metadata: expected an expr_fn_block here")
@@ -383,7 +384,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
383384
}),
384385
_,
385386
_) => {
386-
(ident, fn_decl, Some(generics), span, true)
387+
(ident, fn_decl, generics, span)
387388
}
388389
_ => fcx.ccx.sess.bug(fmt!("create_function_metadata: unexpected sort of node: %?", fnitem))
389390
};
@@ -404,7 +405,6 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
404405
let mut function_name = cx.sess.str_of(ident).to_owned();
405406
let template_parameters = get_template_parameters(fcx,
406407
generics,
407-
is_trait_default_impl,
408408
file_metadata,
409409
span,
410410
&mut function_name);
@@ -506,153 +506,101 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
506506
}
507507

508508
fn get_template_parameters(fcx: &FunctionContext,
509-
generics: Option<&ast::Generics>,
510-
is_trait_default_impl: bool,
509+
generics: &ast::Generics,
511510
file_metadata: DIFile,
512511
span: span,
513512
name_to_append_suffix_to: &mut ~str)
514513
-> DIArray {
515-
// Normalize cases
516-
let generics = match generics {
517-
Some(generics_ref) if generics_ref.is_type_parameterized() => Some(generics_ref),
514+
let cx = fcx.ccx;
515+
516+
let self_type = match fcx.param_substs {
517+
Some(@param_substs{ self_ty: self_type, _ }) => self_type,
518518
_ => None
519519
};
520520

521-
let cx = fcx.ccx;
522-
523-
match generics {
524-
None => {
525-
if (!is_trait_default_impl && fcx.param_substs.is_some()) {
526-
cx.sess.span_bug(span, "debuginfo::create_function_metadata() - \
527-
Mismatch between ast::Generics (does not exist) and \
528-
FunctionContext::param_substs (does exist)");
529-
}
521+
// Only true for static default methods:
522+
let has_self_type = self_type.is_some();
530523

531-
return ptr::null();
532-
}
524+
if !generics.is_type_parameterized() && !has_self_type {
525+
return ptr::null();
526+
}
533527

534-
Some(generics) => {
535-
let (actual_types, actual_self_type) = match fcx.param_substs {
536-
Some(@param_substs { tys: ref types, self_ty: ref self_type, _ }) => {
537-
if is_trait_default_impl && self_type.is_none() {
538-
cx.sess.span_bug(span, "debuginfo::create_function_metadata() - \
539-
Expected self type parameter substitution for default \
540-
implementation of trait method");
541-
}
528+
name_to_append_suffix_to.push_char('<');
542529

543-
(types, self_type)
544-
}
545-
None => {
546-
cx.sess.span_bug(span, "debuginfo::create_function_metadata() - \
547-
Mismatch between ast::Generics (does exist) and \
548-
FunctionContext::param_substs (does not exist)");
549-
}
550-
};
530+
// The list to be filled with template parameters:
531+
let mut template_params: ~[DIDescriptor] = vec::with_capacity(generics.ty_params.len() + 1);
551532

552-
name_to_append_suffix_to.push_char('<');
533+
// Handle self type
534+
if has_self_type {
535+
let actual_self_type = self_type.unwrap();
536+
let actual_self_type_metadata = type_metadata(cx,
537+
actual_self_type,
538+
codemap::dummy_sp());
553539

554-
let mut template_params: ~[DIDescriptor] =
555-
vec::with_capacity(actual_types.len() + 1);
540+
// Add self type name to <...> clause of function name
541+
let actual_self_type_name = ty_to_str(cx.tcx, actual_self_type);
542+
name_to_append_suffix_to.push_str(actual_self_type_name);
543+
if generics.is_type_parameterized() {
544+
name_to_append_suffix_to.push_str(",");
545+
}
556546

557-
if is_trait_default_impl {
558-
let actual_self_type_metadata = type_metadata(cx,
559-
actual_self_type.unwrap(),
560-
codemap::dummy_sp());
547+
let ident = special_idents::type_self;
561548

562-
// Add self type name to <...> clause of function name
563-
let actual_self_type_name = ty_to_str(cx.tcx, actual_self_type.unwrap());
564-
name_to_append_suffix_to.push_str(actual_self_type_name);
565-
if actual_types.len() > 0 {
566-
name_to_append_suffix_to.push_str(",");
567-
}
549+
let param_metadata = do cx.sess.str_of(ident).to_c_str().with_ref |name| {
550+
unsafe {
551+
llvm::LLVMDIBuilderCreateTemplateTypeParameter(
552+
DIB(cx),
553+
file_metadata,
554+
name,
555+
actual_self_type_metadata,
556+
ptr::null(),
557+
0,
558+
0)
559+
}
560+
};
568561

569-
let ident = special_idents::type_self;
562+
template_params.push(param_metadata);
563+
}
570564

571-
let param_metadata = do cx.sess.str_of(ident).to_c_str().with_ref |name| {
572-
unsafe {
573-
llvm::LLVMDIBuilderCreateTemplateTypeParameter(
574-
DIB(cx),
575-
file_metadata,
576-
name,
577-
actual_self_type_metadata,
578-
ptr::null(),
579-
0,
580-
0)
581-
}
582-
};
565+
// Handle other generic parameters
566+
let actual_types = match fcx.param_substs {
567+
Some(@param_substs { tys: ref types, _ }) => types,
568+
None => {
569+
return create_DIArray(DIB(cx), template_params);
570+
}
571+
};
583572

584-
template_params.push(param_metadata);
585-
}
573+
for (index, &ast::TyParam{ ident: ident, _ }) in generics.ty_params.iter().enumerate() {
574+
let actual_type = actual_types[index];
575+
let actual_type_metadata = type_metadata(cx, actual_type, codemap::dummy_sp());
586576

587-
for (index, &ast::TyParam{ ident: ident, _ }) in generics
588-
.ty_params
589-
.iter()
590-
.enumerate() {
591-
let actual_type = actual_types[index];
592-
let actual_type_metadata = type_metadata(cx,
593-
actual_type,
594-
codemap::dummy_sp());
595-
596-
// Add actual type name to <...> clause of function name
597-
let actual_type_name = ty_to_str(cx.tcx, actual_type);
598-
name_to_append_suffix_to.push_str(actual_type_name);
599-
if index != generics.ty_params.len() - 1 {
600-
name_to_append_suffix_to.push_str(",");
601-
}
577+
// Add actual type name to <...> clause of function name
578+
let actual_type_name = ty_to_str(cx.tcx, actual_type);
579+
name_to_append_suffix_to.push_str(actual_type_name);
602580

603-
let param_metadata = do cx.sess.str_of(ident).to_c_str().with_ref |name| {
604-
unsafe {
605-
llvm::LLVMDIBuilderCreateTemplateTypeParameter(
606-
DIB(cx),
607-
file_metadata,
608-
name,
609-
actual_type_metadata,
610-
ptr::null(),
611-
0,
612-
0)
613-
}
614-
};
581+
if index != generics.ty_params.len() - 1 {
582+
name_to_append_suffix_to.push_str(",");
583+
}
615584

616-
template_params.push(param_metadata);
585+
let param_metadata = do cx.sess.str_of(ident).to_c_str().with_ref |name| {
586+
unsafe {
587+
llvm::LLVMDIBuilderCreateTemplateTypeParameter(
588+
DIB(cx),
589+
file_metadata,
590+
name,
591+
actual_type_metadata,
592+
ptr::null(),
593+
0,
594+
0)
617595
}
596+
};
618597

619-
// let template_params: ~[DIDescriptor] = do generics
620-
// .ty_params
621-
// .iter()
622-
// .enumerate()
623-
// .map |(index, &ast::TyParam{ ident: ident, _ })| {
624-
625-
// let actual_type = actual_types[index];
626-
// let actual_type_metadata = type_metadata(cx,
627-
// actual_type,
628-
// codemap::dummy_sp());
629-
630-
// // Add actual type name to <...> clause of function name
631-
// let actual_type_name = ty_to_str(cx.tcx, actual_type);
632-
// name_to_append_suffix_to.push_str(actual_type_name);
633-
// if index != generics.ty_params.len() - 1 {
634-
// name_to_append_suffix_to.push_str(",");
635-
// }
636-
637-
// do cx.sess.str_of(ident).to_c_str().with_ref |name| {
638-
// unsafe {
639-
// llvm::LLVMDIBuilderCreateTemplateTypeParameter(
640-
// DIB(cx),
641-
// file_metadata,
642-
// name,
643-
// actual_type_metadata,
644-
// ptr::null(),
645-
// 0,
646-
// 0)
647-
// }
648-
// }
649-
// }.collect();
650-
651-
name_to_append_suffix_to.push_char('>');
652-
653-
return create_DIArray(DIB(cx), template_params);
654-
}
598+
template_params.push(param_metadata);
655599
}
600+
601+
name_to_append_suffix_to.push_char('>');
602+
603+
return create_DIArray(DIB(cx), template_params);
656604
}
657605
}
658606

0 commit comments

Comments
 (0)