@@ -28,8 +28,9 @@ use middle::pat_util;
28
28
use middle:: subst:: { self , Substs } ;
29
29
use rustc:: ast_map;
30
30
use trans:: { type_of, adt, machine} ;
31
- use trans:: common:: { self , CrateContext , FunctionContext , Block , Field } ;
31
+ use trans:: common:: { self , CrateContext , FunctionContext , Block } ;
32
32
use trans:: _match:: { BindingInfo , TransBindingMode } ;
33
+ use trans:: monomorphize;
33
34
use trans:: type_:: Type ;
34
35
use middle:: ty:: { self , Ty } ;
35
36
use session:: config:: { self , FullDebugInfo } ;
@@ -1094,34 +1095,38 @@ impl<'tcx> MemberDescriptionFactory<'tcx> {
1094
1095
1095
1096
// Creates MemberDescriptions for the fields of a struct
1096
1097
struct StructMemberDescriptionFactory < ' tcx > {
1097
- fields : Vec < Field < ' tcx > > ,
1098
+ variant : & ' tcx ty:: VariantDef < ' tcx > ,
1099
+ substs : & ' tcx subst:: Substs < ' tcx > ,
1098
1100
is_simd : bool ,
1099
1101
span : Span ,
1100
1102
}
1101
1103
1102
1104
impl < ' tcx > StructMemberDescriptionFactory < ' tcx > {
1103
1105
fn create_member_descriptions < ' a > ( & self , cx : & CrateContext < ' a , ' tcx > )
1104
1106
-> Vec < MemberDescription > {
1105
- if self . fields . is_empty ( ) {
1107
+ if let ty :: VariantKind :: Unit = self . variant . kind ( ) {
1106
1108
return Vec :: new ( ) ;
1107
1109
}
1108
1110
1109
1111
let field_size = if self . is_simd {
1112
+ let fty = monomorphize:: field_ty ( cx. tcx ( ) ,
1113
+ self . substs ,
1114
+ & self . variant . fields [ 0 ] ) ;
1110
1115
Some ( machine:: llsize_of_alloc (
1111
1116
cx,
1112
- type_of:: type_of ( cx, self . fields [ 0 ] . 1 )
1117
+ type_of:: type_of ( cx, fty )
1113
1118
) as usize )
1114
1119
} else {
1115
1120
None
1116
1121
} ;
1117
1122
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)
1122
1126
} else {
1123
- name. to_string ( )
1127
+ f . name . to_string ( )
1124
1128
} ;
1129
+ let fty = monomorphize:: field_ty ( cx. tcx ( ) , self . substs , f) ;
1125
1130
1126
1131
let offset = if self . is_simd {
1127
1132
FixedMemberOffset { bytes : i * field_size. unwrap ( ) }
@@ -1146,27 +1151,31 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1146
1151
unique_type_id : UniqueTypeId ,
1147
1152
span : Span )
1148
1153
-> RecursiveTypeDescription < ' tcx > {
1149
- let def_id = struct_type. ty_to_def_id ( ) . unwrap ( ) ;
1150
1154
let struct_name = compute_debuginfo_type_name ( cx, struct_type, false ) ;
1151
1155
let struct_llvm_type = type_of:: in_memory_type_of ( cx, struct_type) ;
1152
1156
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 ) ;
1154
1163
1155
1164
let struct_metadata_stub = create_struct_stub ( cx,
1156
1165
struct_llvm_type,
1157
1166
& struct_name,
1158
1167
unique_type_id,
1159
1168
containing_scope) ;
1160
1169
1161
- let vinfo = common:: VariantInfo :: from_ty ( cx. tcx ( ) , struct_type, None ) ;
1162
1170
create_and_register_recursive_type_forward_declaration (
1163
1171
cx,
1164
1172
struct_type,
1165
1173
unique_type_id,
1166
1174
struct_metadata_stub,
1167
1175
struct_llvm_type,
1168
1176
StructMDF ( StructMemberDescriptionFactory {
1169
- fields : vinfo. fields ,
1177
+ variant : variant,
1178
+ substs : substs,
1170
1179
is_simd : struct_type. is_simd ( cx. tcx ( ) ) ,
1171
1180
span : span,
1172
1181
} )
@@ -1481,7 +1490,7 @@ enum EnumDiscriminantInfo {
1481
1490
fn describe_enum_variant < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
1482
1491
enum_type : Ty < ' tcx > ,
1483
1492
struct_def : & adt:: Struct < ' tcx > ,
1484
- variant_info : & ty:: VariantDef < ' tcx > ,
1493
+ variant : & ty:: VariantDef < ' tcx > ,
1485
1494
discriminant_info : EnumDiscriminantInfo ,
1486
1495
containing_scope : DIScope ,
1487
1496
span : Span )
@@ -1495,7 +1504,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1495
1504
struct_def. packed ) ;
1496
1505
// Could do some consistency checks here: size, align, field count, discr type
1497
1506
1498
- let variant_name = variant_info . name . as_str ( ) ;
1507
+ let variant_name = variant . name . as_str ( ) ;
1499
1508
let unique_type_id = debug_context ( cx) . type_map
1500
1509
. borrow_mut ( )
1501
1510
. get_unique_type_id_of_enum_variant (
@@ -1510,20 +1519,20 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1510
1519
containing_scope) ;
1511
1520
1512
1521
// 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 ( ) {
1514
1523
ty:: VariantKind :: Unit => vec ! [ ] ,
1515
1524
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 ( )
1521
1530
}
1522
1531
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 ( )
1527
1536
}
1528
1537
} ;
1529
1538
0 commit comments