Skip to content

Commit cfd5878

Browse files
author
Ariel Ben-Yehuda
committed
fix debuginfo
1 parent 53f01e4 commit cfd5878

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/librustc_trans/trans/debuginfo/metadata.rs

+34-25
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ use middle::pat_util;
2828
use middle::subst::{self, Substs};
2929
use rustc::ast_map;
3030
use trans::{type_of, adt, machine};
31-
use trans::common::{self, CrateContext, FunctionContext, Block, Field};
31+
use trans::common::{self, CrateContext, FunctionContext, Block};
3232
use trans::_match::{BindingInfo, TransBindingMode};
33+
use trans::monomorphize;
3334
use trans::type_::Type;
3435
use middle::ty::{self, Ty};
3536
use session::config::{self, FullDebugInfo};
@@ -1094,34 +1095,38 @@ impl<'tcx> MemberDescriptionFactory<'tcx> {
10941095

10951096
// Creates MemberDescriptions for the fields of a struct
10961097
struct StructMemberDescriptionFactory<'tcx> {
1097-
fields: Vec<Field<'tcx>>,
1098+
variant: &'tcx ty::VariantDef<'tcx>,
1099+
substs: &'tcx subst::Substs<'tcx>,
10981100
is_simd: bool,
10991101
span: Span,
11001102
}
11011103

11021104
impl<'tcx> StructMemberDescriptionFactory<'tcx> {
11031105
fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
11041106
-> Vec<MemberDescription> {
1105-
if self.fields.is_empty() {
1107+
if let ty::VariantKind::Unit = self.variant.kind() {
11061108
return Vec::new();
11071109
}
11081110

11091111
let field_size = if self.is_simd {
1112+
let fty = monomorphize::field_ty(cx.tcx(),
1113+
self.substs,
1114+
&self.variant.fields[0]);
11101115
Some(machine::llsize_of_alloc(
11111116
cx,
1112-
type_of::type_of(cx, self.fields[0].1)
1117+
type_of::type_of(cx, fty)
11131118
) as usize)
11141119
} else {
11151120
None
11161121
};
11171122

1118-
self.fields.iter().enumerate().map(|(i, &Field(name, fty))| {
1119-
let name = name.to_string();
1120-
let name = if name.chars().all(|s| s.is_digit(10)) {
1121-
format!("__{}", name)
1123+
self.variant.fields.iter().enumerate().map(|(i, f)| {
1124+
let name = if let ty::VariantKind::Tuple = self.variant.kind() {
1125+
format!("__{}", i)
11221126
} else {
1123-
name.to_string()
1127+
f.name.to_string()
11241128
};
1129+
let fty = monomorphize::field_ty(cx.tcx(), self.substs, f);
11251130

11261131
let offset = if self.is_simd {
11271132
FixedMemberOffset { bytes: i * field_size.unwrap() }
@@ -1146,27 +1151,31 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
11461151
unique_type_id: UniqueTypeId,
11471152
span: Span)
11481153
-> RecursiveTypeDescription<'tcx> {
1149-
let def_id = struct_type.ty_to_def_id().unwrap();
11501154
let struct_name = compute_debuginfo_type_name(cx, struct_type, false);
11511155
let struct_llvm_type = type_of::in_memory_type_of(cx, struct_type);
11521156

1153-
let (containing_scope, _) = get_namespace_and_span_for_item(cx, def_id);
1157+
let (variant, substs) = match struct_type.sty {
1158+
ty::TyStruct(def, substs) => (def.struct_variant(), substs),
1159+
_ => cx.tcx().sess.bug("prepare_struct_metadata on a non-struct")
1160+
};
1161+
1162+
let (containing_scope, _) = get_namespace_and_span_for_item(cx, variant.did);
11541163

11551164
let struct_metadata_stub = create_struct_stub(cx,
11561165
struct_llvm_type,
11571166
&struct_name,
11581167
unique_type_id,
11591168
containing_scope);
11601169

1161-
let vinfo = common::VariantInfo::from_ty(cx.tcx(), struct_type, None);
11621170
create_and_register_recursive_type_forward_declaration(
11631171
cx,
11641172
struct_type,
11651173
unique_type_id,
11661174
struct_metadata_stub,
11671175
struct_llvm_type,
11681176
StructMDF(StructMemberDescriptionFactory {
1169-
fields: vinfo.fields,
1177+
variant: variant,
1178+
substs: substs,
11701179
is_simd: struct_type.is_simd(cx.tcx()),
11711180
span: span,
11721181
})
@@ -1481,7 +1490,7 @@ enum EnumDiscriminantInfo {
14811490
fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14821491
enum_type: Ty<'tcx>,
14831492
struct_def: &adt::Struct<'tcx>,
1484-
variant_info: &ty::VariantDef<'tcx>,
1493+
variant: &ty::VariantDef<'tcx>,
14851494
discriminant_info: EnumDiscriminantInfo,
14861495
containing_scope: DIScope,
14871496
span: Span)
@@ -1495,7 +1504,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14951504
struct_def.packed);
14961505
// Could do some consistency checks here: size, align, field count, discr type
14971506

1498-
let variant_name = variant_info.name.as_str();
1507+
let variant_name = variant.name.as_str();
14991508
let unique_type_id = debug_context(cx).type_map
15001509
.borrow_mut()
15011510
.get_unique_type_id_of_enum_variant(
@@ -1510,20 +1519,20 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
15101519
containing_scope);
15111520

15121521
// Get the argument names from the enum variant info
1513-
let mut arg_names: Vec<_> = match variant_info.kind() {
1522+
let mut arg_names: Vec<_> = match variant.kind() {
15141523
ty::VariantKind::Unit => vec![],
15151524
ty::VariantKind::Tuple => {
1516-
variant_info.fields
1517-
.iter()
1518-
.enumerate()
1519-
.map(|(i, _)| format!("__{}", i))
1520-
.collect()
1525+
variant.fields
1526+
.iter()
1527+
.enumerate()
1528+
.map(|(i, _)| format!("__{}", i))
1529+
.collect()
15211530
}
15221531
ty::VariantKind::Dict => {
1523-
variant_info.fields
1524-
.iter()
1525-
.map(|f| f.name.to_string())
1526-
.collect()
1532+
variant.fields
1533+
.iter()
1534+
.map(|f| f.name.to_string())
1535+
.collect()
15271536
}
15281537
};
15291538

0 commit comments

Comments
 (0)