@@ -49,6 +49,7 @@ use std::num::Int;
49
49
use std:: rc:: Rc ;
50
50
51
51
use llvm:: { ValueRef , True , IntEQ , IntNE } ;
52
+ use back:: abi:: slice_elt_base;
52
53
use middle:: subst;
53
54
use middle:: subst:: Subst ;
54
55
use middle:: trans:: _match;
@@ -235,7 +236,7 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr {
235
236
if cases[ 1 - discr] . is_zerolen ( cx, t) {
236
237
let st = mk_struct ( cx, cases[ discr] . tys . as_slice ( ) ,
237
238
false , t) ;
238
- match cases[ discr] . find_ptr ( ) {
239
+ match cases[ discr] . find_ptr ( cx ) {
239
240
Some ( ThinPointer ( _) ) if st. fields . len ( ) == 1 => {
240
241
return RawNullablePointer {
241
242
nndiscr : discr as Disr ,
@@ -290,47 +291,38 @@ struct Case {
290
291
#[ deriving( Eq , PartialEq , Show ) ]
291
292
pub enum PointerField {
292
293
ThinPointer ( uint ) ,
293
- FatPointer ( uint , uint )
294
+ FatPointer ( uint )
294
295
}
295
296
296
297
impl Case {
297
298
fn is_zerolen ( & self , cx : & CrateContext , scapegoat : ty:: t ) -> bool {
298
299
mk_struct ( cx, self . tys . as_slice ( ) , false , scapegoat) . size == 0
299
300
}
300
301
301
- fn find_ptr ( & self ) -> Option < PointerField > {
302
- use back:: abi:: { fn_field_code, slice_elt_base, trt_field_box} ;
303
-
302
+ fn find_ptr ( & self , cx : & CrateContext ) -> Option < PointerField > {
304
303
for ( i, & ty) in self . tys . iter ( ) . enumerate ( ) {
305
304
match ty:: get ( ty) . sty {
306
- // &T/&mut T could either be a thin or fat pointer depending on T
307
- ty:: ty_rptr( _, ty:: mt { ty, .. } ) => match ty:: get ( ty) . sty {
305
+ // &T/&mut T/Box<T> could either be a thin or fat pointer depending on T
306
+ ty:: ty_rptr( _, ty:: mt { ty, .. } ) | ty :: ty_uniq ( ty ) => match ty:: get ( ty) . sty {
308
307
// &[T] and &str are a pointer and length pair
309
- ty:: ty_vec( _, None ) | ty:: ty_str => return Some ( FatPointer ( i, slice_elt_base) ) ,
310
-
311
- // &Trait/&mut Trait are a pair of pointers: the actual object and a vtable
312
- ty:: ty_trait( ..) => return Some ( FatPointer ( i, trt_field_box) ) ,
313
-
314
- // Any other &T/&mut T is just a pointer
315
- _ => return Some ( ThinPointer ( i) )
316
- } ,
308
+ ty:: ty_vec( _, None ) | ty:: ty_str => return Some ( FatPointer ( i) ) ,
317
309
318
- // Box<T> could either be a thin or fat pointer depending on T
319
- ty:: ty_uniq( t) => match ty:: get ( t) . sty {
320
- ty:: ty_vec( _, None ) => return Some ( FatPointer ( i, slice_elt_base) ) ,
310
+ // &Trait is a pair of pointers: the actual object and a vtable
311
+ ty:: ty_trait( ..) => return Some ( FatPointer ( i) ) ,
321
312
322
- // Box<Trait> is a pair of pointers: the actual object and a vtable
323
- ty:: ty_trait( ..) => return Some ( FatPointer ( i, trt_field_box) ) ,
313
+ ty:: ty_struct( ..) if !ty:: type_is_sized ( cx. tcx ( ) , ty) => {
314
+ return Some ( FatPointer ( i) )
315
+ }
324
316
325
- // Any other Box<T> is just a pointer
317
+ // Any other &T is just a pointer
326
318
_ => return Some ( ThinPointer ( i) )
327
319
} ,
328
320
329
321
// Functions are just pointers
330
322
ty:: ty_bare_fn( ..) => return Some ( ThinPointer ( i) ) ,
331
323
332
324
// Closures are a pair of pointers: the code and environment
333
- ty:: ty_closure( ..) => return Some ( FatPointer ( i, fn_field_code ) ) ,
325
+ ty:: ty_closure( ..) => return Some ( FatPointer ( i) ) ,
334
326
335
327
// Anything else is not a pointer
336
328
_ => continue
@@ -636,6 +628,7 @@ pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Optio
636
628
-> ValueRef {
637
629
let signed;
638
630
let val;
631
+ debug ! ( "trans_get_discr r: {}" , r) ;
639
632
match * r {
640
633
CEnum ( ity, min, max) => {
641
634
val = load_discr ( bcx, ity, scrutinee, min, max) ;
@@ -671,7 +664,7 @@ fn struct_wrapped_nullable_bitdiscr(bcx: Block, nndiscr: Disr, ptrfield: Pointer
671
664
scrutinee : ValueRef ) -> ValueRef {
672
665
let llptrptr = match ptrfield {
673
666
ThinPointer ( field) => GEPi ( bcx, scrutinee, [ 0 , field] ) ,
674
- FatPointer ( field, pair ) => GEPi ( bcx, scrutinee, [ 0 , field, pair ] )
667
+ FatPointer ( field) => GEPi ( bcx, scrutinee, [ 0 , field, slice_elt_base ] )
675
668
} ;
676
669
let llptr = Load ( bcx, llptrptr) ;
677
670
let cmp = if nndiscr == 0 { IntEQ } else { IntNE } ;
@@ -767,8 +760,8 @@ pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) {
767
760
ThinPointer ( field) =>
768
761
( GEPi ( bcx, val, [ 0 , field] ) ,
769
762
type_of:: type_of ( bcx. ccx ( ) , nonnull. fields [ field] ) ) ,
770
- FatPointer ( field, pair ) => {
771
- let v = GEPi ( bcx, val, [ 0 , field, pair ] ) ;
763
+ FatPointer ( field) => {
764
+ let v = GEPi ( bcx, val, [ 0 , field, slice_elt_base ] ) ;
772
765
( v, val_ty ( v) . element_type ( ) )
773
766
}
774
767
} ;
@@ -1102,7 +1095,7 @@ pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef)
1102
1095
StructWrappedNullablePointer { nndiscr, ptrfield, .. } => {
1103
1096
let ( idx, sub_idx) = match ptrfield {
1104
1097
ThinPointer ( field) => ( field, None ) ,
1105
- FatPointer ( field, pair ) => ( field, Some ( pair ) )
1098
+ FatPointer ( field) => ( field, Some ( slice_elt_base ) )
1106
1099
} ;
1107
1100
if is_null ( const_struct_field ( ccx, val, idx, sub_idx) ) {
1108
1101
/* subtraction as uint is ok because nndiscr is either 0 or 1 */
0 commit comments