Skip to content

Commit 494ec48

Browse files
---
yaml --- r: 144047 b: refs/heads/try2 c: c1734ce h: refs/heads/master i: 144045: 07e87e2 144043: 11e58fd 144039: 2c27805 144031: 905a5f1 v: v3
1 parent 9e876d3 commit 494ec48

File tree

3 files changed

+267
-46
lines changed

3 files changed

+267
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a36e53730f616479596868ba67fd1932064a00ea
8+
refs/heads/try2: c1734cef33dc235c2564d75abcbc7b8fbb8d1a38
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/debuginfo.rs

Lines changed: 125 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use std::ptr;
7070
use std::vec;
7171
use syntax::codemap::span;
7272
use syntax::{ast, codemap, ast_util, ast_map};
73-
use syntax::parse::token::keywords;
73+
use syntax::parse::token::special_idents;
7474

7575
static DW_LANG_RUST: int = 0x9000;
7676

@@ -195,9 +195,8 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
195195
let loc = span_start(cx, span);
196196
let type_metadata = type_metadata(cx, variable_type, span);
197197
let scope = create_function_metadata(bcx.fcx);
198-
let self_ident = keywords::Self.to_ident();
199198

200-
let var_metadata = do cx.sess.str_of(self_ident).to_c_str().with_ref |name| {
199+
let var_metadata = do cx.sess.str_of(special_idents::self_).to_c_str().with_ref |name| {
201200
unsafe {
202201
llvm::LLVMDIBuilderCreateLocalVariable(
203202
DIB(cx),
@@ -229,8 +228,7 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
229228
///
230229
/// Adds the created metadata nodes directly to the crate's IR.
231230
pub fn create_argument_metadata(bcx: @mut Block,
232-
arg: &ast::arg,
233-
needs_deref: bool) {
231+
arg: &ast::arg) {
234232
let fcx = bcx.fcx;
235233
let cx = fcx.ccx;
236234

@@ -337,11 +335,11 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
337335
}
338336

339337
let fnitem = cx.tcx.items.get_copy(&fcx.id);
340-
let (ident, fn_decl, generics, span) = match fnitem {
338+
let (ident, fn_decl, generics, span, is_trait_default_impl) = match fnitem {
341339
ast_map::node_item(ref item, _) => {
342340
match item.node {
343341
ast::item_fn(ref fn_decl, _, _, ref generics, _) => {
344-
(item.ident, fn_decl, Some(generics), item.span)
342+
(item.ident, fn_decl, Some(generics), item.span, false)
345343
}
346344
_ => fcx.ccx.sess.span_bug(item.span,
347345
"create_function_metadata: item bound to non-function")
@@ -357,7 +355,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
357355
},
358356
_,
359357
_) => {
360-
(ident, fn_decl, Some(generics), span)
358+
(ident, fn_decl, Some(generics), span, false)
361359
}
362360
ast_map::node_expr(ref expr) => {
363361
match expr.node {
@@ -367,7 +365,8 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
367365
// This is not quite right. It should actually inherit the generics of the
368366
// enclosing function.
369367
None,
370-
expr.span)
368+
expr.span,
369+
false)
371370
}
372371
_ => fcx.ccx.sess.span_bug(expr.span,
373372
"create_function_metadata: expected an expr_fn_block here")
@@ -384,7 +383,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
384383
}),
385384
_,
386385
_) => {
387-
(ident, fn_decl, Some(generics), span)
386+
(ident, fn_decl, Some(generics), span, true)
388387
}
389388
_ => fcx.ccx.sess.bug(fmt!("create_function_metadata: unexpected sort of node: %?", fnitem))
390389
};
@@ -405,6 +404,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
405404
let mut function_name = cx.sess.str_of(ident).to_owned();
406405
let template_parameters = get_template_parameters(fcx,
407406
generics,
407+
is_trait_default_impl,
408408
file_metadata,
409409
span,
410410
&mut function_name);
@@ -507,6 +507,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
507507

508508
fn get_template_parameters(fcx: &FunctionContext,
509509
generics: Option<&ast::Generics>,
510+
is_trait_default_impl: bool,
510511
file_metadata: DIFile,
511512
span: span,
512513
name_to_append_suffix_to: &mut ~str)
@@ -521,58 +522,131 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
521522

522523
match generics {
523524
None => {
524-
if (fcx.param_substs.is_some()) {
525+
if (!is_trait_default_impl && fcx.param_substs.is_some()) {
525526
cx.sess.span_bug(span, "debuginfo::create_function_metadata() - \
526-
Mismatch between ast::Generics and FunctionContext::param_substs");
527+
Mismatch between ast::Generics (does not exist) and \
528+
FunctionContext::param_substs (does exist)");
527529
}
528530

529531
return ptr::null();
530532
}
531533

532534
Some(generics) => {
533-
let actual_types = match fcx.param_substs {
534-
Some(@param_substs { tys: ref actual_types, _}) => {
535-
actual_types
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+
}
542+
543+
(types, self_type)
536544
}
537545
None => {
538546
cx.sess.span_bug(span, "debuginfo::create_function_metadata() - \
539-
Mismatch between ast::Generics and FunctionContext::param_substs");
547+
Mismatch between ast::Generics (does exist) and \
548+
FunctionContext::param_substs (does not exist)");
540549
}
541550
};
542551

543552
name_to_append_suffix_to.push_char('<');
544553

545-
let template_params: ~[DIDescriptor] = do generics
546-
.ty_params
547-
.iter()
548-
.enumerate()
549-
.map |(index, &ast::TyParam{ ident: ident, _ })| {
550-
551-
let actual_type = actual_types[index];
552-
let actual_type_metadata = type_metadata(cx,
553-
actual_type,
554-
codemap::dummy_sp());
555-
556-
// Add actual type name to <...> clause of function name
557-
let actual_type_name = ty_to_str(cx.tcx, actual_type);
558-
name_to_append_suffix_to.push_str(actual_type_name);
559-
if index != generics.ty_params.len() - 1 {
560-
name_to_append_suffix_to.push_str(",");
554+
let mut template_params: ~[DIDescriptor] =
555+
vec::with_capacity(actual_types.len() + 1);
556+
557+
if is_trait_default_impl {
558+
let actual_self_type_metadata = type_metadata(cx,
559+
actual_self_type.unwrap(),
560+
codemap::dummy_sp());
561+
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+
}
568+
569+
let ident = special_idents::type_self;
570+
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)
561581
}
582+
};
583+
584+
template_params.push(param_metadata);
585+
}
562586

563-
do cx.sess.str_of(ident).to_c_str().with_ref |name| {
564-
unsafe {
565-
llvm::LLVMDIBuilderCreateTemplateTypeParameter(
566-
DIB(cx),
567-
file_metadata,
568-
name,
569-
actual_type_metadata,
570-
ptr::null(),
571-
0,
572-
0)
573-
}
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+
}
602+
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)
574613
}
575-
}.collect();
614+
};
615+
616+
template_params.push(param_metadata);
617+
}
618+
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();
576650

577651
name_to_append_suffix_to.push_char('>');
578652

@@ -795,7 +869,13 @@ fn struct_metadata(cx: &mut CrateContext,
795869
let struct_llvm_type = type_of::type_of(cx, struct_type);
796870

797871
let field_llvm_types = do fields.map |field| { type_of::type_of(cx, field.mt.ty) };
798-
let field_names = do fields.map |field| { cx.sess.str_of(field.ident).to_owned() };
872+
let field_names = do fields.map |field| {
873+
if field.ident == special_idents::unnamed_field {
874+
~""
875+
} else {
876+
cx.sess.str_of(field.ident).to_owned()
877+
}
878+
};
799879
let field_types_metadata = do fields.map |field| {
800880
type_metadata(cx, field.mt.ty, span)
801881
};

0 commit comments

Comments
 (0)