41
41
//! used unboxed and any field can have pointers (including mutable)
42
42
//! taken to it, implementing them for Rust seems difficult.
43
43
44
- pub use self :: Repr :: * ;
45
44
use super :: Disr ;
46
45
47
46
use std;
@@ -50,7 +49,6 @@ use llvm::{ValueRef, True, IntEQ, IntNE};
50
49
use rustc:: ty:: layout;
51
50
use rustc:: ty:: { self , Ty , AdtKind } ;
52
51
use syntax:: attr;
53
- use syntax:: attr:: IntType ;
54
52
use build:: * ;
55
53
use common:: * ;
56
54
use debuginfo:: DebugLoc ;
@@ -70,66 +68,6 @@ pub enum BranchKind {
70
68
71
69
type Hint = attr:: ReprAttr ;
72
70
73
- /// Representations.
74
- #[ derive( Eq , PartialEq , Debug ) ]
75
- pub enum Repr < ' tcx > {
76
- /// C-like enums; basically an int.
77
- CEnum ( IntType , Disr , Disr ) , // discriminant range (signedness based on the IntType)
78
- /// Single-case variants, and structs/tuples/records.
79
- Univariant ( Struct < ' tcx > ) ,
80
- /// Untagged unions.
81
- UntaggedUnion ( Union < ' tcx > ) ,
82
- /// General-case enums: for each case there is a struct, and they
83
- /// all start with a field for the discriminant.
84
- General ( IntType , Vec < Struct < ' tcx > > ) ,
85
- /// Two cases distinguished by a nullable pointer: the case with discriminant
86
- /// `nndiscr` must have single field which is known to be nonnull due to its type.
87
- /// The other case is known to be zero sized. Hence we represent the enum
88
- /// as simply a nullable pointer: if not null it indicates the `nndiscr` variant,
89
- /// otherwise it indicates the other case.
90
- RawNullablePointer {
91
- nndiscr : Disr ,
92
- nnty : Ty < ' tcx > ,
93
- nullfields : Vec < Ty < ' tcx > >
94
- } ,
95
- /// Two cases distinguished by a nullable pointer: the case with discriminant
96
- /// `nndiscr` is represented by the struct `nonnull`, where the `discrfield`th
97
- /// field is known to be nonnull due to its type; if that field is null, then
98
- /// it represents the other case, which is inhabited by at most one value
99
- /// (and all other fields are undefined/unused).
100
- ///
101
- /// For example, `std::option::Option` instantiated at a safe pointer type
102
- /// is represented such that `None` is a null pointer and `Some` is the
103
- /// identity function.
104
- StructWrappedNullablePointer {
105
- nonnull : Struct < ' tcx > ,
106
- nndiscr : Disr ,
107
- discrfield : DiscrField ,
108
- nullfields : Vec < Ty < ' tcx > > ,
109
- }
110
- }
111
-
112
- /// For structs, and struct-like parts of anything fancier.
113
- #[ derive( Eq , PartialEq , Debug ) ]
114
- pub struct Struct < ' tcx > {
115
- // If the struct is DST, then the size and alignment do not take into
116
- // account the unsized fields of the struct.
117
- pub size : u64 ,
118
- pub align : u32 ,
119
- pub sized : bool ,
120
- pub packed : bool ,
121
- pub fields : Vec < Ty < ' tcx > > ,
122
- }
123
-
124
- /// For untagged unions.
125
- #[ derive( Eq , PartialEq , Debug ) ]
126
- pub struct Union < ' tcx > {
127
- pub min_size : u64 ,
128
- pub align : u32 ,
129
- pub packed : bool ,
130
- pub fields : Vec < Ty < ' tcx > > ,
131
- }
132
-
133
71
#[ derive( Copy , Clone ) ]
134
72
pub struct MaybeSizedValue {
135
73
pub value : ValueRef ,
@@ -696,14 +634,8 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
696
634
697
635
let meta = val. meta ;
698
636
699
- // Calculate the unaligned offset of the unsized field.
700
- let mut offset = 0 ;
701
- for & ty in & fields[ 0 ..ix] {
702
- let llty = type_of:: sizing_type_of ( ccx, ty) ;
703
- let type_align = type_of:: align_of ( ccx, ty) ;
704
- offset = roundup ( offset, type_align) ;
705
- offset += machine:: llsize_of_alloc ( ccx, llty) ;
706
- }
637
+
638
+ let offset = st. offset_of_field ( ix) . bytes ( ) ;
707
639
let unaligned_offset = C_uint ( bcx. ccx ( ) , offset) ;
708
640
709
641
// Get the alignment of the field
0 commit comments