4141//! used unboxed and any field can have pointers (including mutable)
4242//! taken to it, implementing them for Rust seems difficult.
4343
44- pub use self :: Repr :: * ;
4544use super :: Disr ;
4645
4746use std;
@@ -50,7 +49,6 @@ use llvm::{ValueRef, True, IntEQ, IntNE};
5049use rustc:: ty:: layout;
5150use rustc:: ty:: { self , Ty , AdtKind } ;
5251use syntax:: attr;
53- use syntax:: attr:: IntType ;
5452use build:: * ;
5553use common:: * ;
5654use debuginfo:: DebugLoc ;
@@ -70,66 +68,6 @@ pub enum BranchKind {
7068
7169type Hint = attr:: ReprAttr ;
7270
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-
13371#[ derive( Copy , Clone ) ]
13472pub struct MaybeSizedValue {
13573 pub value : ValueRef ,
@@ -696,14 +634,8 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
696634
697635 let meta = val. meta ;
698636
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 ( ) ;
707639 let unaligned_offset = C_uint ( bcx. ccx ( ) , offset) ;
708640
709641 // Get the alignment of the field
0 commit comments